mirror of
https://github.com/Django-LiveView/demo-alarms
synced 2026-01-09 06:43:41 +01:00
Real-time alert system using Django LiveView with WebSocket support. Features include: - Real-time alert creation, viewing, and deletion - Broadcast notifications to all connected users - SQLite database - Stimulus.js integration for interactive UI - Modal dialogs for alert details - Alert form with validation Fixed Stimulus controller scope issue by placing data-controller on html element.
21 lines
712 B
Python
21 lines
712 B
Python
from django import forms
|
|
from .models import Alert
|
|
|
|
|
|
class AlertForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Alert
|
|
fields = ['type', 'description']
|
|
widgets = {
|
|
'type': forms.Select(attrs={'class': 'input'}),
|
|
'description': forms.Textarea(attrs={'class': 'textarea', 'rows': 4}),
|
|
}
|
|
|
|
def clean_description(self):
|
|
description = self.cleaned_data.get('description')
|
|
if not description or len(description.strip()) == 0:
|
|
raise forms.ValidationError('Description is required.')
|
|
if len(description) > 500:
|
|
raise forms.ValidationError('Description must be less than 500 characters.')
|
|
return description
|