예제 #1
0
 def clean_username(self):
     username = self.cleaned_data['username']
     try:
         fetch.get_user_by_username(username)
         raise forms.ValidationError(u'Username is already taken')
     except fetch.DatabaseError:
         pass
     return username
예제 #2
0
def userline(request, username=None):
    try:
        user = fetch.get_user_by_username(username)
    except fetch.DatabaseError:
        raise Http404

    # Query for the friend ids
    friend_usernames = []
    if request.user['is_authenticated']:
        friend_usernames = fetch.get_friend_usernames(username) + [username]

    # Add a property on the user to indicate whether the currently logged-in
    # user is friends with the user
    is_friend = username in friend_usernames

    start = request.GET.get('start')
    tweets, next_timeuuid = fetch.get_userline(username,
                                               start=start,
                                               limit=NUM_PER_PAGE)
    context = {
        'user': user,
        'username': username,
        'tweets': tweets,
        'next': next_timeuuid,
        'is_friend': is_friend,
        'friend_usernames': friend_usernames,
    }
    return render_to_response('tweets/userline.html',
                              context,
                              context_instance=RequestContext(request))
예제 #3
0
def find_friends(request):
    friend_usernames = []
    if request.user['is_authenticated']:
        friend_usernames = fetch.get_friend_usernames(
            request.session['username']) + [request.session['username']]
    q = request.GET.get('q')
    result = None
    searched = False
    if q is not None:
        searched = True
        try:
            result = fetch.get_user_by_username(q)
            result = {
                'username': result.username,
                'friend': q in friend_usernames
            }
        except fetch.DatabaseError:
            pass
    context = {
        'q': q,
        'result': result,
        'searched': searched,
        'friend_usernames': friend_usernames,
    }
    return render_to_response(
        'users/add_friends.html', context, context_instance=RequestContext(request))
예제 #4
0
 def clean(self):
     username = self.cleaned_data['username']
     password = self.cleaned_data['password']
     try:
         user = fetch.get_user_by_username(username)
     except fetch.DatabaseError:
         raise forms.ValidationError(u'Invalid username and/or password')
     if user.password != password:
         raise forms.ValidationError(u'Invalid username and/or password')
     return self.cleaned_data
예제 #5
0
def get_user(request):
    if 'username' in request.session:
        try:
            user = fetch.get_user_by_username(request.session['username'])
            return {
                'username': user.username,
                'password': user.password,
                'is_authenticated': True
            }
        except fetch.DatabaseError:
            pass
    return {
        'password': None,
        'is_authenticated': False,
    }