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
7a09a629
Commit
7a09a629
authored
Sep 25, 2019
by
Gladys Forte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
action
parent
93ea28fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
126 deletions
+127
-126
app/applicationlayer/cms/form/views.py
app/applicationlayer/cms/form/views.py
+34
-57
app/applicationlayer/cms/utils_cr.py
app/applicationlayer/cms/utils_cr.py
+56
-35
app/applicationlayer/utils.py
app/applicationlayer/utils.py
+36
-34
app/entities/enums.py
app/entities/enums.py
+1
-0
No files found.
app/applicationlayer/cms/form/views.py
View file @
7a09a629
...
...
@@ -295,7 +295,7 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
form_header
=
get_object_or_404
(
models
.
ChangeRequestFormHeader
,
pk
=
instance
.
id
)
new_instance
=
model_to_dict
(
form_header
)
# save history in form header
...
...
@@ -343,25 +343,8 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
)
.
aggregate
(
Min
(
'level'
))
min_level
=
min_level
.
get
(
'level__min'
)
# get details of next approver/s
next_approver
=
models
.
ChangeRequestFormApprovers
.
objects
.
filter
(
level
=
str
(
min_level
),
form_code
=
form_code
)
# LOOP on next approver for sending email
for
n_approver
in
next_approver
:
# NOTIF MSG FOR NEXT APPROVER
notification_msg
=
APPROVER_MESSAGE
.
split
(
';'
)[
0
]
if
n_approver
.
delegation
.
lower
()
==
'vendor/implementor'
:
notification_msg
=
VENDOR_ACKNOWLEDGE_MESSAGE
.
split
(
';'
)[
0
]
next_approver_email
(
n_approver
.
user
.
code
,
form_code
,
n_approver
.
delegation
.
lower
(),
notification_msg
)
next_approver_email
(
form_code
,
min_level
)
# update next approver details
models
.
ChangeRequestFormApprovers
.
objects
.
filter
(
...
...
@@ -385,13 +368,15 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
# generate batchno history
batchno
=
get_max_batchno
(
"batch"
)
# partial update
partial
=
kwargs
.
pop
(
'partial'
,
True
)
instance
=
self
.
get_object
()
form_code
=
kwargs
[
'form_code'
]
status_update
=
{
"status"
:
'Draft'
}
serializer
=
self
.
get_serializer
(
instance
,
...
...
@@ -476,41 +461,38 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
# generate batchno history
batchno
=
get_max_batchno
(
"batch"
)
# get old data
old_instance
=
models
.
ChangeRequestFormApprovers
.
objects
.
filter
(
pk
=
id
)
.
values
()
action_data
=
{
'id'
:
int
(
request
.
data
[
'id'
]),
'action'
:
action
,
'remarks'
:
remarks
,
'action_date'
:
datetime
.
now
()
}
old_instance
=
list
(
old_instance
)
# update current row in routing table
models
.
ChangeRequestFormApprovers
.
objects
.
filter
(
pk
=
id
)
.
update
(
action
=
action
,
remarks
=
remarks
,
action_date
=
datetime
.
now
())
approver_instance
=
models
.
ChangeRequestFormApprovers
.
objects
.
get
(
pk
=
id
)
serializer
=
serializers
.
ChangeRequestFormApproversSerializer
(
approver_instance
,
data
=
action_data
,
partial
=
True
)
serializer
.
is_valid
(
raise_exception
=
True
)
old_instance
=
model_to_dict
(
approver_instance
)
# get new data
new_instance
=
models
.
ChangeRequestFormApprovers
.
objects
.
filter
(
pk
=
id
)
.
values
()
self
.
perform_update
(
serializer
)
new_instance
=
serializer
.
data
new_instance
=
list
(
new_instance
)
crenum
=
action
.
upper
()
# save history in form approver
crhistory_save
(
batchno
,
"ACTION"
,
crenum
,
enums
.
CREnum
.
ACTION
.
value
,
enums
.
CREnum
.
UPDATE
.
value
,
enums
.
CREntitiesEnum
.
CR_FRM_APPROVER
.
value
,
form_code
,
old_instance
,
new_instance
)
# get details of next approver/s
next_approver
=
models
.
ChangeRequestFormApprovers
.
objects
.
filter
(
level
=
str
(
next_level
),
form_code
=
form_code
)
if
action
.
lower
()
==
'approved'
:
# NOTIF MSG FOR REQUESTOR
...
...
@@ -526,16 +508,7 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
remarks
,
level
)
# LOOP on next approver for sending email
for
n_approver
in
next_approver
:
if
n_approver
.
delegation
.
lower
()
==
'vendor/implementor'
:
notification_msg
=
VENDOR_ACKNOWLEDGE_MESSAGE
.
split
(
';'
)[
0
]
next_approver_email
(
n_approver
.
user
.
code
,
form_code
,
delegation
,
notification_msg
)
next_approver_email
(
form_code
,
next_level
)
# update next approver details
models
.
ChangeRequestFormApprovers
.
objects
.
filter
(
...
...
@@ -613,11 +586,15 @@ class ChangeRequestFormsViewset(meviewsets.ModelViewSet):
models
.
ChangeRequestFormHeader
.
objects
.
filter
(
form_code
=
form_code
)
.
update
(
status
=
'Cancelled'
)
return
Response
(
"Action performed"
,
status
=
status
.
HTTP_200_OK
message
=
status_message_response
(
200
,
'success'
,
'Action performed'
,
serializer
.
data
)
return
Response
(
message
,
status
=
status
.
HTTP_200_OK
)
@
transaction
.
atomic
@
action
(
methods
=
[
'PATCH'
],
detail
=
True
,
...
...
app/applicationlayer/cms/utils_cr.py
View file @
7a09a629
...
...
@@ -18,6 +18,14 @@ from django.db.models import Max
CR_FRONT_LINK
=
settings
.
CR_FRONT_LINK
APPROVER_MESSAGE
=
settings
.
APPROVER_MESSAGE
REQUESTOR_MESSAGE
=
settings
.
REQUESTOR_MESSAGE
REQUESTOR_REJECT_MESSAGE
=
settings
.
REQUESTOR_REJECT_MESSAGE
VENDOR_ACKNOWLEDGE_MESSAGE
=
settings
.
VENDOR_ACKNOWLEDGE_MESSAGE
REQUESTOR_ACKNOWLEDGE_MESSAGE
=
settings
.
REQUESTOR_ACKNOWLEDGE_MESSAGE
REQUESTOR_COMPLETION_MESSAGE
=
settings
.
REQUESTOR_COMPLETION_MESSAGE
VENDOR_ACCEPTANCE_MESSAGE
=
settings
.
VENDOR_ACCEPTANCE_MESSAGE
VENDOR_REJECT_MESSAGE
=
settings
.
VENDOR_REJECT_MESSAGE
def
entity_log_bulk
(
queryset
,
entity
,
tbl
):
...
...
@@ -277,7 +285,7 @@ def send_mail_requestor(current_user,
current_user
)
def
next_approver_email
(
receiver
,
form_code
,
delegation
,
msg
):
def
next_approver_email
(
form_code
,
next_level
):
cr_link
=
f
'{CR_FRONT_LINK}/{form_code}'
template_instance
=
get_template_instance
(
form_code
)
...
...
@@ -289,12 +297,6 @@ def next_approver_email(receiver, form_code, delegation, msg):
requested_to_priority
=
template_instance
.
requested_to_priority
cr_status
=
template_instance
.
status
# next approver details --------------------------------------------------
receiver_instance
=
get_account_details
(
receiver
)
receiver_name
=
receiver_instance
.
values_list
(
'name'
,
flat
=
True
)[
0
]
receiver_email
=
receiver_instance
.
values_list
(
'email'
,
flat
=
True
)[
0
]
receiver_code
=
receiver_instance
.
values_list
(
'code'
,
flat
=
True
)[
0
]
# requestor details --------------------------------------------------
sender_instance
=
get_account_details
(
requested_by_user
)
sender_email
=
sender_instance
.
values_list
(
'email'
,
flat
=
True
)[
0
]
...
...
@@ -306,34 +308,55 @@ def next_approver_email(receiver, form_code, delegation, msg):
company
=
get_companies_details
(
requested_to_company
)
company_name
=
company
.
values_list
(
'name'
,
flat
=
True
)[
0
]
# call sender email
name
=
receiver_name
cr_number
=
cr_number
cr_name
=
template_name
company_requestedto
=
company_name
department_requestedto
=
dept_name
priority_level
=
requested_to_priority
status
=
cr_status
url
=
cr_link
# get details of next approver/s
next_approver
=
models
.
ChangeRequestFormApprovers
.
objects
.
filter
(
level
=
str
(
next_level
),
form_code
=
form_code
)
recipient
=
receiver_email
delegation_type
=
delegation
admin
=
sender_email
args
=
[
name
,
cr_number
,
cr_name
,
company_requestedto
,
department_requestedto
,
priority_level
,
status
,
url
,
recipient
,
delegation_type
,
admin
]
main_threading
(
args
,
sender
.
routing_table_actions_required
)
message
=
f
"{sender_name} {msg} ({template_name})"
# create notification
notification_create
(
form_code
,
message
,
receiver_code
,
sender_code
)
# LOOP on next approver for sending email
for
n_approver
in
next_approver
:
# NOTIF MSG FOR NEXT APPROVER
msg
=
APPROVER_MESSAGE
.
split
(
';'
)[
0
]
if
n_approver
.
delegation
.
lower
()
==
'vendor/implementor'
:
msg
=
VENDOR_ACKNOWLEDGE_MESSAGE
.
split
(
';'
)[
0
]
# next approver details --------------------------------------------------
receiver_instance
=
get_account_details
(
n_approver
.
user
.
code
)
receiver_name
=
receiver_instance
.
values_list
(
'name'
,
flat
=
True
)[
0
]
receiver_email
=
receiver_instance
.
values_list
(
'email'
,
flat
=
True
)[
0
]
receiver_code
=
receiver_instance
.
values_list
(
'code'
,
flat
=
True
)[
0
]
# call sender email
name
=
receiver_name
cr_number
=
cr_number
cr_name
=
template_name
company_requestedto
=
company_name
department_requestedto
=
dept_name
priority_level
=
requested_to_priority
status
=
cr_status
url
=
cr_link
recipient
=
receiver_email
delegation_type
=
n_approver
.
delegation
.
lower
()
admin
=
sender_email
args
=
[
name
,
cr_number
,
cr_name
,
company_requestedto
,
department_requestedto
,
priority_level
,
status
,
url
,
recipient
,
delegation_type
,
admin
]
main_threading
(
args
,
sender
.
routing_table_actions_required
)
message
=
f
"{sender_name} {msg} ({template_name})"
# create notification
notification_create
(
form_code
,
message
,
receiver_code
,
sender_code
)
def
cancel_overdue
(
request
):
...
...
@@ -448,5 +471,3 @@ def crhistory_log_bulk_delete(queryset, entity, tbl, form_code,
return
True
except
IntegrityError
as
exc
:
raise
APIException
(
detail
=
exc
)
app/applicationlayer/utils.py
View file @
7a09a629
...
...
@@ -139,39 +139,41 @@ def send_broadcast_message(room_name, sender, message):
def
notification_create
(
form_code
,
message
,
account_no
,
sender_account_no
):
# try:
v
=
Notification
.
objects
.
create
(
form_code
=
form_code
,
notif_type
=
'TASK'
,
message
=
message
,
is_read
=
False
,
app
=
'APP-20190909-0000002'
,
account_no
=
account_no
,
sender_account_no
=
sender_account_no
)
print
(
v
)
# ROOM = account_no
# SENDER = sender_account_no
# send_broadcast_message(
# ROOM,
# SENDER,
# 'NEW NOTIFICATIONS'
# )
# message = {
# 'code': 200,
# 'status': 'success',
# 'message': 'Notification successfully created!',
# }
# return Response(message, status=status.HTTP_200_OK)
return
True
try
:
Notification
.
objects
.
create
(
form_code
=
form_code
,
notif_type
=
'TASK'
,
message
=
message
,
is_read
=
False
,
app
=
'APP-20190909-0000002'
,
account_no
=
account_no
,
sender_account_no
=
sender_account_no
)
ROOM
=
account_no
SENDER
=
sender_account_no
send_broadcast_message
(
ROOM
,
SENDER
,
'NEW NOTIFICATIONS'
)
# except Exception as e:
# message = {
# 'code': 500,
# 'status': 'failed',
# 'message': 'Request was not able to process' + str(e.__class__)
# }
# return Response(message,
# status=status.HTTP_500_INTERNAL_SERVER_ERROR)
\ No newline at end of file
# message = {
# 'code': 200,
# 'status': 'success',
# 'message': 'Notification successfully created!',
# }
# return Response(message, status=status.HTTP_200_OK)
return
True
except
Exception
as
e
:
message
=
{
'code'
:
500
,
'status'
:
'failed'
,
'message'
:
'Request was not able to process'
+
str
(
e
.
__class__
)
}
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
\ No newline at end of file
app/entities/enums.py
View file @
7a09a629
...
...
@@ -103,6 +103,7 @@ class CREnum(Enum):
ACCEPTED
=
"ACCEPTED"
ACKNOWLEDGED
=
"ACKNOWLEDGED"
REJECTED
=
"REJECTED"
ACTION
=
"ACTION"
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