(feature) Add schedule editing view for hosts
Add a staff-only Django form for creating and updating host schedules using the SQL-backed ScheduleConfig model. Link the form from host detail pages, validate cron expressions with the existing scheduler parser, and preserve scheduler/CLI behavior by writing to the same source of truth. Cover default rendering, schedule creation, updates, and invalid cron handling with view tests.
This commit is contained in:
33
src/pobsync_backend/forms.py
Normal file
33
src/pobsync_backend/forms.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from django import forms
|
||||
|
||||
from .models import ScheduleConfig
|
||||
from .scheduler import parse_cron_expr
|
||||
|
||||
|
||||
class ScheduleConfigForm(forms.ModelForm):
|
||||
cron_expr = forms.CharField(
|
||||
label="Cron expression",
|
||||
help_text='Five-field cron expression, for example "15 2 * * *".',
|
||||
)
|
||||
prune_max_delete = forms.IntegerField(min_value=0)
|
||||
|
||||
class Meta:
|
||||
model = ScheduleConfig
|
||||
fields = (
|
||||
"cron_expr",
|
||||
"user",
|
||||
"enabled",
|
||||
"prune",
|
||||
"prune_max_delete",
|
||||
"prune_protect_bases",
|
||||
)
|
||||
|
||||
def clean_cron_expr(self) -> str:
|
||||
cron_expr = self.cleaned_data["cron_expr"].strip()
|
||||
try:
|
||||
parse_cron_expr(cron_expr)
|
||||
except ValueError as exc:
|
||||
raise forms.ValidationError(str(exc)) from exc
|
||||
return cron_expr
|
||||
Reference in New Issue
Block a user