Ejemplo n.º 1
0
def mark_user_notifications_read(user):
    if not g.current_user:
        return

    def add_user_filter(query):
        return query.filter(Event.actor_id == user.id)

    Notification.mark_all_read(g.current_user, filter_func=add_user_filter)
    db.session.commit()
Ejemplo n.º 2
0
def mark_flight_notifications_read(flight):
    if not g.current_user:
        return

    def add_flight_filter(query):
        return query.filter(Event.flight_id == flight.id)

    Notification.mark_all_read(g.current_user, filter_func=add_flight_filter)
    db.session.commit()
Ejemplo n.º 3
0
def mark_user_notifications_read(user):
    if not request.user_id:
        return

    def add_user_filter(query):
        return query.filter(Event.actor_id == user.id)

    Notification.mark_all_read(User.get(request.user_id), filter_func=add_user_filter)
    db.session.commit()
Ejemplo n.º 4
0
def mark_flight_notifications_read(flight):
    if not g.current_user:
        return

    def add_flight_filter(query):
        return query.filter(Event.flight_id == flight.id)

    Notification.mark_all_read(g.current_user, filter_func=add_flight_filter)
    db.session.commit()
Ejemplo n.º 5
0
def mark_user_notifications_read(pilot):
    if not request.user_id:
        return

    def add_flight_filter(query):
        return query.filter(Event.actor_id == pilot.id)

    Notification.mark_all_read(User.get(request.user_id), filter_func=add_flight_filter)
    db.session.commit()
Ejemplo n.º 6
0
def mark_flight_notifications_read(flight):
    if not request.user_id:
        return

    def add_flight_filter(query):
        return query.filter(Event.flight_id == flight.id)

    Notification.mark_all_read(User.get(request.user_id), filter_func=add_flight_filter)
    db.session.commit()
Ejemplo n.º 7
0
def clear():
    def filter_func(query):
        return _filter_query(query, request.args)

    current_user = User.get(request.user_id)
    Notification.mark_all_read(current_user, filter_func=filter_func)

    db.session.commit()

    return jsonify()
Ejemplo n.º 8
0
def clear():
    def filter_func(query):
        return _filter_query(query, request.args)

    current_user = User.get(request.user_id)
    Notification.mark_all_read(current_user, filter_func=filter_func)

    db.session.commit()

    return jsonify()
Ejemplo n.º 9
0
    def clear(self, **kwargs):
        if not request.identity:
            raise HTTPForbidden

        def filter_func(query):
            return self.__filter_query(query, kwargs)

        Notification.mark_all_read(request.identity['user'],
                                   filter_func=filter_func)

        redirect('.')
Ejemplo n.º 10
0
def list():
    query = Notification.query(recipient_id=request.user_id) \
        .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)))
Ejemplo n.º 11
0
def _list():
    query = (Notification.query(
        recipient_id=request.user_id).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 = list(
        convert_event(get_event(notification)) for notification in query)

    return jsonify(events=events)
Ejemplo n.º 12
0
def _list():
    query = Notification.query(recipient_id=request.user_id) \
        .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)))
Ejemplo n.º 13
0
def _list():
    query = (
        Notification.query(recipient_id=request.user_id)
        .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 = list(convert_event(get_event(notification)) for notification in query)

    return jsonify(events=events)
Ejemplo n.º 14
0
    def index(self, **kwargs):
        if not request.identity:
            raise HTTPForbidden

        query = DBSession.query(Notification) \
                         .filter(Notification.recipient == request.identity['user']) \
                         .filter(Notification.time_read == None) \
                         .options(joinedload(Notification.sender)) \
                         .options(joinedload(Notification.recipient)) \
                         .options(joinedload(Notification.flight)) \
                         .options(joinedload(Notification.flight_comment)) \
                         .order_by(desc(Notification.time_created))

        query = self.__filter_query(query, kwargs)

        notifications = []
        pilot_flights = defaultdict(list)
        for notification in query.all():
            if (notification.type == Notification.NT_FLIGHT and
                    'type' not in kwargs):
                pilot_flights[notification.sender_id].append(notification)
            else:
                notifications.append(dict(grouped=False,
                                          type=notification.type,
                                          time=notification.time_created,
                                          notification=notification))

        for flights in pilot_flights.itervalues():
            if len(flights) == 1:
                notifications.append(dict(grouped=False,
                                          type=flights[0].type,
                                          time=flights[0].time_created,
                                          notification=flights[0]))
            else:
                notifications.append(dict(grouped=True,
                                          type=flights[0].type,
                                          time=flights[0].time_created,
                                          notifications=flights))

        notifications.sort(key=itemgetter('time'), reverse=True)

        result = dict(notifications=notifications, params=kwargs)
        result.update(Notification.constants())
        return result
Ejemplo n.º 15
0
#!/usr/bin/env python
#
# Mark all notifications as unread
#

import argparse
from config import to_envvar

parser = argparse.ArgumentParser(
    description='Copy flight files by one or more properties.')
parser.add_argument('--config',
                    metavar='config.ini',
                    help='path to the configuration INI file')

args = parser.parse_args()

if not to_envvar(args.config):
    parser.error('Config file "{}" not found.'.format(args.config))

from skylines import app, db
from skylines.model import Notification

app.test_request_context().push()

Notification.query().update(dict(time_read=None))

db.session.commit()
Ejemplo n.º 16
0
 def run(self):
     Notification.query().update(dict(time_read=None))
     db.session.commit()
Ejemplo n.º 17
0
 def run(self):
     Notification.query().update(dict(time_read=None))
     db.session.commit()
Ejemplo n.º 18
0
#!/usr/bin/env python
#
# Mark all notifications as unread
#

import argparse
from config import to_envvar

parser = argparse.ArgumentParser(description='Copy flight files by one or more properties.')
parser.add_argument('--config', metavar='config.ini',
                    help='path to the configuration INI file')

args = parser.parse_args()

if not to_envvar(args.config):
    parser.error('Config file "{}" not found.'.format(args.config))

from skylines import app, db
from skylines.model import Notification

app.test_request_context().push()

Notification.query().update(dict(time_read=None))

db.session.commit()