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")) form = forms.AddCalendarForm() # 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_manager_group=form.calendar_manager_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), ) 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") return flask.redirect(flask.url_for("index"))
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'))