Commit 3f221c0f authored by John Red Medrano's avatar John Red Medrano

Merge pull request #361 in RMS/api-main-service from red-develop to RMSv2

* commit '748706a3':
  added sample endpoint for testing of cronjob
parents 0cbe37e3 748706a3
......@@ -5,6 +5,7 @@ from app.applicationlayer.master.Account.views import AdminAccountViewSet
from app.applicationlayer.master.company.views import AdminCompanyViewSet
from app.applicationlayer.master.department.views import AdminDepartmentViewSet
from app.applicationlayer.master.user_type.views import UserTypeViewSet
from app.applicationlayer.master.user_type.views import cronjob
from app.applicationlayer.master.attachment.views import MasterAttachmentViewSet
router = routers.DefaultRouter()
......@@ -17,4 +18,5 @@ router.register(r'attachments', MasterAttachmentViewSet)
urlpatterns = [
path('', include(router.urls)),
url(r'^user-types/$', UserTypeViewSet.as_view(), name="user-types"),
url(r'^cronjob/$', cronjob.as_view(), name="user-types"),
]
\ No newline at end of file
from rest_framework.views import APIView
from rest_framework.response import Response
from app.entities import enums
from app.applicationlayer.utils import main_threading
from app.helper.email_service import sender
from rest_framework.permissions import AllowAny
class UserTypeViewSet(APIView):
......@@ -48,3 +51,14 @@ class UserTypeViewSet(APIView):
del data['results'][str(enums.UserTypeEnum.DEPARTMENT_USER_ADMIN.name)]
return Response(data)
class cronjob(APIView):
permission_classes = (AllowAny,)
def get(self, request, format=None):
args = ''
main_threading(args, sender.cronjob)
return Response("sent")
......@@ -49,6 +49,50 @@ def account_created(args):
)
return True
def cronjob(args):
# name = args[0]
# username = args[1]
# password = args[2]
# recipient = args[3]
# admin = args[4]
# F = open(os.path.join(settings.EMAIL_TEMPLATES_ROOT, 'RMS-NEWUSER.html'), 'r')
# FC = F.read()
# FC = FC.replace('{name}', name)
# FC = FC.replace('{username}', username)
# FC = FC.replace('{password}', password)
# FC = FC.replace('{url}', settings.FRONT_END_URL + '/cms/profile') #changed
try:
send_mail(
subject='Resource Management System: Welcome!',
message='',
from_email=settings.EMAIL_DEFAULT_SENDER,
recipient_list=('red@tirsolutions.com',),
html_message="FC",
fail_silently=False
)
models.EmailLogs.objects.create(
template='RMS-NEWUSER.html',
recipients="test",
content="FC",
is_sent=True,
createdby=admin,
modifiedby=admin
)
except Exception as e:
models.EmailLogs.objects.create(
template='RMS-NEWUSER.html',
recipients="test",
content="FC",
is_sent=False,
createdby="superuser",
modifiedby="superuser"
)
return True
# direct mailer from django
def forgot_password(args):
reset_code = args[0]
......
<!DOCTYPE html>
<html>
<head>
<title>RMS: Change Request Acknowledged</title>
</head>
<body style="font-family: arial;">
<h3>Resource Management System &#40;RMS&#41;</h3>
<h3 style="color:#888888;">Change Request Acknowledged</h3><br>
<p>cron job test,</p><br>
<p>Your change request has been acknowledged. Please see the details of your change request below.</p><br>
<p>Please click <u><a href="{url}" style="text-decoration:underline;color:#007bff;" target="_blank">here</a></u> to access the change request.</p><br>
<p>Sincerely,</p>
<p>RMS Team</p><br><br>
<p>Powered by</p>
<img src="https://s3-ap-southeast-1.amazonaws.com/oneberry/img/logo_oneberry.png" class="img-responsive" style="width:150px;height:auto;" />
</body>
</html>
\ No newline at end of file
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