Adding logo_small_url to user likes and watches APIs
parent
c280898642
commit
3d3e8f2d49
|
@ -15,12 +15,14 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import validators
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from taiga.base.api import serializers
|
||||
from taiga.base.fields import PgArrayField, TagsField
|
||||
from taiga.base.utils.thumbnails import get_thumbnail_url
|
||||
|
||||
from taiga.projects.models import Project
|
||||
from .models import User, Role
|
||||
|
@ -174,6 +176,7 @@ class HighLightedContentSerializer(serializers.Serializer):
|
|||
tags_colors = serializers.SerializerMethodField("get_tags_color")
|
||||
created_date = serializers.DateTimeField()
|
||||
is_private = serializers.SerializerMethodField("get_is_private")
|
||||
logo_small_url = serializers.SerializerMethodField("get_logo_small_url")
|
||||
|
||||
project = serializers.SerializerMethodField("get_project")
|
||||
project_name = serializers.SerializerMethodField("get_project_name")
|
||||
|
@ -226,6 +229,12 @@ class HighLightedContentSerializer(serializers.Serializer):
|
|||
def get_project_is_private(self, obj):
|
||||
return self._none_if_project(obj, "project_is_private")
|
||||
|
||||
def get_logo_small_url(self, obj):
|
||||
logo = self._none_if_not_project(obj, "logo")
|
||||
if logo:
|
||||
return get_thumbnail_url(logo, settings.THN_LOGO_SMALL)
|
||||
return None
|
||||
|
||||
def get_photo(self, obj):
|
||||
type = obj.get("type", "")
|
||||
if type == "project":
|
||||
|
|
|
@ -322,7 +322,7 @@ def get_watched_list(for_user, from_user, type=None, q=None):
|
|||
-- BEGIN Basic info: we need to mix info from different tables and denormalize it
|
||||
SELECT entities.*,
|
||||
projects_project.name as project_name, projects_project.description as description, projects_project.slug as project_slug, projects_project.is_private as project_is_private,
|
||||
projects_project.tags_colors,
|
||||
projects_project.tags_colors, projects_project.logo,
|
||||
users_user.username assigned_to_username, users_user.full_name assigned_to_full_name, users_user.photo assigned_to_photo, users_user.email assigned_to_email
|
||||
FROM (
|
||||
{userstories_sql}
|
||||
|
@ -417,7 +417,7 @@ def get_liked_list(for_user, from_user, type=None, q=None):
|
|||
-- BEGIN Basic info: we need to mix info from different tables and denormalize it
|
||||
SELECT entities.*,
|
||||
projects_project.name as project_name, projects_project.description as description, projects_project.slug as project_slug, projects_project.is_private as project_is_private,
|
||||
projects_project.tags_colors,
|
||||
projects_project.tags_colors, projects_project.logo,
|
||||
users_user.username assigned_to_username, users_user.full_name assigned_to_full_name, users_user.photo assigned_to_photo, users_user.email assigned_to_email
|
||||
FROM (
|
||||
{projects_sql}
|
||||
|
@ -500,7 +500,7 @@ def get_voted_list(for_user, from_user, type=None, q=None):
|
|||
-- BEGIN Basic info: we need to mix info from different tables and denormalize it
|
||||
SELECT entities.*,
|
||||
projects_project.name as project_name, projects_project.description as description, projects_project.slug as project_slug, projects_project.is_private as project_is_private,
|
||||
projects_project.tags_colors,
|
||||
projects_project.tags_colors, projects_project.logo,
|
||||
users_user.username assigned_to_username, users_user.full_name assigned_to_full_name, users_user.photo assigned_to_photo, users_user.email assigned_to_email
|
||||
FROM (
|
||||
{userstories_sql}
|
||||
|
|
|
@ -22,6 +22,8 @@ from datetime import date, timedelta
|
|||
|
||||
from django.conf import settings
|
||||
|
||||
from .utils import DUMMY_BMP_DATA
|
||||
|
||||
import factory
|
||||
|
||||
|
||||
|
@ -69,6 +71,8 @@ class ProjectFactory(Factory):
|
|||
|
||||
name = factory.Sequence(lambda n: "Project {}".format(n))
|
||||
slug = factory.Sequence(lambda n: "project-{}-slug".format(n))
|
||||
logo = factory.django.FileField(data=DUMMY_BMP_DATA)
|
||||
|
||||
description = "Project description"
|
||||
owner = factory.SubFactory("tests.factories.UserFactory")
|
||||
creation_template = factory.SubFactory("tests.factories.ProjectTemplateFactory")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.files import File
|
||||
|
@ -9,6 +10,7 @@ from .. import factories as f
|
|||
from ..utils import DUMMY_BMP_DATA
|
||||
|
||||
from taiga.base.utils import json
|
||||
from taiga.base.utils.thumbnails import get_thumbnail_url
|
||||
from taiga.users import models
|
||||
from taiga.users.serializers import LikedObjectSerializer, VotedObjectSerializer
|
||||
from taiga.auth.tokens import get_token_for_user
|
||||
|
@ -432,6 +434,7 @@ def test_get_watched_list_valid_info_for_project():
|
|||
assert "tag" in tags_colors
|
||||
|
||||
assert project_watch_info["is_private"] == project.is_private
|
||||
assert project_watch_info["logo_small_url"] == get_thumbnail_url(project.logo, settings.THN_LOGO_SMALL)
|
||||
assert project_watch_info["is_fan"] == False
|
||||
assert project_watch_info["is_watcher"] == False
|
||||
assert project_watch_info["total_watchers"] == 1
|
||||
|
@ -469,7 +472,7 @@ def test_get_liked_list_valid_info():
|
|||
content_type = ContentType.objects.get_for_model(project)
|
||||
like = f.LikeFactory(content_type=content_type, object_id=project.id, user=fan_user)
|
||||
project.refresh_totals()
|
||||
|
||||
|
||||
raw_project_like_info = get_liked_list(fan_user, viewer_user)[0]
|
||||
project_like_info = LikedObjectSerializer(raw_project_like_info).data
|
||||
|
||||
|
@ -489,6 +492,7 @@ def test_get_liked_list_valid_info():
|
|||
assert "tag" in tags_colors
|
||||
|
||||
assert project_like_info["is_private"] == project.is_private
|
||||
assert project_like_info["logo_small_url"] == get_thumbnail_url(project.logo, settings.THN_LOGO_SMALL)
|
||||
|
||||
assert project_like_info["is_fan"] == False
|
||||
assert project_like_info["is_watcher"] == False
|
||||
|
@ -542,6 +546,7 @@ def test_get_watched_list_valid_info_for_not_project_types():
|
|||
assert "test2" in tags_colors
|
||||
|
||||
assert instance_watch_info["is_private"] == None
|
||||
assert instance_watch_info["logo_small_url"] == None
|
||||
assert instance_watch_info["is_voter"] == False
|
||||
assert instance_watch_info["is_watcher"] == False
|
||||
assert instance_watch_info["total_watchers"] == 1
|
||||
|
@ -597,6 +602,7 @@ def test_get_voted_list_valid_info():
|
|||
assert "test2" in tags_colors
|
||||
|
||||
assert instance_vote_info["is_private"] == None
|
||||
assert instance_vote_info["logo_small_url"] == None
|
||||
assert instance_vote_info["is_voter"] == False
|
||||
assert instance_vote_info["is_watcher"] == False
|
||||
assert instance_vote_info["total_watchers"] == 0
|
||||
|
|
Loading…
Reference in New Issue