Exemple #1
0
def get_events():
    """Gets upcoming and past events."""

    events_upcoming = []
    events_past = []

    if app.config.get('USE_SESSIONSTORE_NOT_DB'):
        if session.get('event') is None:
            session['event'] = ['']

        for id, o in enumerate(session['event']):
            if o:
                dt_now_str = datetime.now().strftime('%Y-%m-%d')
                o_d = {
                    'title':
                    o['title'],
                    'start_date': (datetime.strptime(o['start_date'],
                                                     '%Y-%m-%d').date()),
                    'end_date':
                    (o['end_date'] and
                     (datetime.strptime(o['end_date'], '%Y-%m-%d').date())
                     or None),
                    'start_time':
                    (o['start_time'] and
                     (datetime.strptime(dt_now_str + ' ' + o['start_time'],
                                        '%Y-%m-%d %H:%M:%S').time()) or None),
                    'end_time':
                    (o['end_time'] and
                     (datetime.strptime(dt_now_str + ' ' + o['end_time'],
                                        '%Y-%m-%d %H:%M:%S').time()) or None),
                    'event_url':
                    o['event_url'],
                    'location_name':
                    o['location_name'],
                    'location_url':
                    o['location_url']
                }
                model = Event(**o_d)
                model.id = id

                if model.start_date >= date.today():
                    events_upcoming.append(model)
                else:
                    events_past.append(model)

        events_upcoming = sorted(events_upcoming, key=lambda o: o.start_date)
        events_past = sorted(events_past,
                             key=lambda o: o.start_date,
                             reverse=True)
    else:
        events_upcoming = (Event.query.filter_by(active=True).filter(
            Event.start_date >= date.today()).order_by(Event.start_date,
                                                       Event.start_time))

        events_past = (Event.query.filter_by(active=True).filter(
            Event.start_date < date.today()).order_by(Event.start_date.desc(),
                                                      Event.start_time.desc()))

    return (events_upcoming, events_past)
Exemple #2
0
def get_default_events():
    """Gets default events."""

    default_events = Event.default_content()

    if app.config.get('USE_SESSIONSTORE_NOT_DB'):
        session['event'] = ['']

        for o in default_events:
            # If this model isn't currently saved to session
            # storage, save it now.
            session['event'].append({
                'title': o.title,
                'start_date': o.start_date.strftime('%Y-%m-%d'),
                'end_date': (
                    o.end_date
                    and o.end_date.strftime('%Y-%m-%d')
                    or ''),
                'start_time': (
                    o.start_time
                    and o.start_time.strftime('%H:%M:%S')
                    or ''),
                'end_time': (
                    o.end_time
                    and o.end_time.strftime('%H:%M:%S')
                    or ''),
                'event_url': o.event_url,
                'location_name': o.location_name,
                'location_url': o.location_url})
    else:
        for o in default_events:
            # If this model isn't currently saved to the DB,
            # save it now.
            try:
                o.save()
            except IntegrityError as e:
                db.session.rollback()
                raise e

    return default_events
Exemple #3
0
def get_default_events():
    """Gets default events."""

    default_events = Event.default_content()

    if app.config.get('USE_SESSIONSTORE_NOT_DB'):
        session['event'] = ['']

        for o in default_events:
            # If this model isn't currently saved to session
            # storage, save it now.
            session['event'].append({
                'title':
                o.title,
                'start_date':
                o.start_date.strftime('%Y-%m-%d'),
                'end_date': (o.end_date and o.end_date.strftime('%Y-%m-%d')
                             or ''),
                'start_time':
                (o.start_time and o.start_time.strftime('%H:%M:%S') or ''),
                'end_time': (o.end_time and o.end_time.strftime('%H:%M:%S')
                             or ''),
                'event_url':
                o.event_url,
                'location_name':
                o.location_name,
                'location_url':
                o.location_url
            })
    else:
        for o in default_events:
            # If this model isn't currently saved to the DB,
            # save it now.
            try:
                o.save()
            except IntegrityError as e:
                db.session.rollback()
                raise e

    return default_events
Exemple #4
0
def get_events():
    """Gets upcoming and past events."""

    events_upcoming = []
    events_past = []

    if app.config.get('USE_SESSIONSTORE_NOT_DB'):
        if session.get('event') is None:
            session['event'] = ['']

        for id, o in enumerate(session['event']):
            if o:
                dt_now_str = datetime.now().strftime('%Y-%m-%d')
                o_d = {
                    'title': o['title'],
                    'start_date': (
                        datetime.strptime(o['start_date'], '%Y-%m-%d')
                        .date()),
                    'end_date': (
                        o['end_date']
                        and (
                            datetime.strptime(
                                o['end_date'], '%Y-%m-%d')
                            .date())
                        or None),
                    'start_time': (
                        o['start_time']
                        and (
                            datetime.strptime(
                                dt_now_str + ' ' + o['start_time'],
                                '%Y-%m-%d %H:%M:%S')
                            .time())
                        or None),
                    'end_time': (
                        o['end_time']
                        and (
                            datetime.strptime(
                                dt_now_str + ' ' + o['end_time'],
                                '%Y-%m-%d %H:%M:%S')
                            .time()) or None),
                    'event_url': o['event_url'],
                    'location_name': o['location_name'],
                    'location_url': o['location_url']}
                model = Event(**o_d)
                model.id = id

                if model.start_date >= date.today():
                    events_upcoming.append(model)
                else:
                    events_past.append(model)

        events_upcoming = sorted(
            events_upcoming, key=lambda o: o.start_date)
        events_past = sorted(
            events_past, key=lambda o: o.start_date, reverse=True)
    else:
        events_upcoming = (
            Event.query
                 .filter_by(active=True)
                 .filter(Event.start_date >= date.today())
                 .order_by(Event.start_date, Event.start_time))

        events_past = (
            Event.query
                 .filter_by(active=True)
                 .filter(Event.start_date < date.today())
                 .order_by(Event.start_date.desc(),
                           Event.start_time.desc()))

    return (events_upcoming, events_past)