Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
R
red-ci-cd
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
red-group-test
red-ci-cd
Commits
7dee1aa2
Commit
7dee1aa2
authored
Jul 08, 2019
by
Ristylou Dolar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added search and sort field functionalities
parent
25c3b2ec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
10 deletions
+68
-10
api/utils.py
api/utils.py
+17
-0
api/viewsets/applications.py
api/viewsets/applications.py
+17
-2
api/viewsets/endpoints.py
api/viewsets/endpoints.py
+16
-5
api/viewsets/services.py
api/viewsets/services.py
+18
-3
No files found.
api/utils.py
View file @
7dee1aa2
...
...
@@ -9,6 +9,7 @@ from .models import APIEndpoint
from
rest_framework.pagination
import
PageNumberPagination
from
rest_framework.response
import
Response
import
datetime
from
django.db.models.functions
import
Lower
VALIDATE_TOKEN_URL
=
settings
.
VALIDATE_TOKEN_URL
...
...
@@ -169,3 +170,19 @@ def status_message_response(code, status, message, results):
'results'
:
results
}
return
message
# Table ordering
def
tbl_ordering
(
queryset
,
**
kwargs
):
sort_field
=
kwargs
.
get
(
'sort-field'
,
None
)[
0
]
sort_order
=
kwargs
.
get
(
'sort-order'
,
None
)[
0
]
if
sort_order
.
lower
()
==
'asc'
:
queryset
=
queryset
.
order_by
(
Lower
(
sort_field
)
.
asc
())
else
:
queryset
=
queryset
.
order_by
(
Lower
(
sort_field
)
.
desc
())
return
queryset
api/viewsets/applications.py
View file @
7dee1aa2
...
...
@@ -7,8 +7,10 @@ from api.models import Application
from
api.serializers
import
ApplicationSerializer
,
GroupDependentSerializer
from
api.utils
import
(
CustomPagination
,
BadRequestException
,
status_message_response
,
number_generator
status_message_response
,
number_generator
,
tbl_ordering
)
from
django_filters.rest_framework
import
DjangoFilterBackend
from
rest_framework.filters
import
SearchFilter
AUTHENTICATOR_GROUP
=
settings
.
AUTHENTICATOR_GROUP
...
...
@@ -22,6 +24,9 @@ class ApplicationViewSet(viewsets.ModelViewSet):
queryset
=
Application
.
objects
.
all
()
serializer_class
=
ApplicationSerializer
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,)
search_fields
=
(
'application_no'
,
'name'
,
'code'
)
# filter_class = APIEndpointFilter
# CREATE Application
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -58,10 +63,19 @@ class ApplicationViewSet(viewsets.ModelViewSet):
# SHOW LIST of Applications
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
queryset
=
Application
.
objects
.
filter
(
deleted_at__exact
=
None
)
# queryset = Application.objects.filter(deleted_at__exact=None)
queryset
=
self
.
queryset
.
filter
(
deleted_at__exact
=
None
)
queryset
=
self
.
filter_queryset
(
queryset
)
ids
=
self
.
request
.
query_params
.
get
(
'ids'
,
None
)
# table ordering
if
'sort-field'
and
'sort-order'
in
request
.
query_params
:
queryset
=
tbl_ordering
(
queryset
,
**
request
.
query_params
)
if
not
queryset
.
exists
():
message
=
status_message_response
(
200
,
'success'
,
'No records found'
,
[]
...
...
@@ -79,6 +93,7 @@ class ApplicationViewSet(viewsets.ModelViewSet):
ids
=
item
[
'id'
]
req
=
requests
.
get
(
f
'{AUTHENTICATOR_GROUP}/{ids}/'
)
groups
=
req
.
json
()[
'groups'
]
modules
=
req
.
json
()[
'modules'
]
item
[
'groups'
]
=
groups
item
[
'modules'
]
=
modules
...
...
api/viewsets/endpoints.py
View file @
7dee1aa2
...
...
@@ -4,10 +4,11 @@ from rest_framework.response import Response
from
api.models
import
APIEndpoint
from
api.serializers
import
APIEndpointSerializer
from
api.utils
import
(
APIEndpointFilter
,
CustomPagina
tion
,
BadRequestException
,
status_message_response
,
number_generator
CustomPagination
,
BadRequestExcep
tion
,
status_message_response
,
number_generator
,
tbl_ordering
)
from
django_filters.rest_framework
import
DjangoFilterBackend
from
rest_framework.filters
import
SearchFilter
class
APIEndpointViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -17,9 +18,13 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
queryset
=
APIEndpoint
.
objects
.
all
()
.
order_by
(
'service'
)
serializer_class
=
APIEndpointSerializer
lookup_field
=
'pk'
filter_backends
=
(
DjangoFilterBackend
,
)
filter_class
=
APIEndpointFilter
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,)
search_fields
=
(
'api_endpoint_no'
,
'service__name'
,
'name'
,
'description'
,
'http_method'
,
'endpoint_url'
)
# filter_class = APIEndpointFilter
# CREATE Endpoint
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -56,7 +61,13 @@ class APIEndpointViewSet(viewsets.ModelViewSet):
# SHOW LIST of endpoints
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
queryset
=
APIEndpoint
.
objects
.
filter
(
deleted_at__exact
=
None
)
queryset
=
self
.
queryset
.
filter
(
deleted_at__exact
=
None
)
queryset
=
self
.
filter_queryset
(
queryset
)
# table ordering
if
'sort-field'
and
'sort-order'
in
request
.
query_params
:
queryset
=
tbl_ordering
(
queryset
,
**
request
.
query_params
)
if
not
queryset
.
exists
():
message
=
status_message_response
(
...
...
api/viewsets/services.py
View file @
7dee1aa2
...
...
@@ -5,9 +5,11 @@ from api.models import APIService
from
api.serializers
import
APIServiceSerializer
from
api.utils
import
(
CustomPagination
,
BadRequestException
,
status_message_response
,
number_generator
status_message_response
,
number_generator
,
tbl_ordering
)
from
django.utils.crypto
import
get_random_string
from
django_filters.rest_framework
import
DjangoFilterBackend
from
rest_framework.filters
import
SearchFilter
class
APIServiceViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -18,6 +20,10 @@ class APIServiceViewSet(viewsets.ModelViewSet):
serializer_class
=
APIServiceSerializer
lookup_field
=
'pk'
pagination_class
=
CustomPagination
filter_backends
=
(
DjangoFilterBackend
,
SearchFilter
,)
search_fields
=
(
'api_service_no'
,
'name'
,
'service_url'
,
'application__name'
)
# CREATE Service
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -54,8 +60,16 @@ class APIServiceViewSet(viewsets.ModelViewSet):
# SHOW LIST of services
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
queryset
=
APIService
.
objects
.
filter
(
deleted_at__exact
=
None
)
queryset
=
self
.
queryset
.
filter
(
deleted_at__exact
=
None
)
queryset
=
self
.
filter_queryset
(
queryset
)
# table ordering
if
'sort-field'
and
'sort-order'
in
request
.
query_params
:
queryset
=
tbl_ordering
(
queryset
,
**
request
.
query_params
)
if
not
queryset
.
exists
():
message
=
status_message_response
(
...
...
@@ -180,7 +194,8 @@ class APIServiceViewSet(viewsets.ModelViewSet):
@
action
(
methods
=
[
"GET"
],
detail
=
False
)
def
archived
(
self
,
request
,
pk
=
None
):
try
:
queryset
=
APIService
.
objects
.
filter
(
deleted_at__isnull
=
False
)
queryset
=
self
.
queryset
.
filter
(
deleted_at__isnull
=
False
)
queryset
=
self
.
filter_queryset
(
queryset
)
if
not
queryset
.
exists
():
message
=
status_message_response
(
...
...
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