|
|
|
@ -94,17 +94,21 @@ def movie_list(lang):
|
|
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/movie/<mid>/', methods=['GET'], defaults={'lang': 'en'}) |
|
|
|
|
@app.route('/movie/<mid>/<lang>/', methods=['GET']) |
|
|
|
|
@crossdomain(origin='*') |
|
|
|
|
def movie_item(mid, lang): |
|
|
|
|
''' |
|
|
|
|
Compatibility with #ShowtimesTH on Android as of v1.4 |
|
|
|
|
''' |
|
|
|
|
lang = lang if lang in ('en', 'th') else 'en' |
|
|
|
|
try: |
|
|
|
|
movie = db.movies.find_one({'tmdb_id': int(mid)}) |
|
|
|
|
except ValueError: |
|
|
|
|
movie = db.movies.find_one({'_id': bson.objectid.ObjectId(mid)}) |
|
|
|
|
|
|
|
|
|
if not movie: |
|
|
|
|
movie = {} |
|
|
|
|
else: |
|
|
|
|
for k in ('title', 'tagline', 'director', 'cast', 'storyline'): |
|
|
|
|
if movie[k][lang]: |
|
|
|
|
movie[k] = movie[k][lang] |
|
|
|
@ -114,18 +118,56 @@ def movie_item(mid, lang):
|
|
|
|
|
del movie['indexes'] |
|
|
|
|
except KeyError: |
|
|
|
|
pass |
|
|
|
|
r = make_response(dumps(movie, default=miscObjHandler)) |
|
|
|
|
r.mimetype = 'application/json' |
|
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/movie/<mid>/', methods=['GET', 'POST']) |
|
|
|
|
def raw_movie_item(mid): |
|
|
|
|
if request.method == 'GET': |
|
|
|
|
try: |
|
|
|
|
movie = db.movies.find_one({'tmdb_id': int(mid)}) |
|
|
|
|
except ValueError: |
|
|
|
|
movie = db.movies.find_one({'_id': bson.objectid.ObjectId(mid)}) |
|
|
|
|
|
|
|
|
|
r = make_response(dumps(movie, default=miscObjHandler)) |
|
|
|
|
r.mimetype = 'application/json' |
|
|
|
|
return r |
|
|
|
|
|
|
|
|
|
## This is POST -- updating with information provided |
|
|
|
|
if not request.json: |
|
|
|
|
abort(400) |
|
|
|
|
try: |
|
|
|
|
key = {'_id': bson.objectid.ObjectId(mid)} |
|
|
|
|
prev = db.movies.find_one(key) |
|
|
|
|
if not prev: |
|
|
|
|
abort(500) |
|
|
|
|
is_allowed = True |
|
|
|
|
## simple check if dict is smaller, then we don't update that |
|
|
|
|
posting_keys = request.json.keys() |
|
|
|
|
prev_keys = prev.keys() |
|
|
|
|
missing_fields = set(prev_keys) - set(posting_keys) |
|
|
|
|
is_allowed = False if missing_fields else True |
|
|
|
|
if is_allowed: |
|
|
|
|
result = db.movies.update(key, {'$set': request.json}, False) |
|
|
|
|
else: |
|
|
|
|
result = { # mimicking mongo update result for consistency |
|
|
|
|
'updatedExisting': False, 'ok': 0, 'nModified': 0, |
|
|
|
|
'error': "missing_fields:%s" % (','.join(missing_fields)), |
|
|
|
|
} |
|
|
|
|
r = make_response(dumps(result, default=miscObjHandler)) |
|
|
|
|
r.mimetype = 'application/json' |
|
|
|
|
return r |
|
|
|
|
except bson.errors.InvalidId: |
|
|
|
|
abort(500) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/groups/', methods=['GET']) |
|
|
|
|
@crossdomain(origin='*') |
|
|
|
|
def groups(): |
|
|
|
|
result = db.groups.find() |
|
|
|
|
known_groups = [] # ['sf', 'major', 'etc'] |
|
|
|
|
print result.count() |
|
|
|
|
if result.count() == 0: |
|
|
|
|
for i in ('sf', 'major', 'etc'): |
|
|
|
|
db.groups.insert({'name': str(i)}) |
|
|
|
|