Пример #1
0
def edit_calendar(calendar_name):
    """ Edit a specific calendar based on the calendar identifier.

    :arg calendar_name: the identifier of the calendar to edit.
    """
    if not flask.g.fas_user:
        return flask.redirect(flask.url_for('index'))
    if not is_admin():
        flask.flash('You are not a fedocal admin, you are not allowed '
                    'to edit the calendar.', 'errors')
        return flask.redirect(flask.url_for('index'))

    calendarobj = Calendar.by_id(SESSION, calendar_name)
    status = fedocallib.get_calendar_statuses(SESSION)
    form = forms.AddCalendarForm(status=status)
    # pylint: disable=E1101
    if form.validate_on_submit():
        try:
            calendarobj.calendar_name = form.calendar_name.data
            calendarobj.calendar_contact = form.calendar_contact.data
            calendarobj.calendar_description = form.calendar_description.data
            calendarobj.calendar_editor_group = \
                form.calendar_editor_groups.data
            calendarobj.calendar_admin_group = \
                form.calendar_admin_groups.data
            calendarobj.calendar_multiple_meetings = bool(
                form.calendar_multiple_meetings.data)
            calendarobj.calendar_regional_meetings = bool(
                form.calendar_regional_meetings.data)
            calendarobj.calendar_status = form.calendar_status.data
            calendarobj.save(SESSION)
            SESSION.commit()
        except SQLAlchemyError, err:
            SESSION.rollback()
            print 'edit_calendar:', err
            flask.flash('Could not update this calendar.', 'errors')
            return flask.render_template(
                'edit_calendar.html', form=form, calendar=calendarobj)

        flask.flash('Calendar updated')
        fedmsg.publish(topic="calendar.update", msg=dict(
            agent=flask.g.fas_user.username,
            calendar=calendarobj.to_json(),
        ))
        return flask.redirect(flask.url_for(
            'calendar', calendar_name=calendarobj.calendar_name))
Пример #2
0
def add_calendar():
    """ Add a calendar to the database.
    This function is only accessible to admin of the webapp.
    """
    if not flask.g.fas_user:
        return flask.redirect(flask.url_for('index'))
    if not is_admin():
        flask.flash('You are not a fedocal admin, you are not allowed '
                    'to add calendars.', 'errors')
        return flask.redirect(flask.url_for('index'))

    status = fedocallib.get_calendar_statuses(SESSION)

    form = forms.AddCalendarForm(status=status)
    # pylint: disable=E1101
    if form.validate_on_submit():
        calendarobj = Calendar(
            calendar_name=form.calendar_name.data,
            calendar_contact=form.calendar_contact.data,
            calendar_description=form.calendar_description.data,
            calendar_editor_group=form.calendar_editor_groups.data,
            calendar_admin_group=form.calendar_admin_groups.data,
            calendar_multiple_meetings=bool(
                form.calendar_multiple_meetings.data),
            calendar_regional_meetings=bool(
                form.calendar_regional_meetings.data),
            calendar_status=form.calendar_status.data
        )
        try:
            calendarobj.save(SESSION)
            SESSION.commit()
        except SQLAlchemyError, err:
            SESSION.rollback()
            print 'add_calendar:', err
            flask.flash('Could not add this calendar to the database',
                        'errors')
            return flask.render_template('add_calendar.html',
                                         form=form)

        flask.flash('Calendar added')
        fedmsg.publish(topic="calendar.new", msg=dict(
            agent=flask.g.fas_user.username,
            calendar=calendarobj.to_json(),
        ))
        return flask.redirect(flask.url_for('index'))