예제 #1
0
 def test_favorites_order_before(self):
     public_id = Picture.objects.get(title="1").public_id
     result = list(get_pictures(5, order="most_favorites",
                                before=public_id))
     result.reverse()
     self.assertEqual([picture.title for picture in result],
                      ["3", "5", "4"])
예제 #2
0
def profile(request):
    context = {"favorites": True}
    if request.user.is_authenticated:
        pictures = list(
            get_pictures(
                project_settings.PAGE_SIZE + 1,
                favorited_by=request.user,
                get_num_favs=True,
            ))
        context["pictures"] = get_images_grid_context(pictures)
        context["more_left"] = len(pictures) >= project_settings.PAGE_SIZE + 1
        context["grid_placeholders"] = [1] * (
            18 - len(pictures[:project_settings.PAGE_SIZE]))
        context["main_qsp"] = {"favorites": "true"}
    return render(request, "users/profile.html.j2", context=context)
예제 #3
0
def user(request, user_public_id):
    context = {}
    try:
        target = models.CustomUser.objects.get(public_id=user_public_id)
    except (ObjectDoesNotExist, ValidationError):
        pass
    else:
        context["display_name"] = target.display_name
        context["search_uploaded_by"] = target.public_id

        pictures = get_pictures(project_settings.PAGE_SIZE + 1,
                                uploaded_by=target,
                                get_num_favs=True)

        context["pictures"] = get_images_grid_context(pictures)
        context["more_left"] = len(pictures) >= project_settings.PAGE_SIZE + 1
        context["grid_placeholders"] = [1] * (
            18 - len(pictures[:project_settings.PAGE_SIZE]))
        context["main_qsp"] = {"uploaded_by": str(target.public_id)}

    return render(request, "users/user.html.j2", context)
예제 #4
0
 def test_favorites_order_after(self):
     public_id = Picture.objects.get(title="4").public_id
     result = list(get_pictures(5, order="most_favorites", after=public_id))
     self.assertEqual([picture.title for picture in result], ["1", "2"])
예제 #5
0
 def test_favorites_order(self):
     result = list(get_pictures(5, order="most_favorites"))
     self.assertEqual([picture.title for picture in result],
                      ["3", "5", "4", "1", "2"])
예제 #6
0
 def test_default_order_after(self):
     public_id = Picture.objects.get(title="4").public_id
     result = list(get_pictures(5, after=public_id))
     self.assertEqual([picture.title for picture in result],
                      ["3", "2", "1"])
예제 #7
0
 def test_default_order_before(self):
     public_id = Picture.objects.get(title="3").public_id
     result = list(get_pictures(5, before=public_id))
     result.reverse()
     self.assertEqual([picture.title for picture in result], ["5", "4"])
예제 #8
0
 def test_default_order(self):
     result = list(get_pictures(5))
     self.assertEqual(result[0].title, "5")
예제 #9
0
 def test_only_favs_favorites_order(self):
     faved_by = CustomUser.objects.get(email="*****@*****.**")
     result = list(
         get_pictures(16, favorited_by=faved_by, order="most_favorites"))
     self.assertEqual([picture.title for picture in result],
                      ["3", "5", "4", "1"])