Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
a86369e7
Commit
a86369e7
authored
Mar 17, 2018
by
Maël Kervella
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Add support for mailings
parent
ee3f4fb5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
0 deletions
+109
-0
api/serializers.py
api/serializers.py
+15
-0
api/urls.py
api/urls.py
+6
-0
api/views.py
api/views.py
+88
-0
No files found.
api/serializers.py
View file @
a86369e7
...
...
@@ -23,6 +23,7 @@ Serializers for the API app
"""
from
rest_framework
import
serializers
from
users.models
import
Club
,
Adherent
from
machines.models
import
Service_link
...
...
@@ -34,6 +35,20 @@ class ServiceLinkSerializer(serializers.ModelSerializer):
fields
=
(
'name'
,)
class
MailingSerializer
(
serializers
.
ModelSerializer
):
name
=
serializers
.
CharField
(
source
=
'pseudo'
)
class
Meta
:
model
=
Club
fields
=
(
'name'
,)
class
MailingMemberSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Adherent
fields
=
(
'email'
,
'name'
,
'surname'
,
'pseudo'
,)
class
ServicesSerializer
(
serializers
.
ModelSerializer
):
"""Evaluation d'un Service, et serialisation"""
server
=
serializers
.
SerializerMethodField
(
'get_server_name'
)
...
...
api/urls.py
View file @
a86369e7
...
...
@@ -34,4 +34,10 @@ urlpatterns = [
url
(
r
'^services/$'
,
views
.
services
),
url
(
r
'^services/(?P<server_name>\w+)/(?P<service_name>\w+)/regen/$'
,
views
.
services_server_service_regen
),
url
(
r
'^services/(?P<server_name>\w+)/$'
,
views
.
services_server
),
# Mailings
url
(
r
'^mailing/standard/$'
,
views
.
mailing_standard
),
url
(
r
'^mailing/standard/(?P<ml_name>\w+)/members/$'
,
views
.
mailing_standard_ml_members
),
url
(
r
'^mailing/club/$'
,
views
.
mailing_club
),
url
(
r
'^mailing/club/(?P<ml_name>\w+)/members/$'
,
views
.
mailing_club_ml_members
),
]
api/views.py
View file @
a86369e7
...
...
@@ -27,6 +27,9 @@ HTML pages such as the login and index pages for a better integration.
from
django.contrib.auth.decorators
import
login_required
,
permission_required
from
django.views.decorators.csrf
import
csrf_exempt
from
re2o.utils
import
all_has_access
from
users.models
import
Club
from
machines.models
import
Service_link
,
Service
,
Interface
,
Domain
from
.serializers
import
*
...
...
@@ -109,3 +112,88 @@ def services_server(request, server_name):
services
=
query
.
all
()
seria
=
ServiceLinkSerializer
(
services
,
many
=
True
)
return
JSONSuccess
(
seria
.
data
)
@
csrf_exempt
@
login_required
@
permission_required
(
'machines.serveur'
)
@
accept_method
([
'GET'
])
def
mailing_standard
(
request
):
"""All the available standard mailings.
Returns:
GET:
A JSONSucess response with a field `data` containing:
* a list of dictionnaries (one for each mailing) containing:
* a field `name`: the name of a mailing
"""
return
JSONSuccess
([
{
'name'
:
'adherents'
}
])
@
csrf_exempt
@
login_required
@
permission_required
(
'machines.serveur'
)
@
accept_method
([
'GET'
])
def
mailing_standard_ml_members
(
request
):
"""All the members of a specific standard mailing
Returns:
GET:
A JSONSucess response with a field `data` containing:
* a list if dictionnaries (one for each member) containing:
* a field `email`: the email of the member
* a field `name`: the name of the member
* a field `surname`: the surname of the member
* a field `pseudo`: the pseudo of the member
"""
# All with active connextion
if
ml_name
==
'adherents'
:
members
=
all_has_access
().
values
(
'email'
).
distinct
()
# Unknown mailing
else
:
return
JSONError
(
"This mailing does not exist"
)
seria
=
MailingMemberSerializer
(
members
,
many
=
True
)
return
JSONSuccess
(
seria
.
data
)
@
csrf_exempt
@
login_required
@
permission_required
(
'machines.serveur'
)
@
accept_method
([
'GET'
])
def
mailing_club
(
request
):
"""All the available club mailings.
Returns:
GET:
A JSONSucess response with a field `data` containing:
* a list of dictionnaries (one for each mailing) containing:
* a field `name` indicating the name of a mailing
"""
clubs
=
Club
.
objects
.
filter
(
mailing
=
True
).
values
(
'pseudo'
)
seria
=
MailingSerializer
(
clubs
,
many
=
True
)
return
JSONSuccess
(
seria
.
data
)
@
csrf_exempt
@
login_required
@
permission_required
(
'machines.serveur'
)
@
accept_method
([
'GET'
])
def
mailing_club_ml_members
(
request
):
"""All the members of a specific club mailing
Returns:
GET:
A JSONSucess response with a field `data` containing:
* a list if dictionnaries (one for each member) containing:
* a field `email`: the email of the member
* a field `name`: the name of the member
* a field `surname`: the surname of the member
* a field `pseudo`: the pseudo of the member
"""
try
:
club
=
Club
.
objects
.
get
(
mailing
=
True
,
pseudo
=
ml_name
)
except
Club
.
DoesNotExist
:
return
JSONError
(
"This mailing does not exist"
)
members
=
club
.
administrators
.
all
().
values
(
'email'
).
distinct
()
seria
=
MailingMemberSerializer
(
members
,
many
=
True
)
return
JSONSuccess
(
seria
.
data
)
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