forms.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from django import forms
  2. from .models import Contrib
  3. ORIENTATIONS = (
  4. ('N', 'Nord'),
  5. ('NO', 'Nord-Ouest'),
  6. ('O', 'Ouest'),
  7. ('SO', 'Sud-Ouest'),
  8. ('S', 'Sud'),
  9. ('SE', 'Sud-Est'),
  10. ('E', 'Est'),
  11. ('NE', 'Nord-Est'),
  12. )
  13. class PublicContribForm(forms.ModelForm):
  14. class Meta:
  15. model = Contrib
  16. fields = [
  17. 'name', 'contrib_type',
  18. 'latitude', 'longitude',
  19. 'phone', 'email',
  20. 'comment',
  21. 'access_type',
  22. 'connect_local', 'connect_internet',
  23. 'bandwidth', 'share_part',
  24. 'floor', 'floor_total', 'orientations', 'roof',
  25. 'comment',
  26. 'privacy_name', 'privacy_email', 'privacy_coordinates',
  27. 'privacy_place_details', 'privacy_comment',
  28. ]
  29. widgets = {
  30. 'contrib_type': forms.RadioSelect,
  31. 'latitude': forms.HiddenInput,
  32. 'longitude': forms.HiddenInput,
  33. 'access_type': forms.RadioSelect,
  34. 'connect_local': forms.CheckboxInput,
  35. 'connect_internet': forms.CheckboxInput,
  36. 'comment': forms.Textarea({'rows': 3}),
  37. 'floor': forms.TextInput(
  38. attrs={'placeholder': "Étage (0 pour RDC)"}),
  39. 'floor_total': forms.TextInput(
  40. attrs={'placeholder': "Nb. d'étages du bâtiment"}),
  41. }
  42. # Widget rendering is managed by hand in template for orientions.
  43. orientations = forms.MultipleChoiceField(choices=ORIENTATIONS)
  44. _privacy_fieldnames = (
  45. 'privacy_name', 'privacy_email', 'privacy_coordinates',
  46. 'privacy_place_details', 'privacy_comment',
  47. )
  48. def privacy_fields(self):
  49. for i in self._privacy_fieldnames:
  50. field = self[i]
  51. # FIXME: What a hack
  52. field.label = field.label\
  53. .replace('public', '')\
  54. .replace('publiques', '')
  55. yield field