Exemplo n.º 1
0
    def clean_username(self):
        username = self.cleaned_data["username"]

        if User.fetch_one_by_username(username):
            message = _("A user with that username (%(username)s) already exists.") % {'username': username}
            raise forms.ValidationError(message)

        return username
Exemplo n.º 2
0
def profile(request, username):
    profile_user = User.fetch_one_by_username(username)
    if not profile_user.id:
        return HttpResponseNotFound('User with this username (%s) not found' % username)

    posts = profile_user.get_posts(0, -1)

    can_follow = request.user.is_authenticated() and request.user.id != profile_user.id
    is_following = can_follow and request.user.is_following(profile_user.id)

    tpl_vars = {'profile_user': profile_user, 'posts': posts, 'can_follow': can_follow, 'is_following': is_following}
    return render_to_response('profile.html', tpl_vars, context_instance=RequestContext(request))
Exemplo n.º 3
0
    def test_fetch_one_by_username(self):
        user = User.create_new('test', 11111)

        test_user = User.fetch_one_by_username('test')

        self.assertEqual(user.id, test_user.id)