104 lines
3 KiB
Python
104 lines
3 KiB
Python
from flask_wtf import FlaskForm
|
|
from wtforms import (
|
|
StringField,
|
|
PasswordField,
|
|
FieldList,
|
|
FloatField,
|
|
BooleanField,
|
|
SelectField,
|
|
SubmitField,
|
|
validators,
|
|
Field,
|
|
)
|
|
from wtforms.widgets.html5 import NumberInput
|
|
from wtforms.widgets import TextInput
|
|
from wtforms.validators import ValidationError
|
|
|
|
class StringListField(Field):
|
|
widget = TextInput()
|
|
|
|
def _value(self):
|
|
if self.data:
|
|
return u",".join(self.data)
|
|
else:
|
|
return u""
|
|
|
|
def process_formdata(self, valuelist):
|
|
if valuelist:
|
|
self.data = [x.strip() for x in valuelist[0].split(",")]
|
|
else:
|
|
self.data = []
|
|
|
|
|
|
class RouteForm(FlaskForm):
|
|
systems = StringListField("Systems", [validators.DataRequired()])
|
|
jump_range = FloatField(
|
|
"Jump Range (Ly)",
|
|
[validators.DataRequired(), validators.NumberRange(0, None)],
|
|
widget=NumberInput(min=0, step=0.1),
|
|
)
|
|
mode = SelectField(
|
|
"Routing Mode",
|
|
choices=[
|
|
("bfs", "Breadth-First Search"),
|
|
("greedy", "Greedy Search"),
|
|
("a-star", "A*-Search"),
|
|
],
|
|
)
|
|
permute = SelectField(
|
|
"Permutation Mode",
|
|
choices=[
|
|
("off", "Off"),
|
|
("keep_first", "Keep starting system"),
|
|
("keep_last", "Keep destination system"),
|
|
("keep_both", "Keep both endpoints"),
|
|
],
|
|
)
|
|
primary = BooleanField("Only route through primary stars")
|
|
factor = FloatField(
|
|
"Greedyness for A*-Search (%)",
|
|
[validators.NumberRange(0, 100)],
|
|
default=50,
|
|
widget=NumberInput(min=0, max=100, step=1),
|
|
)
|
|
|
|
priority = FloatField(
|
|
"Priority (0=max, 100=min)",
|
|
[validators.NumberRange(0, 100)],
|
|
default=0,
|
|
widget=NumberInput(min=0, max=100, step=1),
|
|
)
|
|
submit = SubmitField("GO!")
|
|
|
|
|
|
class LoginForm(FlaskForm):
|
|
username = StringField("Username", [validators.Required()])
|
|
password = PasswordField("Password", [validators.Required()])
|
|
remember = BooleanField("Remember me")
|
|
submit = SubmitField("Login")
|
|
|
|
|
|
class RegisterForm(FlaskForm):
|
|
username = StringField("Username", [validators.Required()])
|
|
password = PasswordField(
|
|
"Password",
|
|
[
|
|
validators.Required(),
|
|
validators.EqualTo("confirm", message="Passwords must match"),
|
|
],
|
|
)
|
|
confirm = PasswordField("Verify password", [validators.Required()])
|
|
submit = SubmitField("Login")
|
|
|
|
|
|
class ChangePasswordForm(FlaskForm):
|
|
old_password = PasswordField("Current Password", [validators.Required()])
|
|
password = PasswordField(
|
|
"Password",
|
|
[
|
|
validators.Required(),
|
|
validators.EqualTo("confirm", message="Passwords must match"),
|
|
],
|
|
)
|
|
confirm = PasswordField("Verify password", [validators.Required()])
|
|
submit = SubmitField("Change")
|