Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
3fc30aa9
Commit
3fc30aa9
authored
Nov 18, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改tickets
parent
bb1349e9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
7 deletions
+32
-7
mixins.py
apps/tickets/mixins.py
+4
-6
ticket.py
apps/tickets/models/ticket.py
+24
-0
ticket_list.html
apps/tickets/templates/tickets/ticket_list.html
+1
-1
views.py
apps/tickets/views.py
+3
-0
No files found.
apps/tickets/mixins.py
View file @
3fc30aa9
# -*- 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
apps/tickets/models/ticket.py
View file @
3fc30aa9
...
...
@@ -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'
,)
...
...
apps/tickets/templates/tickets/ticket_list.html
View file @
3fc30aa9
...
...
@@ -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"
>
...
...
apps/tickets/views.py
View file @
3fc30aa9
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment