Ejemplo n.º 1
0
Archivo: backend.py Proyecto: zyuyou/N1
def schedule(key):
    """
    Schedules an event at the time range corresponding to the passed
    "key" param, by sending an email to all participants containing an
    attached ICS file.
    """
    with session_scope() as dbsession:
        try:
            etime = dbsession.query(
                m.EventTime).filter(m.EventTime.key == key).one()
        except NoResultFound:
            return render_template("bad_event_link.html")
        event = etime.event

        msg = _create_email(event, etime)
        _send_email(msg)

        for t in event.times:
            dbsession.delete(t)
        for a in event.attendees:
            dbsession.delete(a)
        dbsession.commit()
        dbsession.delete(event)

        return 'Success!'
Ejemplo n.º 2
0
def register_events():
    """
    Accepts new event data to be stored in the database, awaiting scheduling.
    """
    data = request.get_json(force=True)

    # Save new event details and times to database
    with session_scope() as dbsession:

        conflicts = [
            dbsession.query(m.EventTime)
            .filter(m.EventTime.key == tm['serverKey']).first()
            for tm in data['times']
        ]
        if any(n is not None for n in conflicts):
            raise 'An event key conflicts with an existing key: %s' % conflicts
        times = [_make_event_time(d) for d in data['times']]
        attendees = [_make_attendee(d) for d in data['attendees']]

        event = _make_event(data["event"])
        event.times = times
        event.attendees = attendees

        dbsession.add(event)

    return ''
Ejemplo n.º 3
0
def load_event(key):
    """
    Displays the scheduling page for this event, with time range for the
    passed "key" param selected.
    """
    with session_scope() as dbsession:
        try:
            etime = dbsession.query(m.EventTime).filter(m.EventTime.key == key).one()
        except NoResultFound:
            return render_template("bad_event_link.html")
        event = etime.event
        times = []
        for t in event.times:
            times.append({"start": timestamp(t.start), "end": timestamp(t.end), "key": t.key})
        return render_template("show_event.html", event=event, selected_key=key, times_json=times)
Ejemplo n.º 4
0
def register_events():
    """
    Accepts new event data to be stored in the database, awaiting scheduling.
    """
    data = request.get_json(force=True)

    # Save new event details and times to database
    with session_scope() as dbsession:
        times = [_make_event_time(d) for d in data['times']]
        attendees = [_make_attendee(d) for d in data['attendees']]

        event = _make_event(data["event"])
        event.times = times
        event.attendees = attendees

        dbsession.add(event)

    return ''
Ejemplo n.º 5
0
Archivo: backend.py Proyecto: zyuyou/N1
def register_events():
    """
    Accepts new event data to be stored in the database, awaiting scheduling.
    """
    data = request.get_json(force=True)

    # Save new event details and times to database
    with session_scope() as dbsession:
        times = [_make_event_time(d) for d in data['times']]
        attendees = [_make_attendee(d) for d in data['attendees']]

        event = _make_event(data["event"])
        event.times = times
        event.attendees = attendees

        dbsession.add(event)

    return ''
Ejemplo n.º 6
0
    def seed_user(self, number_user=10):
        print('Start seed user')
        user_service = UserService(session=self.session)
        user_infos = []
        if number_user <= 0:
            number_user = 10
        domain_list = set()
        for i in range(number_user):
            user_info = {
                'name': domain_name,
                'email': self.fake.email(),
                'password': self.fake.sha256(),
                'status': 'ACTIVE',
            }
            user_infos.append(user_info)

        with session_scope(self.session):
            user_service.bulk_create(user_infos)

        print('Seed shop done')
Ejemplo n.º 7
0
Archivo: backend.py Proyecto: zyuyou/N1
def load_event(key):
    """
    Displays the scheduling page for this event, with time range for the
    passed "key" param selected.
    """
    with session_scope() as dbsession:
        try:
            etime = dbsession.query(
                m.EventTime).filter(m.EventTime.key == key).one()
        except NoResultFound:
            return render_template("bad_event_link.html")
        event = etime.event
        times = []
        for t in event.times:
            times.append({
                "start": time.mktime(t.start.timetuple()),
                "end": time.mktime(t.end.timetuple()),
                "key": t.key
            })
        return render_template("show_event.html",
                               event=event,
                               selected_key=key,
                               times_json=times)
Ejemplo n.º 8
0
def schedule(key):
    """
    Schedules an event at the time range corresponding to the passed
    "key" param, by sending an email to all participants containing an
    attached ICS file.
    """
    with session_scope() as dbsession:
        try:
            etime = dbsession.query(m.EventTime).filter(m.EventTime.key == key).one()
        except NoResultFound:
            return render_template("bad_event_link.html")
        event = etime.event

        msg = _create_email(event, etime)
        _send_email(msg)

        for t in event.times:
            dbsession.delete(t)
        for a in event.attendees:
            dbsession.delete(a)
        dbsession.commit()
        dbsession.delete(event)

        return render_template('success.html')