default.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. help_text = _(
  28. 'If you own website in the internet you wish to share on your profile '
  29. 'you may enter its address here. Remember to for it to be valid http '
  30. 'address starting with either "http://" or "https://".'
  31. )
  32. class SkypeHandleField(basefields.TextProfileField):
  33. fieldname = 'skype'
  34. label = _("Skype ID")
  35. help_text = _(
  36. "Entering your Skype ID in this field may invite other users to contact you over "
  37. "the Skype instead of via private threads."
  38. )
  39. class TwitterHandleField(basefields.TextProfileField):
  40. fieldname = 'twitter'
  41. label = _("Twitter handle")
  42. def get_help_text(self, user):
  43. return _(
  44. 'If you own Twitter account, here you may enter your Twitter handle for other users '
  45. 'to find you. Starting your handle with "@" sign is optional. Either "@%(slug)s" or '
  46. '"%(slug)s" are valid values.'
  47. ) % {
  48. 'slug': user.slug
  49. }
  50. def get_value_display_data(self, request, user, data):
  51. return {
  52. 'text': '@{}'.format(data),
  53. 'url': 'https://twitter.com/{}'.format(data),
  54. }
  55. def clean(self, request, user, data):
  56. data = data.lstrip('@')
  57. if data and not re.search('^[A-Za-z0-9_]+$', data):
  58. raise ValidationError(ugettext("This is not a valid twitter handle."))
  59. return data
  60. class JoinIpField(basefields.TextProfileField):
  61. fieldname = 'join_ip'
  62. label = _("Join IP")
  63. readonly = True
  64. def get_value_display_data(self, request, user, value):
  65. if not request.user.acl_cache.get('can_see_users_ips'):
  66. return None
  67. return {
  68. 'text': user.joined_from_ip
  69. }
  70. class LastIpField(basefields.TextProfileField):
  71. fieldname = 'last_ip'
  72. label = _("Last IP")
  73. readonly = True
  74. def get_value_display_data(self, request, user, value):
  75. if not request.user.acl_cache.get('can_see_users_ips'):
  76. return None
  77. return {
  78. 'text': user.last_ip or user.joined_from_ip
  79. }