1
0

forms.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from django import forms
  2. from django.core.validators import RegexValidator, MaxLengthValidator
  3. from . models import Project, Setting
  4. numeric = RegexValidator(r'^[0-9+]', 'Only numeric characters.')
  5. time_max_length = MaxLengthValidator(4, 'Length limit exceeds 4 characters')
  6. max_daily_hours_length = MaxLengthValidator(2, 'Only 2 place values allowed')
  7. session_timeout_length = MaxLengthValidator(4, 'Only 4 place values allowed')
  8. hours = []
  9. try:
  10. max_daily_hours = Setting.objects.get(setting='Max Daily Hours')
  11. for hour in range(0, int(max_daily_hours.value)+1):
  12. hours.append(("%i" % hour, "%i" % hour))
  13. except Exception as e:
  14. print(e)
  15. for hour in range(0, 9):
  16. hours.append(("%i" % hour, "%i" % hour))
  17. minutes = (
  18. ('0', '0'),
  19. ('0.25', '15'),
  20. ('0.50', '30'),
  21. ('0.75', '45')
  22. )
  23. class LoginForm(forms.Form):
  24. pin = forms.CharField(strip=True, widget=forms.PasswordInput(attrs={
  25. 'class': 'form-control form-control-lg p-4 text-center',
  26. 'id': 'pin',
  27. 'placeholder': 'PIN',
  28. }), validators=[numeric])
  29. class CreateUserForm(forms.Form):
  30. first_name = forms.CharField(strip=True, required=True)
  31. last_name = forms.CharField(strip=True, required=True)
  32. pin = forms.CharField(strip=True, required=True, validators=[numeric], help_text="Numeric values only")
  33. class TimeEntryForm(forms.Form):
  34. project = forms.ModelChoiceField(Project.objects.all(), required=False, widget=forms.Select(attrs={
  35. 'class': 'form-control form-control-lg'
  36. }))
  37. hours = forms.ChoiceField(required=True, choices=hours, widget=forms.Select(attrs={
  38. 'class': 'form-control form-control-lg',
  39. }))
  40. minutes = forms.ChoiceField(required=True, choices=minutes, widget=forms.Select(attrs={
  41. 'class': 'form-control form-control-lg',
  42. }))
  43. class SettingsForm(forms.Form):
  44. max_daily_hours = forms.CharField(required=True, validators=[max_daily_hours_length])
  45. session_timeout = forms.CharField(required=True, validators=[session_timeout_length])
  46. allow_entry_edit = forms.BooleanField(required=True)