Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forms.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from django import forms
  2. from datetime import datetime
  3. from .models import Post, CustomUser
  4. from django.forms import ModelForm, ValidationError
  5. from taggit.forms import *
  6. from django.contrib.auth.forms import UserCreationForm, UserChangeForm
  7. from datetime import datetime
  8. from croniter import croniter
  9. from django.forms import ModelForm, ValidationError
  10. from .models import ScheduledReport
  11. class PostForm(forms.ModelForm):
  12. class Meta:
  13. model = Post
  14. fields = ('title', 'text', 'published_date','tags')
  15. class NewTagForm(forms.ModelForm):
  16. m_tags = TagField()
  17. class Meta:
  18. model = CustomUser
  19. fields = ['m_tags']
  20. class ScheduledReportForm(ModelForm):
  21. class Meta:
  22. model = ScheduledReport
  23. fields = ['subject', 'cron_expression']
  24. fields = ['subject', 'cron_expression']
  25. help_texts = {'cron_expression': 'Scheduled time is considered in UTC'}
  26. def clean(self):
  27. cleaned_data = super(ScheduledReportForm, self).clean()
  28. cron_expression = cleaned_data.get("cron_expression")
  29. try:
  30. iter = croniter(cron_expression, datetime.now())
  31. except:
  32. raise ValidationError("Incorrect cron expression:\
  33. The information you must include is (in order of appearance):\
  34. A number (or list of numbers, or range of numbers), m, representing the minute of the hour\
  35. A number (or list of numbers, or range of numbers), h, representing the hour of the day\
  36. A number (or list of numbers, or range of numbers), dom, representing the day of the month\
  37. A number (or list, or range), or name (or list of names), mon, representing the month of the year\
  38. A number (or list, or range), or name (or list of names), dow, representing the day of the week\
  39. The asterisks (*) in our entry tell cron that for that unit of time, the job should be run every.\
  40. Eg. */5 * * * * cron for executing every 5 mins")
  41. return cleaned_data