Exemplo n.º 1
0
    def validate_period(self, field):
        periods = PeriodCollection(self.request.session)
        period = periods.by_id(field.data)

        if not period.finalized:
            raise ValidationError(
                "The billing of this period has not been finalized yet")
Exemplo n.º 2
0
def clone_occasion(self, request, form):

    if form.submitted(request):
        occasions = OccasionCollection(request.session)
        periods = PeriodCollection(request.session)

        form.populate_obj(occasions.add(
            activity=self.activity,
            start=form.parsed_dates[0].start,
            end=form.parsed_dates[0].end,
            timezone=form.timezone,
            period=periods.by_id(form.period_id.data)
        ))

        request.success(_("Your changes were saved"))
        return request.redirect(request.link(self.activity))
    elif not request.POST:
        form.process(obj=self)

    return {
        'layout': OccasionFormLayout(
            self.activity, request, _("Clone Occasion")),
        'title': _("Clone Occasion"),
        'form': form
    }