Exemplo n.º 1
0
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 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")
        return flask.redirect(flask.url_for("calendar", calendar_name=meeting.calendar_name))
Exemplo n.º 2
0
def inject_calendars():
    """ With this decorator we add the list of all the calendars
    available to all the function, so the variable calendars is available
    in all templates.
    """
    calendars = Calendar.get_all(SESSION)

    return dict(calendars=calendars)
Exemplo n.º 3
0
def index():
    """ Displays the index page with containing the first calendar (by
    order of creation and if any) for the current week.
    """
    calendars = Calendar.get_all(SESSION)
    auth_form = forms.LoginForm()
    admin = is_admin()
    return flask.render_template(
        "index.html", calendars=calendars, calendars_table=chunks(calendars, 3), auth_form=auth_form, admin=admin
    )
Exemplo n.º 4
0
def ical_all():
    """ Returns a iCal feed of all calendars from today - 1 month to
    today + 6 month.
    """
    startd = datetime.date.today() - datetime.timedelta(days=30)
    endd = datetime.date.today() + datetime.timedelta(days=180)
    ical = vobject.iCalendar()
    meetings = []
    for calendar in Calendar.get_all(SESSION):
        meetings.extend(fedocallib.get_meetings_by_date(SESSION, calendar.calendar_name, startd, endd))
    fedocallib.add_meetings_to_vcal(ical, meetings)
    return flask.Response(ical.serialize(), mimetype="text/calendar")
Exemplo n.º 5
0
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))
Exemplo n.º 6
0
def get_calendars(session):
    """ Retrieve the list of Calendar from the database. """
    return Calendar.get_all(session)