Commit 76d354fa authored by John Red Medrano's avatar John Red Medrano

Merge branch 'RMSv2' of http://42.61.118.105:7990/scm/rms/api-main-service into red-develop

parents e15e62b2 59fbdf26
...@@ -117,4 +117,4 @@ class ChangeRequestFormHeaderSerializer( ...@@ -117,4 +117,4 @@ class ChangeRequestFormHeaderSerializer(
'template_no', 'frm_approvers', 'frm_stakes', 'template_no', 'frm_approvers', 'frm_stakes',
'frm_attachments', 'frm_details') 'frm_attachments', 'frm_details')
read_only_fields = ['created', 'archived_at', 'form_code'] read_only_fields = ['created', 'form_code']
This diff is collapsed.
...@@ -6,7 +6,7 @@ import requests ...@@ -6,7 +6,7 @@ import requests
from app.entities import models from app.entities import models
from datetime import timedelta from datetime import timedelta
from django.db.models import Q 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 from app.helper.email_service import sender
CR_FRONT_LINK = settings.CR_FRONT_LINK CR_FRONT_LINK = settings.CR_FRONT_LINK
...@@ -249,12 +249,11 @@ def send_mail_vendor(receiver, ...@@ -249,12 +249,11 @@ def send_mail_vendor(receiver,
) )
def send_mail_requestor(receiver, def send_mail_requestor(current_user,
form_code, form_code,
delegation, delegation,
msg, msg,
action, action,
code,
remarks, remarks,
routing_level): routing_level):
...@@ -273,9 +272,10 @@ def send_mail_requestor(receiver, ...@@ -273,9 +272,10 @@ def send_mail_requestor(receiver,
requestor_instance = get_account_details(requested_by_user) requestor_instance = get_account_details(requested_by_user)
requestor_name = requestor_instance.values_list('name', flat=True)[0] requestor_name = requestor_instance.values_list('name', flat=True)[0]
requestor_email = requestor_instance.values_list('email', 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 details --------------------------------------------------
sender_instance = get_account_details(receiver) sender_instance = get_account_details(current_user)
sender_email = sender_instance.values_list('email', flat=True)[0] sender_email = sender_instance.values_list('email', flat=True)[0]
sender_name = sender_instance.values_list('name', flat=True)[0] sender_name = sender_instance.values_list('name', flat=True)[0]
...@@ -307,34 +307,20 @@ def send_mail_requestor(receiver, ...@@ -307,34 +307,20 @@ def send_mail_requestor(receiver,
url, recipient, action_type, admin] url, recipient, action_type, admin]
main_threading(args, sender.routing_table_actions) 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( notification_create(form_code, message, requestor_code,
# form_code, cr_number, current_user)
# requestor_account_id, requestor_name,
# message, app,
# sender_account_id, sender_account_username
# )
def next_appover_email(receiver, form_code, delegation, msg, action, code): def next_approver_email(receiver, form_code, delegation, msg, action, code):
cr_link = f'{CR_FRONT_LINK}/{form_code}' cr_link = f'{CR_FRONT_LINK}/{form_code}'
template_instance = get_template_instance(form_code) template_instance = get_template_instance(form_code)
app = 'cms' app = 'cms'
cr_number = template_instance.requested_to_template_id cr_number = template_instance.requested_to_template_id
template_name = template_instance.requested_to_template_name template_name = template_instance.requested_to_template_name
requested_to_company = template_instance.requested_to_company requested_to_company = template_instance.requested_to_company
...@@ -456,4 +442,5 @@ def crhistory_save(action, entity, form_code, fromValue, toValue): ...@@ -456,4 +442,5 @@ def crhistory_save(action, entity, form_code, fromValue, toValue):
fromValue=fromValue, fromValue=fromValue,
toValue=toValue toValue=toValue
) )
return True return True
\ No newline at end of file
...@@ -65,7 +65,7 @@ class DepartmentViewSet(viewsets.ModelViewSet): ...@@ -65,7 +65,7 @@ class DepartmentViewSet(viewsets.ModelViewSet):
@decorators.error_safe @decorators.error_safe
@transaction.atomic @transaction.atomic
def destroy(self, request, *args, **kwargs): def destroy(self, request, *args, **kwargs):
instance = self.get_object() instance = self.get_object()
new_instance = model_to_dict(instance) new_instance = model_to_dict(instance)
self.perform_destroy(instance) self.perform_destroy(instance)
......
from django.conf import settings
from websocket import create_connection
import json
from rest_framework.pagination import PageNumberPagination from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response 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): class CustomPagination(PageNumberPagination):
page_size = 10 page_size = 10
......
...@@ -14,14 +14,11 @@ from rest_framework import status ...@@ -14,14 +14,11 @@ from rest_framework import status
from django.conf import settings from django.conf import settings
from app.applicationlayer.management.notification.utils_notif import ( from app.applicationlayer.management.notification.utils_notif import (
send_broadcast_message,
CustomPagination) CustomPagination)
from app.applicationlayer.utils import (status_message_response)
from rest_framework.exceptions import ValidationError from rest_framework.exceptions import ValidationError
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from rest_framework.decorators import action from rest_framework.decorators import action
from app.applicationlayer.utils import (status_message_response)
from rest_framework.views import APIView
class NotificationsViewset(meviewsets.ModelViewSet): class NotificationsViewset(meviewsets.ModelViewSet):
...@@ -141,47 +138,6 @@ class NotificationsViewset(meviewsets.ModelViewSet): ...@@ -141,47 +138,6 @@ class NotificationsViewset(meviewsets.ModelViewSet):
return Response(message, return Response(message,
status=status.HTTP_500_INTERNAL_SERVER_ERROR) 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): def index(request):
return render(request, 'chat/index.html', {}) return render(request, 'chat/index.html', {})
......
...@@ -3,9 +3,14 @@ from rest_framework.pagination import PageNumberPagination ...@@ -3,9 +3,14 @@ from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response from rest_framework.response import Response
from functools import wraps from functools import wraps
from app.entities import enums 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.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): class CustomPagination(PageNumberPagination):
page_size = 5 page_size = 5
...@@ -119,3 +124,54 @@ def main_threading(args, func_name): ...@@ -119,3 +124,54 @@ def main_threading(args, func_name):
) )
t1.start() t1.start()
return True 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
...@@ -84,6 +84,16 @@ CR HISTORY ENUMS ...@@ -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): class CREntitiesEnum(Enum):
CR_FRM_APPROVER = "CR_FRM_APPROVER" CR_FRM_APPROVER = "CR_FRM_APPROVER"
CR_FRM_ATTACHMENT = "CR_FRM_ATTACHMENT" CR_FRM_ATTACHMENT = "CR_FRM_ATTACHMENT"
......
# 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),
),
]
...@@ -873,14 +873,8 @@ CR HISTORY ...@@ -873,14 +873,8 @@ CR HISTORY
class ChangeRequestHistory(AuditClass): class ChangeRequestHistory(AuditClass):
action = models.CharField( action = models.CharField(
choices=[
(tag.value, tag.value) for tag in enums.LogEnum],
default=enums.LogEnum.ADD.value,
max_length=50) max_length=50)
entity = models.CharField( entity = models.CharField(
choices=[
(tag.value, tag.value) for tag in enums.CREntitiesEnum],
default=enums.CREntitiesEnum.CR_FRM_HEADER.value,
max_length=50) max_length=50)
form_code = models.CharField( form_code = models.CharField(
max_length=255, max_length=255,
...@@ -888,7 +882,7 @@ class ChangeRequestHistory(AuditClass): ...@@ -888,7 +882,7 @@ class ChangeRequestHistory(AuditClass):
null=True) null=True)
fromValue = models.TextField(blank=True, null=True) fromValue = models.TextField(blank=True, null=True)
toValue = models.TextField(blank=True, null=True) toValue = models.TextField(blank=True, null=True)
def __str__(self): def __str__(self):
return self.entity return self.entity
...@@ -906,24 +900,23 @@ class Notification(models.Model): ...@@ -906,24 +900,23 @@ class Notification(models.Model):
code = models.CharField( code = models.CharField(
unique=True, unique=True,
max_length=255) # primary key max_length=255) # primary key
form_code = models.ForeignKey( form_code = models.CharField(
ChangeRequestFormHeader, null=True,
on_delete=models.DO_NOTHING, blank=True,
to_field='form_code') max_length=255)
app = models.ForeignKey( app = models.CharField(
Application, null=True,
on_delete=models.DO_NOTHING, blank=True,
to_field='code') max_length=255)
notif_type = models.CharField( notif_type = models.CharField(
choices=[(tag.value, tag.value) for tag in enums.NotifTypeEnum], choices=[(tag.value, tag.value) for tag in enums.NotifTypeEnum],
default=enums.NotifTypeEnum.TASK.value, default=enums.NotifTypeEnum.TASK.value,
max_length=20 max_length=20
) )
account_no = models.ForeignKey( account_no = models.CharField(
User, null=True,
on_delete=models.DO_NOTHING, blank=True,
to_field='code', max_length=255)
related_name='receiver_account_no')
message = models.CharField( message = models.CharField(
max_length=255, max_length=255,
null=True, null=True,
...@@ -931,10 +924,10 @@ class Notification(models.Model): ...@@ -931,10 +924,10 @@ class Notification(models.Model):
is_read = models.BooleanField( is_read = models.BooleanField(
default=False, default=False,
null=True) null=True)
sender_account_no = models.ForeignKey( sender_account_no = models.CharField(
User, on_delete=models.DO_NOTHING, null=True,
to_field='code', blank=True,
related_name='sender_account_no') max_length=255)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
......
...@@ -498,13 +498,13 @@ def routing_table_actions(args): ...@@ -498,13 +498,13 @@ def routing_table_actions(args):
if action_type.lower() == 'approved': if action_type.lower() == 'approved':
email_template = 'RMS-CRAPPROVED.html' email_template = 'RMS-CRAPPROVED.html'
subject = 'Resource Management System - Change Request Approved' subject = 'Resource Management System - Change Request Approved'
elif action_type == 'acknowledged': elif action_type.lower() == 'acknowledged':
email_template = 'RMS-CRACKNOWLEDGE.html' email_template = 'RMS-CRACKNOWLEDGE.html'
subject = 'Resource Management System - Change Request Acknowledged' subject = 'Resource Management System - Change Request Acknowledged'
elif action_by == 'completed': elif action_by.lower() == 'completed':
email_template = 'RMS-CRCOMPLETED.html' email_template = 'RMS-CRCOMPLETED.html'
subject = 'Resource Management System - Change Request Completed' subject = 'Resource Management System - Change Request Completed'
elif action_type == 'accepted': elif action_type.lower() == 'accepted':
email_template = 'RMS-CRACCEPTED.html' email_template = 'RMS-CRACCEPTED.html'
subject = 'Resource Management System - Change Request Accepted' subject = 'Resource Management System - Change Request Accepted'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment