Skip to content

Commit

Permalink
Added required methods for the mobile app.
Browse files Browse the repository at this point in the history
  • Loading branch information
exhuma committed May 9, 2015
1 parent 26bd664 commit 0cb4930
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lost_tracker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def get_local_photos(conf, url_generator):
}


def set_score(session, group_id, station_id, station_score, form_score):
def set_score(session, group_id, station_id, station_score, form_score,
state=None):
GroupStation.set_score(session, group_id, station_id, station_score,
form_score)
form_score, state)
return 'OK'
23 changes: 23 additions & 0 deletions lost_tracker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from json import dumps
from operator import attrgetter
from urllib import unquote_plus
import io
import mimetypes
import os.path
Expand Down Expand Up @@ -673,6 +674,28 @@ def save_settings():
return redirect(url_for("settings"))


@app.route('/group_state/<group>/<station>', methods=['PUT'])
def update_group_station_state(group, station):
group = unquote_plus(group)
station = unquote_plus(station)
try:
form_score = request.json['form']
station_score = request.json['station']
station_state = request.json['state']
except LookupError:
return jsonify({'message': 'Missing value'}), 400

loco.set_score(g.session, group, station, station_score, form_score,
station_state)

return jsonify(
name=group,
form_score=form_score,
score=station_score,
state=station_state,
station_name=station)


if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.DEBUG)
Expand Down
15 changes: 14 additions & 1 deletion lost_tracker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,32 @@ def get(group_id, station_id):
GroupStation.station_id == station_id)).first()

@staticmethod
def set_score(session, group_id, station_id, station_score, form_score):
def set_score(session, group_id, station_id, station_score, form_score,
state=None):

if isinstance(group_id, basestring):
group_id = Group.query.filter_by(name=group_id).one().id

if isinstance(station_id, basestring):
station_id = Station.query.filter_by(name=station_id).one().id

query = GroupStation.query.filter(and_(
GroupStation.group_id == group_id,
GroupStation.station_id == station_id))

row = query.first()
if not row:
gs = GroupStation(group_id, station_id)
gs.score = station_score
gs.form_score = form_score
if state:
gs.state = state
session.add(gs)
else:
row.score = station_score
row.form_score = form_score
if state:
row.state = state

def to_dict(self):
return {
Expand Down

0 comments on commit 0cb4930

Please sign in to comment.