Exemplo n.º 1
0
    def test_gen_epoch_choices(self, app, client):
        from app.calendar.helpers import gen_epoch_choices

        self.assertEqual(len(gen_epoch_choices()), 0)

        self.set_up_epochs()

        self.assertEqual(len(gen_epoch_choices()), 3)
Exemplo n.º 2
0
def settings():
    settings = EventSetting.query.get(1)
    form = SettingsForm()
    form.default_category.choices = gen_event_category_choices()
    form.default_epoch.choices = gen_epoch_choices()

    if form.validate_on_submit():
        settings.default_visible = form.default_visible.data
        settings.default_category = form.default_category.data
        settings.default_epoch = form.default_epoch.data
        settings.default_year = form.default_year.data

        db.session.commit()

        flash("Event settings have been changed.", "success")
    elif request.method == "GET":
        form.default_visible.data = settings.default_visible
        form.default_category.data = settings.default_category
        form.default_epoch.data = settings.default_epoch
        form.default_year.data = settings.default_year

    categories = EventCategory.query.all()

    return render_template("event/settings.html",
                           settings=settings,
                           categories=categories,
                           form=form,
                           title=page_title("Event Settings"))
Exemplo n.º 3
0
def preview():
    cset = CalendarSetting.query.get(1)
    if cset.finalized is True:
        flash("Calendar has already been finalized, preview not possible.",
              "danger")
        return redirect(url_for('calendar.index'))

    status = calendar_sanity_check()

    if status is False:
        flash(
            "There were errors previewing the calendar. See the other messages for more details.",
            "danger")
        return redirect(url_for("calendar.settings"))
    else:
        flash("All checks passed.", "success")

    stats = gen_calendar_preview_data()

    preview_form = EventForm()

    del preview_form.submit
    del preview_form.name
    del preview_form.category
    del preview_form.is_visible
    del preview_form.description

    preview_form.epoch.choices = gen_epoch_choices()
    preview_form.month.choices = gen_month_choices()
    preview_form.day.choices = gen_day_choices(1)

    return render_template("calendar/preview.html",
                           calendar=stats,
                           form=preview_form,
                           title=page_title("Preview Calendar"))
Exemplo n.º 4
0
def edit(id, name=None):
    event = Event.query.filter_by(id=id).first_or_404()

    if not event.is_editable_by_user():
        return deny_access(no_perm_url)

    form = EventForm()
    form.submit.label.text = "Save Event"
    form.category.choices = gen_event_category_choices()
    form.epoch.choices = gen_epoch_choices()
    form.month.choices = gen_month_choices()

    if request.method == "POST":
        form.day.choices = gen_day_choices(form.month.data)
    else:
        form.day.choices = gen_day_choices(event.month_id)

    if not event.is_hideable_by_user():
        del form.is_visible

    if form.validate_on_submit():
        event.name = form.name.data
        event.category_id = form.category.data
        event.description = form.description.data
        event.epoch_id = form.epoch.data
        event.year = form.year.data
        event.month_id = form.month.data
        event.day = form.day.data
        event.duration = form.duration.data

        if event.is_hideable_by_user():
            event.is_visible = form.is_visible.data

        db.session.commit()

        update_timestamp(event.id)

        flash("Event was edited.", "success")

        return redirect(event.view_url())
    elif request.method == "GET":
        form.name.data = event.name
        form.category.data = event.category_id
        form.description.data = event.description
        form.epoch.data = event.epoch_id
        form.year.data = event.year
        form.month.data = event.month_id
        form.day.data = event.day
        form.duration.data = event.duration

        if event.is_hideable_by_user():
            form.is_visible.data = event.is_visible

    calendar_helper = gen_calendar_stats()
    return render_template("event/edit.html", form=form, calendar=calendar_helper,
                           title=page_title(f"Edit Event '{event.name}'"))
