mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-16 00:09:05 +00:00
Better bans (#341)
* better bans * put jinja2 template into correct file
This commit is contained in:
committed by
Arylide
parent
6aab5557d6
commit
f8a314df4f
@@ -148,6 +148,33 @@ class CommentForm(FlaskForm):
|
||||
])
|
||||
|
||||
|
||||
class InlineButtonWidget(object):
|
||||
"""
|
||||
Render a basic ``<button>`` field.
|
||||
"""
|
||||
input_type = 'submit'
|
||||
html_params = staticmethod(html_params)
|
||||
|
||||
def __call__(self, field, label=None, **kwargs):
|
||||
kwargs.setdefault('id', field.id)
|
||||
kwargs.setdefault('type', self.input_type)
|
||||
if not label:
|
||||
label = field.label.text
|
||||
return HTMLString('<button %s>' % self.html_params(name=field.name, **kwargs) + label)
|
||||
|
||||
|
||||
class StringSubmitField(StringField):
|
||||
"""
|
||||
Represents an ``<button type="submit">``. This allows checking if a given
|
||||
submit button has been pressed.
|
||||
"""
|
||||
widget = InlineButtonWidget()
|
||||
|
||||
|
||||
class StringSubmitForm(FlaskForm):
|
||||
submit = StringSubmitField('Submit')
|
||||
|
||||
|
||||
class EditForm(FlaskForm):
|
||||
display_name = StringField('Torrent display name', [
|
||||
Length(min=3, max=255, message='Torrent display name must be at least %(min)d characters '
|
||||
@@ -185,6 +212,8 @@ class EditForm(FlaskForm):
|
||||
Length(max=10 * 1024, message='Description must be at most %(max)d characters long.')
|
||||
])
|
||||
|
||||
submit = SubmitField('Save Changes')
|
||||
|
||||
|
||||
class DeleteForm(FlaskForm):
|
||||
delete = SubmitField("Delete")
|
||||
@@ -193,6 +222,23 @@ class DeleteForm(FlaskForm):
|
||||
unban = SubmitField("Unban")
|
||||
|
||||
|
||||
class BanForm(FlaskForm):
|
||||
ban_user = SubmitField("Delete & Ban and Ban User")
|
||||
ban_userip = SubmitField("Delete & Ban and Ban User+IP")
|
||||
unban = SubmitField("Unban")
|
||||
|
||||
_validator = DataRequired()
|
||||
|
||||
def _validate_reason(form, field):
|
||||
if form.ban_user.data or form.ban_userip.data:
|
||||
return BanForm._validator(form, field)
|
||||
|
||||
reason = TextAreaField('Ban Reason', [
|
||||
_validate_reason,
|
||||
Length(max=1024, message='Reason must be at most %(max)d characters long.')
|
||||
])
|
||||
|
||||
|
||||
class UploadForm(FlaskForm):
|
||||
torrent_file = FileField('Torrent file', [
|
||||
FileRequired()
|
||||
|
||||
Reference in New Issue
Block a user