Skip to content

Commit

Permalink
Merge pull request #335 from CTPUG/bugs/issue-235-twitter-handle-fixes
Browse files Browse the repository at this point in the history
Bugs/issue 235 twitter handle fixes
  • Loading branch information
drnlm committed Jan 25, 2017
2 parents 7338047 + 0903ab7 commit 85e7886
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions wafer/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def __init__(self, *args, **kwargs):
username = kwargs['instance'].user.username
self.helper.form_action = reverse('wafer_user_edit_profile',
args=(username,))
self.helper['twitter_handle'].wrap(PrependedText, 'twitter_handle',
self.helper['twitter_handle'].wrap(PrependedText,
'@', placeholder=_('handle'))
self.helper['github_username'].wrap(PrependedText, 'github_username',
self.helper['github_username'].wrap(PrependedText,
'@', placeholder=_('username'))
self.helper.add_input(Submit('submit', _('Save')))

Expand Down
11 changes: 10 additions & 1 deletion wafer/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db.models import Q
from django.db.models.signals import post_save
from django.utils.encoding import python_2_unicode_compatible
from django.core.validators import RegexValidator

from libravatar import libravatar_url
try:
Expand All @@ -16,6 +17,13 @@
PROVISIONAL, CANCELLED)


# validate format of twitter handle
# Max 15 characters, alphanumeric and _ only
# Specification taken from https://support.twitter.com/articles/101299
TwitterValidator = RegexValidator('^[A-Za-z0-9_]{1,15}$',
'Incorrectly formatted twitter handle')


@python_2_unicode_compatible
class UserProfile(models.Model):

Expand All @@ -30,7 +38,8 @@ class Meta:
homepage = models.CharField(max_length=256, null=True, blank=True)
# We should probably do social auth instead
# And care about other code hosting sites...
twitter_handle = models.CharField(max_length=15, null=True, blank=True)
twitter_handle = models.CharField(max_length=15, null=True, blank=True,
validators=[TwitterValidator])
github_username = models.CharField(max_length=32, null=True, blank=True)

def __str__(self):
Expand Down

0 comments on commit 85e7886

Please sign in to comment.