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
3acde449
Commit
3acde449
authored
May 24, 2019
by
John Red Medrano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust model of account
parent
27a81cfc
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
29 deletions
+59
-29
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
+13
-3
No files found.
api/models.py
View file @
3acde449
...
@@ -3,7 +3,7 @@ from django.utils import timezone
...
@@ -3,7 +3,7 @@ from django.utils import timezone
class
Application
(
models
.
Model
):
class
Application
(
models
.
Model
):
application_no
=
models
.
CharField
(
max_length
=
250
)
application_no
=
models
.
CharField
(
max_length
=
250
)
name
=
models
.
CharField
(
max_length
=
200
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
200
,
unique
=
True
)
theme
=
models
.
IntegerField
()
theme
=
models
.
IntegerField
()
code
=
models
.
CharField
(
max_length
=
300
)
code
=
models
.
CharField
(
max_length
=
300
)
...
@@ -14,7 +14,7 @@ class Application(models.Model):
...
@@ -14,7 +14,7 @@ class Application(models.Model):
def
delete
(
self
):
def
delete
(
self
):
self
.
deleted_at
=
timezone
.
now
()
self
.
deleted_at
=
timezone
.
now
()
self
.
save
()
self
.
save
()
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
...
@@ -60,7 +60,7 @@ class APIEndpoint(models.Model):
...
@@ -60,7 +60,7 @@ class APIEndpoint(models.Model):
def
delete
(
self
):
def
delete
(
self
):
self
.
deleted_at
=
timezone
.
now
()
self
.
deleted_at
=
timezone
.
now
()
self
.
save
()
self
.
save
()
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
...
...
api/serializers.py
View file @
3acde449
...
@@ -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 @
3acde449
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 @
3acde449
...
@@ -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,13 +153,14 @@ def number_generator(prefix, id):
...
@@ -149,13 +153,14 @@ 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
,
'message'
:
message
,
'message'
:
message
,
'results'
:
results
'results'
:
results
}
}
return
message
return
message
api/viewsets/applications.py
View file @
3acde449
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,12 +27,11 @@ class ApplicationViewSet(viewsets.ModelViewSet):
...
@@ -29,12 +27,11 @@ 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'
,
'New application created'
,
serializer
.
data
'New application created'
,
serializer
.
data
)
)
return
Response
(
message
)
return
Response
(
message
)
except
BadRequestException
as
e
:
except
BadRequestException
as
e
:
...
@@ -43,9 +40,9 @@ class ApplicationViewSet(viewsets.ModelViewSet):
...
@@ -43,9 +40,9 @@ class ApplicationViewSet(viewsets.ModelViewSet):
except
Exception
as
e
:
except
Exception
as
e
:
message
=
status_message_response
(
message
=
status_message_response
(
500
,
'failed'
,
500
,
'failed'
,
'Request was not able to process'
+
str
(
e
),
[]
'Request was not able to process'
+
str
(
e
),
[]
)
)
return
Response
(
message
,
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
...
@@ -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 @
3acde449
version
:
'
3'
version
:
'
3'
services
:
services
:
main-service
:
web
:
build
:
.
build
:
.
command
:
python manage.py runserver 0.0.0.0:8000
command
:
python manage.py runserver 0.0.0.0:8000
container_name
:
main-service
volumes
:
volumes
:
-
.:/code
-
.:/code
ports
:
ports
:
-
9080:8000
-
"
7010:8000"
\ No newline at end of file
container_name
:
devrms_apimain-service
networks
:
apidevrms_net
:
ipv4_address
:
172.168.70.10
networks
:
apidevrms_net
:
driver
:
bridge
ipam
:
config
:
-
subnet
:
172.168.70.0/16
\ No newline at end of file
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