MediaDash/forms.py

97 lines
2.9 KiB
Python
Raw Normal View History

2021-08-29 13:03:28 +00:00
# -*- coding: utf-8 -*-
from flask_wtf import FlaskForm
import json
import os
from cryptography.hazmat.primitives.serialization import load_ssh_public_key
from wtforms import (
StringField,
PasswordField,
FieldList,
FloatField,
BooleanField,
SelectField,
SubmitField,
validators,
Field,
FieldList,
SelectMultipleField,
TextAreaField,
FieldList,
FormField,
)
from flask_wtf.file import FileField, FileAllowed, FileRequired
from wtforms.ext.sqlalchemy.orm import model_form
from wtforms.fields.html5 import SearchField
from wtforms.widgets.html5 import NumberInput
from wtforms.widgets import TextInput, CheckboxInput, ListWidget, PasswordInput
from wtforms.validators import (
ValidationError,
DataRequired,
URL,
ValidationError,
Optional,
)
def json_prettify(file):
with open(file, "r") as fh:
return json.dumps(json.load(fh), indent=4)
class SearchForm(FlaskForm):
query = SearchField("Query", validators=[DataRequired()])
tv_shows = BooleanField("TV Shows", default=True)
movies = BooleanField("Movies", default=True)
torrents = BooleanField("Torrents", default=True)
indexer = SelectMultipleField(choices=[])
group_by_tracker = BooleanField("Group torrents by tracker")
search = SubmitField("Search")
class HiddenPassword(PasswordField):
widget = PasswordInput(hide_value=False)
class TranscodeProfileForm(FlaskForm):
test = TextAreaField()
save = SubmitField("Save")
class AddSSHUser(FlaskForm):
name = StringField("Name", validators=[DataRequired()])
ssh_key = StringField("Public key", validators=[DataRequired()])
add = SubmitField("Add")
def validate_ssh_key(self,field):
key=load_ssh_public_key(bytes(field.data,"utf8"))
class ConfigForm(FlaskForm):
jellyfin_url = StringField("URL", validators=[URL()])
jellyfin_api_key = StringField("API Key")
qbt_url = StringField("URL", validators=[URL()])
qbt_username = StringField("Username")
qbt_passwd = HiddenPassword("Password")
sonarr_url = StringField("URL", validators=[URL()])
sonarr_api_key = HiddenPassword("API key")
radarr_url = StringField("URL", validators=[URL()])
radarr_api_key = HiddenPassword("API key")
jackett_url = StringField("URL", validators=[URL()])
jackett_api_key = HiddenPassword("API key")
portainer_url = StringField("URL", validators=[URL()])
portainer_username = StringField("Username")
portainer_passwd = HiddenPassword("Password")
transcode_default_profile = SelectField(
"Default profile", choices=[], validators=[]
)
transcode_profiles = FileField(
"Transcode profiles JSON",
validators=[Optional(), FileAllowed(["json"], "JSON files only!")],
)
test = SubmitField("Test")
save = SubmitField("Save")