From 07cbab2610605e7b12eb0d834b8169ba6de719e5 Mon Sep 17 00:00:00 2001 From: sipp11 Date: Sun, 16 Nov 2014 10:31:57 +0700 Subject: [PATCH] update /movie/ to support en/th --- flasky.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/flasky.py b/flasky.py index ea38421..242e69c 100644 --- a/flasky.py +++ b/flasky.py @@ -95,14 +95,26 @@ def movie_list(lang='en'): @app.route('/movie//', methods=['GET']) +@app.route('/movie///', methods=['GET']) @crossdomain(origin='*') -def movie_item(mid): +def movie_item(mid, lang='en'): + 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 = {} + for k in ('title', 'tagline', 'director', 'cast', 'storyline'): + if movie[k][lang]: + movie[k] = movie[k][lang] + else: + movie[k] = movie[k]['th' if lang == 'en' else lang] + try: + del movie['indexes'] + except KeyError: + pass + r = make_response(dumps(movie, default=miscObjHandler)) r.mimetype = 'application/json' return r