~homeworkprod/byceps

ref: b5dc62d48db9823a9577f67bc65815116d0d3cfe byceps/byceps/blueprints/admin/news/forms.py -rw-r--r-- 1.6 KiB
b5dc62d4 — Jochen Kupperschmidt Add admin UI to publish news item later 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
byceps.blueprints.admin.news.forms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

import re

from wtforms import FileField, StringField, TextAreaField
from wtforms.fields.html5 import DateField, TimeField
from wtforms.validators import InputRequired, Length, Optional, Regexp

from ....util.l10n import LocalizedForm


SLUG_REGEX = re.compile('^[a-z0-9-]+$')


class ChannelCreateForm(LocalizedForm):
    channel_id = StringField('ID', validators=[Length(min=1, max=40)])
    url_prefix = StringField('URL-Präfix', [InputRequired(), Length(max=80)])


class _ImageFormBase(LocalizedForm):
    alt_text = StringField('Alternativtext', [InputRequired()])
    caption = StringField('Bildunterschrift', [Optional()])
    attribution = StringField('Bildquelle', [Optional()])


class ImageCreateForm(_ImageFormBase):
    image = FileField('Bilddatei', [InputRequired()])


class ImageUpdateForm(_ImageFormBase):
    pass


class ItemCreateForm(LocalizedForm):
    slug = StringField('Slug', [InputRequired(), Length(max=100), Regexp(SLUG_REGEX, message='Nur Kleinbuchstaben, Ziffern und Bindestrich sind erlaubt.')])
    title = StringField('Titel', [InputRequired(), Length(max=100)])
    body = TextAreaField('Text', [InputRequired()])
    image_url_path = StringField('Bild-URL-Pfad', [Optional(), Length(max=100)])


class ItemUpdateForm(ItemCreateForm):
    pass


class ItemPublishLaterForm(LocalizedForm):
    publish_on = DateField('Datum', [InputRequired()])
    publish_at = TimeField('Uhrzeit', [InputRequired()])