/graph/forms.py

https://github.com/jblomo/twigra · Python · 104 lines · 8 code · 1 blank · 95 comment · 0 complexity · e45b0bae2d0450fe61daaa06971c2d6c MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. from django import forms
  3. from django.contrib.auth.models import User
  4. from django.core.files.uploadedfile import UploadedFile
  5. from django.utils.translation import ugettext_lazy as _, ugettext as __
  6. #from myapp.models import Person, File, Contract
  7. from ragendja.auth.models import UserTraits
  8. from ragendja.forms import FormWithSets, FormSetField
  9. from registration.forms import RegistrationForm, RegistrationFormUniqueEmail
  10. from registration.models import RegistrationProfile
  11. # class UserRegistrationForm(forms.ModelForm):
  12. # username = forms.RegexField(regex=r'^\w+$', max_length=30,
  13. # label=_(u'Username'))
  14. # email = forms.EmailField(widget=forms.TextInput(attrs=dict(maxlength=75)),
  15. # label=_(u'Email address'))
  16. # password1 = forms.CharField(widget=forms.PasswordInput(render_value=False),
  17. # label=_(u'Password'))
  18. # password2 = forms.CharField(widget=forms.PasswordInput(render_value=False),
  19. # label=_(u'Password (again)'))
  20. #
  21. # def clean_username(self):
  22. # """
  23. # Validate that the username is alphanumeric and is not already
  24. # in use.
  25. #
  26. # """
  27. # user = User.get_by_key_name("key_"+self.cleaned_data['username'].lower())
  28. # if user and user.is_active:
  29. # raise forms.ValidationError(__(u'This username is already taken. Please choose another.'))
  30. # return self.cleaned_data['username']
  31. #
  32. # def clean(self):
  33. # """
  34. # Verifiy that the values entered into the two password fields
  35. # match. Note that an error here will end up in
  36. # ``non_field_errors()`` because it doesn't apply to a single
  37. # field.
  38. #
  39. # """
  40. # if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
  41. # if self.cleaned_data['password1'] != self.cleaned_data['password2']:
  42. # raise forms.ValidationError(__(u'You must type the same password each time'))
  43. # return self.cleaned_data
  44. #
  45. # def save(self, domain_override=""):
  46. # """
  47. # Create the new ``User`` and ``RegistrationProfile``, and
  48. # returns the ``User``.
  49. #
  50. # This is essentially a light wrapper around
  51. # ``RegistrationProfile.objects.create_inactive_user()``,
  52. # feeding it the form data and a profile callback (see the
  53. # documentation on ``create_inactive_user()`` for details) if
  54. # supplied.
  55. #
  56. # """
  57. # new_user = RegistrationProfile.objects.create_inactive_user(
  58. # username=self.cleaned_data['username'],
  59. # password=self.cleaned_data['password1'],
  60. # email=self.cleaned_data['email'],
  61. # domain_override=domain_override)
  62. # self.instance = new_user
  63. # return super(UserRegistrationForm, self).save()
  64. #
  65. # def clean_email(self):
  66. # """
  67. # Validate that the supplied email address is unique for the
  68. # site.
  69. #
  70. # """
  71. # email = self.cleaned_data['email'].lower()
  72. # if User.all().filter('email =', email).filter(
  73. # 'is_active =', True).count(1):
  74. # raise forms.ValidationError(__(u'This email address is already in use. Please supply a different email address.'))
  75. # return email
  76. #
  77. # class Meta:
  78. # model = User
  79. # exclude = UserTraits.properties().keys()
  80. #
  81. # class FileForm(forms.ModelForm):
  82. # name = forms.CharField(required=False, label='Name (set automatically)')
  83. #
  84. # def clean(self):
  85. # file = self.cleaned_data.get('file')
  86. # if not self.cleaned_data.get('name'):
  87. # if isinstance(file, UploadedFile):
  88. # self.cleaned_data['name'] = file.name
  89. # else:
  90. # del self.cleaned_data['name']
  91. # return self.cleaned_data
  92. #
  93. # class Meta:
  94. # model = File
  95. #
  96. # class PersonForm(forms.ModelForm):
  97. # files = FormSetField(File, form=FileForm, exclude='content_type')
  98. # employers = FormSetField(Contract, fk_name='employee')
  99. # employees = FormSetField(Contract, fk_name='employer')
  100. #
  101. # class Meta:
  102. # model = Person
  103. # PersonForm = FormWithSets(PersonForm)