Commit 3fc30aa9 authored by ibuler's avatar ibuler

[Update] 修改tickets

parent bb1349e9
# -*- coding: utf-8 -*-
#
from django.db.models import Q
from .models import Ticket
class TicketMixin:
def get_queryset(self):
queryset = super().get_queryset()
assign = self.request.GET.get('assign', None)
if assign is None:
queryset = queryset.filter(
Q(assignees=self.request.user) | Q(user=self.request.user)
).distinct()
queryset = Ticket.get_related_tickets(self.request.user)
elif assign in ['1']:
queryset = queryset.filter(assignees=self.request.user)
queryset = Ticket.get_assigned_tickets(self.request.user)
else:
queryset = queryset.filter(user=self.request.user)
queryset = Ticket.get_my_tickets(self.request.user)
return queryset
......@@ -2,6 +2,7 @@
#
from django.db import models
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from common.mixins.models import CommonModelMixin
......@@ -95,6 +96,29 @@ class Ticket(CommonModelMixin):
def is_user(self, user):
return self.user == user
@classmethod
def get_related_tickets(cls, user, queryset=None):
if queryset is None:
queryset = cls.objects.all()
queryset = queryset.filter(
Q(assignees=user) | Q(user=user)
).distinct()
return queryset
@classmethod
def get_assigned_tickets(cls, user, queryset=None):
if queryset is None:
queryset = cls.objects.all()
queryset = queryset.filter(assignees=user)
return queryset
@classmethod
def get_my_tickets(cls, user, queryset=None):
if queryset is None:
queryset = cls.objects.all()
queryset = queryset.filter(user=user)
return queryset
class Meta:
ordering = ('-date_created',)
......
......@@ -7,7 +7,7 @@
<div class="tabs-container">
<ul class="nav nav-tabs">
<li {% if not assign %} class="active" {% endif %}><a href="{% url 'tickets:ticket-list' %}"> {% trans 'My tickets' %}</a></li>
<li {% if assign %}class="active" {% endif %}><a href="{% url 'tickets:ticket-list' %}?assign=1">{% trans 'Assigned me' %}</a></li>
<li {% if assign %}class="active" {% endif %}><a href="{% url 'tickets:ticket-list' %}?assign=1" >{% trans 'Assigned me' %} <span class="label label-primary">{{ assigned_open_count }}</span></a></li>
</ul>
<div class="tab-content">
<div id="my-tickets" class="tab-pane active">
......
......@@ -13,10 +13,13 @@ class TicketListView(PermissionsMixin, TemplateView):
def get_context_data(self, **kwargs):
assign = self.request.GET.get('assign', '0') == '1'
context = super().get_context_data(**kwargs)
assigned_open_count = Ticket.get_assigned_tickets(self.request.user)\
.filter(status=Ticket.STATUS_OPEN).count()
context.update({
'app': _("Tickets"),
'action': _("Ticket list"),
'assign': assign,
'assigned_open_count': assigned_open_count
})
return context
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment