Exemplo n.º 1
0
def get_org_events(id):
    serialized = []
    org_name = Organization.query.get(id).name

    #events rsvp with status
    events_and_status = db.session.query(Event, EventRSVP.status).filter_by(org_id=id).outerjoin(EventRSVP) \
                                                .filter(EventRSVP.user_id.is_(current_identity.id)) \
                                                .order_by(Event.event_start.desc()).all()

    #events not rsvped to
    events_rsvp = EventRSVP.query.with_entities(
        EventRSVP.event_id).filter_by(user_id=current_identity.id).subquery()
    events_not_rsvp = db.session.query(Event).filter(~Event.id.in_(events_rsvp)).filter_by(org_id=id)\
                                             .order_by(Event.event_start.desc()).all()

    events_serialized = [(Event.serialize(event),
                          get_rsvp_status_string(rsvp_status))
                         for (event, rsvp_status) in events_and_status]
    [
        events_serialized.append((Event.serialize(event), ""))
        for event in events_not_rsvp
    ]

    serialized = [{"title": org_name, "events": events_serialized}]

    return jsonify(message=serialized), 200
Exemplo n.º 2
0
def get_events_rsvp(sel):
    serialized = []
    if sel == 'false':
        #returns all the events that the current user has not RSVP to
        subquery = EventRSVP.query.with_entities(
            EventRSVP.event_id).filter_by(user_id=current_identity.id)
        events = db.session.query(Event).filter(~Event.id.in_(subquery)).all()

        serialized = [Event.serialize(e) for e in events]
    else:
        #returns all the events that the current user has RSVPed to, grouped by organization
        events_and_status = db.session.query(Event, Event.org_id, EventRSVP.status).outerjoin(EventRSVP) \
                                                .filter(EventRSVP.user_id.is_(current_identity.id)) \
                                                .order_by(Event.event_start.desc()).all()

        orgs = db.session.query(Organization).outerjoin(Event).outerjoin(EventRSVP) \
                                                .filter(EventRSVP.user_id.is_(current_identity.id)).all()

        serialized = [{
            "title":
            item.name,
            "events":
            [(Event.serialize(event), get_rsvp_status_string(rsvp_status))
             for (event, org_id, rsvp_status) in events_and_status
             if org_id is item.id]
        } for item in orgs]

    return jsonify(message=serialized), 200
Exemplo n.º 3
0
def get_all_events():
    serialized = []
    try:
        events = Event.query.all()
        serialized = [Event.serialize(item) for item in events]
    except:
        db.session.rollback()
    return jsonify(message=serialized), 200
Exemplo n.º 4
0
def get_events(sel):
    serialized = []

    if sel == 'true':
        #gets all the events for the orgs you are an admin of
        orgs = current_identity.organizations_as_admin
    else:
        #gets all the events for the orgs you are a member of
        orgs = current_identity.organizations_as_member

    serialized = [{
        "title": item.name,
        "admin": True,
        "events": [Event.serialize(i) for i in item.events]
    } for item in orgs]

    return jsonify(message=serialized), 200
Exemplo n.º 5
0
def get_events_filtered():
    serialized = []
    tag = request.args.get("filter")

    #default when there is no filter, returns all the events you have not rsvp to
    if tag == "":
        return get_events_rsvp("false")

    try:
        subquery = EventRSVP.query.with_entities(
            EventRSVP.event_id).filter_by(user_id=current_identity.id)
        events = db.session.query(Event).filter(~Event.id.in_(subquery)) \
                                        .filter((Event.tags.like("%#" + tag + "#%")) | (Event.name.like("%" + tag + "%"))).all()
        serialized = [Event.serialize(item) for item in events]
    except:
        db.session.rollback()

    return jsonify(message=serialized), 200