def index(): if 'application/json' not in request.headers.get('Accept', ''): return render_template('ember-page.jinja', active_page='notifications') query = Notification.query(recipient=g.current_user) \ .join('event') \ .options(contains_eager('event')) \ .options(subqueryload('event.actor')) \ .outerjoin(Event.flight) \ .options(contains_eager('event.flight')) \ .filter(or_(Event.flight == None, Flight.is_rankable())) \ .order_by(Event.time.desc()) query = _filter_query(query, request.args) page = request.args.get('page', type=int, default=1) per_page = request.args.get('per_page', type=int, default=50) query = query.limit(per_page) query = query.offset((page - 1) * per_page) def get_event(notification): event = notification.event event.unread = (notification.time_read is None) return event events = map(get_event, query) return jsonify(events=(map(convert_event, events)))
def index(): if not g.current_user: abort(401) query = Notification.query(recipient=g.current_user) \ .join('event') \ .options(contains_eager('event')) \ .options(subqueryload('event.actor')) \ .outerjoin(Event.flight) \ .options(contains_eager('event.flight')) \ .filter(or_(Event.flight == None, Flight.is_rankable())) \ .order_by(Event.time.desc()) query = _filter_query(query, request.args) page = request.args.get('page', type=int, default=1) per_page = request.args.get('per_page', type=int, default=50) query = query.limit(per_page) query = query.offset((page - 1) * per_page) def get_event(notification): event = notification.event event.unread = (notification.time_read is None) return event events = map(get_event, query) events_count = len(events) if request.args.get('grouped', True, type=str_to_bool): events = group_events(events) template_vars = dict(events=events, types=Event.Type) if page > 1: template_vars['prev_page'] = page - 1 if events_count == per_page: template_vars['next_page'] = page + 1 return render_template('notifications/list.jinja', **template_vars)
def index(): query = ( Notification.query(recipient=g.current_user) .join("event") .options(contains_eager("event")) .options(subqueryload("event.actor")) .outerjoin(Event.flight) .options(contains_eager("event.flight")) .filter(or_(Event.flight == None, Flight.is_rankable())) .order_by(Event.time.desc()) ) query = _filter_query(query, request.args) page = request.args.get("page", type=int, default=1) per_page = request.args.get("per_page", type=int, default=50) query = query.limit(per_page) query = query.offset((page - 1) * per_page) def get_event(notification): event = notification.event event.unread = notification.time_read is None return event events = map(get_event, query) events_count = len(events) if request.args.get("grouped", True, type=str_to_bool): events = group_events(events) template_vars = dict(events=events, types=Event.Type) if page > 1: template_vars["prev_page"] = page - 1 if events_count == per_page: template_vars["next_page"] = page + 1 return render_template("notifications/list.jinja", **template_vars)