BTHLABS-50: Safari Web extension

Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl>
Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
This commit is contained in:
2025-09-08 18:11:36 +00:00
committed by Tomek Wójcik
parent ffecf780ee
commit b6d02dbe78
184 changed files with 7536 additions and 163 deletions

View File

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
from crispy_forms.layout import Submit
from django import forms
from django.utils.translation import gettext_lazy as _
from hotpocket_backend.apps.ui.forms.base import ConfirmationMixin, Form
class AppForm(Form):
pass
class ConfirmationForm(ConfirmationMixin, AppForm):
origin_app = forms.CharField(
label=_('App'),
required=False,
disabled=True,
show_hidden_initial=True,
)
platform = forms.CharField(
label=_('Platform'),
required=False,
disabled=True,
show_hidden_initial=True,
)
version = forms.CharField(
label=_('Version'),
required=False,
disabled=True,
show_hidden_initial=True,
)
def get_layout_fields(self) -> list[str]:
return [
'canhazconfirm',
'origin_app',
'platform',
'version',
]
class DeleteForm(ConfirmationForm):
def get_submit_button(self) -> Submit:
return Submit('submit', _('Delete'), css_class='btn btn-danger')

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Submit
from django.contrib.auth.forms import (
AuthenticationForm as BaseAuthenticationForm,
)
from django.utils.translation import gettext_lazy as _
class LoginForm(BaseAuthenticationForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.attrs = {
'id': self.__class__.__name__,
'novalidate': '',
}
self.helper.layout = Layout(
'username',
'password',
FormActions(
Submit('submit', _('Log in'), css_class='btn btn-primary'),
template='ui/ui/forms/formactions.html',
css_class='mb-0',
),
)

View File

@@ -0,0 +1,194 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Submit
from django import forms
from django.contrib.auth.forms import (
PasswordChangeForm as BasePasswordChangeForm,
)
from django.utils.translation import gettext_lazy as _
from hotpocket_backend.apps.ui.forms.base import Form
class ProfileForm(Form):
INCLUDE_CANCEL = False
username = forms.CharField(
label=_('Username'),
disabled=True,
required=False,
)
first_name = forms.CharField(
label=_('First name'),
max_length=150,
required=True,
)
last_name = forms.CharField(
label=_('Last name'),
max_length=150,
required=True,
)
email = forms.EmailField(
label=_('E-mail address'),
required=True,
)
def get_layout_fields(self) -> list[str]:
return [
'username',
'first_name',
'last_name',
'email',
]
class FederatedProfileForm(ProfileForm):
username = forms.CharField(
label=_('Username'),
disabled=True,
required=False,
)
first_name = forms.CharField(
label=_('First name'),
disabled=True,
required=False,
)
last_name = forms.CharField(
label=_('Last name'),
disabled=True,
required=False,
)
email = forms.EmailField(
label=_('E-mail address'),
disabled=True,
required=False,
)
def get_submit_button(self) -> Submit:
return Submit(
'submit',
_('Save'),
css_class='btn btn-primary',
disabled=True,
)
def clean(self) -> dict:
return {}
class PasswordForm(BasePasswordChangeForm):
def get_submit_button(self) -> Submit:
return Submit(
'submit',
_('Save'),
css_class='btn btn-primary',
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-md-3 col-form-label'
self.helper.field_class = 'col-md-9'
self.helper.attrs = {
'id': self.__class__.__name__,
'novalidate': '',
}
self.helper.layout = Layout(
'old_password',
'new_password1',
'new_password2',
FormActions(
self.get_submit_button(),
template='ui/ui/forms/formactions-horizontal.html',
),
)
class FederatedPasswordForm(PasswordForm):
old_password = forms.CharField(
label=_('Old password'),
disabled=True,
required=False,
)
new_password1 = forms.CharField(
label=_('New password'),
disabled=True,
required=False,
)
new_password2 = forms.CharField(
label=_('New password confirmation'),
disabled=True,
required=False,
)
def get_submit_button(self) -> Submit:
return Submit(
'submit',
_('Save'),
css_class='btn btn-primary disable',
disabled=True,
)
def clean(self) -> dict:
return {}
class SettingsForm(Form):
INCLUDE_CANCEL = False
theme = forms.ChoiceField(
label=_('Theme'),
disabled=True,
required=False,
choices=[
(None, _('Bootstrap')),
('cosmo', _('Cosmo')),
],
show_hidden_initial=True,
)
auto_load_embeds = forms.ChoiceField(
label=_('Auto load embedded content'),
required=False,
choices=[
(None, _('---')),
(True, _('Yes')),
(False, _('No')),
],
help_text=_((
'Auto loading embedded content (e.g. YouTube videos) means that '
'you allow cookies from these sites.'
)),
)
def get_layout_fields(self) -> list[str]:
return [
'theme',
'auto_load_embeds',
]
def get_submit_button(self) -> Submit:
return Submit(
'submit',
_('Save'),
css_class='btn btn-primary',
)
def clean(self) -> dict:
result = super().clean()
theme = result.get('theme', None)
if not theme:
result['theme'] = None
auto_load_embeds = result.get('auto_load_embeds', None)
if not auto_load_embeds:
result['auto_load_embeds'] = None
else:
result['auto_load_embeds'] = (auto_load_embeds == 'True')
return result