default.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from __future__ import unicode_literals
  2. import re
  3. from django.forms import ValidationError
  4. from django.utils.translation import ugettext, ugettext_lazy as _
  5. from . import basefields
  6. class BioField(basefields.UrlifiedTextareaProfileField):
  7. fieldname = 'bio'
  8. label = _("Bio")
  9. class FullNameField(basefields.TextProfileField):
  10. fieldname = 'fullname'
  11. label = _("Full name")
  12. class LocationField(basefields.TextProfileField):
  13. fieldname = 'location'
  14. label = _("Location")
  15. class GenderField(basefields.ChoiceProfileField):
  16. fieldname = 'gender'
  17. label = _("Gender")
  18. choices = (
  19. ('', _('Not specified')),
  20. ('secret', _('Not telling')),
  21. ('female', _('Female')),
  22. ('male', _('Male')),
  23. )
  24. class WebsiteField(basefields.UrlProfileField):
  25. fieldname = 'website'
  26. label = _("Website")
  27. class SkypeHandleField(basefields.TextProfileField):
  28. fieldname = 'skype'
  29. label = _("Skype ID")
  30. class TwitterHandleField(basefields.TextProfileField):
  31. fieldname = 'twitter'
  32. label = _("Twitter handle")
  33. help_text = _('Without leading "@" sign.')
  34. def get_value_display_data(self, request, user, data):
  35. return {
  36. 'text': '@{}'.format(data),
  37. 'url': 'https://twitter.com/{}'.format(data),
  38. }
  39. def clean(self, request, user, data):
  40. data = data.lstrip('@')
  41. if data and not re.search('^[A-Za-z0-9_]+$', data):
  42. raise ValidationError(ugettext("This is not a valid twitter handle."))
  43. return data