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
e913cfde
Commit
e913cfde
authored
Sep 24, 2019
by
Gladys Forte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean code for save and submit
parent
8b1ed17e
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
234 additions
and
948 deletions
+234
-948
app/applicationlayer/cms/form/views.py
app/applicationlayer/cms/form/views.py
+121
-946
app/applicationlayer/cms/template/views.py
app/applicationlayer/cms/template/views.py
+9
-1
app/applicationlayer/cms/utils_cr.py
app/applicationlayer/cms/utils_cr.py
+21
-1
app/businesslayer/changerequest/change_request.py
app/businesslayer/changerequest/change_request.py
+83
-0
No files found.
app/applicationlayer/cms/form/views.py
View file @
e913cfde
This diff is collapsed.
Click to expand it.
app/applicationlayer/cms/template/views.py
View file @
e913cfde
...
...
@@ -285,7 +285,15 @@ class ChangeRequestTemplatesViewset(meviewsets.ModelViewSet):
template_no
)
return
Response
(
serializer
.
data
)
serializer
=
self
.
get_serializer
(
instance
)
message
=
status_message_response
(
200
,
'success'
,
'Change Request Template successfully updated'
,
serializer
.
data
)
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
return
Response
(
"Unable to edit due to existing transaction"
,
...
...
app/applicationlayer/cms/utils_cr.py
View file @
e913cfde
...
...
@@ -427,4 +427,24 @@ def crhistory_save(batch_no, main_action,
toValue
=
toValue
)
return
True
\ No newline at end of file
return
True
def
crhistory_log_bulk_delete
(
queryset
,
entity
,
tbl
,
form_code
,
batch_no
,
main_action
):
try
:
# print(entity)
for
data
in
queryset
:
test
=
model_to_dict
(
data
)
crhistory_save
(
batch_no
,
main_action
,
enums
.
CREnum
.
DELETED
.
value
,
entity
,
form_code
,
test
,
''
)
tbl
.
objects
.
filter
(
id
=
test
[
'id'
])
.
delete
()
return
True
except
IntegrityError
as
exc
:
raise
APIException
(
detail
=
exc
)
\ No newline at end of file
app/businesslayer/changerequest/change_request.py
View file @
e913cfde
...
...
@@ -13,6 +13,14 @@ from django.http import Http404
from
django.db.models
import
Q
from
app.applicationlayer.cms.utils_cr
import
(
number_generator
,
crhistory_save
,
entity_log_bulk
,
crhistory_log_bulk_delete
)
from
django.forms.models
import
model_to_dict
from
app.entities
import
enums
,
models
from
app.applicationlayer.utils
import
log_save
,
CustomPagination
from
app.applicationlayer.cms.template
import
serializers
def
list_by_user
(
user_id_number
):
...
...
@@ -242,3 +250,78 @@ def filter_awaiting(base_queryset,
pass
return
return_queryset
def
form_add_edit_delete
(
form_request_body
,
queryset
,
entity
,
serializer_data
,
partial
,
self
,
form_code
,
batch_no
,
main_action
):
# delete ids not in request body
request_ids
=
[
i
[
'id'
]
for
i
in
form_request_body
if
"id"
in
i
]
delete_query
=
queryset
.
objects
.
filter
(
form_code
=
form_code
)
.
exclude
(
id__in
=
request_ids
)
if
delete_query
.
count
()
>
0
:
crhistory_log_bulk_delete
(
delete_query
,
entity
,
queryset
,
form_code
,
batch_no
,
main_action
)
# update or create
for
i
in
form_request_body
:
if
"id"
in
i
:
frm_instance
=
queryset
.
objects
.
get
(
pk
=
i
[
'id'
]
)
serializer
=
serializer_data
(
frm_instance
,
data
=
i
,
partial
=
partial
)
serializer
.
is_valid
(
raise_exception
=
True
)
old_instance
=
model_to_dict
(
frm_instance
)
self
.
perform_update
(
serializer
)
new_instance
=
serializer
.
data
crhistory_save
(
batch_no
,
main_action
,
enums
.
CREnum
.
UPDATE
.
value
,
entity
,
form_code
,
old_instance
,
new_instance
)
else
:
serializer
=
serializer_data
(
data
=
i
)
serializer
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
serializer
)
new_instance
=
serializer
.
data
crhistory_save
(
batch_no
,
main_action
,
enums
.
CREnum
.
ADD
.
value
,
entity
,
form_code
,
None
,
new_instance
)
return
True
\ 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