Skip to content

Commit

Permalink
fix page_url bug
Browse files Browse the repository at this point in the history
  • Loading branch information
baffolobill committed Apr 11, 2012
1 parent e417239 commit b7b92d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cgpeople_me/apps/generic/forms.py
Expand Up @@ -82,13 +82,14 @@ def clean_page_url(self):
raise forms.ValidationError(_('Page url may contain only latin letters, numbers and minus sign.'))

if url in app_settings.RESERVED_USERNAMES:
raise forms.ValidationError(_('That page url is in reserved words.'))
raise forms.ValidationError(_('That page url is reserved.'))

# check if user paid for that
if not self.instance.is_paid and url != self.instance.username:
raise forms.ValidationError(_('It is a paid service a change page url.'))

if not len(Profile.objects.filter(page_url=url).exclude(user=self.instance.user)):
if not len(Profile.objects.filter(page_url=url).exclude(user=self.instance.user)) \
and not len(User.objects.filter(username=url).exclude(id=self.instance.user.id)):
return url

raise forms.ValidationError(_('That page url is already used.'))
Expand Down
10 changes: 9 additions & 1 deletion cgpeople_me/apps/generic/views.py
Expand Up @@ -225,7 +225,15 @@ class ProfileView(TemplateView):
def get_context_data(self, **kwargs):
kwargs = super(ProfileView, self).get_context_data(**kwargs)

profile = get_object_or_404(models.Profile, user__username=kwargs['params']['username'])

try:
profile = models.Profile.objects.get(page_url=kwargs['params']['username'])
if not profile.is_paid and profile.page_url != profile.user.username:
raise models.Profile.DoesNotExist

except models.Profile.DoesNotExist:
profile = get_object_or_404(models.Profile, user__username=kwargs['params']['username'])

profile.profile_views += 1
profile.save()

Expand Down

0 comments on commit b7b92d1

Please sign in to comment.