mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-09-14 05:42:00 +02:00
feat(transactions): update cuelume; bring back improved volume user setting
This commit is contained in:
@@ -3,3 +3,20 @@ from crispy_forms.layout import Field
|
||||
|
||||
class Switch(Field):
|
||||
template = "crispy-daisyui/layout/switch.html"
|
||||
|
||||
|
||||
class Range(Field):
|
||||
template = "crispy-daisyui/layout/range.html"
|
||||
|
||||
def render(self, form, context, extra_context=None, **kwargs):
|
||||
extra_context = extra_context or {}
|
||||
|
||||
# Build the measure (ticks + labels) from the field's min/max/step
|
||||
attrs = form.fields[self.fields[0]].widget.attrs
|
||||
if "min" in attrs and "max" in attrs:
|
||||
step = attrs.get("step") or 1
|
||||
extra_context["range_steps"] = list(
|
||||
range(int(attrs["min"]), int(attrs["max"]) + 1, int(step))
|
||||
)
|
||||
|
||||
return super().render(form, context, extra_context=extra_context, **kwargs)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
from django import forms
|
||||
|
||||
|
||||
class RangeInput(forms.NumberInput):
|
||||
input_type = "range"
|
||||
+18
-1
@@ -2,7 +2,9 @@ from datetime import timedelta
|
||||
|
||||
from apps.common.middleware.thread_local import get_current_user
|
||||
from apps.users.models import APIToken
|
||||
from apps.common.widgets.crispy.daisyui import Range
|
||||
from apps.common.widgets.crispy.submit import NoClassSubmit
|
||||
from apps.common.widgets.range import RangeInput
|
||||
from apps.common.widgets.tom_select import TomSelect
|
||||
from apps.users.models import UserSettings
|
||||
from apps.accounts.models import Account
|
||||
@@ -131,6 +133,20 @@ class UserSettingsForm(forms.ModelForm):
|
||||
required=False,
|
||||
)
|
||||
|
||||
volume = forms.IntegerField(
|
||||
min_value=0,
|
||||
max_value=10,
|
||||
label=_("Volume"),
|
||||
help_text=_("Set to 0 to mute all sounds"),
|
||||
widget=RangeInput(
|
||||
attrs={
|
||||
"step": 1,
|
||||
# Preview the selected volume
|
||||
"_": "on change call playSound('sparkle', my valueAsNumber)",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = UserSettings
|
||||
fields = [
|
||||
@@ -141,6 +157,7 @@ class UserSettingsForm(forms.ModelForm):
|
||||
"datetime_format",
|
||||
"number_format",
|
||||
"default_account",
|
||||
"volume",
|
||||
]
|
||||
widgets = {
|
||||
"default_account": TomSelect(clear_button=False, group_by="group"),
|
||||
@@ -167,7 +184,7 @@ class UserSettingsForm(forms.ModelForm):
|
||||
"start_page",
|
||||
"default_account",
|
||||
HTML('<hr class="hr my-3" />'),
|
||||
"volume",
|
||||
Range("volume"),
|
||||
FormActions(
|
||||
NoClassSubmit("submit", _("Save"), css_class="btn btn-primary"),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.2.16 on 2026-09-12 21:53
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0027_alter_usersettings_timezone'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='usersettings',
|
||||
name='volume',
|
||||
field=models.PositiveIntegerField(default=10, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(10)], verbose_name='Volume'),
|
||||
),
|
||||
]
|
||||
@@ -481,7 +481,7 @@ class UserSettings(models.Model):
|
||||
mute_sounds = models.BooleanField(default=False)
|
||||
volume = models.PositiveIntegerField(
|
||||
default=10,
|
||||
validators=[MinValueValidator(1), MaxValueValidator(10)],
|
||||
validators=[MinValueValidator(0), MaxValueValidator(10)],
|
||||
verbose_name=_("Volume"),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user