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"])
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)
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)
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"])
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"])
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"])
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"])
def test_default_order(self): result = list(get_pictures(5)) self.assertEqual(result[0].title, "5")
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"])