Exemplo n.º 5
0
def create():  # noqa: C901
    settings = EventSetting.query.get(1)
    form = EventForm()
    form.submit.label.text = "Create Event"
    form.category.choices = gen_event_category_choices()
    form.epoch.choices = gen_epoch_choices()
    form.month.choices = gen_month_choices()

    if request.method == "POST":
        form.day.choices = gen_day_choices(form.month.data)
    else:
        form.day.choices = gen_day_choices(1)
        form.category.data = settings.default_category
        form.is_visible.data = True

        if settings.default_epoch:
            form.epoch.data = settings.default_epoch

        if settings.default_year:
            form.year.data = settings.default_year

    if form.validate_on_submit():
        new_event = Event(name=form.name.data,
                          category_id=form.category.data,
                          description=form.description.data,
                          epoch_id=form.epoch.data,
                          year=form.year.data,
                          month_id=form.month.data,
                          day=form.day.data,
                          duration=form.duration.data)

        new_event.is_visible = form.is_visible.data

        db.session.add(new_event)
        db.session.commit()

        update_timestamp(new_event.id)

        flash("Event was created.", "success")
        return redirect(new_event.view_url())
    elif request.method == "GET":
        # pre-select fields if get-params were passed
        epoch_id = request.args.get("epoch")
        year = request.args.get("year")
        category_id = request.args.get("category")

        # will do nothing if var is not an int or not in choices
        if epoch_id:
            try:
                form.epoch.data = int(epoch_id)
            except ValueError:
                pass

        # will do nothing if var is not an int or not in choices
        if year:
            try:
                form.year.data = int(year)
            except ValueError:
                pass

        # will do nothing if var is not an int or not in choices
        if category_id:
            try:
                form.category.data = int(category_id)
            except ValueError:
                pass

    calendar_helper = gen_calendar_stats()
    return render_template("event/create.html", form=form, calendar=calendar_helper, title=page_title("Add Event"))
Exemplo n.º 6
0
def edit(id):
    event = Event.query.filter_by(id=id).first_or_404()

    form = EventForm()
    form.submit.label.text = "Save Event"
    form.category.choices = gen_event_category_choices()
    form.epoch.choices = gen_epoch_choices()
    form.month.choices = gen_month_choices()

    if request.method == "POST":
        form.day.choices = gen_day_choices(form.month.data)
    else:
        form.day.choices = gen_day_choices(event.month_id)

    # TODO: write custom decorator for this?
    if not current_user.has_admin_role() and current_user.has_event_role(
    ) and event.is_visible == False and event.created_by.has_admin_role():
        flash_no_permission()
        return redirect(url_for(no_perm_url))

    if not current_user.is_event_admin(
    ) and event.is_visible == False and not event.created_by == current_user:
        flash_no_permission()
        return redirect(url_for(no_perm_url))

    if not current_user.is_event_admin():
        del form.is_visible

    if form.validate_on_submit():
        event.name = form.name.data
        event.category_id = form.category.data
        event.description = form.description.data
        event.epoch_id = form.epoch.data
        event.year = form.year.data
        event.month_id = form.month.data
        event.day = form.day.data
        event.duration = form.duration.data

        if current_user.is_event_admin():
            event.is_visible = form.is_visible.data

        db.session.commit()

        update_timestamp(event.id)

        flash("Event was edited.", "success")

        return redirect(url_for("event.view", id=id))
    elif request.method == "GET":
        form.name.data = event.name
        form.category.data = event.category_id
        form.description.data = event.description
        form.epoch.data = event.epoch_id
        form.year.data = event.year
        form.month.data = event.month_id
        form.day.data = event.day
        form.duration.data = event.duration

        if current_user.is_event_admin():
            form.is_visible.data = event.is_visible

    calendar_helper = gen_calendar_stats()
    return render_template("event/edit.html",
                           form=form,
                           calendar=calendar_helper,
                           title=page_title("Edit Event '%s'" % event.name))