-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathforms.py
More file actions
98 lines (89 loc) · 3.34 KB
/
forms.py
File metadata and controls
98 lines (89 loc) · 3.34 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
forms.py
Defines Flask-WTF form classes for handling user input across the application.
This includes forms for configuration management, user login, and managing RSS feed URLs.
"""
# =============================================================================
# STANDARD LIBRARY IMPORTS
# =============================================================================
# (No standard library imports are needed in this file)
# =============================================================================
# THIRD-PARTY IMPORTS
# =============================================================================
from flask_wtf import FlaskForm
from wtforms import (
StringField,
PasswordField,
BooleanField,
IntegerField,
TextAreaField,
FormField,
FieldList,
validators
)
# =============================================================================
# LOCAL IMPORTS
# =============================================================================
# (No local imports are needed in this file)
# =============================================================================
# FORM DEFINITIONS
# =============================================================================
class UrlForm(FlaskForm):
"""
Form for managing an individual, existing RSS feed URL.
Used within a FieldList in the main ConfigForm.
"""
pri = IntegerField('Priority', validators=[validators.Optional()])
url = StringField('URL', render_kw={"readonly": True, "style": "width: 300px;"})
reset = BooleanField('Reset', default=False)
class CustomRSSForm(FlaskForm):
"""
Form for adding or editing a custom RSS feed URL.
Used within a FieldList in the main ConfigForm.
"""
pri = IntegerField('Priority', validators=[validators.Optional()])
url = StringField(
'URL',
validators=[
validators.Optional(),
validators.Length(max=120, message="URL must be 120 characters or less"),
],
render_kw={"style": "width: 300px;"}
)
class ConfigForm(FlaskForm):
"""
Main configuration form for the admin panel.
Allows an admin to manage site settings, headlines, and RSS feeds.
"""
delete_cookie = BooleanField(label="Delete cookies")
no_underlines = BooleanField(label="No Underlines")
headlines = TextAreaField(
label="Headlines HTML",
validators=[
validators.Optional(),
validators.Length(max=50000, message="Headlines content is too long (max 50,000 characters)")
],
render_kw={"style": "width: 100%; height: 200px; font-family: monospace;"}
)
urls = FieldList(FormField(UrlForm))
url_custom = FieldList(FormField(CustomRSSForm))
class LoginForm(FlaskForm):
"""
Form for user authentication with CSRF protection.
"""
username = StringField(
'Username',
validators=[
validators.DataRequired(message="Username is required"),
validators.Length(min=1, max=50, message="Username must be between 1 and 50 characters")
],
default='admin'
)
password = PasswordField(
'Password',
validators=[
validators.DataRequired(message="Password is required"),
validators.Length(min=1, max=100, message="Password must be between 1 and 100 characters")
]
)
remember_me = BooleanField('Remember Me')