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
bb59c77c
Commit
bb59c77c
authored
Oct 08, 2019
by
Gladys Forte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file upload update
parent
2ebe8a2a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
16 deletions
+122
-16
app/applicationlayer/cms/form/header/views.py
app/applicationlayer/cms/form/header/views.py
+36
-16
app/businesslayer/changerequest/change_request.py
app/businesslayer/changerequest/change_request.py
+85
-0
app/entities/enums.py
app/entities/enums.py
+1
-0
No files found.
app/applicationlayer/cms/form/header/views.py
View file @
bb59c77c
...
@@ -1252,36 +1252,56 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
...
@@ -1252,36 +1252,56 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
@
transaction
.
atomic
()
@
transaction
.
atomic
()
@
action
(
@
action
(
methods
=
[
'P
OST
'
],
detail
=
True
,
methods
=
[
'P
ATCH
'
],
detail
=
True
,
url_path
=
'file_upload'
,
url_name
=
'file_upload'
url_path
=
'file_upload'
,
url_name
=
'file_upload'
)
)
def
file_upload
(
self
,
request
,
*
args
,
**
kwargs
):
def
file_upload
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
try
:
partial
=
kwargs
.
pop
(
'partial'
,
True
)
attach_body
=
request
.
data
attach_body
=
request
.
data
form_code
=
kwargs
[
'form_code'
]
form_code
=
kwargs
[
'form_code'
]
id_number
=
self
.
request
.
user
.
code
id_number
=
self
.
request
.
user
.
code
data_list_attach
=
[]
# generate batchno history
batchno
=
get_max_batchno
(
"batch"
)
# create form attachments
change_request
.
attachment_add_edit_delete
(
if
attach_body
[
'attachments'
]:
attach_body
[
'attachments'
],
frm_attachments
=
attach_body
[
'attachments'
]
models
.
ChangeRequestFormAttachments
,
for
frm_attachment
in
frm_attachments
:
enums
.
CREntitiesEnum
.
CR_FRM_ATTACHMENT
.
value
,
frm_attachment
[
'form_code'
]
=
form_code
ChangeRequestFormAttachmentsSerializer
,
frm_attachment
[
'uploaded_by'
]
=
id_number
partial
,
data_list_attach
.
append
(
frm_attachment
)
self
,
form_code
,
batchno
,
enums
.
CREnum
.
FILE_UPLOAD
.
value
,
id_number
)
serializerAttach
=
ChangeRequestFormAttachmentsSerializer
(
data
=
data_list_attach
,
many
=
True
)
if
serializerAttach
.
is_valid
(
raise_exception
=
True
):
serializerAttach
.
save
()
# data_list_attach = []
# # create form attachments
# if attach_body['attachments']:
# frm_attachments = attach_body['attachments']
# for frm_attachment in frm_attachments:
# frm_attachment['form_code'] = form_code
# frm_attachment['uploaded_by'] = id_number
# data_list_attach.append(frm_attachment)
# serializerAttach = ChangeRequestFormAttachmentsSerializer(
# data=data_list_attach, many=True)
# if serializerAttach.is_valid(raise_exception=True):
# serializerAttach.save()
message
=
status_message_response
(
message
=
status_message_response
(
200
,
'success'
,
200
,
'success'
,
'
New Attachments successfully sav
ed!'
,
'
Attachments successfully updat
ed!'
,
serializerAttach
.
data
''
)
)
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
...
...
app/businesslayer/changerequest/change_request.py
View file @
bb59c77c
...
@@ -328,3 +328,88 @@ def form_add_edit_delete(form_request_body,
...
@@ -328,3 +328,88 @@ def form_add_edit_delete(form_request_body,
)
)
return
True
return
True
def
attachment_add_edit_delete
(
form_request_body
,
queryset
,
entity
,
serializer_data
,
partial
,
self
,
form_code
,
batch_no
,
main_action
,
id_number
):
# 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'
]
)
frm_code
=
{
"form_code"
:
form_code
}
data
=
{
**
i
,
**
frm_code
}
serializer
=
serializer_data
(
frm_instance
,
data
=
data
,
partial
=
partial
)
serializer
.
is_valid
(
raise_exception
=
True
)
old_instance
=
model_to_dict
(
frm_instance
)
self
.
perform_update
(
serializer
)
new_instance
=
serializer
.
data
# comment
crhistory_save
(
batch_no
,
main_action
,
enums
.
CREnum
.
UPDATE
.
value
,
entity
,
form_code
,
old_instance
,
new_instance
)
else
:
frm_code
=
{
"form_code"
:
form_code
,
"uploaded_by"
:
id_number
}
data
=
{
**
i
,
**
frm_code
}
serializer
=
serializer_data
(
data
=
data
)
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
app/entities/enums.py
View file @
bb59c77c
...
@@ -111,6 +111,7 @@ class CREnum(Enum):
...
@@ -111,6 +111,7 @@ class CREnum(Enum):
REJECTED
=
"REJECTED"
REJECTED
=
"REJECTED"
ACTION
=
"ACTION"
ACTION
=
"ACTION"
CREATE
=
"CREATE"
CREATE
=
"CREATE"
FILE_UPLOAD
=
"FILE_UPLOAD"
class
CREntitiesEnum
(
Enum
):
class
CREntitiesEnum
(
Enum
):
...
...
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