forms.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. from django.utils import timezone
  2. from django import forms
  3. from django.contrib.auth.models import User
  4. from name_extractor.models import Staff
  5. from django.contrib.auth.forms import UserCreationForm
  6. from tempus_dominus.widgets import DatePicker
  7. GOOGLE_CHOICE = [
  8. (1, '1* rating'),
  9. (2, '2* rating'),
  10. (3, '3* rating'),
  11. (4, '4* rating'),
  12. (5, '5* rating'),
  13. (6, 'All Reviews'),
  14. ]
  15. FACEBOOK_CHOICE = [
  16. (1, 'Recommended'),
  17. (0, 'Not Recommended'),
  18. (6, 'All Reviews')
  19. ]
  20. class UserRegisterForm(UserCreationForm):
  21. email = forms.EmailField()
  22. class Meta:
  23. model = User
  24. fields = ['username', 'email', 'password1', 'password2']
  25. class StaffRegistrationForm(forms.ModelForm):
  26. class Meta:
  27. model = Staff
  28. fields = ['name', 'department', 'nick_names']
  29. class StaffSheetDateForm(forms.Form):
  30. now = timezone.now()
  31. today = now.date().strftime('%Y-%m-%d')
  32. last_month = (now - timezone.timedelta(days=30)).replace(day=now.day).date().strftime('%Y-%m-%d')
  33. start_date = forms.DateField(
  34. required=True,
  35. widget=DatePicker(
  36. options={
  37. 'minDate': '2012-01-01',
  38. 'maxDate': today,
  39. },
  40. attrs={
  41. 'append': 'fa fa-calendar',
  42. 'icon_toggle': True,
  43. }
  44. ),
  45. initial=last_month,
  46. )
  47. end_date = forms.DateField(
  48. required=True,
  49. widget=DatePicker(
  50. options={
  51. 'minDate': '2012-01-01',
  52. 'maxDate': today,
  53. },
  54. attrs={
  55. 'append': 'fa fa-calendar',
  56. 'icon_toggle': True,
  57. }
  58. ),
  59. initial=today,
  60. )
  61. class GoogleReviewsFilter(forms.Form):
  62. now = timezone.now()
  63. today = now.date().strftime('%Y-%m-%d')
  64. last_month = (now - timezone.timedelta(days=30)).replace(day=now.day).date().strftime('%Y-%m-%d')
  65. start_date = forms.DateField(
  66. required=True,
  67. widget=DatePicker(
  68. options={
  69. 'minDate': '2012-01-01',
  70. 'maxDate': today,
  71. },
  72. attrs={
  73. 'append': 'fa fa-calendar',
  74. 'icon_toggle': True,
  75. }
  76. ),
  77. initial=last_month,
  78. )
  79. end_date = forms.DateField(
  80. required=True,
  81. widget=DatePicker(
  82. options={
  83. 'minDate': '2012-01-01',
  84. 'maxDate': today,
  85. },
  86. attrs={
  87. 'append': 'fa fa-calendar',
  88. 'icon_toggle': True,
  89. }
  90. ),
  91. initial=today,
  92. )
  93. star_ratings = forms.MultipleChoiceField(
  94. required=False,
  95. choices=GOOGLE_CHOICE,
  96. widget=forms.Select(attrs={'class': 'custom-select'}),
  97. initial=(6, 'All reviews')
  98. )
  99. class FacebookReviewsFilter(forms.Form):
  100. now = timezone.now()
  101. today = now.date().strftime('%Y-%m-%d')
  102. last_month = (now - timezone.timedelta(days=30)).replace(day=now.day).date().strftime('%Y-%m-%d')
  103. start_date = forms.DateField(
  104. required=True,
  105. widget=DatePicker(
  106. options={
  107. 'minDate': '2012-01-01',
  108. 'maxDate': today,
  109. },
  110. attrs={
  111. 'append': 'fa fa-calendar',
  112. 'icon_toggle': True,
  113. }
  114. ),
  115. initial=last_month,
  116. )
  117. end_date = forms.DateField(
  118. required=True,
  119. widget=DatePicker(
  120. options={
  121. 'minDate': '2012-01-01',
  122. 'maxDate': today,
  123. },
  124. attrs={
  125. 'append': 'fa fa-calendar',
  126. 'icon_toggle': True,
  127. }
  128. ),
  129. initial=today,
  130. )
  131. star_ratings = forms.MultipleChoiceField(
  132. required=False,
  133. choices=FACEBOOK_CHOICE,
  134. widget=forms.Select(attrs={'class': 'custom-select'}),
  135. initial=(6, 'All Reviews')
  136. )