Exemple #1
0
 def test_get_object_or_404(self):
     user = self.create_user('test', 'test')
     
     # test with model as first arg
     self.assertRaises(NotFound, get_object_or_404, User, username='******')
     self.assertEqual(user, get_object_or_404(User, username='******'))
     
     # test with query as first arg
     active = User.select().where(active=True)
     inactive = User.select().where(active=False)
     self.assertRaises(NotFound, get_object_or_404, active, username='******')
     self.assertRaises(NotFound, get_object_or_404, inactive, username='******')
     self.assertEqual(user, get_object_or_404(active, username='******'))
Exemple #2
0
def user_unfollow(username):
    user = get_object_or_404(User, username=username)
    Relationship.delete().where(
        from_user=auth.get_logged_in_user(),
        to_user=user,
    ).execute()
    flash('You are no longer following %s' % user.username)
    return redirect(url_for('user_detail', username=user.username))
Exemple #3
0
def user_follow(username):
    user = get_object_or_404(User, username=username)
    Relationship.get_or_create(
        from_user=auth.get_logged_in_user(),
        to_user=user,
    )
    flash('You are now following %s' % user.username)
    return redirect(url_for('user_detail', username=user.username))
Exemple #4
0
    def api_detail(self, pk):
        obj = get_object_or_404(self.get_query(), **{self.model._meta.pk_name: pk})

        if not getattr(self, "check_%s" % request.method.lower())(obj):
            return self.response_forbidden()

        if request.method == "GET":
            return self.object_detail(obj)
        elif request.method == "PUT":
            return self.edit(obj)
        elif request.method == "DELETE":
            return self.delete(obj)
Exemple #5
0
def user_detail(username):
    user = get_object_or_404(User, username=username)
    messages = user.message_set.order_by(('pub_date', 'desc'))
    return object_list('user_detail.html', messages, 'message_list', person=user)