FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patchwork/patchwork/api/cover.py at main · getpatchwork/patchwork · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
getpatchwork
/
patchwork
Public
Notifications
You must be signed in to change notification settings
Fork
90
Star
315
Code
Issues
97
Pull requests
22
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
patchwork
/
patchwork
/
api
/
cover.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
127 lines (103 loc) · 4 KB
Breadcrumbs
patchwork
/
patchwork
/
api
/
cover.py
Copy path
File metadata and controls
127 lines (103 loc) · 4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Patchwork - automated patch tracking system
# Copyright (C) 2016 Stephen Finucane <stephen@that.guru>
#
# SPDX-License-Identifier: GPL-2.0-or-later
import
email
.
parser
from
rest_framework
.
generics
import
ListAPIView
from
rest_framework
.
generics
import
RetrieveAPIView
from
rest_framework
.
reverse
import
reverse
from
rest_framework
.
serializers
import
SerializerMethodField
from
patchwork
.
api
.
base
import
BaseHyperlinkedModelSerializer
from
patchwork
.
api
.
filters
import
CoverFilterSet
from
patchwork
.
api
.
embedded
import
PersonSerializer
from
patchwork
.
api
.
embedded
import
ProjectSerializer
from
patchwork
.
api
.
embedded
import
SeriesSerializer
from
patchwork
.
models
import
Cover
class
CoverListSerializer
(
BaseHyperlinkedModelSerializer
):
web_url
=
SerializerMethodField
()
project
=
ProjectSerializer
(
read_only
=
True
)
submitter
=
PersonSerializer
(
read_only
=
True
)
mbox
=
SerializerMethodField
()
series
=
SeriesSerializer
(
read_only
=
True
)
comments
=
SerializerMethodField
()
def
get_web_url
(
self
,
instance
):
request
=
self
.
context
.
get
(
'request'
)
return
request
.
build_absolute_uri
(
instance
.
get_absolute_url
())
def
get_mbox
(
self
,
instance
):
request
=
self
.
context
.
get
(
'request'
)
return
request
.
build_absolute_uri
(
instance
.
get_mbox_url
())
def
get_comments
(
self
,
cover
):
return
self
.
context
.
get
(
'request'
).
build_absolute_uri
(
reverse
(
'api-cover-comment-list'
,
kwargs
=
{
'cover_id'
:
cover
.
id
})
)
def
to_representation
(
self
,
instance
):
# NOTE(stephenfin): This is here to ensure our API looks the same even
# after we changed the series-patch relationship from M:N to 1:N. It
# will be removed in API v2
data
=
super
(
CoverListSerializer
,
self
).
to_representation
(
instance
)
data
[
'series'
]
=
[
data
[
'series'
]]
if
data
[
'series'
]
else
[]
return
data
class
Meta
:
model
=
Cover
fields
=
(
'id'
,
'url'
,
'web_url'
,
'project'
,
'msgid'
,
'list_archive_url'
,
'date'
,
'name'
,
'submitter'
,
'mbox'
,
'series'
,
'comments'
,
)
read_only_fields
=
fields
versioned_fields
=
{
'1.1'
: (
'web_url'
,
'mbox'
,
'comments'
),
'1.2'
: (
'list_archive_url'
,),
}
extra_kwargs
=
{
'url'
: {
'view_name'
:
'api-cover-detail'
},
}
class
CoverDetailSerializer
(
CoverListSerializer
):
headers
=
SerializerMethodField
()
def
get_headers
(
self
,
instance
):
headers
=
{}
if
instance
.
headers
:
parsed
=
email
.
parser
.
Parser
().
parsestr
(
instance
.
headers
,
True
)
for
key
in
parsed
.
keys
():
headers
[
key
]
=
parsed
.
get_all
(
key
)
# Let's return a single string instead of a list if only one
# header with this key is present
if
len
(
headers
[
key
])
==
1
:
headers
[
key
]
=
headers
[
key
][
0
]
return
headers
class
Meta
:
model
=
Cover
fields
=
CoverListSerializer
.
Meta
.
fields
+
(
'headers'
,
'content'
)
read_only_fields
=
fields
extra_kwargs
=
CoverListSerializer
.
Meta
.
extra_kwargs
versioned_fields
=
CoverListSerializer
.
Meta
.
versioned_fields
class
CoverList
(
ListAPIView
):
"""List cover letters."""
serializer_class
=
CoverListSerializer
filter_class
=
filterset_class
=
CoverFilterSet
search_fields
=
(
'name'
,)
ordering_fields
=
(
'id'
,
'name'
,
'date'
,
'submitter'
)
ordering
=
'id'
def
get_queryset
(
self
):
return
(
Cover
.
objects
.
all
()
.
prefetch_related
(
'series__project'
)
.
select_related
(
'project'
,
'submitter'
,
'series'
)
.
defer
(
'content'
,
'headers'
)
)
class
CoverDetail
(
RetrieveAPIView
):
"""Show a cover letter."""
serializer_class
=
CoverDetailSerializer
def
get_queryset
(
self
):
return
Cover
.
objects
.
all
().
select_related
(
'project'
,
'submitter'
,
'series'
)
Back
|
FazBrowse Home
|
New Git URL