Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalBackend
Commits
8a0bb0d0
Commit
8a0bb0d0
authored
Dec 18, 2017
by
Lukas Burgey
Browse files
Let clients fetch only a part of their services
parent
162f2077
Changes
2
Hide whitespace changes
Inline
Side-by-side
django_backend/backend/clientapi/views.py
View file @
8a0bb0d0
from
rest_framework
import
generics
from
rest_framework.authentication
import
TokenAuthentication
from
..
import
rabbitmq
from
.
import
serializers
,
models
...
...
@@ -15,14 +14,24 @@ class DeploymentsView(generics.RetrieveAPIView):
serializer_class
=
serializers
.
DeploymentsSerializer
def
get_object
(
self
):
all
=
False
all
_services
=
False
if
(
'all'
in
self
.
request
.
query_params
and
self
.
request
.
query_params
[
'all'
]
==
'true'
):
all
=
True
all_services
=
True
# the client may want only a special selection of services
if
's'
in
self
.
request
.
query_params
:
filter_services
=
self
.
request
.
query_params
.
getlist
(
's'
)
print
(
filter_services
)
else
:
filter_services
=
None
d
=
models
.
Deployments
()
d
.
services
=
self
.
request
.
user
.
site
.
clientapi_get_deployments
(
all
=
all
)
d
.
services
=
self
.
request
.
user
.
site
.
clientapi_get_deployments
(
all
=
all_services
,
filter
=
filter_services
,
)
return
d
...
...
django_backend/backend/models.py
View file @
8a0bb0d0
...
...
@@ -70,7 +70,7 @@ class Site(models.Model):
self
.
last_fetch
=
make_aware
(
datetime
.
now
())
self
.
save
()
def
clientapi_get_deployments
(
self
,
all
=
False
):
def
clientapi_get_deployments
(
self
,
all
=
False
,
filter
=
None
):
def
service_deployments
(
service
):
if
all
:
ds
=
(
...
...
@@ -92,9 +92,17 @@ class Site(models.Model):
return
ds
if
filter
is
not
None
:
services
=
[
s
for
s
in
self
.
services
.
all
()
if
s
.
name
in
filter
]
else
:
services
=
self
.
services
.
all
()
deployments
=
{
service
.
name
:
service_deployments
(
service
)
for
service
in
self
.
services
.
all
()
}
in
services
}
# TODO we expect the client to get the update here
self
.
client_updated
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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