Source code for gazette.forms.issue

from onegov.form import Form
from onegov.form.fields import DateTimeLocalField
from onegov.form.validators import UniqueColumnValue
from onegov.gazette import _
from onegov.gazette.models import GazetteNotice
from onegov.gazette.models import Issue
from onegov.gazette.models import IssueName
from onegov.gazette.validators import UnusedColumnKeyValue
from sedate import standardize_date
from sedate import to_timezone
from wtforms.fields import DateField
from wtforms.fields import HiddenField
from wtforms.fields import IntegerField
from wtforms.validators import InputRequired
from wtforms.validators import NumberRange

from typing import TYPE_CHECKING
    from onegov.gazette.request import GazetteRequest

[docs] class IssueForm(Form):
[docs] request: 'GazetteRequest'
[docs] number = IntegerField( label=_("Number"), validators=[ InputRequired(), NumberRange(min=1) ] )
[docs] date_ = DateField( label=_("Date"), validators=[ InputRequired() ] )
[docs] deadline = DateTimeLocalField( label=_("Deadline"), validators=[ InputRequired() ] )
[docs] timezone = HiddenField()
[docs] name = HiddenField( validators=[ UniqueColumnValue(Issue), UnusedColumnKeyValue(GazetteNotice._issues) ] )
[docs] def validate(self) -> bool: # type:ignore[override] if and = str( IssueName(, ) return super().validate()
[docs] def on_request(self) -> None: =
[docs] def update_model(self, model: Issue) -> None: assert is not None model.number = assert is not None = model.deadline = = str(IssueName(, model.number)) # Convert the deadline from the local timezone to UTC if model.deadline: # FIXME: This seems very fragile, how are we ensuring # that timezone is actually set? Should we default # to UTC if we didn't get one? assert is not None model.deadline = standardize_date( model.deadline, )
[docs] def apply_model(self, model: Issue) -> None: = model.number = = = model.deadline # Convert the deadline from UTC to the local timezone if # FIXME: This is even more dubious, since it's even less # likely that the timezone is set, sedate happens # to actually work with `to_timezone(dt, None)` # but I don't think its supposed to = to_timezone(, # type:ignore[arg-type] ).replace(tzinfo=None) if model.in_use: self.number.render_kw = {'readonly': True}