UI tweaks

This commit is contained in:
2026-05-11 21:53:43 +10:00
parent ea1417a04f
commit f587ab3053
6 changed files with 155 additions and 57 deletions
+5 -3
View File
@@ -11,17 +11,19 @@ class PriceWatcherForm(forms.ModelForm):
model = PriceWatcher
fields = [
'name', 'url', 'css_selector', 'check_interval_hours',
'alert_threshold_pct', 'enabled',
'alert_price_threshold', 'recurring_notification', 'enabled',
]
widgets = {
'name': forms.TextInput(attrs={'class': _input}),
'url': forms.URLInput(attrs={'class': _input}),
'css_selector': forms.TextInput(attrs={'class': _mono, 'placeholder': 'e.g. span.price or .product-price'}),
'check_interval_hours': forms.Select(attrs={'class': _select}),
'alert_threshold_pct': forms.NumberInput(attrs={'class': _input, 'step': '0.01', 'min': '0'}),
'alert_price_threshold': forms.NumberInput(attrs={'class': _input, 'step': '0.01', 'min': '0', 'placeholder': 'e.g. 999.00'}),
'recurring_notification': forms.CheckboxInput(attrs={'class': 'h-4 w-4 text-indigo-600 border-gray-300 rounded'}),
'enabled': forms.CheckboxInput(attrs={'class': 'h-4 w-4 text-indigo-600 border-gray-300 rounded'}),
}
help_texts = {
'css_selector': 'CSS selector pointing to the element containing the price text.',
'alert_threshold_pct': 'Minimum percentage drop to send an alert. Use 0 to alert on any drop.',
'alert_price_threshold': 'Notify when detected price is at or below this amount. Leave blank to disable alerts.',
'recurring_notification': 'Keep notifying on every check while the price meets the threshold. Uncheck to notify only once (until the alert is dismissed).',
}
@@ -0,0 +1,42 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pricemon', '0003_delete_pricemonsettings'),
]
operations = [
migrations.RenameField(
model_name='pricewatcher',
old_name='alert_threshold_pct',
new_name='alert_price_threshold',
),
migrations.AlterField(
model_name='pricewatcher',
name='alert_price_threshold',
field=models.DecimalField(
blank=True, decimal_places=2, max_digits=12, null=True,
help_text='Send an alert when the detected price is at or below this value. Leave blank to disable alerts.',
),
),
migrations.AddField(
model_name='pricewatcher',
name='recurring_notification',
field=models.BooleanField(
default=True,
help_text='Keep notifying on every check while the price meets the threshold. Disable to notify only once (until you dismiss the alert).',
),
),
migrations.AlterField(
model_name='pricealert',
name='old_price',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True),
),
migrations.AlterField(
model_name='pricealert',
name='drop_pct',
field=models.DecimalField(decimal_places=2, default=0, max_digits=5),
),
]
+9 -5
View File
@@ -18,9 +18,13 @@ class PriceWatcher(models.Model):
help_text='CSS selector for the price element, e.g. span.price or .product-price',
)
check_interval_hours = models.IntegerField(choices=INTERVAL_CHOICES, default=24)
alert_threshold_pct = models.DecimalField(
max_digits=5, decimal_places=2, default=0,
help_text='Minimum % price drop to trigger an alert (0 = any drop)',
alert_price_threshold = models.DecimalField(
max_digits=12, decimal_places=2, null=True, blank=True,
help_text='Send an alert when the detected price is at or below this value. Leave blank to disable alerts.',
)
recurring_notification = models.BooleanField(
default=True,
help_text='Keep notifying on every check while the price meets the threshold. Disable to notify only once (until you dismiss the alert).',
)
enabled = models.BooleanField(default=True)
last_checked_at = models.DateTimeField(null=True, blank=True)
@@ -50,9 +54,9 @@ class PriceSnapshot(models.Model):
class PriceAlert(models.Model):
watcher = models.ForeignKey(PriceWatcher, on_delete=models.CASCADE, related_name='alerts')
old_price = models.DecimalField(max_digits=12, decimal_places=2)
old_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
new_price = models.DecimalField(max_digits=12, decimal_places=2)
drop_pct = models.DecimalField(max_digits=5, decimal_places=2)
drop_pct = models.DecimalField(max_digits=5, decimal_places=2, default=0)
created_at = models.DateTimeField(auto_now_add=True)
dismissed = models.BooleanField(default=False)
+22 -10
View File
@@ -28,16 +28,28 @@ def check_watcher(watcher_pk: int) -> None:
error=error or '',
)
if price is not None and watcher.last_price is not None and price < watcher.last_price:
drop_pct = (watcher.last_price - price) / watcher.last_price * 100
if drop_pct >= watcher.alert_threshold_pct:
alert = PriceAlert.objects.create(
watcher=watcher,
old_price=watcher.last_price,
new_price=price,
drop_pct=drop_pct,
)
notify_telegram(watcher, alert)
if price is not None and watcher.alert_price_threshold:
if price <= watcher.alert_price_threshold:
should_alert = True
if not watcher.recurring_notification:
# Only alert if there is no undismissed alert already
if PriceAlert.objects.filter(watcher=watcher, dismissed=False).exists():
should_alert = False
if should_alert:
old_price = watcher.last_price
drop_pct = 0
if old_price and old_price > price:
drop_pct = (old_price - price) / old_price * 100
alert = PriceAlert.objects.create(
watcher=watcher,
old_price=old_price,
new_price=price,
drop_pct=drop_pct,
)
notify_telegram(watcher, alert)
update_fields = ['last_checked_at']
if price is not None: