Skip to content

Commit db5c0e3

Browse files
committedSep 22, 2016
Fixed query in models to limit display of private coordinates to only members of the same team. Made minor edits to visual components on index and greater layout to clarify this functionality.
1 parent 30a0961 commit db5c0e3

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed
 

Diff for: ‎models.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Coordinate(Model):
8585
notes = TextField()
8686
recommended_visit = DateField(null=True)
8787
slug = CharField(unique=True)
88-
published = BooleanField(index=True) # Coordinates/points can be made public
88+
published = BooleanField(index=True) # Published is being used as an alias for public
8989
timestamp = DateTimeField(default=datetime.datetime.now, index=True)
9090
user = ForeignKeyField(
9191
rel_model=User,
@@ -125,8 +125,15 @@ def update_search_index(self):
125125
base_coord.save(force_insert=force_insert)
126126

127127
@classmethod
128-
def private(cls):
129-
return Coordinate.select().where(Coordinate.published == False)
128+
def private(cls, user):
129+
team = user.team
130+
return (Coordinate
131+
.select(Coordinate, User)
132+
.join(User)
133+
.where(
134+
(User.team == team) &
135+
(Coordinate.published == False))
136+
.order_by(Coordinate.timestamp.desc()))
130137

131138
@classmethod
132139
def public(cls):

Diff for: ‎sos_tracker.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def logout():
116116
def parse_file(filename, publish):
117117
file = os.path.join(app.config['UPLOAD_FOLDER'], filename)
118118
parsed = []
119-
user = models.User.select().where(models.User.username == g.user._get_current_object().username)
119+
user = models.User.get(models.User.username == g.user._get_current_object().username)
120120
if filename[-3:] == 'txt':
121121
with open(file, 'r') as f:
122122
csv_input = csv.reader(f)
@@ -228,7 +228,7 @@ def index():
228228
def create():
229229
form = forms.CreateCoordForm()
230230
if form.validate_on_submit():
231-
user = models.User.select().where(models.User.username == g.user._get_current_object().username)
231+
user = models.User.get(models.User.username == g.user._get_current_object().username)
232232
point = models.Coordinate.create(
233233
user = user,
234234
latitude = form.latitude.data,
@@ -275,7 +275,8 @@ def download():
275275
@app.route('/private')
276276
@login_required
277277
def private():
278-
query = models.Coordinate.private().order_by(models.Coordinate.timestamp.desc())
278+
user = models.User.get(models.User.username == g.user._get_current_object().username)
279+
query = models.Coordinate.private(user)
279280
return object_list('index.html', query, check_bounds=False)
280281

281282

Diff for: ‎templates/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
{% block content_title %}{% if search %}Search "{{ search }}"{% else %}Coordinates{% endif %}{% endblock %}
66

7+
{% block content_subtitle %}
8+
Public coordinates are visible to all registered users. Private coordinates are visible only to you and other members of your team.
9+
{% endblock content_subtitle %}
10+
711
{% block content %}
812
{% for point in object_list %}
913
{% if search %}

Diff for: ‎templates/layout.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
{% block page_header %}
6969
<div class="page-header">
7070
<h1>{% block content_title %}{% endblock %}</h1>
71-
<h3>{% block content_subtitle %}{% endblock %}</h3>
71+
<h5>{% block content_subtitle %}{% endblock %}</h5>
7272
</div>
7373
{% endblock %}
7474

0 commit comments

Comments
 (0)
Please sign in to comment.