From 3b48c1fa95ce37817afad656d01bb9f6875fcab4 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 28 Aug 2014 13:10:55 +0200 Subject: [PATCH] Adding pagination disabled for history --- taiga/base/api/__init__.py | 4 +++- taiga/base/api/viewsets.py | 7 +++++++ taiga/projects/history/api.py | 6 ++---- taiga/users/services.py | 15 +++++++++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/taiga/base/api/__init__.py b/taiga/base/api/__init__.py index e9bd5aca..973f17ef 100644 --- a/taiga/base/api/__init__.py +++ b/taiga/base/api/__init__.py @@ -20,7 +20,9 @@ from .viewsets import ModelListViewSet from .viewsets import ModelCrudViewSet from .viewsets import GenericViewSet +from .viewsets import ReadOnlyListViewSet __all__ = ["ModelCrudViewSet", "ModelListViewSet", - "GenericViewSet"] + "GenericViewSet", + "ReadOnlyListViewSet"] diff --git a/taiga/base/api/viewsets.py b/taiga/base/api/viewsets.py index 40619056..edb8cfff 100644 --- a/taiga/base/api/viewsets.py +++ b/taiga/base/api/viewsets.py @@ -124,6 +124,13 @@ class GenericViewSet(ViewSetMixin, generics.GenericAPIView): """ pass +class ReadOnlyListViewSet(pagination.HeadersPaginationMixin, + pagination.ConditionalPaginationMixin, + GenericViewSet): + """ + A viewset that provides default `list()` action. + """ + pass class ReadOnlyModelViewSet(mixins.RetrieveModelMixin, mixins.ListModelMixin, diff --git a/taiga/projects/history/api.py b/taiga/projects/history/api.py index 19c91fcc..b606fb28 100644 --- a/taiga/projects/history/api.py +++ b/taiga/projects/history/api.py @@ -18,17 +18,15 @@ from django.contrib.contenttypes.models import ContentType from django.shortcuts import get_object_or_404 from rest_framework.response import Response -from rest_framework.permissions import IsAuthenticated -from taiga.base.api import GenericViewSet -from taiga.base.filters import IsProjectMemberFilterBackend +from taiga.base.api import ReadOnlyListViewSet from . import permissions from . import serializers from . import services -class HistoryViewSet(GenericViewSet): +class HistoryViewSet(ReadOnlyListViewSet): serializer_class = serializers.HistoryEntrySerializer content_type = None diff --git a/taiga/users/services.py b/taiga/users/services.py index ce670e94..df56c053 100644 --- a/taiga/users/services.py +++ b/taiga/users/services.py @@ -23,6 +23,7 @@ from django.db.models import Q from django.conf import settings from easy_thumbnails.files import get_thumbnailer +from easy_thumbnails.exceptions import InvalidImageFormatError from taiga.base import exceptions as exc from taiga.base.utils.urls import get_absolute_url @@ -54,8 +55,11 @@ def get_and_validate_user(*, username:str, password:str) -> bool: def get_photo_url(photo): """Get a photo absolute url and the photo automatically cropped.""" - url = get_thumbnailer(photo)['avatar'].url - return get_absolute_url(url) + try: + url = get_thumbnailer(photo)['avatar'].url + return get_absolute_url(url) + except InvalidImageFormatError as e: + return None def get_photo_or_gravatar_url(user): @@ -67,8 +71,11 @@ def get_photo_or_gravatar_url(user): def get_big_photo_url(photo): """Get a big photo absolute url and the photo automatically cropped.""" - url = get_thumbnailer(photo)['big-avatar'].url - return get_absolute_url(url) + try: + url = get_thumbnailer(photo)['big-avatar'].url + return get_absolute_url(url) + except InvalidImageFormatError as e: + return None def get_big_photo_or_gravatar_url(user):