1
|
|
|
""" |
2
|
|
|
byceps.blueprints.admin.site.forms |
3
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4
|
|
|
|
5
|
|
|
:Copyright: 2006-2019 Jochen Kupperschmidt |
6
|
|
|
:License: Modified BSD, see LICENSE for details. |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
from wtforms import BooleanField, SelectField, StringField |
10
|
|
|
from wtforms.validators import InputRequired, Length, Optional |
11
|
|
|
|
12
|
|
|
from ....util.l10n import LocalizedForm |
13
|
|
|
|
14
|
|
|
from ....services.email import service as email_service |
15
|
|
|
from ....services.party import service as party_service |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class _BaseForm(LocalizedForm): |
19
|
|
|
title = StringField('Titel', validators=[Length(min=1, max=40)]) |
20
|
|
|
server_name = StringField('Servername', validators=[InputRequired()]) |
21
|
|
|
email_config_id = SelectField('E-Mail-Konfiguration', validators=[InputRequired()]) |
22
|
|
|
party_id = SelectField('Party-ID', validators=[Optional()]) |
23
|
|
|
enabled = BooleanField('aktiv') |
24
|
|
|
user_account_creation_enabled = BooleanField('Benutzerregistrierung geöffnet') |
25
|
|
|
login_enabled = BooleanField('Benutzeranmeldung geöffnet') |
26
|
|
|
|
27
|
|
|
def set_email_config_choices(self): |
28
|
|
|
configs = email_service.get_all_configs() |
29
|
|
|
configs.sort(key=lambda config: config.id) |
30
|
|
|
self.email_config_id.choices = [(c.id, c.id) for c in configs] |
31
|
|
|
|
32
|
|
|
def set_party_choices(self): |
33
|
|
|
parties = party_service.get_all_parties() |
34
|
|
|
parties.sort(key=lambda party: party.id) |
35
|
|
|
|
36
|
|
|
choices = [(str(p.id), p.title) for p in parties] |
37
|
|
|
choices.insert(0, ('', '<keine>')) |
38
|
|
|
self.party_id.choices = choices |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
class CreateForm(_BaseForm): |
42
|
|
|
id = StringField('ID', validators=[Length(min=1, max=40)]) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class UpdateForm(_BaseForm): |
46
|
|
|
archived = BooleanField('archiviert') |
47
|
|
|
|