added Support for ntfy and apprise

This commit is contained in:
jschaufuss@leitwerk.de
2025-08-15 13:02:19 +02:00
parent 839fafdb33
commit defbe0dc9c
14 changed files with 443 additions and 103 deletions

View File

@@ -14,9 +14,11 @@ class CustomUserChangeForm(UserChangeForm):
class Meta:
model = User
fields = ('email',)
fields = ('email', 'notification_channel', 'ntfy_topic', 'apprise_url')
widgets = {
'email': forms.EmailInput(attrs={'class': 'text-input', 'placeholder': 'Email address'}),
'ntfy_topic': forms.TextInput(attrs={'class': 'text-input', 'placeholder': 'ntfy topic (optional)'}),
'apprise_url': forms.Textarea(attrs={'rows': 2, 'placeholder': 'apprise://... or other URL'}),
}
class JellyfinLoginForm(forms.Form):

View File

@@ -0,0 +1,26 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0002_user_jellyfin_server_user_jellyfin_token_and_more'),
]
operations = [
migrations.AddField(
model_name='user',
name='notification_channel',
field=models.CharField(choices=[('email', 'Email'), ('ntfy', 'ntfy'), ('apprise', 'Apprise')], default='email', max_length=10),
),
migrations.AddField(
model_name='user',
name='ntfy_topic',
field=models.CharField(blank=True, max_length=200, null=True),
),
migrations.AddField(
model_name='user',
name='apprise_url',
field=models.TextField(blank=True, null=True),
),
]

View File

@@ -16,6 +16,24 @@ class User(AbstractUser):
jellyfin_user_id = models.CharField(max_length=100, blank=True, null=True)
jellyfin_token = models.CharField(max_length=500, blank=True, null=True)
jellyfin_server = models.CharField(max_length=200, blank=True, null=True)
# Notifications
NOTIFY_EMAIL = 'email'
NOTIFY_NTFY = 'ntfy'
NOTIFY_APPRISE = 'apprise'
NOTIFY_CHOICES = [
(NOTIFY_EMAIL, 'Email'),
(NOTIFY_NTFY, 'ntfy'),
(NOTIFY_APPRISE, 'Apprise'),
]
notification_channel = models.CharField(
max_length=10,
choices=NOTIFY_CHOICES,
default=NOTIFY_EMAIL,
)
# Optional per-user targets/overrides
ntfy_topic = models.CharField(max_length=200, blank=True, null=True)
apprise_url = models.TextField(blank=True, null=True)
def check_jellyfin_admin(self):
"""Check if user is Jellyfin admin on the server"""

View File

@@ -18,13 +18,26 @@
{% endif %}
<div class="profile-section">
<h3>Email address</h3>
<h3>Notifications</h3>
<form method="post" class="profile-form compact-form">
{% csrf_token %}
<div class="form-row">
<label for="id_email">Email</label>
{{ form.email }}
</div>
<div class="form-row">
<label for="id_notification_channel">Channel</label>
{{ form.notification_channel }}
<div class="help">Email, ntfy, or Apprise</div>
</div>
<div class="form-row">
<label for="id_ntfy_topic">ntfy topic (optional)</label>
{{ form.ntfy_topic }}
</div>
<div class="form-row">
<label for="id_apprise_url">Apprise URL(s)</label>
{{ form.apprise_url }}
</div>
<button type="submit" class="btn-primary">Save</button>
</form>

View File

@@ -26,7 +26,7 @@ def profile(request):
form = CustomUserChangeForm(request.POST, instance=request.user)
if form.is_valid():
form.save()
messages.success(request, 'Email saved.')
messages.success(request, 'Profile saved.')
return redirect('accounts:profile')
else:
form = CustomUserChangeForm(instance=request.user)