Unify aggregates and project services.
parent
3927c354e0
commit
5aa4a8a784
|
@ -1,32 +0,0 @@
|
|||
from contextlib import closing
|
||||
from django.db import connection
|
||||
|
||||
def _get_issues_tags(project):
|
||||
extra_sql = ("select unnest(unpickle(tags)) as tagname "
|
||||
"from issues_issue where project_id = %s "
|
||||
"group by unnest(unpickle(tags)) "
|
||||
"order by tagname asc")
|
||||
|
||||
with closing(connection.cursor()) as cursor:
|
||||
cursor.execute(extra_sql, [project.id])
|
||||
rows = cursor.fetchall()
|
||||
|
||||
return set([x[0] for x in rows])
|
||||
|
||||
def _get_stories_tags(project):
|
||||
extra_sql = ("select unnest(unpickle(tags)) as tagname, count(unnest(unpickle(tags))) "
|
||||
"from userstories_userstory where project_id = %s "
|
||||
"group by unnest(unpickle(tags)) "
|
||||
"order by tagname asc")
|
||||
|
||||
with closing(connection.cursor()) as cursor:
|
||||
cursor.execute(extra_sql, [project.id])
|
||||
rows = cursor.fetchall()
|
||||
|
||||
return set([x[0] for x in rows])
|
||||
|
||||
def get_all_tags(project):
|
||||
result = set()
|
||||
result.update(_get_issues_tags(project))
|
||||
result.update(_get_stories_tags(project))
|
||||
return sorted(result)
|
|
@ -18,19 +18,14 @@ from taiga.base import filters
|
|||
from taiga.base import exceptions as exc
|
||||
from taiga.base.decorators import list_route, detail_route
|
||||
from taiga.base.permissions import has_project_perm
|
||||
from taiga.base.api import ModelCrudViewSet, ModelListViewSet, RetrieveModelMixin
|
||||
from taiga.base.api import ModelCrudViewSet, RetrieveModelMixin
|
||||
from taiga.base.users.models import Role
|
||||
from taiga.base.notifications.api import NotificationSenderMixin
|
||||
from taiga.projects.aggregates.tags import get_all_tags
|
||||
|
||||
from . import serializers
|
||||
from . import models
|
||||
from . import permissions
|
||||
from . import services
|
||||
|
||||
from .aggregates import stats
|
||||
from .aggregates import filters as filters_aggr
|
||||
|
||||
|
||||
class ProjectAdminViewSet(ModelCrudViewSet):
|
||||
model = models.Project
|
||||
|
@ -69,22 +64,22 @@ class ProjectViewSet(ModelCrudViewSet):
|
|||
@detail_route(methods=['get'])
|
||||
def stats(self, request, pk=None):
|
||||
project = self.get_object()
|
||||
return Response(stats.get_stats_for_project(project))
|
||||
return Response(services.get_stats_for_project(project))
|
||||
|
||||
@detail_route(methods=['get'])
|
||||
def issues_stats(self, request, pk=None):
|
||||
project = self.get_object()
|
||||
return Response(stats.get_stats_for_project_issues(project))
|
||||
return Response(services.get_stats_for_project_issues(project))
|
||||
|
||||
@detail_route(methods=['get'])
|
||||
def issue_filters_data(self, request, pk=None):
|
||||
project = self.get_object()
|
||||
return Response(filters_aggr.get_issues_filters_data(project))
|
||||
return Response(services.get_issues_filters_data(project))
|
||||
|
||||
@detail_route(methods=['get'])
|
||||
def tags(self, request, pk=None):
|
||||
project = self.get_object()
|
||||
return Response(get_all_tags(project))
|
||||
return Response(services.get_all_tags(project))
|
||||
|
||||
def get_queryset(self):
|
||||
qs = super().get_queryset()
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# This makes all code that import services works and
|
||||
# is not the baddest practice ;)
|
||||
|
||||
from .bulk_update_order import bulk_update_question_status_order
|
||||
from .bulk_update_order import bulk_update_severity_order
|
||||
from .bulk_update_order import bulk_update_priority_order
|
||||
from .bulk_update_order import bulk_update_issue_type_order
|
||||
from .bulk_update_order import bulk_update_issue_status_order
|
||||
from .bulk_update_order import bulk_update_task_status_order
|
||||
from .bulk_update_order import bulk_update_points_order
|
||||
from .bulk_update_order import bulk_update_userstory_status_order
|
||||
|
||||
from .filters import get_all_tags
|
||||
from .filters import get_issues_filters_data
|
||||
|
||||
from .stats import get_stats_for_project_issues
|
||||
from .stats import get_stats_for_project
|
|
@ -1,8 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from contextlib import closing
|
||||
from django.db import connection
|
||||
|
||||
def _get_issues_tags(project):
|
||||
extra_sql = ("select unnest(unpickle(tags)) as tagname "
|
||||
"from issues_issue where project_id = %s "
|
||||
"group by unnest(unpickle(tags)) "
|
||||
"order by tagname asc")
|
||||
|
||||
with closing(connection.cursor()) as cursor:
|
||||
cursor.execute(extra_sql, [project.id])
|
||||
rows = cursor.fetchall()
|
||||
|
||||
return set([x[0] for x in rows])
|
||||
|
||||
def _get_stories_tags(project):
|
||||
extra_sql = ("select unnest(unpickle(tags)) as tagname, count(unnest(unpickle(tags))) "
|
||||
"from userstories_userstory where project_id = %s "
|
||||
"group by unnest(unpickle(tags)) "
|
||||
"order by tagname asc")
|
||||
|
||||
with closing(connection.cursor()) as cursor:
|
||||
cursor.execute(extra_sql, [project.id])
|
||||
rows = cursor.fetchall()
|
||||
|
||||
return set([x[0] for x in rows])
|
||||
|
||||
|
||||
def _get_issues_tags(project):
|
||||
extra_sql = ("select unnest(unpickle(tags)) as tagname, count(unnest(unpickle(tags))) "
|
||||
|
@ -110,7 +132,26 @@ def _get_issues_owners(project):
|
|||
return rows
|
||||
|
||||
|
||||
# Public api
|
||||
|
||||
def get_all_tags(project):
|
||||
"""
|
||||
Given a project, return sorted list of unique
|
||||
tags found on it.
|
||||
"""
|
||||
|
||||
result = set()
|
||||
result.update(_get_issues_tags(project))
|
||||
result.update(_get_stories_tags(project))
|
||||
return sorted(result)
|
||||
|
||||
|
||||
def get_issues_filters_data(project):
|
||||
"""
|
||||
Given a project, return a simple data structure
|
||||
of all possible filters for issues.
|
||||
"""
|
||||
|
||||
data = {
|
||||
"types": _get_issues_types(project),
|
||||
"statuses": _get_issues_statuses(project),
|
Loading…
Reference in New Issue