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
a0f98277
Commit
a0f98277
authored
Sep 17, 2019
by
Gladys Forte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notif model update
parent
f16d05bb
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
278 additions
and
311 deletions
+278
-311
app/applicationlayer/cms/form/serializers.py
app/applicationlayer/cms/form/serializers.py
+1
-1
app/applicationlayer/cms/form/views.py
app/applicationlayer/cms/form/views.py
+134
-196
app/applicationlayer/cms/utils_cr.py
app/applicationlayer/cms/utils_cr.py
+11
-24
app/applicationlayer/management/department/views.py
app/applicationlayer/management/department/views.py
+1
-1
app/applicationlayer/management/notification/utils_notif.py
app/applicationlayer/management/notification/utils_notif.py
+0
-16
app/applicationlayer/management/notification/views.py
app/applicationlayer/management/notification/views.py
+1
-45
app/applicationlayer/utils.py
app/applicationlayer/utils.py
+57
-1
app/entities/enums.py
app/entities/enums.py
+10
-0
app/entities/migrations/0013_auto_20190917_1620.py
app/entities/migrations/0013_auto_20190917_1620.py
+43
-0
app/entities/models.py
app/entities/models.py
+17
-24
app/helper/email_service/sender.py
app/helper/email_service/sender.py
+3
-3
No files found.
app/applicationlayer/cms/form/serializers.py
View file @
a0f98277
...
...
@@ -117,4 +117,4 @@ class ChangeRequestFormHeaderSerializer(
'template_no'
,
'frm_approvers'
,
'frm_stakes'
,
'frm_attachments'
,
'frm_details'
)
read_only_fields
=
[
'created'
,
'
archived_at'
,
'
form_code'
]
read_only_fields
=
[
'created'
,
'form_code'
]
app/applicationlayer/cms/form/views.py
View file @
a0f98277
This diff is collapsed.
Click to expand it.
app/applicationlayer/cms/utils_cr.py
View file @
a0f98277
...
...
@@ -6,7 +6,7 @@ import requests
from
app.entities
import
models
from
datetime
import
timedelta
from
django.db.models
import
Q
from
app.applicationlayer.utils
import
main_threading
from
app.applicationlayer.utils
import
main_threading
,
notification_create
from
app.helper.email_service
import
sender
CR_FRONT_LINK
=
settings
.
CR_FRONT_LINK
...
...
@@ -249,12 +249,11 @@ def send_mail_vendor(receiver,
)
def
send_mail_requestor
(
receiv
er
,
def
send_mail_requestor
(
current_us
er
,
form_code
,
delegation
,
msg
,
action
,
code
,
remarks
,
routing_level
):
...
...
@@ -273,9 +272,10 @@ def send_mail_requestor(receiver,
requestor_instance
=
get_account_details
(
requested_by_user
)
requestor_name
=
requestor_instance
.
values_list
(
'name'
,
flat
=
True
)[
0
]
requestor_email
=
requestor_instance
.
values_list
(
'email'
,
flat
=
True
)[
0
]
requestor_code
=
requestor_instance
.
values_list
(
'code'
,
flat
=
True
)[
0
]
# sender details --------------------------------------------------
sender_instance
=
get_account_details
(
receiv
er
)
sender_instance
=
get_account_details
(
current_us
er
)
sender_email
=
sender_instance
.
values_list
(
'email'
,
flat
=
True
)[
0
]
sender_name
=
sender_instance
.
values_list
(
'name'
,
flat
=
True
)[
0
]
...
...
@@ -307,34 +307,20 @@ def send_mail_requestor(receiver,
url
,
recipient
,
action_type
,
admin
]
main_threading
(
args
,
sender
.
routing_table_actions
)
# if action.lower() == 'approved':
# new_body = {"approved_by": sender_name}
# elif action.lower() == 'rejected':
# new_body = {"rejected_by": sender_name,
# "remarks": remarks}
# elif action.lower() == 'completed':
# new_body = {"completed_by": sender_name}
# elif action.lower() == 'acknowledged':
# new_body = {"acknowledge_by": sender_name}
# data = {**data, **new_body}
message
=
f
"{sender_name} {msg} ({template_name})"
#
message = f"{sender_name} {msg} ({template_name})"
#
create notification
# notif = send_notification(
# form_code, cr_number,
# requestor_account_id, requestor_name,
# message, app,
# sender_account_id, sender_account_username
# )
notification_create
(
form_code
,
message
,
requestor_code
,
current_user
)
def
next_appover_email
(
receiver
,
form_code
,
delegation
,
msg
,
action
,
code
):
def
next_app
r
over_email
(
receiver
,
form_code
,
delegation
,
msg
,
action
,
code
):
cr_link
=
f
'{CR_FRONT_LINK}/{form_code}'
template_instance
=
get_template_instance
(
form_code
)
app
=
'cms'
cr_number
=
template_instance
.
requested_to_template_id
template_name
=
template_instance
.
requested_to_template_name
requested_to_company
=
template_instance
.
requested_to_company
...
...
@@ -456,4 +442,5 @@ def crhistory_save(action, entity, form_code, fromValue, toValue):
fromValue
=
fromValue
,
toValue
=
toValue
)
return
True
\ No newline at end of file
app/applicationlayer/management/department/views.py
View file @
a0f98277
...
...
@@ -64,7 +64,7 @@ class DepartmentViewSet(viewsets.ModelViewSet):
@
decorators
.
error_safe
@
transaction
.
atomic
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
new_instance
=
model_to_dict
(
instance
)
self
.
perform_destroy
(
instance
)
...
...
app/applicationlayer/management/notification/utils_notif.py
View file @
a0f98277
from
django.conf
import
settings
from
websocket
import
create_connection
import
json
from
rest_framework.pagination
import
PageNumberPagination
from
rest_framework.response
import
Response
REALTIMESERVER_IP
=
settings
.
REALTIMESERVER_IP
def
send_broadcast_message
(
room_name
,
sender
,
message
):
# ws = create_connection(f"ws://{REALTIMESERVER_IP}/ws/realtimeserver/{room_name}/")
ws
=
create_connection
(
f
"ws://{REALTIMESERVER_IP}/ws/chat/{room_name}/"
)
data
=
{
'sender'
:
sender
,
'message'
:
message
}
ws
.
send
(
json
.
dumps
(
data
))
ws
.
close
()
class
CustomPagination
(
PageNumberPagination
):
page_size
=
10
...
...
app/applicationlayer/management/notification/views.py
View file @
a0f98277
...
...
@@ -14,14 +14,11 @@ from rest_framework import status
from
django.conf
import
settings
from
app.applicationlayer.management.notification.utils_notif
import
(
send_broadcast_message
,
CustomPagination
)
from
app.applicationlayer.utils
import
(
status_message_response
)
from
rest_framework.exceptions
import
ValidationError
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
rest_framework.decorators
import
action
from
rest_framework.views
import
APIView
from
app.applicationlayer.utils
import
(
status_message_response
)
class
NotificationsViewset
(
meviewsets
.
ModelViewSet
):
...
...
@@ -141,47 +138,6 @@ class NotificationsViewset(meviewsets.ModelViewSet):
return
Response
(
message
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
serializer
=
serializers
.
NotificationSerializer
(
data
=
request
.
data
)
try
:
if
serializer
.
is_valid
():
serializer
.
save
()
message
=
{
'code'
:
201
,
'status'
:
'success'
,
'message'
:
'Notification created.'
,
'results'
:
serializer
.
data
}
ROOM
=
serializer
.
data
[
'account_no'
]
SENDER
=
serializer
.
data
[
'sender_account_no'
]
send_broadcast_message
(
ROOM
,
SENDER
,
'NEW NOTIFICATIONS'
)
return
Response
(
message
,
status
=
status
.
HTTP_201_CREATED
)
except
ValidationError
as
e
:
message
=
{
'code'
:
400
,
'status'
:
'failed'
,
'message'
:
str
(
e
),
}
return
Response
(
message
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
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
)
def
index
(
request
):
return
render
(
request
,
'chat/index.html'
,
{})
...
...
app/applicationlayer/utils.py
View file @
a0f98277
...
...
@@ -3,9 +3,14 @@ from rest_framework.pagination import PageNumberPagination
from
rest_framework.response
import
Response
from
functools
import
wraps
from
app.entities
import
enums
from
app.entities.models
import
EntityLog
from
app.entities.models
import
EntityLog
,
Notification
from
django.forms.models
import
model_to_dict
from
django.conf
import
settings
from
websocket
import
create_connection
import
json
from
rest_framework
import
status
REALTIMESERVER_IP
=
settings
.
REALTIMESERVER_IP
class
CustomPagination
(
PageNumberPagination
):
page_size
=
5
...
...
@@ -119,3 +124,54 @@ def main_threading(args, func_name):
)
t1
.
start
()
return
True
# notification
def
send_broadcast_message
(
room_name
,
sender
,
message
):
ws
=
create_connection
(
f
"ws://{REALTIMESERVER_IP}/ws/chat/{room_name}/"
)
data
=
{
'sender'
:
sender
,
'message'
:
message
}
ws
.
send
(
json
.
dumps
(
data
))
ws
.
close
()
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
# 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 @
a0f98277
...
...
@@ -84,6 +84,16 @@ CR HISTORY ENUMS
*********
'''
class
CREnum
(
Enum
):
ADD
=
"ADD"
UPDATE
=
"UPDATE"
DELETED
=
"DELETED"
REROUTE
=
"REROUTE"
RESUBMIT
=
"RESUBMIT"
SUBMIT
=
"SUBMIT"
SAVE
=
"SAVE"
class
CREntitiesEnum
(
Enum
):
CR_FRM_APPROVER
=
"CR_FRM_APPROVER"
CR_FRM_ATTACHMENT
=
"CR_FRM_ATTACHMENT"
...
...
app/entities/migrations/0013_auto_20190917_1620.py
0 → 100644
View file @
a0f98277
# Generated by Django 2.2 on 2019-09-17 16:20
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'entities'
,
'0012_auto_20190913_1704'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'changerequesthistory'
,
name
=
'action'
,
field
=
models
.
CharField
(
max_length
=
50
),
),
migrations
.
AlterField
(
model_name
=
'changerequesthistory'
,
name
=
'entity'
,
field
=
models
.
CharField
(
max_length
=
50
),
),
migrations
.
AlterField
(
model_name
=
'notification'
,
name
=
'account_no'
,
field
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
,
null
=
True
),
),
migrations
.
AlterField
(
model_name
=
'notification'
,
name
=
'app'
,
field
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
,
null
=
True
),
),
migrations
.
AlterField
(
model_name
=
'notification'
,
name
=
'form_code'
,
field
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
,
null
=
True
),
),
migrations
.
AlterField
(
model_name
=
'notification'
,
name
=
'sender_account_no'
,
field
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
,
null
=
True
),
),
]
app/entities/models.py
View file @
a0f98277
...
...
@@ -857,14 +857,8 @@ CR HISTORY
class
ChangeRequestHistory
(
AuditClass
):
action
=
models
.
CharField
(
choices
=
[
(
tag
.
value
,
tag
.
value
)
for
tag
in
enums
.
LogEnum
],
default
=
enums
.
LogEnum
.
ADD
.
value
,
max_length
=
50
)
entity
=
models
.
CharField
(
choices
=
[
(
tag
.
value
,
tag
.
value
)
for
tag
in
enums
.
CREntitiesEnum
],
default
=
enums
.
CREntitiesEnum
.
CR_FRM_HEADER
.
value
,
max_length
=
50
)
form_code
=
models
.
CharField
(
max_length
=
255
,
...
...
@@ -872,7 +866,7 @@ class ChangeRequestHistory(AuditClass):
null
=
True
)
fromValue
=
models
.
TextField
(
blank
=
True
,
null
=
True
)
toValue
=
models
.
TextField
(
blank
=
True
,
null
=
True
)
def
__str__
(
self
):
return
self
.
entity
...
...
@@ -890,24 +884,23 @@ class Notification(models.Model):
code
=
models
.
CharField
(
unique
=
True
,
max_length
=
255
)
# primary key
form_code
=
models
.
ForeignKey
(
ChangeRequestFormHeader
,
on_delete
=
models
.
DO_NOTHING
,
to_field
=
'form_code'
)
app
=
models
.
ForeignKey
(
Application
,
on_delete
=
models
.
DO_NOTHING
,
to_field
=
'code'
)
form_code
=
models
.
CharField
(
null
=
True
,
blank
=
True
,
max_length
=
255
)
app
=
models
.
CharField
(
null
=
True
,
blank
=
True
,
max_length
=
255
)
notif_type
=
models
.
CharField
(
choices
=
[(
tag
.
value
,
tag
.
value
)
for
tag
in
enums
.
NotifTypeEnum
],
default
=
enums
.
NotifTypeEnum
.
TASK
.
value
,
max_length
=
20
)
account_no
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
DO_NOTHING
,
to_field
=
'code'
,
related_name
=
'receiver_account_no'
)
account_no
=
models
.
CharField
(
null
=
True
,
blank
=
True
,
max_length
=
255
)
message
=
models
.
CharField
(
max_length
=
255
,
null
=
True
,
...
...
@@ -915,10 +908,10 @@ class Notification(models.Model):
is_read
=
models
.
BooleanField
(
default
=
False
,
null
=
True
)
sender_account_no
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
DO_NOTHING
,
to_field
=
'code'
,
related_name
=
'sender_account_no'
)
sender_account_no
=
models
.
CharField
(
null
=
True
,
blank
=
True
,
max_length
=
255
)
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
modified
=
models
.
DateTimeField
(
auto_now
=
True
)
...
...
app/helper/email_service/sender.py
View file @
a0f98277
...
...
@@ -498,13 +498,13 @@ def routing_table_actions(args):
if
action_type
.
lower
()
==
'approved'
:
email_template
=
'RMS-CRAPPROVED.html'
subject
=
'Resource Management System - Change Request Approved'
elif
action_type
==
'acknowledged'
:
elif
action_type
.
lower
()
==
'acknowledged'
:
email_template
=
'RMS-CRACKNOWLEDGE.html'
subject
=
'Resource Management System - Change Request Acknowledged'
elif
action_by
==
'completed'
:
elif
action_by
.
lower
()
==
'completed'
:
email_template
=
'RMS-CRCOMPLETED.html'
subject
=
'Resource Management System - Change Request Completed'
elif
action_type
==
'accepted'
:
elif
action_type
.
lower
()
==
'accepted'
:
email_template
=
'RMS-CRACCEPTED.html'
subject
=
'Resource Management System - Change Request Accepted'
...
...
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