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
57a98392
Commit
57a98392
authored
May 24, 2019
by
John Red Medrano
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6 in RMS/api-main-service from red-develop to dev
* commit '
9b27b1b7
': adjust model of account
parents
e6c001b7
9b27b1b7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
26 deletions
+50
-26
api/models.py
api/models.py
+3
-3
api/serializers.py
api/serializers.py
+5
-2
api/urls.py
api/urls.py
+2
-1
api/utils.py
api/utils.py
+15
-10
api/viewsets/applications.py
api/viewsets/applications.py
+21
-10
docker-compose.yml
docker-compose.yml
+4
-0
No files found.
api/models.py
View file @
57a98392
api/serializers.py
View file @
57a98392
...
@@ -3,9 +3,12 @@ from .models import APIService, APIEndpoint, Application
...
@@ -3,9 +3,12 @@ from .models import APIService, APIEndpoint, Application
from
api.utils
import
BadRequestException
,
number_generator
from
api.utils
import
BadRequestException
,
number_generator
from
rest_framework.exceptions
import
ValidationError
from
rest_framework.exceptions
import
ValidationError
from
django.utils.crypto
import
get_random_string
from
django.utils.crypto
import
get_random_string
from
django.conf
import
settings
ACCOUNT_GROUP
=
settings
.
ACCOUNT_GROUP
class
GroupDependentSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Application
fields
=
(
'id'
,
'name'
,
'code'
)
class
ApplicationSerializer
(
serializers
.
ModelSerializer
):
class
ApplicationSerializer
(
serializers
.
ModelSerializer
):
...
...
api/urls.py
View file @
57a98392
from
api.viewsets.applications
import
ApplicationViewSet
from
api.viewsets.applications
import
ApplicationViewSet
,
GroupDependentViewSet
from
api.viewsets.services
import
APIServiceViewSet
from
api.viewsets.services
import
APIServiceViewSet
from
api.viewsets.endpoints
import
APIEndpointViewSet
from
api.viewsets.endpoints
import
APIEndpointViewSet
from
django.urls
import
path
,
include
from
django.urls
import
path
,
include
...
@@ -11,6 +11,7 @@ router = DefaultRouter()
...
@@ -11,6 +11,7 @@ router = DefaultRouter()
router
.
register
(
r'applications'
,
ApplicationViewSet
)
router
.
register
(
r'applications'
,
ApplicationViewSet
)
router
.
register
(
r'services'
,
APIServiceViewSet
)
router
.
register
(
r'services'
,
APIServiceViewSet
)
router
.
register
(
r'endpoint'
,
APIEndpointViewSet
)
router
.
register
(
r'endpoint'
,
APIEndpointViewSet
)
router
.
register
(
r'group-dependent'
,
GroupDependentViewSet
)
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
include
(
router
.
urls
)),
path
(
''
,
include
(
router
.
urls
)),
...
...
api/utils.py
View file @
57a98392
...
@@ -13,9 +13,11 @@ import datetime
...
@@ -13,9 +13,11 @@ import datetime
VALIDATE_TOKEN_URL
=
settings
.
VALIDATE_TOKEN_URL
VALIDATE_TOKEN_URL
=
settings
.
VALIDATE_TOKEN_URL
class
BadRequestException
(
Exception
):
class
BadRequestException
(
Exception
):
pass
pass
class
APIEndpointFilter
(
FilterSet
):
class
APIEndpointFilter
(
FilterSet
):
service
=
filters
.
CharFilter
(
'service__name'
)
service
=
filters
.
CharFilter
(
'service__name'
)
...
@@ -123,9 +125,10 @@ class Helper:
...
@@ -123,9 +125,10 @@ class Helper:
status
.
HTTP_500_INTERNAL_SERVER_ERROR
,
status
.
HTTP_500_INTERNAL_SERVER_ERROR
,
self
.
_headers
)
self
.
_headers
)
class
CustomPagination
(
PageNumberPagination
):
class
CustomPagination
(
PageNumberPagination
):
page_size
=
5
# Set number of result to display per page
page_size
=
5
max_page_size
=
50
# Sets max page size that user may request
max_page_size
=
50
page_query_param
=
'page'
page_query_param
=
'page'
page_size_query_param
=
'page_size'
page_size_query_param
=
'page_size'
...
@@ -141,6 +144,7 @@ class CustomPagination(PageNumberPagination):
...
@@ -141,6 +144,7 @@ class CustomPagination(PageNumberPagination):
'results'
:
data
[
'results'
]
'results'
:
data
[
'results'
]
})
})
# autogenerated number
# autogenerated number
def
number_generator
(
prefix
,
id
):
def
number_generator
(
prefix
,
id
):
date
=
'{:
%
Y
%
m
%
d}'
.
format
(
datetime
.
datetime
.
now
())
date
=
'{:
%
Y
%
m
%
d}'
.
format
(
datetime
.
datetime
.
now
())
...
@@ -149,8 +153,10 @@ def number_generator(prefix, id):
...
@@ -149,8 +153,10 @@ def number_generator(prefix, id):
return
autogenerated_no
return
autogenerated_no
# status message
# status message
def
status_message_response
(
code
,
status
,
message
,
results
):
def
status_message_response
(
code
,
status
,
message
,
results
):
print
(
'ddd'
)
message
=
{
message
=
{
'code'
:
code
,
'code'
:
code
,
'status'
:
status
,
'status'
:
status
,
...
@@ -158,4 +164,3 @@ def status_message_response(code, status, message, results):
...
@@ -158,4 +164,3 @@ def status_message_response(code, status, message, results):
'results'
:
results
'results'
:
results
}
}
return
message
return
message
api/viewsets/applications.py
View file @
57a98392
import
requests
import
requests
# from django.db.models import F
# from django.db.models import OuterRef, Subquery
from
django.conf
import
settings
from
django.conf
import
settings
from
rest_framework
import
viewsets
,
status
from
rest_framework
import
viewsets
,
status
from
rest_framework.decorators
import
action
from
rest_framework.decorators
import
action
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
api.models
import
Application
from
api.models
import
Application
from
api.serializers
import
ApplicationSerializer
from
api.serializers
import
ApplicationSerializer
,
GroupDependentSerializer
from
api.utils
import
(
CustomPagination
,
BadRequestException
,
from
api.utils
import
(
CustomPagination
,
BadRequestException
,
status_message_response
)
status_message_response
)
...
@@ -29,7 +27,6 @@ class ApplicationViewSet(viewsets.ModelViewSet):
...
@@ -29,7 +27,6 @@ class ApplicationViewSet(viewsets.ModelViewSet):
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
self
.
perform_create
(
serializer
)
headers
=
self
.
get_success_headers
(
serializer
.
data
)
message
=
status_message_response
(
message
=
status_message_response
(
201
,
'success'
,
201
,
'success'
,
...
@@ -238,3 +235,17 @@ class ApplicationViewSet(viewsets.ModelViewSet):
...
@@ -238,3 +235,17 @@ class ApplicationViewSet(viewsets.ModelViewSet):
)
)
return
Response
(
message
,
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
class
GroupDependentViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Application
.
objects
.
all
()
serializer_class
=
GroupDependentSerializer
# def get_queryset(self):
# groups = self.request.query_params.get(
# 'groups', None
# )
# groups = groups.split(',')
# # print()
# app = Application.objects.filter(id__in=groups)
# return app
docker-compose.yml
View file @
57a98392
...
@@ -18,6 +18,10 @@ networks:
...
@@ -18,6 +18,10 @@ networks:
driver
:
bridge
driver
:
bridge
ipam
:
ipam
:
config
:
config
:
<<<<<<< HEAD
- subnet
:
172.168.70.0/16
=======
- subnet
:
172.168.70.0/16
- subnet
:
172.168.70.0/16
>
>>>>>>
e6c001b78c8f9c9e6279ba90d72e5f86f7eea858
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