only accept image files in certain forms

This commit is contained in:
rimu 2024-06-16 14:03:59 +08:00
parent 1a266c83ab
commit b578bf27a4
4 changed files with 17 additions and 8 deletions

View file

@ -15,7 +15,7 @@ class SiteProfileForm(FlaskForm):
description = StringField(_l('Tagline')) description = StringField(_l('Tagline'))
icon = FileField(_l('Icon'), validators=[ icon = FileField(_l('Icon'), validators=[
FileAllowed(['jpg', 'jpeg', 'png', 'webp'], 'Images only!') FileAllowed(['jpg', 'jpeg', 'png', 'webp'], 'Images only!')
]) ], render_kw={'accept': 'image/*'})
sidebar = TextAreaField(_l('Sidebar')) sidebar = TextAreaField(_l('Sidebar'))
about = TextAreaField(_l('About')) about = TextAreaField(_l('About'))
announcement = TextAreaField(_l('Announcement at top of home page')) announcement = TextAreaField(_l('Announcement at top of home page'))

View file

@ -19,8 +19,8 @@ class AddCommunityForm(FlaskForm):
community_name = StringField(_l('Name'), validators=[DataRequired()]) community_name = StringField(_l('Name'), validators=[DataRequired()])
url = StringField(_l('Url')) url = StringField(_l('Url'))
description = TextAreaField(_l('Description')) description = TextAreaField(_l('Description'))
icon_file = FileField(_l('Icon image')) icon_file = FileField(_l('Icon image'), render_kw={'accept': 'image/*'})
banner_file = FileField(_l('Banner image')) banner_file = FileField(_l('Banner image'), render_kw={'accept': 'image/*'})
rules = TextAreaField(_l('Rules')) rules = TextAreaField(_l('Rules'))
nsfw = BooleanField('NSFW') nsfw = BooleanField('NSFW')
local_only = BooleanField('Local only') local_only = BooleanField('Local only')
@ -47,8 +47,8 @@ class AddCommunityForm(FlaskForm):
class EditCommunityForm(FlaskForm): class EditCommunityForm(FlaskForm):
title = StringField(_l('Title'), validators=[DataRequired()]) title = StringField(_l('Title'), validators=[DataRequired()])
description = TextAreaField(_l('Description')) description = TextAreaField(_l('Description'))
icon_file = FileField(_l('Icon image')) icon_file = FileField(_l('Icon image'), render_kw={'accept': 'image/*'})
banner_file = FileField(_l('Banner image')) banner_file = FileField(_l('Banner image'), render_kw={'accept': 'image/*'})
rules = TextAreaField(_l('Rules')) rules = TextAreaField(_l('Rules'))
nsfw = BooleanField(_l('Porn community')) nsfw = BooleanField(_l('Porn community'))
local_only = BooleanField(_l('Only accept posts from current instance')) local_only = BooleanField(_l('Only accept posts from current instance'))
@ -154,7 +154,7 @@ class CreateImageForm(FlaskForm):
image_title = StringField(_l('Title'), validators=[DataRequired(), Length(min=3, max=255)]) image_title = StringField(_l('Title'), validators=[DataRequired(), Length(min=3, max=255)])
image_alt_text = StringField(_l('Alt text'), validators=[Optional(), Length(min=3, max=1500)]) image_alt_text = StringField(_l('Alt text'), validators=[Optional(), Length(min=3, max=1500)])
image_body = TextAreaField(_l('Body'), validators=[Optional(), Length(min=3, max=5000)], render_kw={'rows': 5}) image_body = TextAreaField(_l('Body'), validators=[Optional(), Length(min=3, max=5000)], render_kw={'rows': 5})
image_file = FileField(_l('Image'), validators=[DataRequired()]) image_file = FileField(_l('Image'), validators=[DataRequired()], render_kw={'accept': 'image/*'})
tags = StringField(_l('Tags'), validators=[Optional(), Length(min=3, max=5000)]) tags = StringField(_l('Tags'), validators=[Optional(), Length(min=3, max=5000)])
sticky = BooleanField(_l('Sticky')) sticky = BooleanField(_l('Sticky'))
nsfw = BooleanField(_l('NSFW')) nsfw = BooleanField(_l('NSFW'))

View file

@ -1489,6 +1489,15 @@ class Site(db.Model):
return User.query.filter_by(deleted=False, banned=False).join(user_role).filter(user_role.c.role_id == 4).all() return User.query.filter_by(deleted=False, banned=False).join(user_role).filter(user_role.c.role_id == 4).all()
#class IngressQueue(db.Model):
# id = db.Column(db.Integer, primary_key=True)
# waiting_for = db.Column(db.String(255), index=True) # The AP ID of the object we're waiting to be created before this Activity can be ingested
# activity_pub_log_id = db.Column(db.Integer, db.ForeignKey('activity_pub_log.id')) # The original Activity that failed because some target object does not exist
# ap_date_published = db.Column(db.DateTime, default=utcnow) # The value of the datePublished field on the Activity
# created_at = db.Column(db.DateTime, default=utcnow)
# expires = db.Column(db.DateTime, default=utcnow) # When to give up waiting and delete this row
#
#
@login.user_loader @login.user_loader
def load_user(id): def load_user(id):
return User.query.get(int(id)) return User.query.get(int(id))

View file

@ -17,8 +17,8 @@ class ProfileForm(FlaskForm):
render_kw={"autocomplete": 'new-password'}) render_kw={"autocomplete": 'new-password'})
about = TextAreaField(_l('Bio'), validators=[Optional(), Length(min=3, max=5000)], render_kw={'rows': 5}) about = TextAreaField(_l('Bio'), validators=[Optional(), Length(min=3, max=5000)], render_kw={'rows': 5})
matrixuserid = StringField(_l('Matrix User ID'), validators=[Optional(), Length(max=255)], render_kw={'autocomplete': 'off'}) matrixuserid = StringField(_l('Matrix User ID'), validators=[Optional(), Length(max=255)], render_kw={'autocomplete': 'off'})
profile_file = FileField(_l('Avatar image')) profile_file = FileField(_l('Avatar image'), render_kw={'accept': 'image/*'})
banner_file = FileField(_l('Top banner image')) banner_file = FileField(_l('Top banner image'), render_kw={'accept': 'image/*'})
bot = BooleanField(_l('This profile is a bot')) bot = BooleanField(_l('This profile is a bot'))
submit = SubmitField(_l('Save profile')) submit = SubmitField(_l('Save profile'))