~homeworkprod/byceps

ref: aab620e36207ab5255fc3ab47d5513c803726195 byceps/byceps/blueprints/admin/news/forms.py -rw-r--r-- 1.4 KiB
aab620e3 — Jochen Kupperschmidt Block attempts to publish an already published news item 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
"""
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.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