Total Complexity | 4 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 93.75% |
Changes | 0 |
1 | """ |
||
2 | byceps.blueprints.admin.snippet.mountpoint.forms |
||
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
4 | |||
5 | :Copyright: 2006-2021 Jochen Kupperschmidt |
||
6 | :License: Revised BSD (see `LICENSE` file for details) |
||
7 | """ |
||
8 | |||
9 | 1 | from __future__ import annotations |
|
10 | |||
11 | 1 | from flask_babel import lazy_gettext |
|
12 | 1 | from wtforms import SelectField, StringField |
|
13 | 1 | from wtforms.validators import InputRequired, ValidationError |
|
14 | |||
15 | 1 | from .....services.site.transfer.models import Site |
|
16 | 1 | from .....util.l10n import LocalizedForm |
|
17 | |||
18 | |||
19 | 1 | class SiteSelectForm(LocalizedForm): |
|
20 | 1 | site_id = SelectField(lazy_gettext('Site'), [InputRequired()]) |
|
21 | |||
22 | 1 | def set_site_id_choices(self, sites: set[Site]) -> None: |
|
23 | 1 | self.site_id.choices = [ |
|
24 | (site.id, site.title) |
||
25 | for site in sorted(sites, key=lambda site: site.title) |
||
26 | ] |
||
27 | |||
28 | |||
29 | 1 | class CreateForm(LocalizedForm): |
|
30 | 1 | endpoint_suffix = StringField(lazy_gettext('Identifier'), [InputRequired()]) |
|
31 | 1 | url_path = StringField(lazy_gettext('URL path'), [InputRequired()]) |
|
32 | |||
33 | 1 | @staticmethod |
|
34 | def validate_url_path(form, field): |
||
35 | 1 | if not field.data.startswith('/'): |
|
36 | raise ValidationError( |
||
37 | lazy_gettext('URL path has to start with a slash.') |
||
38 | ) |
||
39 |