default.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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
  44. class JoinIpField(basefields.TextProfileField):
  45. fieldname = 'join_ip'
  46. label = _("Join IP")
  47. readonly = True
  48. def get_value_display_data(self, request, user, value):
  49. if not request.user.acl_cache.get('can_see_users_ips'):
  50. return None
  51. return {
  52. 'text': user.joined_from_ip
  53. }
  54. class LastIpField(basefields.TextProfileField):
  55. fieldname = 'last_ip'
  56. label = _("Last IP")
  57. readonly = True
  58. def get_value_display_data(self, request, user, value):
  59. if not request.user.acl_cache.get('can_see_users_ips'):
  60. return None
  61. return {
  62. 'text': user.last_ip or user.joined_from_ip
  63. }