lenticular_cloud2/lenticular_cloud/form/admin.py

61 lines
2.5 KiB
Python
Raw Normal View History

2022-02-19 09:21:00 +00:00
from flask_babel import gettext
from flask_wtf import FlaskForm
2022-06-17 07:25:14 +00:00
from wtforms import StringField, SubmitField, \
2022-02-19 09:21:00 +00:00
TextAreaField, PasswordField, IntegerField, FloatField, \
DateTimeField, DateField, FormField, BooleanField, \
SelectField, Form as NoCsrfForm, SelectMultipleField
2022-06-17 07:25:14 +00:00
from wtforms.fields import URLField
from wtforms.fields import FormField, SelectMultipleField
2022-02-19 09:21:00 +00:00
from .base import FieldList
class SerilizedSelectField(SelectMultipleField):
def process_data(self, value):
try:
self.data = ','.join(list(self.coerce(v) for v in value))
except (ValueError, TypeError):
self.data = None
def process_formdata(self, valuelist):
try:
self.data = ','.join(list(self.coerce(x) for x in valuelist))
except ValueError as exc:
raise ValueError(
self.gettext(
"Invalid choice(s): one or more data inputs could not be coerced."
)
) from exc
def populate_obj(self, obj, name) -> None:
setattr(obj, name, ','.join(self.data))
2022-02-19 09:21:00 +00:00
class OAuth2ClientForm(FlaskForm):
client_id = StringField(gettext('client_id') )
client_name = StringField(gettext('client_name'))
client_uri = URLField(gettext('client_uri'))
2023-01-13 16:08:27 +00:00
token_endpoint_auth_method = SelectField('token_endpoint_auth_method', choices=[(x, x) for x in ['client_secret_basic', 'client_secret_post', 'private_key_jwt', 'none']])
2022-02-19 09:21:00 +00:00
client_secret = PasswordField(gettext('client_secret'))
logo_uri = URLField(gettext('logo_uri'))
redirect_uris = FieldList(URLField(gettext('redirect_uri')), min_entries=1)
contacts = FieldList(StringField('contacts'))
2023-01-13 16:08:27 +00:00
grant_types = SelectMultipleField('grant_types',choices=[(x, x) for x in ['authorization_code', 'refresh_token', 'implicit', 'urn:ietf:params:oauth:grant-type:jwt-bearer']])
response_types = SelectMultipleField('repsonse_type',choices=[(x, x) for x in ['code', 'token', 'id_token']])
2022-02-19 09:21:00 +00:00
scope = StringField(gettext('scope'))
subject_type = StringField(gettext('subject_type'))
2023-01-13 16:08:27 +00:00
userinfo_signed_response_alg = SelectField(gettext('userinfo_signed_response_alg'), choices=[(x, x) for x in ['none', 'RS256']])
allowed_cors_origins = FieldList(StringField('allowed_cors_origins'))
2022-02-19 09:21:00 +00:00
client_secret_expires_at = IntegerField('client_secret_expires_at')
#allowed_cross_origins = Array
contacts = FieldList(StringField('contacts'))
2022-02-19 09:21:00 +00:00
#audience = List[str]
submit = SubmitField(gettext('Update'))