pyfedi/app/admin/forms.py

115 lines
5.5 KiB
Python
Raw Normal View History

2023-11-03 21:59:48 +13:00
from flask_wtf import FlaskForm
from flask_wtf.file import FileRequired, FileAllowed
from wtforms import StringField, PasswordField, SubmitField, HiddenField, BooleanField, TextAreaField, SelectField, \
FileField, IntegerField
2024-01-01 14:49:15 +13:00
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length, Optional
2023-11-03 21:59:48 +13:00
from flask_babel import _, lazy_gettext as _l
class SiteProfileForm(FlaskForm):
name = StringField(_l('Name'))
description = StringField(_l('Tagline'))
icon = FileField(_('Icon'), validators=[
FileAllowed(['jpg', 'jpeg', 'png', 'webp'], 'Images only!')
])
sidebar = TextAreaField(_l('Sidebar'))
legal_information = TextAreaField(_l('Legal information'))
submit = SubmitField(_l('Save'))
class SiteMiscForm(FlaskForm):
enable_downvotes = BooleanField(_l('Enable downvotes'))
allow_local_image_posts = BooleanField(_l('Allow local image posts'))
remote_image_cache_days = IntegerField(_l('Days to cache images from remote instances for'))
2023-12-31 12:09:20 +13:00
enable_nsfw = BooleanField(_l('Allow NSFW communities'))
enable_nsfl = BooleanField(_l('Allow NSFL communities and posts'))
community_creation_admin_only = BooleanField(_l('Only admins can create new local communities'))
reports_email_admins = BooleanField(_l('Notify admins about reports, not just moderators'))
types = [('Open', _l('Open')), ('RequireApplication', _l('Require application')), ('Closed', _l('Closed'))]
registration_mode = SelectField(_l('Registration mode'), choices=types, default=1, coerce=str)
application_question = TextAreaField(_l('Question to ask people applying for an account'))
2024-01-13 11:12:31 +13:00
log_activitypub_json = BooleanField(_l('Log ActivityPub JSON for debugging'))
themes = [('', _l('PieFed')),
('high_contrast', _l('High contrast'))]
default_theme = SelectField(_l('Default theme'), choices=themes, coerce=str)
submit = SubmitField(_l('Save'))
class FederationForm(FlaskForm):
2023-11-03 21:59:48 +13:00
use_allowlist = BooleanField(_l('Allowlist instead of blocklist'))
allowlist = TextAreaField(_l('Allow federation with these instances'))
use_blocklist = BooleanField(_l('Blocklist instead of allowlist'))
blocklist = TextAreaField(_l('Deny federation with these instances'))
submit = SubmitField(_l('Save'))
2023-12-31 12:09:20 +13:00
class EditCommunityForm(FlaskForm):
title = StringField(_l('Title'), validators=[DataRequired()])
url = StringField(_l('Url'), validators=[DataRequired()])
description = TextAreaField(_l('Description'))
icon_file = FileField(_('Icon image'))
banner_file = FileField(_('Banner image'))
rules = TextAreaField(_l('Rules'))
2024-01-21 15:44:13 +13:00
nsfw = BooleanField(_l('Porn community'))
local_only = BooleanField(_l('Only accept posts from current instance'))
restricted_to_mods = BooleanField(_l('Only moderators can post'))
new_mods_wanted = BooleanField(_l('New moderators wanted'))
show_home = BooleanField(_l('Posts show on home page'))
show_popular = BooleanField(_l('Posts can be popular'))
show_all = BooleanField(_l('Posts show in All list'))
low_quality = BooleanField(_l("Low quality / toxic - upvotes in here don't add to reputation"))
2023-12-31 12:09:20 +13:00
options = [(-1, _l('Forever')),
(7, _l('1 week')),
(14, _l('2 weeks')),
(28, _l('1 month')),
(56, _l('2 months')),
(84, _l('3 months')),
(168, _l('6 months')),
(365, _l('1 year')),
(730, _l('2 years')),
(1825, _l('5 years')),
(3650, _l('10 years')),
]
content_retention = SelectField(_l('Retain content'), choices=options, default=1, coerce=int)
topic = SelectField(_l('Topic'), coerce=int, validators=[Optional()])
2024-01-21 15:44:13 +13:00
layouts = [('', _l('List')),
('masonry', _l('Masonry')),
('masonry_wide', _l('Wide masonry'))]
default_layout = SelectField(_l('Layout'), coerce=str, choices=layouts, validators=[Optional()])
2023-12-31 12:09:20 +13:00
submit = SubmitField(_l('Save'))
def validate(self, extra_validators=None):
if not super().validate():
return False
if self.url.data.strip() == '':
self.url.errors.append(_('Url is required.'))
return False
else:
if '-' in self.url.data.strip():
self.url.errors.append(_('- cannot be in Url. Use _ instead?'))
return False
2024-01-01 14:49:15 +13:00
return True
class EditTopicForm(FlaskForm):
name = StringField(_l('Name'), validators=[DataRequired()])
machine_name = StringField(_l('Url'), validators=[DataRequired()])
add_community = SelectField(_l('Community to add'), coerce=int, validators=[Optional()])
submit = SubmitField(_l('Save'))
2024-01-01 14:49:15 +13:00
class EditUserForm(FlaskForm):
about = TextAreaField(_l('Bio'), validators=[Optional(), Length(min=3, max=5000)])
matrix_user_id = StringField(_l('Matrix User ID'), validators=[Optional(), Length(max=255)])
2024-01-21 15:44:13 +13:00
profile_file = FileField(_l('Avatar image'))
banner_file = FileField(_l('Top banner image'))
2024-01-01 14:49:15 +13:00
bot = BooleanField(_l('This profile is a bot'))
newsletter = BooleanField(_l('Subscribe to email newsletter'))
ignore_bots = BooleanField(_l('Hide posts by bots'))
nsfw = BooleanField(_l('Show NSFW posts'))
nsfl = BooleanField(_l('Show NSFL posts'))
searchable = BooleanField(_l('Show profile in user list'))
indexable = BooleanField(_l('Allow search engines to index this profile'))
manually_approves_followers = BooleanField(_l('Manually approve followers'))
submit = SubmitField(_l('Save'))