Commit aa4ce06b authored by John Red Medrano's avatar John Red Medrano

Merge pull request #363 in RMS/api-main-service from RMSv2 to staging

* commit 'eabbf03a':
  fixing retrieve form headers
  added sample endpoint for testing of cronjob
  push
  exclude oneberry on company management
parents a46ca4ba eabbf03a
......@@ -7,27 +7,20 @@ class ChangeRequestFormAttachmentsSerializer(
serializers.ModelSerializer
):
def to_representation(self, instance):
try:
ret = super().to_representation(instance)
user_object = {
"id": instance.uploaded_by.id,
"name": instance.uploaded_by.name,
"username": instance.uploaded_by.username,
"code": instance.uploaded_by.code,
"email": instance.uploaded_by.email,
"contact_no": instance.uploaded_by.contact_no
}
ret['uploaded_by'] = user_object
ret['file_upload'] = self.context['request'].build_absolute_uri(
instance.file_upload.url.url)
ret['file_upload_id'] = self.context['request'].build_absolute_uri(
instance.file_upload.url
)
return ret
except Exception as e:
ret['uploaded_by'] = user_object
ret['file_upload'] = "none"
return ret
ret = super().to_representation(instance)
user_object = {
"id": instance.uploaded_by.id,
"name": instance.uploaded_by.name,
"username": instance.uploaded_by.username,
"code": instance.uploaded_by.code,
"email": instance.uploaded_by.email,
"contact_no": instance.uploaded_by.contact_no
}
ret['uploaded_by'] = user_object
ret['file_upload'] = self.context['request'].build_absolute_uri(
instance.file_upload.url.url)
ret['file_upload_id'] = instance.file_upload.id
return ret
class Meta:
model = models.ChangeRequestFormAttachments
......
......@@ -22,9 +22,7 @@ class ChangeRequestTemplateAttachmentsSerializer(
ret['file_upload'] = self.context['request'].build_absolute_uri(
instance.file_upload.url.url
)
ret['file_upload_id'] = self.context['request'].build_absolute_uri(
instance.file_upload.url
)
ret['file_upload_id'] = instance.file_upload.id
return ret
except Exception as e:
ret['uploaded_by'] = user_object
......
......@@ -45,6 +45,9 @@ class CompanyViewSet(viewsets.ModelViewSet):
@decorators.rms.company_list
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
queryset = queryset.exclude(id=1)
page = self.paginate_queryset(queryset)
if page is not None:
......
......@@ -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