def delete_calendar(calendar_name): """ Delete a specific calendar given its identifier. :arg calendar_name: the identifier of the calendar to delete. """ 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 delete the calendar.', 'errors') return flask.redirect(flask.url_for('index')) calendarobj = Calendar.by_id(SESSION, calendar_name) deleteform = forms.DeleteCalendarForm() # pylint: disable=E1101 if deleteform.validate_on_submit(): if deleteform.confirm_delete.data: calendarobj.delete(SESSION) try: SESSION.commit() except SQLAlchemyError, err: SESSION.rollback() print 'delete_calendar:', err flask.flash('Could not delete this calendar.', 'errors') flask.flash('Calendar deleted') fedmsg.publish(topic="calendar.delete", msg=dict( agent=flask.g.fas_user.username, calendar=calendarobj.to_json(), )) return flask.redirect(flask.url_for('index'))
def delete_meeting(meeting_id): """ Delete a specific meeting given its identifier. :arg meeting_id: the identifier of the meeting to delete. """ if not flask.g.fas_user: return flask.redirect(flask.url_for('index')) meeting = Meeting.by_id(SESSION, meeting_id) if meeting.calendar.calendar_status != 'Enabled': flask.flash('This calendar is "%s", you are not allowed to delete ' 'its meetings anymore.' % calendarobj.calendar_status, 'errors') return flask.redirect(flask.url_for('calendar', calendar_name=calendar_name)) if not (is_meeting_manager(meeting) or is_calendar_admin(meeting.calendar) or is_admin()): flask.flash('You are not one of the manager of this meeting, ' 'or an admin, you are not allowed to delete it.', 'errors') return flask.redirect(flask.url_for('view_meeting', meeting_id=meeting_id)) calendars = Calendar.get_all(SESSION) deleteform = forms.DeleteMeetingForm() # pylint: disable=E1101 if deleteform.validate_on_submit(): if deleteform.confirm_delete.data: if deleteform.confirm_futher_delete.data: fedocallib.delete_recursive_meeting(SESSION, meeting) else: meeting.delete(SESSION) try: SESSION.commit() except SQLAlchemyError, err: SESSION.rollback() print 'edit_meeting:', err flask.flash('Could not update this meeting.', 'error') flask.flash('Meeting deleted') fedmsg.publish(topic="meeting.delete", msg=dict( agent=flask.g.fas_user.username, meeting=meeting.to_json(), calendar=meeting.calendar.to_json(), )) return flask.redirect(flask.url_for( 'calendar', calendar_name=meeting.calendar_name))
def fedmsg_publish(meeting, meeting_id): """ Publish the meeting.reminder messages on fedora-messaging. :arg meeting: a Meeting object from fedocallib.model :arg meeting_id: an int representing the meeting identifier in the database """ _log.debug('Publishing a message for meeting: %s', meeting_id) meeting_dict = meeting.to_json() meeting_dict['meeting_id'] = meeting_id message = dict( meeting=meeting_dict, calendar=meeting.calendar.to_json() ) fedmsg.publish(topic='reminder', msg=message)
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))
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'))
return flask.render_template( 'add_meeting.html', calendar=calendarobj, form=form, tzone=tzone) except SQLAlchemyError, err: SESSION.rollback() print 'add_meeting:', err flask.flash('Could not add this meeting to this calendar', 'errors') return flask.render_template( 'add_meeting.html', calendar=calendarobj, form=form, tzone=tzone) flask.flash('Meeting added') fedmsg.publish(topic="meeting.new", msg=dict( agent=flask.g.fas_user.username, meeting=meeting.to_json(), calendar=calendarobj.to_json(), )) return flask.redirect(flask.url_for( 'calendar', calendar_name=calendarobj.calendar_name, year=form.meeting_date.data.year, month=form.meeting_date.data.month, day=form.meeting_date.data.day)) return flask.render_template( 'add_meeting.html', calendar=calendarobj, form=form, tzone=tzone) # pylint: disable=R0915,R0912,R0911 # CLA + 1 @APP.route('/meeting/edit/<int:meeting_id>/', methods=('GET', 'POST'))