Merge pull request #871 from taigaio/add-total-comments-to-kanban
Add total comments to kanban and taskboardremotes/origin/issue/4795/notification_even_they_are_disabled
commit
2a8927c06a
|
@ -20,6 +20,9 @@ import warnings
|
|||
|
||||
from .services import take_snapshot
|
||||
from taiga.projects.notifications import services as notifications_services
|
||||
from taiga.base.api import serializers
|
||||
from taiga.base.fields import MethodField
|
||||
|
||||
|
||||
class HistoryResourceMixin(object):
|
||||
"""
|
||||
|
@ -77,3 +80,11 @@ class HistoryResourceMixin(object):
|
|||
def pre_delete(self, obj):
|
||||
self.persist_history_snapshot(obj, delete=True)
|
||||
super().pre_delete(obj)
|
||||
|
||||
|
||||
class TotalCommentsSerializerMixin(serializers.LightSerializer):
|
||||
total_comments = MethodField()
|
||||
|
||||
def get_total_comments(self, obj):
|
||||
# The "total_comments" attribute is attached in the get_queryset of the viewset.
|
||||
return getattr(obj, "total_comments", 0) or 0
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2014-2016 Andrey Antukh <niwi@niwi.nz>
|
||||
# Copyright (C) 2014-2016 Jesús Espino <jespinog@gmail.com>
|
||||
# Copyright (C) 2014-2016 David Barragán <bameda@dbarragan.com>
|
||||
# Copyright (C) 2014-2016 Alejandro Alonso <alejandro.alonso@kaleidos.net>
|
||||
# Copyright (C) 2014-2016 Anler Hernández <hello@anler.me>
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 taiga.projects.history.services import get_typename_for_model_class
|
||||
|
||||
|
||||
def attach_total_comments_to_queryset(queryset, as_field="total_comments"):
|
||||
"""Attach a total comments counter to each object of the queryset.
|
||||
|
||||
:param queryset: A Django projects queryset object.
|
||||
:param as_field: Attach the counter as an attribute with this name.
|
||||
|
||||
:return: Queryset object with the additional `as_field` field.
|
||||
"""
|
||||
model = queryset.model
|
||||
sql = """
|
||||
SELECT COUNT(history_historyentry.id)
|
||||
FROM history_historyentry
|
||||
WHERE history_historyentry.key = CONCAT('{key_prefix}', {tbl}.id) AND
|
||||
history_historyentry.comment is not null AND
|
||||
history_historyentry.comment != ''
|
||||
"""
|
||||
|
||||
typename = get_typename_for_model_class(model)
|
||||
|
||||
sql = sql.format(tbl=model._meta.db_table, key_prefix="{}:".format(typename))
|
||||
|
||||
queryset = queryset.extra(select={as_field: sql})
|
||||
return queryset
|
|
@ -318,7 +318,6 @@ class Command(BaseCommand):
|
|||
attachment = self.create_attachment(wiki_page, i+1)
|
||||
|
||||
take_snapshot(wiki_page,
|
||||
comment=self.sd.paragraph(),
|
||||
user=wiki_page.owner)
|
||||
|
||||
# Add history entry
|
||||
|
@ -374,7 +373,6 @@ class Command(BaseCommand):
|
|||
bug.save()
|
||||
|
||||
take_snapshot(bug,
|
||||
comment=self.sd.paragraph(),
|
||||
user=bug.owner)
|
||||
|
||||
# Add history entry
|
||||
|
@ -421,7 +419,6 @@ class Command(BaseCommand):
|
|||
attachment = self.create_attachment(task, i+1)
|
||||
|
||||
take_snapshot(task,
|
||||
comment=self.sd.paragraph(),
|
||||
user=task.owner)
|
||||
|
||||
# Add history entry
|
||||
|
@ -476,7 +473,6 @@ class Command(BaseCommand):
|
|||
|
||||
|
||||
take_snapshot(us,
|
||||
comment=self.sd.paragraph(),
|
||||
user=us.owner)
|
||||
|
||||
# Add history entry
|
||||
|
@ -533,7 +529,6 @@ class Command(BaseCommand):
|
|||
epic.save()
|
||||
|
||||
take_snapshot(epic,
|
||||
comment=self.sd.paragraph(),
|
||||
user=epic.owner)
|
||||
|
||||
# Add history entry
|
||||
|
@ -559,9 +554,15 @@ class Command(BaseCommand):
|
|||
|
||||
# Add history entry
|
||||
take_snapshot(epic,
|
||||
comment=self.sd.paragraph(),
|
||||
user=epic.owner)
|
||||
|
||||
# Add history entry
|
||||
epic.status=self.sd.db_object_from_queryset(project.epic_statuses.filter(is_closed=False))
|
||||
epic.save()
|
||||
take_snapshot(epic,
|
||||
comment=self.sd.paragraph(),
|
||||
user=epic.owner)
|
||||
|
||||
return epic
|
||||
|
||||
def create_project(self, counter, is_private=None, blocked_code=None):
|
||||
|
@ -633,4 +634,3 @@ class Command(BaseCommand):
|
|||
def generate_color(self, tag):
|
||||
color = sha1(tag.encode("utf-8")).hexdigest()[0:6]
|
||||
return "#{}".format(color)
|
||||
|
||||
|
|
|
@ -28,11 +28,13 @@ from taiga.projects.mixins.serializers import StatusExtraInfoSerializerMixin
|
|||
from taiga.projects.notifications.mixins import WatchedResourceSerializer
|
||||
from taiga.projects.tagging.serializers import TaggedInProjectResourceSerializer
|
||||
from taiga.projects.votes.mixins.serializers import VoteResourceSerializerMixin
|
||||
from taiga.projects.history.mixins import TotalCommentsSerializerMixin
|
||||
|
||||
class TaskListSerializer(VoteResourceSerializerMixin, WatchedResourceSerializer,
|
||||
OwnerExtraInfoSerializerMixin, AssignedToExtraInfoSerializerMixin,
|
||||
StatusExtraInfoSerializerMixin, BasicAttachmentsInfoSerializerMixin,
|
||||
TaggedInProjectResourceSerializer, serializers.LightSerializer):
|
||||
TaggedInProjectResourceSerializer, TotalCommentsSerializerMixin,
|
||||
serializers.LightSerializer):
|
||||
|
||||
id = Field()
|
||||
user_story = Field(attr="user_story_id")
|
||||
|
|
|
@ -23,6 +23,7 @@ from taiga.projects.notifications.utils import attach_total_watchers_to_queryset
|
|||
from taiga.projects.notifications.utils import attach_is_watcher_to_queryset
|
||||
from taiga.projects.votes.utils import attach_total_voters_to_queryset
|
||||
from taiga.projects.votes.utils import attach_is_voter_to_queryset
|
||||
from taiga.projects.history.utils import attach_total_comments_to_queryset
|
||||
|
||||
|
||||
def attach_user_story_extra_info(queryset, as_field="user_story_extra_info"):
|
||||
|
@ -76,4 +77,5 @@ def attach_extra_info(queryset, user=None, include_attachments=False):
|
|||
queryset = attach_is_voter_to_queryset(queryset, user)
|
||||
queryset = attach_is_watcher_to_queryset(queryset, user)
|
||||
queryset = attach_user_story_extra_info(queryset)
|
||||
queryset = attach_total_comments_to_queryset(queryset)
|
||||
return queryset
|
||||
|
|
|
@ -29,6 +29,7 @@ from taiga.projects.mixins.serializers import StatusExtraInfoSerializerMixin
|
|||
from taiga.projects.notifications.mixins import WatchedResourceSerializer
|
||||
from taiga.projects.tagging.serializers import TaggedInProjectResourceSerializer
|
||||
from taiga.projects.votes.mixins.serializers import VoteResourceSerializerMixin
|
||||
from taiga.projects.history.mixins import TotalCommentsSerializerMixin
|
||||
|
||||
|
||||
class OriginIssueSerializer(serializers.LightSerializer):
|
||||
|
@ -47,7 +48,7 @@ class UserStoryListSerializer(ProjectExtraInfoSerializerMixin,
|
|||
VoteResourceSerializerMixin, WatchedResourceSerializer,
|
||||
OwnerExtraInfoSerializerMixin, AssignedToExtraInfoSerializerMixin,
|
||||
StatusExtraInfoSerializerMixin, BasicAttachmentsInfoSerializerMixin,
|
||||
TaggedInProjectResourceSerializer,
|
||||
TaggedInProjectResourceSerializer, TotalCommentsSerializerMixin,
|
||||
serializers.LightSerializer):
|
||||
|
||||
id = Field()
|
||||
|
|
|
@ -21,6 +21,7 @@ from taiga.projects.attachments.utils import attach_basic_attachments
|
|||
from taiga.projects.notifications.utils import attach_watchers_to_queryset
|
||||
from taiga.projects.notifications.utils import attach_total_watchers_to_queryset
|
||||
from taiga.projects.notifications.utils import attach_is_watcher_to_queryset
|
||||
from taiga.projects.history.utils import attach_total_comments_to_queryset
|
||||
from taiga.projects.votes.utils import attach_total_voters_to_queryset
|
||||
from taiga.projects.votes.utils import attach_is_voter_to_queryset
|
||||
|
||||
|
@ -174,4 +175,5 @@ def attach_extra_info(queryset, user=None, include_attachments=False, include_ta
|
|||
queryset = attach_total_watchers_to_queryset(queryset)
|
||||
queryset = attach_is_voter_to_queryset(queryset, user)
|
||||
queryset = attach_is_watcher_to_queryset(queryset, user)
|
||||
queryset = attach_total_comments_to_queryset(queryset)
|
||||
return queryset
|
||||
|
|
Loading…
Reference in New Issue