def api_people(): try: criteria = request.get_json(force=True) or {} except: criteria = {} people = Person.search(criteria) return to_json(people)
def api_filters(): filters = {} for category in Person.__filterable__: filters[category] = untuple( db.session.query(distinct(getattr(Person, category))).order_by( getattr(Person, category))) return to_json(filters)
def api_students(): criteria = request.get_json() or {} if not criteria.get('filters'): criteria['filters'] = {} if not criteria['filters'].get('school_code'): criteria['filters']['school_code'] = [] criteria['filters']['school_code'].append('YC') students = Person.search(criteria) return to_json(students)
def api_hall_meals(hall_id): # TODO: use this later on, right now it's mostly a 404 check hall = Hall.query.get_or_404(hall_id) meals = Meal.query.filter_by(hall_id=hall_id) date = request.args.get('date') if date is not None: meals = meals.filter(Meal.date == date) else: start_date = request.args.get('start_date') if start_date is None: start_date = datetime.date.today() else: start_date = datetime.datetime.strptime(start_date, DATE_FMT) meals = meals.filter(start_date <= Meal.date) end_date = request.args.get('end_date') if end_date is not None: meals = meals.filter(Meal.date <= end_date) meals = meals.order_by(Meal.date, Meal.start_time) meals = meals.all() return to_json(meals)
def api_items(): items = Item.query.all() return to_json(items)
def api_meals(): meals = Meal.query.all() return to_json(meals)
def api_meal_items(meal_id): meal = Meal.query.get_or_404(meal_id) items = meal.items return to_json(items)
def api_item(item_id): item = Item.query.get_or_404(item_id) return to_json(item)
def create_key(): payload = request.get_json() key = g.user.create_key(payload['description']) db.session.add(key) db.session.commit() return to_json(key)
def add_entry(person_id): try: subject = get_person(person_id) except NoResultFound: return common_render("404.jinja"), 404 except UnauthorizedException: return common_render("error.jinja"), 403 #fetch and serlialize all people managed by the current user current_person_id = current_user.person.id managed_by = Person.query.filter(and_(\ Person.managed_by_id == current_person_id,\ Person.id != subject.id))\ .all() managed_by = [to_json(p, Person) for p in managed_by] managed_by_str = json.dumps(managed_by) # get all pinned notes pinned = Note.query.filter(and_(\ Note.is_pinned == True, \ Note.author_id == current_person_id, \ Note.subject_id == subject.id)).all() pinned = [to_json(p, Note) for p in pinned] pinned_str = json.dumps(pinned) # get all feedback feedback = Feedback.query.filter(and_(\ Feedback.to_id == subject.id, Feedback.has_communicated == False)).all() feedback = [to_json(p, Feedback) for p in feedback] feedback_str = json.dumps(feedback) if request.method == 'POST': e = Entry(current_user.person.id, subject.id, datetime.date.today()) db.session.add(e) db.session.commit() notes = json.loads(request.form['notes']) for note in notes: if note['body']: if note['type'] == "FEEDBACK": f = Feedback() f.from_id = subject.id f.to_id = int(note['meta']['feedback-for']) f.has_communicated = False f.body = note['body'] #FIXME: this could lead to numerous commits db.session.add(f) db.session.commit() else: f = None is_pinned = note['type'] == 'CHECKIN' n = Note(e, note["type"], note['body'], is_pinned=is_pinned) if f: n.linked_feedback = f.id db.session.add(n) db.session.commit() return redirect(url_for("people.view", person_id=subject.id)) return common_render("add_entry.jinja", \ person=subject,\ managed_by_str=managed_by_str,\ feedback_str=feedback_str,\ pinned_str=pinned_str)
def do_crawler_new_taipei_city_dig_point(next_year): next_year = util._int(next_year) results = crawler_new_taipei_city_dig_point({'next_year': next_year}) util.to_json(results['data'], 'log.new_taipei_city_dig_point.json')
def do_crawler_taipei_city_road_case(next_road_case): results = crawler_taipei_city_road_case({'next_road_case': next_road_case}) util.to_json(results['data'], 'log.taipei_city_road_case.json')
def api_people(): criteria = request.get_json() or {} people = Person.search(criteria) return to_json(people)
def api_managers(hall_id): hall = Hall.query.get_or_404(hall_id) managers = hall.managers return to_json(managers)
def api_hall(hall_id): hall = Hall.query.get_or_404(hall_id) return to_json(hall)
def api_halls(): halls = Hall.query.order_by(Hall.nickname).all() return to_json(halls)
def api_recipe_nutrition(recipe_id): recipe = Item.query.get_or_404(recipe_id) nutrition = recipe.nutrition return to_json(nutrition)
from app import db from app.models import Location, Meal, Item, Nutrition from app.util import to_json import os import datetime DATE_FMT = '%Y-%m-%d' api_bp = Blueprint('api', __name__) STATUS = to_json({ 'message': os.environ.get('STATUS_MESSAGE'), 'min_version_ios': int(os.environ.get('STATUS_MIN_VERSION_IOS', 0)), 'min_version_android': int(os.environ.get('STATUS_MIN_VERSION_ANDROID', 0)), }) @api_bp.route('/status') def api_status(): return STATUS @api_bp.route('/halls') def api_halls(): halls = Hall.query.order_by(Hall.nickname).all() return to_json(halls)
def api_meal(meal_id): meal = Meal.query.get_or_404(meal_id) return to_json(meal)
def do_crawler_taipei_city_dig_point(next_dig_point): results = crawler_taipei_city_dig_point({'next_dig_point': next_dig_point}) util.to_json(results['data'], 'log.taipei_city_dig_point.json')
def api_meal_recipes(meal_id): meal = Meal.query.get_or_404(meal_id) recipes = meal.recipes return to_json(recipes)
def api_recipes(): recipes = Item.query.all() return to_json(recipes)
def get_keys(): keys = Key.query.filter_by(user_id=g.user.id, deleted=False).all() return to_json(keys)
def api_recipe(recipe_id): recipe = Item.query.get_or_404(recipe_id) return to_json(recipe)
def _process_results(results): data = results.get('data', []) cron.to_http_post(data) util.to_json(data, 'log.taipei_city_dig_point.json')
def _process_results(results): data = results.get('data', []) cron.to_http_post(data) util.to_json(data, 'log.taipei_city_road_case.json')
def _process_results(results): data = results.get('data', []) cron.to_http_post(data) util.to_json(data, 'log.new_taipei_city_dig_point.json')
def api_item_nutrition(item_id): item = Item.query.get_or_404(item_id) nutrition = item.nutrition return to_json(nutrition)