示例#1
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"))
    def test_own_sanity(self, app, client):
        """
        test that the static calendar in this test passes the sanity check
        """
        from app.calendar.helpers import calendar_sanity_check

        self.set_up_calendar()
        self.assertTrue(calendar_sanity_check())
示例#3
0
def check():
    cset = CalendarSetting.query.get(1)
    if cset.finalized is True:
        flash("Calendar has already been finalized, check not possible.",
              "danger")
        return redirect(url_for('calendar.index'))

    status = calendar_sanity_check()

    if status is True:
        flash(
            "All checks have passed. The calendar works with this configuration.",
            "success")
    else:
        flash(
            "There were errors checking the calendar. See the other messages for more details.",
            "danger")

    return redirect(url_for("calendar.settings"))
示例#4
0
def finalize():
    cset = CalendarSetting.query.get(1)
    if cset.finalized is True:
        flash("Calendar has already been finalized.", "danger")
        return redirect(url_for('calendar.index'))

    status = calendar_sanity_check()

    if status is False:
        flash(
            "There were errors finalizing the calendar. See the other messages for more details.",
            "danger")
        return redirect(url_for("calendar.settings"))

    gen_calendar_preview_data(commit=True)
    cset = CalendarSetting.query.get(1)
    cset.finalized = True
    db.session.commit()

    flash("The calendar was finalized.", "success")
    return redirect(url_for('calendar.settings'))
    def test_calendar_sanity_check(self, app, client):
        from app.calendar.helpers import calendar_sanity_check

        # need settings with id 1 to exist (part of install)
        settings = CalendarSetting(finalized=True)
        self.add(settings)
        self.commit()

        # fail-case: calendar is already finalized
        client.get("/")
        with client.session_transaction():
            self.assertFalse(calendar_sanity_check())
            self.assertTrue("already finalized" in get_flashed_messages()[0])

        settings.finalized = False
        self.commit()

        # fail-case: calendar has no epochs
        client.get("/")
        with client.session_transaction():
            self.assertFalse(calendar_sanity_check())
            self.assertTrue(
                "needs at least one epoch" in get_flashed_messages()[0])

        self.set_up_epochs()
        self.epochs[2].years = 100
        self.commit()

        # fail-case: current epoch has years != 0
        client.get("/")
        with client.session_transaction():
            self.assertFalse(calendar_sanity_check())
            self.assertTrue(
                "needs a duration of 0" in get_flashed_messages()[0])

        self.epochs[2].years = 0
        self.epochs[1].years = 0
        self.commit()

        # fail-case: not-current epoch has duration 0
        client.get("/")
        with client.session_transaction():
            self.assertFalse(calendar_sanity_check())
            self.assertTrue("need a duration > 0" in get_flashed_messages()[0])

        self.epochs[1].years = 200
        self.commit()

        # fail-case: calendar has no months
        client.get("/")
        with client.session_transaction():
            self.assertFalse(calendar_sanity_check())
            self.assertTrue(
                "needs at least one month" in get_flashed_messages()[0])

        self.set_up_months()

        # fail-case: calendar has no days
        client.get("/")
        with client.session_transaction():
            self.assertFalse(calendar_sanity_check())
            self.assertTrue(
                "needs at least one day" in get_flashed_messages()[0])

        self.set_up_days()

        # success case
        client.get("/")
        with client.session_transaction():
            self.assertTrue(calendar_sanity_check())