46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
from datetime import timedelta
|
|
|
|
from django import forms
|
|
from django.utils import timezone
|
|
|
|
from .models import TimelapseJob
|
|
|
|
|
|
class TimelapseJobCreateForm(forms.ModelForm):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
if not self.is_bound:
|
|
today = timezone.localdate()
|
|
self.initial.setdefault('date_to', today)
|
|
self.initial.setdefault('date_from', today - timedelta(days=7))
|
|
|
|
class Meta:
|
|
model = TimelapseJob
|
|
fields = (
|
|
'date_from',
|
|
'date_to',
|
|
'sampling_preset',
|
|
'fps',
|
|
'include_night',
|
|
'anchor_time',
|
|
'day_start_time',
|
|
'day_end_time',
|
|
)
|
|
widgets = {
|
|
'date_from': forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}),
|
|
'date_to': forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}),
|
|
'sampling_preset': forms.NumberInput(
|
|
attrs={
|
|
'type': 'range',
|
|
'min': 0,
|
|
'max': len(TimelapseJob.SAMPLING_PRESET_MINUTES) - 1,
|
|
'step': 1,
|
|
'class': 'form-range',
|
|
}
|
|
),
|
|
'fps': forms.NumberInput(attrs={'class': 'form-control', 'min': 1, 'max': 120}),
|
|
'include_night': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
|
|
'anchor_time': forms.TimeInput(attrs={'type': 'time', 'class': 'form-control', 'step': 60}),
|
|
'day_start_time': forms.TimeInput(attrs={'type': 'time', 'class': 'form-control'}),
|
|
'day_end_time': forms.TimeInput(attrs={'type': 'time', 'class': 'form-control'}),
|
|
} |