From b07ea3f963bb86ee5afd678284097cf0ba7b0984 Mon Sep 17 00:00:00 2001 From: Divyansh Tripathi <55395696+theoden42@users.noreply.github.com> Date: Mon, 19 Feb 2024 11:56:57 +0530 Subject: [PATCH 01/34] fix 1. order of files in inbox and outbox 2. order of files is mantained in uniqueList function --- .../applications/filetracking/sdk/methods.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/FusionIIIT/applications/filetracking/sdk/methods.py b/FusionIIIT/applications/filetracking/sdk/methods.py index d85bc4755..4401d3913 100644 --- a/FusionIIIT/applications/filetracking/sdk/methods.py +++ b/FusionIIIT/applications/filetracking/sdk/methods.py @@ -102,7 +102,7 @@ def view_inbox(username: str, designation: str, src_module: str) -> list: receiver_id=recipient_object, receive_design=user_designation, file_id__src_module=src_module, - file_id__is_read=False) + file_id__is_read=False).order_by('receive_date'); received_files = [tracking.file_id for tracking in received_files_tracking] # remove duplicate file ids (from sending back and forth) @@ -131,7 +131,7 @@ def view_outbox(username: str, designation: str, src_module: str) -> list: current_id=sender_ExtraInfo_object, current_design=user_HoldsDesignation_object, file_id__src_module=src_module, - file_id__is_read=False) + file_id__is_read=False).order_by('-receive_date') sent_files = [tracking.file_id for tracking in sent_files_tracking] # remove duplicate file ids (from sending back and forth) @@ -141,9 +141,6 @@ def view_outbox(username: str, designation: str, src_module: str) -> list: return sent_files_serialized.data -# need: view_archived, archive_file, (can get details of archived files by view_file, etc) -# view_drafts, create_draft, (delete_draft can be via delete_file), -# (forward_draft can be via forward_file, but lets implement a send draft that follows our remark convention) def view_archived(username: str, designation: str, src_module: str) -> dict: ''' @@ -348,8 +345,12 @@ def uniqueList(l: list) -> list: This function is used to return a list with unique elements O(n) time and space ''' - s = set(l) - unique_list = (list(s)) + seen = set() + unique_list = [] + for item in l: + if item not in seen: + unique_list.append(item) + seen.add(item) return unique_list def add_uploader_department_to_files_list(files: list) -> list: @@ -402,4 +403,4 @@ def get_last_forw_tracking_for_user(file_id: int, username: str, designation: st return last_tracking def get_extra_info_object_from_id(id: int): - return ExtraInfo.objects.get(id=id) \ No newline at end of file + return ExtraInfo.objects.get(id=id) From 402c8c4a2f16951b2e120308b0d327a1f5237888 Mon Sep 17 00:00:00 2001 From: Divyansh Tripathi <55395696+theoden42@users.noreply.github.com> Date: Mon, 19 Feb 2024 12:02:57 +0530 Subject: [PATCH 02/34] fix login required on viewing file --- FusionIIIT/applications/filetracking/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/FusionIIIT/applications/filetracking/views.py b/FusionIIIT/applications/filetracking/views.py index fef932a9b..b3b49866e 100644 --- a/FusionIIIT/applications/filetracking/views.py +++ b/FusionIIIT/applications/filetracking/views.py @@ -359,6 +359,7 @@ def confirmdelete(request, id): return render(request, 'filetracking/confirmdelete.html', context) +@login_required(login_url="/accounts/login") def view_file(request, id): ''' This function is used to view a particular file received by an employee from another. From 5c6ab078448007d35d09fec160a9346c7421f014 Mon Sep 17 00:00:00 2001 From: Divyansh Tripathi <55395696+theoden42@users.noreply.github.com> Date: Mon, 19 Feb 2024 12:52:33 +0530 Subject: [PATCH 03/34] fix create_file method so that subject and description are also accepted --- FusionIIIT/applications/filetracking/sdk/methods.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/FusionIIIT/applications/filetracking/sdk/methods.py b/FusionIIIT/applications/filetracking/sdk/methods.py index 4401d3913..6431aafb9 100644 --- a/FusionIIIT/applications/filetracking/sdk/methods.py +++ b/FusionIIIT/applications/filetracking/sdk/methods.py @@ -11,6 +11,8 @@ def create_file( uploader_designation: str, receiver: str, receiver_designation: str, + subject: str = "", + description: str = "", src_module: str = "filetracking", src_object_id: str = "", file_extra_JSON: dict = {}, @@ -38,11 +40,14 @@ def create_file( new_file = File.objects.create( uploader=uploader_extrainfo_obj, + subject=subject, + description=description, designation=uploader_designation_obj, src_module=src_module, src_object_id=src_object_id, file_extra_JSON=file_extra_JSON, ) + if attached_file is not None: new_file.upload_file.save(attached_file.name, attached_file, save=True) From a4e01b3bbb443b50bd661eb956a1504f62dbaa03 Mon Sep 17 00:00:00 2001 From: Divyansh Tripathi <55395696+theoden42@users.noreply.github.com> Date: Sun, 3 Mar 2024 19:13:23 +0530 Subject: [PATCH 04/34] add rest api for create file and view file --- .../applications/filetracking/api/views.py | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/FusionIIIT/applications/filetracking/api/views.py b/FusionIIIT/applications/filetracking/api/views.py index 6694e749f..c4bb01189 100644 --- a/FusionIIIT/applications/filetracking/api/views.py +++ b/FusionIIIT/applications/filetracking/api/views.py @@ -2,25 +2,47 @@ from rest_framework.response import Response from rest_framework import status, permissions from rest_framework.authentication import TokenAuthentication +from ..models import File from ..sdk.methods import create_file, view_file, delete_file, view_inbox, view_outbox, view_history, forward_file, get_designations - class CreateFileView(APIView): - #authentication_classes = [TokenAuthentication] - #permission_classes = [permissions.IsAuthenticated] + authentication_classes = [TokenAuthentication] + permission_classes = [permissions.IsAuthenticated] - def post(self, request, *args, **kwargs): - file_id = create_file(**request.data) - return Response({'file_id': file_id}, status=status.HTTP_201_CREATED) + def post(self, request): + try: + current_user = request.user.username + current_designation = request.data.get('designation') + receiver_username = request.data.get('receiver_username') + receiver_designation = request.data.get('receiver_designation') + subject = request.data.get('subject') + description = request.data.get('description') + if None in [current_designation, receiver_username, receiver_designation, subject, description]: + return Response({'error': 'One or more required fields are missing.'}, status=status.HTTP_400_BAD_REQUEST) -class ViewFileView(APIView): - #authentication_classes = [TokenAuthentication] - #permission_classes = [permissions.IsAuthenticated] + file_id = create_file(uploader=current_user, uploader_designation=current_designation, + receiver=receiver_username, receiver_designation=receiver_designation, subject=subject, description=description) - def get(self, request, file_id, *args, **kwargs): - file_details = view_file(int(file_id)) - return Response(file_details) + return Response({'file_id': file_id}, status=status.HTTP_201_CREATED) + except Exception as e: + return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST) + + +class ViewFileView(APIView): + authentication_classes = [TokenAuthentication] + permission_classes = [permissions.IsAuthenticated] + + def get(self, request, file_id): + try: + file_details = view_file(int(file_id)) + return Response(file_details, status=status.HTTP_200_OK) + except ValueError: + return Response({'error': 'Invalid file ID format.'}, status=status.HTTP_400_BAD_REQUEST) + except File.DoesNotExist: + return Response({'error': 'File not found.'}, status=status.HTTP_404_NOT_FOUND) + except Exception as e: + return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST) class DeleteFileView(APIView): From 3760068d5468b61ffbb3fb68a61ed4ba924e2817 Mon Sep 17 00:00:00 2001 From: aish0749 Date: Mon, 4 Mar 2024 00:05:28 +0530 Subject: [PATCH 05/34] add rest api for create, view and delete file --- .../applications/filetracking/api/urls.py | 2 -- .../applications/filetracking/api/views.py | 34 +++++++++++++------ .../applications/filetracking/sdk/methods.py | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/FusionIIIT/applications/filetracking/api/urls.py b/FusionIIIT/applications/filetracking/api/urls.py index 90f03b2ef..c375fd452 100644 --- a/FusionIIIT/applications/filetracking/api/urls.py +++ b/FusionIIIT/applications/filetracking/api/urls.py @@ -2,7 +2,6 @@ from .views import ( CreateFileView, ViewFileView, - DeleteFileView, ViewInboxView, ViewOutboxView, ViewHistoryView, @@ -13,7 +12,6 @@ urlpatterns = [ url(r'^file/$', CreateFileView.as_view(), name='create_file'), url(r'^file/(?P\d+)/$', ViewFileView.as_view(), name='view_file'), - url(r'^file/(?P\d+)/$', DeleteFileView.as_view(), name='delete_file'), url(r'^inbox/$', ViewInboxView.as_view(), name='view_inbox'), url(r'^outbox/$', ViewOutboxView.as_view(), name='view_outbox'), url(r'^history/(?P\d+)/$', ViewHistoryView.as_view(), name='view_history'), diff --git a/FusionIIIT/applications/filetracking/api/views.py b/FusionIIIT/applications/filetracking/api/views.py index c4bb01189..bf780fd30 100644 --- a/FusionIIIT/applications/filetracking/api/views.py +++ b/FusionIIIT/applications/filetracking/api/views.py @@ -1,3 +1,5 @@ +from venv import logger +from django.forms import ValidationError from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status, permissions @@ -36,6 +38,7 @@ class ViewFileView(APIView): def get(self, request, file_id): try: file_details = view_file(int(file_id)) + # print(file_details) return Response(file_details, status=status.HTTP_200_OK) except ValueError: return Response({'error': 'Invalid file ID format.'}, status=status.HTTP_400_BAD_REQUEST) @@ -43,20 +46,29 @@ def get(self, request, file_id): return Response({'error': 'File not found.'}, status=status.HTTP_404_NOT_FOUND) except Exception as e: return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST) + + def delete(self, request, file_id): + try: + # file_details = view_file(int(file_id)) + # print(file_details) + success = delete_file(int(file_id)) + if success: + return Response({'message': 'File deleted successfully'}, + status=status.HTTP_204_NO_CONTENT) + else : + return - -class DeleteFileView(APIView): - #authentication_classes = [TokenAuthentication] - #permission_classes = [permissions.IsAuthenticated] - - def delete(self, request, file_id, *args, **kwargs): - success = delete_file(int(file_id)) - if success: - return Response({'message': 'File deleted successfully'}, - status=status.HTTP_204_NO_CONTENT) - else: + except ValueError: + return Response({'error': 'Invalid file ID format'}, + status=status.HTTP_400_BAD_REQUEST) + except File.DoesNotExist: return Response({'error': 'File not found'}, status=status.HTTP_404_NOT_FOUND) + except ValidationError as e: + return Response(e.detail, status=status.HTTP_400_BAD_REQUEST) # Handle ValidationError specifically + except Exception as e: # Catch unexpected errors + logger.error(f"Unexpected error in DeleteFileView: {e}") + return Response({'error': 'An internal server error occurred'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) class ViewInboxView(APIView): diff --git a/FusionIIIT/applications/filetracking/sdk/methods.py b/FusionIIIT/applications/filetracking/sdk/methods.py index 6431aafb9..bcfae52fb 100644 --- a/FusionIIIT/applications/filetracking/sdk/methods.py +++ b/FusionIIIT/applications/filetracking/sdk/methods.py @@ -1,3 +1,4 @@ +from amqp import NotFound from django.contrib.auth.models import User from applications.filetracking.models import Tracking, File from applications.globals.models import Designation, HoldsDesignation, ExtraInfo From a06d4372a630533f17fb7d5651248402b05b59fa Mon Sep 17 00:00:00 2001 From: aish0749 Date: Mon, 4 Mar 2024 01:11:53 +0530 Subject: [PATCH 06/34] add rest api for inbox, outbox, history view --- .../applications/filetracking/api/urls.py | 2 +- .../applications/filetracking/api/views.py | 139 ++++++++++++++---- 2 files changed, 110 insertions(+), 31 deletions(-) diff --git a/FusionIIIT/applications/filetracking/api/urls.py b/FusionIIIT/applications/filetracking/api/urls.py index c375fd452..9d26bc959 100644 --- a/FusionIIIT/applications/filetracking/api/urls.py +++ b/FusionIIIT/applications/filetracking/api/urls.py @@ -15,6 +15,6 @@ url(r'^inbox/$', ViewInboxView.as_view(), name='view_inbox'), url(r'^outbox/$', ViewOutboxView.as_view(), name='view_outbox'), url(r'^history/(?P\d+)/$', ViewHistoryView.as_view(), name='view_history'), - url(r'^file/(?P\d+)/$', ForwardFileView.as_view(), name='forward_file'), + url(r'^forwardfile/(?P\d+)/$', ForwardFileView.as_view(), name='forward_file'), url(r'^designations/(?P\w+)/$', GetDesignationsView.as_view(), name='get_designations'), ] diff --git a/FusionIIIT/applications/filetracking/api/views.py b/FusionIIIT/applications/filetracking/api/views.py index bf780fd30..50def429e 100644 --- a/FusionIIIT/applications/filetracking/api/views.py +++ b/FusionIIIT/applications/filetracking/api/views.py @@ -1,10 +1,11 @@ +import logging from venv import logger from django.forms import ValidationError from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status, permissions from rest_framework.authentication import TokenAuthentication -from ..models import File +from ..models import File, Tracking from ..sdk.methods import create_file, view_file, delete_file, view_inbox, view_outbox, view_history, forward_file, get_designations class CreateFileView(APIView): @@ -72,48 +73,126 @@ def delete(self, request, file_id): class ViewInboxView(APIView): - #authentication_classes = [TokenAuthentication] - #permission_classes = [permissions.IsAuthenticated] + authentication_classes = [TokenAuthentication] + permission_classes = [permissions.IsAuthenticated] - def get(self, request, *args, **kwargs): - inbox_files = view_inbox( - request.user.username, - request.query_params.get('designation'), - request.query_params.get('src_module')) - return Response(inbox_files) + def get(self, request): + """ + API endpoint to view inbox files. + Expects query parameters: + - username (required): User requesting the inbox. + - designation (optional): Designation to filter files by. + - src_module (required): Source module to filter files by. + + Returns: + JSON response containing a list of serialized file data, including sender information. + """ + + username = request.data.get('username') + designation = request.data.get('designation') + src_module = request.data.get('src_module') + + if not username or not src_module: + return Response({'error': 'Missing required query parameters: username and src_module.'}, status=400) + + inbox_files = view_inbox(username, designation, src_module) + return Response(inbox_files) class ViewOutboxView(APIView): - #authentication_classes = [TokenAuthentication] - #permission_classes = [permissions.IsAuthenticated] + authentication_classes = [TokenAuthentication] + permission_classes = [permissions.IsAuthenticated] - def get(self, request, *args, **kwargs): - outbox_files = view_outbox( - request.user.username, - request.query_params.get('designation'), - request.query_params.get('src_module')) - return Response(outbox_files) + def get(self, request): + """ + API endpoint to view outbox files. -class ViewHistoryView(APIView): - #authentication_classes = [TokenAuthentication] - #permission_classes = [permissions.IsAuthenticated] + Expects query parameters: + - username (required): User requesting the outbox. + - designation (optional): Designation to filter files by. + - src_module (required): Source module to filter files by. - def get(self, request, file_id, *args, **kwargs): - history = view_history(int(file_id)) - return Response(history) + Returns: + JSON response containing a paginated list of serialized file data. + """ + username = request.data.get('username') + designation = request.data.get('designation') + src_module = request.data.get('src_module') -class ForwardFileView(APIView): - #authentication_classes = [TokenAuthentication] - #permission_classes = [permissions.IsAuthenticated] + if not username or not src_module: + return Response({'error': 'Missing required query parameters: username and src_module.'}, status=400) - def post(self, request, file_id, *args, **kwargs): - new_tracking_id = forward_file(int(file_id), **request.data) - return Response({'tracking_id': new_tracking_id}, - status=status.HTTP_201_CREATED) + outbox_files = view_outbox(username, designation, src_module) + return Response(outbox_files) +class ViewHistoryView(APIView): + authentication_classes = [TokenAuthentication] + permission_classes = [permissions.IsAuthenticated] + + def get(self, request, file_id): + """ + View history of a particular file with the given file_id. + + Args: + request (rest_framework.request.Request): The incoming request object. + file_id (int): Primary key of the file to retrieve history for. + + Returns: + rest_framework.response.Response: JSON response containing serialized tracking history. + """ + + try: + history = view_history(file_id) + return Response(history) + except Tracking.DoesNotExist: + return Response({'error': f'File with ID {file_id} not found.'}, status=404) + except Exception as e: + logger.error(f"An unexpected error occurred: {e}") + return Response({'error': 'Internal server error.'}, status=500) + +class ForwardFileView(APIView): +# # Authentication and permission classes (adjust based on your needs) + # authentication_classes = [TokenAuthentication] + # permission_classes = [permissions.IsAuthenticated] + + def post(self, request, file_id): +# # Extract data from request.data + receiver = request.data.get('receiver') + # receiver_designation = request.data.get('receiver_designation') + # file_extra_JSON = request.data.get('file_extra_JSON', {}) + # remarks = request.data.get('remarks', "") + + # # Validate data + # if not receiver or not receiver_designation: + # raise ValidationError("Missing required fields: receiver and receiver_designation") + + # # Extract and validate file attachment (if present) + # file_attachment = request.FILES.get('file_attachment') + # if file_attachment: + # if file_attachment.size > 10 * 1024 * 1024: # Adjust size limit as needed + # raise ValidationError("File size exceeds limit (10 MB)") + + # # Call forward_file function + # try: + # new_tracking_id = forward_file( + # int(file_id), + # receiver, + # receiver_designation, + # file_extra_JSON, + # remarks, + # file_attachment + # ) + # logging.info(f"Successfully forwarded file {file_id} with tracking ID: {new_tracking_id}") + # except Exception as e: + # logging.error(f"Error forwarding file {file_id}: {str(e)}") + # raise ValidationError(str(e)) # Re-raise exception with a user-friendly message + + # # Return response + # return Response({'tracking_id': new_tracking_id}, status=status.HTTP_201_CREATED) + class GetDesignationsView(APIView): #authentication_classes = [TokenAuthentication] #permission_classes = [permissions.IsAuthenticated] From 2ab199e7da0436611778042b6f501be35365ed7e Mon Sep 17 00:00:00 2001 From: aish0749 Date: Mon, 4 Mar 2024 16:39:54 +0530 Subject: [PATCH 07/34] add rest api for draft view, forward file --- .../applications/filetracking/api/urls.py | 2 + .../applications/filetracking/api/views.py | 82 +++++++++++-------- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/FusionIIIT/applications/filetracking/api/urls.py b/FusionIIIT/applications/filetracking/api/urls.py index 9d26bc959..f63f45ff3 100644 --- a/FusionIIIT/applications/filetracking/api/urls.py +++ b/FusionIIIT/applications/filetracking/api/urls.py @@ -6,6 +6,7 @@ ViewOutboxView, ViewHistoryView, ForwardFileView, + DraftFileView, GetDesignationsView, ) @@ -16,5 +17,6 @@ url(r'^outbox/$', ViewOutboxView.as_view(), name='view_outbox'), url(r'^history/(?P\d+)/$', ViewHistoryView.as_view(), name='view_history'), url(r'^forwardfile/(?P\d+)/$', ForwardFileView.as_view(), name='forward_file'), + url(r'^draft/$', DraftFileView.as_view(), name='view_drafts'), url(r'^designations/(?P\w+)/$', GetDesignationsView.as_view(), name='get_designations'), ] diff --git a/FusionIIIT/applications/filetracking/api/views.py b/FusionIIIT/applications/filetracking/api/views.py index 50def429e..145ccac5d 100644 --- a/FusionIIIT/applications/filetracking/api/views.py +++ b/FusionIIIT/applications/filetracking/api/views.py @@ -6,7 +6,7 @@ from rest_framework import status, permissions from rest_framework.authentication import TokenAuthentication from ..models import File, Tracking -from ..sdk.methods import create_file, view_file, delete_file, view_inbox, view_outbox, view_history, forward_file, get_designations +from ..sdk.methods import create_file, view_drafts, view_file, delete_file, view_inbox, view_outbox, view_history, forward_file, get_designations class CreateFileView(APIView): authentication_classes = [TokenAuthentication] @@ -154,44 +154,62 @@ def get(self, request, file_id): return Response({'error': 'Internal server error.'}, status=500) class ForwardFileView(APIView): -# # Authentication and permission classes (adjust based on your needs) - # authentication_classes = [TokenAuthentication] - # permission_classes = [permissions.IsAuthenticated] +# # # Authentication and permission classes (adjust based on your needs) + authentication_classes = [TokenAuthentication] + permission_classes = [permissions.IsAuthenticated] def post(self, request, file_id): # # Extract data from request.data receiver = request.data.get('receiver') - # receiver_designation = request.data.get('receiver_designation') - # file_extra_JSON = request.data.get('file_extra_JSON', {}) - # remarks = request.data.get('remarks', "") + receiver_designation = request.data.get('receiver_designation') + file_extra_JSON = request.data.get('file_extra_JSON', {}) + remarks = request.data.get('remarks', "") - # # Validate data - # if not receiver or not receiver_designation: - # raise ValidationError("Missing required fields: receiver and receiver_designation") + # Validate data + if not receiver or not receiver_designation: + raise ValidationError("Missing required fields: receiver and receiver_designation") # # Extract and validate file attachment (if present) - # file_attachment = request.FILES.get('file_attachment') - # if file_attachment: - # if file_attachment.size > 10 * 1024 * 1024: # Adjust size limit as needed - # raise ValidationError("File size exceeds limit (10 MB)") - - # # Call forward_file function - # try: - # new_tracking_id = forward_file( - # int(file_id), - # receiver, - # receiver_designation, - # file_extra_JSON, - # remarks, - # file_attachment - # ) - # logging.info(f"Successfully forwarded file {file_id} with tracking ID: {new_tracking_id}") - # except Exception as e: - # logging.error(f"Error forwarding file {file_id}: {str(e)}") - # raise ValidationError(str(e)) # Re-raise exception with a user-friendly message - - # # Return response - # return Response({'tracking_id': new_tracking_id}, status=status.HTTP_201_CREATED) + file_attachment = request.FILES.get('file_attachment') + if file_attachment: + if file_attachment.size > 10 * 1024 * 1024: # Adjust size limit as needed + raise ValidationError("File size exceeds limit (10 MB)") + + # Call forward_file function + try: + new_tracking_id = forward_file( + int(file_id), + receiver, + receiver_designation, + file_extra_JSON, + remarks, + file_attachment + ) + logging.info(f"Successfully forwarded file {file_id} with tracking ID: {new_tracking_id}") + except Exception as e: + logging.error(f"Error forwarding file {file_id}: {str(e)}") + raise ValidationError(str(e)) # Re-raise exception with a user-friendly message + + # Return response + return Response({'tracking_id': new_tracking_id}, status=status.HTTP_201_CREATED) + +class DraftFileView(APIView): + authentication_classes = [TokenAuthentication] + permission_classes = [permissions.IsAuthenticated] + + def get(self, request): + username = request.data.get('username') + designation = request.data.get('designation') + src_module = request.data.get('src_module') + + try: + draft_files = view_drafts(username, designation, src_module) + print(draft_files) + return Response(draft_files, status=status.HTTP_200_OK) + except Exception as e: + return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + class GetDesignationsView(APIView): #authentication_classes = [TokenAuthentication] From daab40e418348d735243f982e79610bfa69ab9d4 Mon Sep 17 00:00:00 2001 From: nidhibarapatre Date: Mon, 4 Mar 2024 18:09:04 +0530 Subject: [PATCH 08/34] Minor changes --- FusionIIIT/applications/filetracking/admin.py | 7 - FusionIIIT/applications/filetracking/apps.py | 5 - .../filetracking/migrations/0001_initial.py | 53 -- .../filetracking/migrations/__init__.py | 0 .../applications/filetracking/models.py | 45 -- FusionIIIT/applications/filetracking/tests.py | 3 - FusionIIIT/applications/filetracking/urls.py | 31 - FusionIIIT/applications/filetracking/utils.py | 7 - FusionIIIT/applications/filetracking/views.py | 637 ------------------ FusionIIIT/templates/dashboard/modules.html | 2 +- .../templates/dashboard/sidenavbar.html | 2 +- 11 files changed, 2 insertions(+), 790 deletions(-) delete mode 100644 FusionIIIT/applications/filetracking/admin.py delete mode 100644 FusionIIIT/applications/filetracking/apps.py delete mode 100644 FusionIIIT/applications/filetracking/migrations/0001_initial.py delete mode 100644 FusionIIIT/applications/filetracking/migrations/__init__.py delete mode 100644 FusionIIIT/applications/filetracking/models.py delete mode 100644 FusionIIIT/applications/filetracking/tests.py delete mode 100644 FusionIIIT/applications/filetracking/urls.py delete mode 100644 FusionIIIT/applications/filetracking/utils.py delete mode 100644 FusionIIIT/applications/filetracking/views.py diff --git a/FusionIIIT/applications/filetracking/admin.py b/FusionIIIT/applications/filetracking/admin.py deleted file mode 100644 index 82b78df95..000000000 --- a/FusionIIIT/applications/filetracking/admin.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.contrib import admin - -# Register your models here. -from applications.filetracking.models import File, Tracking - -admin.site.register(File) -admin.site.register(Tracking) diff --git a/FusionIIIT/applications/filetracking/apps.py b/FusionIIIT/applications/filetracking/apps.py deleted file mode 100644 index 7e3d3b6d2..000000000 --- a/FusionIIIT/applications/filetracking/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class FileTrackingConfig(AppConfig): - name = 'applications.filetracking' diff --git a/FusionIIIT/applications/filetracking/migrations/0001_initial.py b/FusionIIIT/applications/filetracking/migrations/0001_initial.py deleted file mode 100644 index 6924ae1ff..000000000 --- a/FusionIIIT/applications/filetracking/migrations/0001_initial.py +++ /dev/null @@ -1,53 +0,0 @@ -# Generated by Django 3.1.5 on 2023-03-15 18:53 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('globals', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='File', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('subject', models.CharField(blank=True, max_length=100, null=True)), - ('description', models.CharField(blank=True, max_length=400, null=True)), - ('upload_date', models.DateTimeField(auto_now_add=True)), - ('upload_file', models.FileField(blank=True, upload_to='')), - ('is_read', models.BooleanField(default=False)), - ('designation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='upload_designation', to='globals.designation')), - ('uploader', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='uploaded_files', to='globals.extrainfo')), - ], - options={ - 'db_table': 'File', - }, - ), - migrations.CreateModel( - name='Tracking', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('receive_date', models.DateTimeField(auto_now_add=True)), - ('forward_date', models.DateTimeField(auto_now_add=True)), - ('remarks', models.CharField(blank=True, max_length=250, null=True)), - ('upload_file', models.FileField(blank=True, upload_to='')), - ('is_read', models.BooleanField(default=False)), - ('current_design', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='globals.holdsdesignation')), - ('current_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='globals.extrainfo')), - ('file_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='filetracking.file')), - ('receive_design', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='rec_design', to='globals.designation')), - ('receiver_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='receiver_id', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'Tracking', - }, - ), - ] diff --git a/FusionIIIT/applications/filetracking/migrations/__init__.py b/FusionIIIT/applications/filetracking/migrations/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/FusionIIIT/applications/filetracking/models.py b/FusionIIIT/applications/filetracking/models.py deleted file mode 100644 index 5f9581a08..000000000 --- a/FusionIIIT/applications/filetracking/models.py +++ /dev/null @@ -1,45 +0,0 @@ -from django.db import models -from django.contrib.auth.models import User -from applications.globals.models import ExtraInfo, HoldsDesignation, Designation - - -class File(models.Model): - """ - This is file table which contains the all the files created by user - """ - uploader = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE, related_name='uploaded_files') - designation = models.ForeignKey(Designation, on_delete=models.CASCADE, null=True, related_name='upload_designation') - subject = models.CharField(max_length=100, null=True, blank=True) - description = models.CharField(max_length=400, null=True, blank=True) - upload_date = models.DateTimeField(auto_now_add=True) - upload_file = models.FileField(blank=True) - is_read = models.BooleanField(default = False) - - - class Meta: - db_table = 'File' - - #def __str__(self): - #return str(self.ref_id) - - -class Tracking(models.Model): - """ - This is File Tracing Table which contains the status of each indivisual file created by the user - """ - file_id = models.ForeignKey(File, on_delete=models.CASCADE, null=True) - current_id = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE) - current_design = models.ForeignKey(HoldsDesignation, null=True, on_delete=models.CASCADE) - # receiver_id = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE, related_name='receiver_id') - # receive_design = models.ForeignKey(HoldsDesignation, null=True, on_delete=models.CASCADE, related_name='rec_design') - receiver_id = models.ForeignKey(User,null = True, on_delete=models.CASCADE, related_name='receiver_id') - receive_design = models.ForeignKey(Designation, null=True, on_delete=models.CASCADE, related_name='rec_design') - - receive_date = models.DateTimeField(auto_now_add=True) - forward_date = models.DateTimeField(auto_now_add=True) - remarks = models.CharField(max_length=250, null=True, blank=True) - upload_file = models.FileField(blank=True) - is_read = models.BooleanField(default = False) - - class Meta: - db_table = 'Tracking' diff --git a/FusionIIIT/applications/filetracking/tests.py b/FusionIIIT/applications/filetracking/tests.py deleted file mode 100644 index e9137c85e..000000000 --- a/FusionIIIT/applications/filetracking/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.test import TestCase - -# Create your tests here. diff --git a/FusionIIIT/applications/filetracking/urls.py b/FusionIIIT/applications/filetracking/urls.py deleted file mode 100644 index cb4a7563d..000000000 --- a/FusionIIIT/applications/filetracking/urls.py +++ /dev/null @@ -1,31 +0,0 @@ -from django.conf.urls import url - -from . import views - -app_name = 'filetracking' - -urlpatterns = [ - - url(r'^$', views.filetracking, name='filetracking'), - url(r'^drafts/$', views.drafts, name='drafts'), - url(r'^fileview/(?P\d+)$', views.fileview, name='fileview'), - url(r'^fileview1/(?P\d+)$', views.fileview1, name='fileview1'), - url(r'^fileview2/(?P\d+)$', views.fileview2, name='fileview2'), - url(r'^outward/$', views.outward, name='outward'), - url(r'^inward/$', views.inward, name='inward'), - url(r'^confirmdelete/(?P\d+)$', views.confirmdelete, name='confirm_delete'), - url(r'^archive/(?P\d+)/$', views.archive, name='archive'), - url(r'^finish/(?P\d+)/$', views.finish, name='finish'), - url(r'^forward/(?P\d+)/$', views.forward, name='forward'), - url(r'^ajax/$', views.AjaxDropdown1, name='ajax_dropdown1'), - url(r'^ajax_dropdown/$', views.AjaxDropdown, name='ajax_dropdown'), - url(r'^test/$',views.test, name='test'), - url(r'^delete/(?P\d+)$',views.delete, name='delete'), - url(r'^forward_inward/(?P\d+)/$', views.forward_inward, name='forward_inward'), - - ## correction team 24 - url(r'^finish_design/$', views.finish_design, name='finish_design'), - url(r'^finish_fileview/(?P\d+)$', views.finish_fileview, name='finish_fileview'), - url(r'^archive_design/$', views.archive_design, name='archive_design'), - url(r'^archive_finish/(?P\d+)/$', views.archive_finish, name='archive_finish'), -] diff --git a/FusionIIIT/applications/filetracking/utils.py b/FusionIIIT/applications/filetracking/utils.py deleted file mode 100644 index 5ebd27374..000000000 --- a/FusionIIIT/applications/filetracking/utils.py +++ /dev/null @@ -1,7 +0,0 @@ -from .models import File, Tracking -from applications.globals.models import ExtraInfo, HoldsDesignation, Designation -from django.contrib.auth.models import User - -def get_designation(userid): - user_designation=HoldsDesignation.objects.select_related('user','working','designation').filter(user=userid) - return user_designation \ No newline at end of file diff --git a/FusionIIIT/applications/filetracking/views.py b/FusionIIIT/applications/filetracking/views.py deleted file mode 100644 index ef5d8f347..000000000 --- a/FusionIIIT/applications/filetracking/views.py +++ /dev/null @@ -1,637 +0,0 @@ -from django.contrib import messages -from django.shortcuts import render, get_object_or_404, redirect -from .models import File, Tracking -from applications.globals.models import ExtraInfo, HoldsDesignation, Designation -from django.template.defaulttags import csrf_token -from django.http import HttpResponse, HttpResponseRedirect, JsonResponse -from django.contrib.auth.decorators import login_required -from django.db import IntegrityError -from django.core import serializers -from django.contrib.auth.models import User -from timeit import default_timer as time -from notification.views import office_module_notif,file_tracking_notif -from .utils import * - - -@login_required(login_url = "/accounts/login/") -def filetracking(request): - """ - The function is used to create files by current user(employee). - It adds the employee(uploader) and file datails to a file(table) of filetracking(model) - if he intends to create file. - - @param: - request - trivial. - - @variables: - - - uploader - Employee who creates file. - subject - Title of the file. - description - Description of the file. - upload_file - Attachment uploaded while creating file. - file - The file object. - extrainfo - The Extrainfo object. - holdsdesignations - The HoldsDesignation object. - context - Holds data needed to make necessary changes in the template. - """ - if request.method =="POST": - try: - if 'save' in request.POST: - uploader = request.user.extrainfo - subject = request.POST.get('title') - description = request.POST.get('desc') - design = request.POST.get('design') - designation = Designation.objects.get(id = HoldsDesignation.objects.select_related('user','working','designation').get(id = design).designation_id) - upload_file = request.FILES.get('myfile') - if(upload_file.size / 1000 > 10240): - messages.error(request,"File should not be greater than 10MB") - return redirect("/filetracking") - - File.objects.create( - uploader=uploader, - description=description, - subject=subject, - designation=designation, - upload_file=upload_file - ) - - messages.success(request,'File Draft Saved Successfully') - - if 'send' in request.POST: - uploader = request.user.extrainfo - subject = request.POST.get('title') - description = request.POST.get('desc') - design = request.POST.get('design') - designation = Designation.objects.get(id = HoldsDesignation.objects.select_related('user','working','designation').get(id = design).designation_id) - - upload_file = request.FILES.get('myfile') - if(upload_file.size / 1000 > 10240): - messages.error(request,"File should not be greater than 10MB") - return redirect("/filetracking") - - file = File.objects.create( - uploader=uploader, - description=description, - subject=subject, - designation=designation, - upload_file=upload_file - ) - - - current_id = request.user.extrainfo - remarks = request.POST.get('remarks') - - sender = request.POST.get('design') - current_design = HoldsDesignation.objects.select_related('user','working','designation').get(id=sender) - - receiver = request.POST.get('receiver') - try: - receiver_id = User.objects.get(username=receiver) - except Exception as e: - messages.error(request, 'Enter a valid Username') - return redirect('/filetracking/') - receive = request.POST.get('recieve') - try: - receive_design = Designation.objects.get(name=receive) - except Exception as e: - messages.error(request, 'Enter a valid Designation') - return redirect('/filetracking/') - - upload_file = request.FILES.get('myfile') - - Tracking.objects.create( - file_id=file, - current_id=current_id, - current_design=current_design, - receive_design=receive_design, - receiver_id=receiver_id, - remarks=remarks, - upload_file=upload_file, - ) - #office_module_notif(request.user, receiver_id) - file_tracking_notif(request.user,receiver_id,subject) - messages.success(request,'File sent successfully') - - except IntegrityError: - message = "FileID Already Taken.!!" - return HttpResponse(message) - - - - file = File.objects.select_related('uploader__user','uploader__department','designation').all() - extrainfo = ExtraInfo.objects.select_related('user','department').all() - holdsdesignations = HoldsDesignation.objects.select_related('user','working','designation').all() - designations = get_designation(request.user) - - context = { - 'file': file, - 'extrainfo': extrainfo, - 'holdsdesignations': holdsdesignations, - 'designations': designations, - } - return render(request, 'filetracking/composefile.html', context) - - -@login_required(login_url = "/accounts/login") -def drafts(request): - """ - The function is used to get the designation of the user and renders it on draft template. - - @param: - request - trivial. - - @variables: - - - context - Holds data needed to make necessary changes in the template. - """ - designation = get_designation(request.user) - context = { - 'designation': designation, - } - return render(request, 'filetracking/drafts.html', context) - - -@login_required(login_url = "/accounts/login") -def fileview(request,id): - - """ - This function is used to veiw all all created files by the user ordered by upload date.it collects all the created files from File object. - - @param: - request - trivial - id - user id - - @parameters - draft - file obeject containing all the files created by user - context - holds data needed to render the template - - - - """ - # draft = File.objects.select_related('uploader__user','uploader__department','designation').filter(uploader=request.user.extrainfo).order_by('-upload_date') - # extrainfo = ExtraInfo.objects.select_related('user','department').all() - - extrainfo = ExtraInfo.objects.select_related('user','department').all() - - ids = File.objects.filter(uploader=request.user.extrainfo).order_by('-upload_date').values_list('id', flat=True) - draft_files_pk=[] - - for i in ids: - file_tracking_ids = Tracking.objects.filter(file_id=i).values_list('id', flat=True) - if(len(file_tracking_ids)==0): - draft_files_pk.append(i) - - draft_file_list=[] - for i in draft_files_pk: - draft_file_list.append(File.objects.get(pk=i)) - - - - user_designation = HoldsDesignation.objects.select_related('user','working','designation').get(pk=id) - s = str(user_designation).split(" - ") - designations = s[1] - context = { - - 'draft': draft_file_list, - 'extrainfo': extrainfo, - 'designations': designations, - } - return render(request, 'filetracking/fileview.html', context) - - - -@login_required(login_url = "/accounts/login") -def fileview1(request,id): - - """ - The function is used to get all the files sent by user(employee) to other employees - which are filtered from Tracking(table) objects by current user i.e. current_id. - It displays files sent by user to other employees of a Tracking(table) of filetracking(model) - in the 'Outbox' tab of template. - - @param: - request - trivial. - id - user id - - @variables: - out - The Tracking object filtered by current_id i.e, present working user. - context - Holds data needed to make necessary changes in the template. - - """ - - outward_files = Tracking.objects.select_related('file_id__uploader__user','file_id__uploader__department','file_id__designation','current_id__user','current_id__department', - 'current_design__user','current_design__working','current_design__designation','receiver_id','receive_design').filter(current_id=request.user.extrainfo).order_by('-forward_date') - - user_designation = HoldsDesignation.objects.select_related('user','working','designation').get(pk=id) - - context = { - - 'out': outward_files, - 'abcd': user_designation, - } - return render(request, 'filetracking/fileview1.html', context) - - -@login_required(login_url = "/accounts/login") -def fileview2(request,id): - - """ - The function is used to fetch the files received by the user form other employees. - These files are filtered by receiver id and ordered by receive date. - - @param: - request - trivial. - id - user id - - @variables: - inward_file - The Tracking object filtered by receiver_id i.e, present working user. - context - Holds data needed to make necessary changes in the template. - - """ - inward_file = Tracking.objects.select_related('file_id__uploader__user','file_id__uploader__department','file_id__designation','current_id__user','current_id__department', - 'current_design__user','current_design__working','current_design__designation','receiver_id','receive_design').filter(receiver_id=request.user).order_by('-receive_date') - - user_designation = HoldsDesignation.objects.select_related('user','working','designation').get(pk=id) - s = str(user_designation).split(" - ") - designations = s[1] - - context = { - - 'in_file': inward_file, - 'designations': designations, - } - return render(request, 'filetracking/fileview2.html', context) - - -@login_required(login_url = "/accounts/login") -def outward(request): - """ - This function fetches the different designations of the user and renders it on outward template - @param: - request - trivial. - - @variables: - context - Holds the different designation data of the user - - """ - designation = get_designation(request.user) - - context = { - 'designation': designation, - } - return render( request, 'filetracking/outward.html', context) - - -@login_required(login_url = "/accounts/login") -def inward(request): - """ - This function fetches the different designations of the user and renders it on inward template - - - @param: - request - trivial. - - @variables: - context - Holds the different designation data of the user - """ - designation = get_designation(request.user) - context = { - - 'designation': designation, - } - return render(request, 'filetracking/inward.html', context) - - -@login_required(login_url = "/accounts/login") -def confirmdelete(request,id): - - """ - The function is used to confirm the deletion of a file. - @param: - request - trivial. - id - user id - - @variables: - context - Holds data needed to make necessary changes in the template. - """ - file = File.objects.select_related('uploader__user','uploader__department','designation').get(pk = id) - - context = { - 'j': file, - } - - return render(request, 'filetracking/confirmdelete.html',context) - - -@login_required(login_url = "/accounts/login") -def forward(request, id): - """ - The function is used to forward files received by user(employee) from other - employees which are filtered from Tracking(table) objects by current user - i.e. receiver_id to other employees. - It also gets track of file created by uploader through all users involved in file - along with their remarks and attachments - It displays details file of a File(table) and remarks and attachments of user involved - in file of Tracking(table) of filetracking(model) in the template. - - @param: - request - trivial. - id - id of the file object which the user intends to forward to other employee. - - @variables: - file - The File object. - track - The Tracking object. - remarks = Remarks posted by user. - receiver = Receiver to be selected by user for forwarding file. - receiver_id = Receiver_id who has been selected for forwarding file. - upload_file = File attached by user. - extrainfo = ExtraInfo object. - holdsdesignations = HoldsDesignation objects. - context - Holds data needed to make necessary changes in the template. - """ - - file = get_object_or_404(File, id=id) - track = Tracking.objects.select_related('file_id__uploader__user','file_id__uploader__department','file_id__designation','current_id__user','current_id__department', - 'current_design__user','current_design__working','current_design__designation','receiver_id','receive_design').filter(file_id=file) - - if request.method == "POST": - if 'finish' in request.POST: - file.complete_flag = True - file.save() - - if 'send' in request.POST: - current_id = request.user.extrainfo - remarks = request.POST.get('remarks') - track.update(is_read=True) - - sender = request.POST.get('sender') - current_design = HoldsDesignation.objects.select_related('user','working','designation').get(id=sender) - - receiver = request.POST.get('receiver') - try: - receiver_id = User.objects.get(username=receiver) - except Exception as e: - messages.error(request, 'Enter a valid destination') - designations = HoldsDesignation.objects.select_related('user','working','designation').filter(user=request.user) - - context = { - - 'designations': designations, - 'file': file, - 'track': track, - } - return render(request, 'filetracking/forward.html', context) - receive = request.POST.get('recieve') - try: - receive_design = Designation.objects.get(name=receive) - except Exception as e: - messages.error(request, 'Enter a valid Designation') - designations = get_designation(request.user) - - context = { - - 'designations': designations, - 'file': file, - 'track': track, - } - return render(request, 'filetracking/forward.html', context) - - - upload_file = request.FILES.get('myfile') - - Tracking.objects.create( - file_id=file, - current_id=current_id, - current_design=current_design, - receive_design=receive_design, - receiver_id=receiver_id, - remarks=remarks, - upload_file=upload_file, - ) - messages.success(request, 'File sent successfully') - - - designations = get_designation(request.user) - - context = { - - 'designations':designations, - 'file': file, - 'track': track, - } - - return render(request, 'filetracking/forward.html', context) - - -@login_required(login_url = "/accounts/login") -def archive_design(request): - - designation = HoldsDesignation.objects.select_related('user','working','designation').filter(user=request.user) - - context = { - 'designation': designation, - } - return render( request, 'filetracking/archive_design.html', context) - - - - - -@login_required(login_url = "/accounts/login") -def archive(request , id): - - draft = File.objects.select_related('uploader__user','uploader__department','designation').filter(is_read=True).order_by('-upload_date') - - - extrainfo = ExtraInfo.objects.select_related('user','department').all() - # designations = Designation.objects.filter(upload_designation=extrainfo.id) - abcd = HoldsDesignation.objects.select_related('user','working','designation').get(pk=id) - s = str(abcd).split(" - ") - designations = s[1] - #designations = HoldsDesignation.objects.filter(user=request.user) - # for x in designations: - # if abcd==x: - # designations=abcd - - context = { - - 'draft': draft, - 'extrainfo': extrainfo, - 'designations': designations, - } - - - - - return render(request, 'filetracking/archive.html' , context) - - -@login_required(login_url = "/accounts/login") -def archive_finish(request, id): - file1 = get_object_or_404(File, id=id) ##file = get_object_or_404(File, ref_id=id) - track = Tracking.objects.filter(file_id=file1) - - - - return render(request, 'filetracking/archive_finish.html', {'file': file1, 'track': track}) - - - - -@login_required(login_url = "/accounts/login") -def finish_design(request): - - designation = HoldsDesignation.objects.select_related('user','working','designation').filter(user=request.user) - - context = { - 'designation': designation, - } - return render( request, 'filetracking/finish_design.html', context) - - -@login_required(login_url = "/accounts/login") -def finish_fileview(request, id): - - out = Tracking.objects.select_related('file_id__uploader__user','file_id__uploader__department','file_id__designation','current_id__user','current_id__department', - 'current_design__user','current_design__working','current_design__designation','receiver_id','receive_design').filter(file_id__uploader=request.user.extrainfo, is_read=False).order_by('-forward_date') - - - - - abcd = HoldsDesignation.objects.select_related('user','working','designation').get(pk=id) - - - context = { - - 'out': out, - 'abcd': abcd, - } - return render(request, 'filetracking/finish_fileview.html', context) - - - - -@login_required(login_url = "/accounts/login") -def finish(request, id): - file1 = get_object_or_404(File, id=id) ##file = get_object_or_404(File, ref_id=id) - track = Tracking.objects.filter(file_id=file1) - - - if request.method == "POST": - if 'Finished' in request.POST: - File.objects.filter(pk=id).update(is_read=True) - track.update(is_read=True) - messages.success(request,'File Archived') - - - - - - - - return render(request, 'filetracking/finish.html', {'file': file1, 'track': track,'fileid':id}) - - - - -def AjaxDropdown1(request): - """ - This function returns the designation of receiver on the forward or compose file template. - - @param: - request - trivial. - - - @variables: - context - return the httpresponce containing the matched designation of the user - """ - if request.method == 'POST': - value = request.POST.get('value') - - hold = Designation.objects.filter(name__startswith=value) - holds = serializers.serialize('json', list(hold)) - context = { - 'holds' : holds - } - - return HttpResponse(JsonResponse(context), content_type='application/json') - - -def AjaxDropdown(request): - - """ - This function returns the usernames of receiver on the forward or compose file template. - - @param: - request - trivial. - - - @variables: - context - return the httpresponce containing the matched username - """ - if request.method == 'POST': - value = request.POST.get('value') - users = User.objects.filter(username__startswith=value) - users = serializers.serialize('json', list(users)) - - context = { - 'users': users - } - return HttpResponse(JsonResponse(context), content_type='application/json') - - -def test(request): - return HttpResponse('success') - - - -@login_required(login_url = "/accounts/login") -def delete(request,id): - - """ - The function is used the delete of a file and it returns to the drafts page. - - @param: - request - trivial. - id - id of the file that is going to be deleted - - """ - file = File.objects.get(pk = id) - file.delete() - return redirect('/filetracking/drafts/') - - - - -def forward_inward(request,id): - - """ This function is used forward the files which are available in the inbox of the user . - - @param: - request - trivial - id - id of the file that is going to forward - - @variables: - file - file object - track - tracking object of the file - context - necessary data to render - - """ - - file = get_object_or_404(File, id=id) - file.is_read = True - track = Tracking.objects.select_related('file_id__uploader__user','file_id__uploader__department','file_id__designation','current_id__user','current_id__department', - 'current_design__user','current_design__working','current_design__designation','receiver_id','receive_design').filter(file_id=file) - designations = get_designation(request.user) - - context = { - - 'designations':designations, - 'file': file, - 'track': track, - } - return render(request, 'filetracking/forward.html', context) - - diff --git a/FusionIIIT/templates/dashboard/modules.html b/FusionIIIT/templates/dashboard/modules.html index 73fc33d85..1b1e7b07f 100755 --- a/FusionIIIT/templates/dashboard/modules.html +++ b/FusionIIIT/templates/dashboard/modules.html @@ -130,7 +130,7 @@
- +
diff --git a/FusionIIIT/templates/dashboard/sidenavbar.html b/FusionIIIT/templates/dashboard/sidenavbar.html index 81cecbe94..655780b8c 100644 --- a/FusionIIIT/templates/dashboard/sidenavbar.html +++ b/FusionIIIT/templates/dashboard/sidenavbar.html @@ -77,7 +77,7 @@

Library Module

Awards & Scholarship

- +

Complaint Module

{% if user.extrainfo.user_type != 'faculty' %} From 92faf40bf6067c8bac4dea5748a7d73dbc0cf41f Mon Sep 17 00:00:00 2001 From: nidhibarapatre Date: Mon, 4 Mar 2024 18:31:41 +0530 Subject: [PATCH 09/34] Implementation of FTS and completion of the redirect functionality --- .gitignore | 3 + .../applications/complaint_system/models.py | 6 +- .../applications/complaint_system/urls.py | 7 +- .../applications/complaint_system/views.py | 1330 +++++++++++++++-- FusionIIIT/applications/filetracking/admin.py | 7 + .../filetracking/api/serializers.py | 24 + .../applications/filetracking/api/urls.py | 22 + .../applications/filetracking/api/views.py | 89 ++ FusionIIIT/applications/filetracking/apps.py | 5 + .../applications/filetracking/models.py | 51 + .../applications/filetracking/sdk/methods.py | 405 +++++ FusionIIIT/applications/filetracking/tests.py | 3 + FusionIIIT/applications/filetracking/urls.py | 42 + FusionIIIT/applications/filetracking/utils.py | 7 + FusionIIIT/applications/filetracking/views.py | 727 +++++++++ .../complaintModule/add_workers.html | 32 +- .../complaintModule/assignworker.html | 41 +- .../complaintModule/carefeedback.html | 127 ++ .../complaintModule/complaint_caretaker.html | 47 +- .../complaint_caretaker_detail.html | 6 +- .../complaint_user_detail.html | 3 +- .../complainthistory_care_final.html | 325 ++++ .../complainthistory_super_final.html | 362 +++++ .../complainthistory_user.html | 608 +------- .../complainthistory_user_final.html | 343 ++--- .../templates/complaintModule/feedback.html | 8 +- .../complaintModule/overdue_super.html | 12 +- .../complaintModule/overduecomplaint.html | 38 +- ..._caretaker.html => resolve_caretaker.html} | 12 +- .../complaintModule/resolve_pending.html | 13 +- .../complaintModule/resolved_super.html | 6 +- .../complaintModule/supervisor1.html | 54 +- ...complaint.html => unresolvecomplaint.html} | 62 +- .../complaintModule/unresolved_super.html | 42 +- .../templates/filetracking/archive.html | 51 +- .../filetracking/archive_design.html | 2 +- .../filetracking/archive_finish.html | 57 +- .../templates/filetracking/confirmdelete.html | 4 +- .../templates/filetracking/draft_design.html | 30 + FusionIIIT/templates/filetracking/drafts.html | 76 +- .../templates/filetracking/filetracking.html | 14 +- .../templates/filetracking/fileview.html | 51 - .../templates/filetracking/fileview1.html | 49 - .../templates/filetracking/fileview2.html | 57 - .../templates/filetracking/forward.html | 8 +- FusionIIIT/templates/filetracking/inbox.html | 50 + FusionIIIT/templates/filetracking/inward.html | 2 +- FusionIIIT/templates/filetracking/outbox.html | 45 + .../templates/filetracking/outward.html | 2 +- .../templates/filetracking/viewfile.html | 126 ++ docker-compose.yml | 4 +- requirements.txt | 4 +- 52 files changed, 4083 insertions(+), 1418 deletions(-) create mode 100644 FusionIIIT/applications/filetracking/admin.py create mode 100644 FusionIIIT/applications/filetracking/api/serializers.py create mode 100644 FusionIIIT/applications/filetracking/api/urls.py create mode 100644 FusionIIIT/applications/filetracking/api/views.py create mode 100644 FusionIIIT/applications/filetracking/apps.py create mode 100644 FusionIIIT/applications/filetracking/models.py create mode 100644 FusionIIIT/applications/filetracking/sdk/methods.py create mode 100644 FusionIIIT/applications/filetracking/tests.py create mode 100644 FusionIIIT/applications/filetracking/urls.py create mode 100644 FusionIIIT/applications/filetracking/utils.py create mode 100644 FusionIIIT/applications/filetracking/views.py create mode 100644 FusionIIIT/templates/complaintModule/carefeedback.html create mode 100644 FusionIIIT/templates/complaintModule/complainthistory_care_final.html create mode 100644 FusionIIIT/templates/complaintModule/complainthistory_super_final.html rename FusionIIIT/templates/complaintModule/{complainthistory_caretaker.html => resolve_caretaker.html} (96%) rename FusionIIIT/templates/complaintModule/{resolvecomplaint.html => unresolvecomplaint.html} (85%) create mode 100644 FusionIIIT/templates/filetracking/draft_design.html delete mode 100644 FusionIIIT/templates/filetracking/fileview.html delete mode 100644 FusionIIIT/templates/filetracking/fileview1.html delete mode 100644 FusionIIIT/templates/filetracking/fileview2.html create mode 100644 FusionIIIT/templates/filetracking/inbox.html create mode 100644 FusionIIIT/templates/filetracking/outbox.html create mode 100644 FusionIIIT/templates/filetracking/viewfile.html diff --git a/.gitignore b/.gitignore index 497fd7a16..3801de163 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,6 @@ node_modules/ FusionIIIT/static/ package-lock.json + +# migrations +migrations/ \ No newline at end of file diff --git a/FusionIIIT/applications/complaint_system/models.py b/FusionIIIT/applications/complaint_system/models.py index 9f8849e69..22bb59832 100644 --- a/FusionIIIT/applications/complaint_system/models.py +++ b/FusionIIIT/applications/complaint_system/models.py @@ -42,7 +42,7 @@ class Caretaker(models.Model): # no_of_comps = models.CharField(max_length=1000) def __str__(self): - return str(self.id) + '-' + self.area + return str(self.id) + '-' + str(self.area) class Workers(models.Model): @@ -82,7 +82,7 @@ def __str__(self): class Supervisor(models.Model): sup_id = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE) - area = models.CharField(choices=Constants.AREA, max_length=20) + area = models.CharField(choices=Constants.AREA, max_length=20,default='hall-3') def __str__(self): - return str(self.sup_id.user.username) + return str(self.id) + '-' + str(self.area) diff --git a/FusionIIIT/applications/complaint_system/urls.py b/FusionIIIT/applications/complaint_system/urls.py index b95605ade..c6d68fdef 100644 --- a/FusionIIIT/applications/complaint_system/urls.py +++ b/FusionIIIT/applications/complaint_system/urls.py @@ -18,6 +18,7 @@ # caretaker + url(r'^caretaker/lodge/$', views.caretakerlodge), url(r'^caretaker/$', views.caretaker, name='caretaker'), url(r'^caretaker/feedback/(?P[0-9]+)/$', views.feedback_care), url(r'^caretaker/worker_id_know_more/(?P[0-9]+)/complaint_reassign/(?P[0-9]+)/discharge_worker/$', views.discharge_worker,name='discharge_worker'), @@ -27,15 +28,18 @@ url(r'^caretaker/pending/(?P[0-9]+)/$', views.resolvepending), url(r'^caretaker/detail2/(?P[0-9]+)/$', views.detail2,name='detail2'), url(r'^caretaker/search_complaint$', views.search_complaint), + url(r'^caretaker/(?P[0-9]+)/feedback/$', views.submitfeedbackcaretaker), # supervisor + url(r'^supervisor/lodge/$', views.supervisorlodge), url(r'^supervisor/$', views.supervisor), url(r'^supervisor/feedback/(?P[0-9]+)/$', views.feedback_super), url(r'^supervisor/caretaker_id_know_more/(?P[0-9]+)/$', views.caretaker_id_know_more), url(r'^supervisor/caretaker_id_know_more/(?P[0-9]+)/complaint_reassign_super/(?P[0-9]+)/$', views.complaint_reassign_super, name = 'complaint_reassign_super'), url(r'^supervisor/detail3/(?P[0-9]+)/$', views.detail3, name = 'detail3'), - + url(r'^supervisor/pending/(?P[0-9]+)/$', views.resolvependingsuper), + url(r'^supervisor/(?P[0-9]+)/$', views.submitfeedbacksuper), @@ -45,6 +49,7 @@ url(r'^caretaker/deletecomplaint/(?P[0-9]+)/$', views.deletecomplaint), # url(r'^caretaker/(?P[0-9]+)/$', views.assign_worker), url(r'^caretaker/(?P[0-9]+)/(?P[0-9]+)/$', views.changestatus), + url(r'^supervisor/(?P[0-9]+)/(?P[0-9]+)/$', views.changestatussuper), url(r'^api/',include('applications.complaint_system.api.urls')) diff --git a/FusionIIIT/applications/complaint_system/views.py b/FusionIIIT/applications/complaint_system/views.py index b566856aa..38852979c 100644 --- a/FusionIIIT/applications/complaint_system/views.py +++ b/FusionIIIT/applications/complaint_system/views.py @@ -12,6 +12,12 @@ from notifications.models import Notification from .models import Caretaker, StudentComplain, Supervisor, Workers from notification.views import complaint_system_notif + + +from applications.filetracking.sdk.methods import * +from applications.filetracking.models import * + + #function for reassign to another worker @login_required def complaint_reassign(request,wid,iid): @@ -121,30 +127,60 @@ def assign_worker(request, comp_id1): a = get_object_or_404(User, username=request.user.username) y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() comp_id = y.id - if type == 'assign': - complaint_finish = request.POST.get('complaint_finish', '') - worker_id = request.POST.get('assign_worker', '') - w = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').get(id=worker_id) - StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').select_for_update().filter(id=comp_id1).\ - update(worker_id=w, status=1) - complainer_details = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').get(id=comp_id1) - student = 0 - message = "Worker has been assigned to your complaint" - complaint_system_notif(request.user, complainer_details.complainer.user ,'assign_worker_alert',complainer_details.id,student,message) - return HttpResponseRedirect('/complaint/caretaker/') - elif type == 'redirect': - assign_caretaker = request.POST.get('assign_caretaker', '') - c = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(id=assign_caretaker) - c1 = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(id=comp_id) - remark = 'Redirect complaint from ' + c1.area - StudentComplain.objects.select_for_update().filter(id=comp_id1).\ - update(location=c.area, remarks=remark) - complainer_details = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').get(id=comp_id1) - student=0 - message = "Your Complaint has been redirected to another caretaker" - complaint_system_notif(request.user, complainer_details.complainer.user ,'comp_redirect_alert',complainer_details.id,student,message) - return HttpResponseRedirect('/complaint/caretaker/') + # if a.username=="shyams": + # desgn="hall3caretaker" + # if type == 'assign': + # complaint_finish = request.POST.get('complaint_finish', '') + # worker_id = request.POST.get('assign_worker', '') + # w = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').get(id=worker_id) + # StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').select_for_update().filter(id=comp_id1).\ + # update(worker_id=w, status=1) + # complainer_details = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').get(id=comp_id1) + # student = 0 + # message = "Worker has been assigned to your complaint" + # complaint_system_notif(request.user, complainer_details.complainer.user ,'assign_worker_alert',complainer_details.id,student,message) + + # return HttpResponseRedirect('/complaint/caretaker/') + # elif type == 'redirect': + print(comp_id1) + print("1234567890") + assign_caretaker = request.POST.get('assign_caretaker', '') + # c = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(id=assign_caretaker) + c1 = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(staff_id=comp_id) + c2=Supervisor.objects.all().filter(area=c1.area) + # c3=User.objects.all().filter(id=c2[0].sup_id.id) + # print(c3[0]) + y1 = ExtraInfo.objects.all().select_related('user','department').filter(id=c2[0].sup_id.id).first() + print(y1) + # b = get_object_or_404(User, id=y1.user.username) + # remark = 'Redirect complaint from ' + c1.area + # StudentComplain.objects.select_for_update().filter(id=comp_id1).\ + # update(location=c.area, remarks=remark) + complainer_details = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').get(id=comp_id1) + student=0 + message = "Your Complaint has been redirected to supervisor" + complaint_system_notif(request.user, complainer_details.complainer.user ,'comp_redirect_alert',complainer_details.id,student,message) + # return render(request, "complaintModule/assignworker.html", + # {'detail': detail, 'worker': worker, 'flag': + # flag, 'total_caretaker': total_caretaker,'a':a, 'total_caretakers_in_area':total_caretakers_in_area}) + + sup = HoldsDesignation.objects.select_related('user','working','designation').get(user = y1.user_id) + print(sup.designation) + + user_details=User.objects.get(id=y.user_id) + des=HoldsDesignation.objects.filter(user=user_details).all() + file_id = create_file(uploader=a.username, + uploader_designation=des[0].designation, + receiver=c2[0].sup_id.user, + receiver_designation=sup.designation, + src_module="complaint", + src_object_id= str(comp_id1), + file_extra_JSON= {}, + attached_file = None) + + + return HttpResponseRedirect('/complaint/caretaker/') else: y = ExtraInfo.objects.all().select_related('user','department').get(id=y.id) a = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(staff_id=y) @@ -153,7 +189,8 @@ def assign_worker(request, comp_id1): try: detail = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=comp_id1).first() total_caretaker = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').all() - total_caretakers_in_area = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').filter(area=b and id!=a.id) + total_caretakers_in_area = Supervisor.objects.select_related('sup_id').filter(area=b ) + # supervisors_in_area= HoldsDesignation.objects.select_related('user','working','designation').get(total_caretakers_in_area = dsgn) workertemp = [] worker = [] flag = '' @@ -283,12 +320,31 @@ def check(request): print('----------------------------') print('----------------------------') print('----------------------------') - if b.user_type == 'student': + supervisor_list=Supervisor.objects.all() + caretaker_list=Caretaker.objects.all() + is_supervisor=False + is_caretaker=False + for i in supervisor_list: + if b.id==i.sup_id_id: + is_supervisor=True + break + for i in caretaker_list: + if b.id==i.staff_id_id: + is_caretaker=True + break + if is_supervisor: + return HttpResponseRedirect('/complaint/supervisor/') + elif is_caretaker: + return HttpResponseRedirect('/complaint/caretaker/') + + elif b.user_type == 'student': return HttpResponseRedirect('/complaint/user/') + # elif b.user_type == 'fx': + # return HttpResponseRedirect('/complaint/supervisor/') elif b.user_type == 'staff': - return HttpResponseRedirect('/complaint/caretaker/') + return HttpResponseRedirect('/complaint/user/') elif b.user_type == 'faculty': - return HttpResponseRedirect('/complaint/supervisor/') + return HttpResponseRedirect('/complaint/user/') else: return HttpResponse("

wrong user credentials

") else: @@ -338,7 +394,7 @@ def user(request): complaint_finish = datetime.now() + timedelta(days=4) elif comp_type == 'other': complaint_finish = datetime.now() + timedelta(days=3) - y = ExtraInfo.objects.all().select_related('user','department').get(id=comp_id) + # y = ExtraInfo.objects.all().get(id=comp_id) #check if location given if location!="": # x = StudentComplain(complainer=y, @@ -352,6 +408,8 @@ def user(request): # x.save() + user_details=User.objects.get(id=y.user_id) + obj1, created = StudentComplain.objects.get_or_create(complainer=y, complaint_type=comp_type, location=location, @@ -361,7 +419,8 @@ def user(request): complaint_finish=complaint_finish, upload_complaint=comp_file) - + + historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') history = [] j = 1 @@ -408,6 +467,19 @@ def user(request): dsgn = "rewacaretaker" caretaker_name = HoldsDesignation.objects.select_related('user','working','designation').get(designation__name = dsgn) + c1=HoldsDesignation.objects.filter(user_id=y.user_id).all() + print(c1[0].designation) + file_id = create_file(uploader=user_details.username, + uploader_designation=c1[0].designation, + receiver=caretaker_name.user.username, + receiver_designation=caretaker_name.designation, + src_module="complaint", + src_object_id= str(obj1.id), + file_extra_JSON= {}, + attached_file = None) + + # print(" wertyuioiuhygfdsdfghjk") + print(file_id) # This is to allow the student student = 1 @@ -419,6 +491,9 @@ def user(request): # next = request.POST.get('next', '/') messages.success(request,message) + + + return HttpResponseRedirect('/complaint/user') else: @@ -426,6 +501,8 @@ def user(request): y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') history=[] + user_details=User.objects.get(id=y.user_id) + notification = Notification.objects.filter(recipient=a.id) notification = notification.filter(data__exact={'url':'complaint:detail','module':'Complaint System'}) @@ -437,45 +514,48 @@ def user(request): # notification_message.append(notification.verb+' by '+ to + ' ' + duration + ' ago ') - + c1=HoldsDesignation.objects.filter(user_id=y.user_id).all() + print(c1[0].designation) + # c2=Designation.objects.filter(i) j = 1 for i in historytemp: history.append(i) - # if j%2 != 0: - # history.append(i) - # j = j+1 - - for i in history: - i.serial_no = j - j = j+1 + # # if j%2 != 0: + # # history.append(i) + # # j = j+1 - # if location == "hall-1": - # dsgn ="hall1caretaker" - # elif location =="hall-3": - # dsgn ="hall3caretaker" - # elif location =="hall-4": - # dsgn ="hall4caretaker" - # elif location =="CC1": - # dsgn ="CC convenor" - # elif location =="CC2": - # dsgn ="CC2 convener" - # elif location == "core_lab": - # dsgn = "corelabcaretaker" - # elif location =="LHTC": - # dsgn ="lhtccaretaker" - # elif location =="NR2": - # dsgn ="nr2caretaker" - # else: - # dsgn = "rewacaretaker" - # caretaker_name = HoldsDesignation.objects.get(designation__name = dsgn) + - # complaint_system_notif(request.user, caretaker_name.user,'lodge_comp_alert') + outbox_files = view_outbox( + username=user_details.username, + designation=c1[0].designation, + src_module="complaint" + ) + + outbox=[] + comp_list=set() + for i in outbox_files: + + outbox.append(i) + + for i in outbox: + file_history = view_history(file_id=i['id']) + + comp=File.objects.filter(uploader=file_history[0]['current_id']) + for j in comp: + c=StudentComplain.objects.all().filter(id=j.src_object_id) + comp_list.add(c) + print(c[0]) + + break + complaint_final_list=[] + for i in comp_list: + complaint_final_list.append(i[0]) return render(request, "complaintModule/complaint_user.html", - {'history': history,'notification':notification, 'comp_id': y.id}) + {'history': complaint_final_list,'notification':notification, 'comp_id': y.id, 'outbox':outbox}) + - return render(request, "complaintModule/complaint_user.html", - {'history': history, 'comp_id': comp_id }) @login_required def save_comp(request): """ @@ -543,21 +623,21 @@ def caretaker(request): """ current_user = get_object_or_404(User, username=request.user.username) y = ExtraInfo.objects.all().select_related('user','department').filter(user=current_user).first() - + if request.method == 'POST': - type = request.POST.get('submit', '') - worker_type = request.POST.get('complaint_type', '') - name = request.POST.get('name', '') - phone = request.POST.get('phone_no', '') - age = request.POST.get('age', '') - try: - y = ExtraInfo.objects.all().select_related('user','department').get(id=y.id) - a = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(staff_id=y) - except Exception as e: - a = None - y = None - intage = int(age) - intphone = int(phone) + # type = request.POST.get('submit', '') + # worker_type = request.POST.get('complaint_type', '') + # name = request.POST.get('name', '') + # phone = request.POST.get('phone_no', '') + # age = request.POST.get('age', '') + # try: + # y = ExtraInfo.objects.all().select_related('user','department').get(id=y.id) + # a = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(staff_id=y) + # except Exception as e: + # a = None + # y = None + # intage = int(age) + # intphone = int(phone) # if len(phone) == 10 and intage > 20 and intage < 50 and intphone > 1999999999: # x = Workers(caretaker_id=a, # name=name, @@ -567,77 +647,211 @@ def caretaker(request): # if not Workers.objects.filter(caretaker_id=a,name=name, age=age,phone=phone,worker_type=worker_type).exists(): # x.save() - if len(phone) == 10 and intage > 20 and intage < 50 and intphone > 1999999999: - obj, created = Workers.objects.get_or_create(caretaker_id=a, - name=name, - age=age, - phone=phone, - worker_type=worker_type) + # if len(phone) == 10 and intage > 20 and intage < 50 and intphone > 1999999999: + # obj, created = Workers.objects.get_or_create(caretaker_id=a, + # name=name, + # age=age, + # phone=phone, + # worker_type=worker_type) - b = a.area - historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(location=b).order_by('-id') + # b = a.area + # historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(location=b).order_by('-id') + # history = [] + # j = 1 + # k = 1 + # for i in historytemp: + # history.append(i) + # # if j%2 == 1: + # # history.append(i) + # # j = j+1 + + # for h in history: + # h.serial_no = k + # k=k+1 + user_details=User.objects.get(id=y.user_id) + # if user_details.username=="shyams": + # desgn="hall3caretaker" + # if user_details.username=="hall4caretaker": + # desgn="hall4caretaker" + + # total_worker = [] + + + # total_workertemp = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').filter(caretaker_id=a) + # j = 1 + # for i in total_workertemp: + # if j%2 != 0: + # total_worker.append(i) + # j = j + 1 + + + # for i in total_workertemp: + # total_worker.append(i) + + complaint_assign_no = [] + comp_type = request.POST.get('complaint_type', '') + location = request.POST.get('Location', '') + specific_location = request.POST.get('specific_location', '') + comp_file = request.FILES.get('myfile') + + details = request.POST.get('details', '') + status = 0 + # finish time is according to complaint type + complaint_finish = datetime.now() + timedelta(days=2) + if comp_type == 'Electricity': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'carpenter': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'plumber': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'garbage': + complaint_finish = datetime.now() + timedelta(days=1) + elif comp_type == 'dustbin': + complaint_finish = datetime.now() + timedelta(days=1) + elif comp_type == 'internet': + complaint_finish = datetime.now() + timedelta(days=4) + elif comp_type == 'other': + complaint_finish = datetime.now() + timedelta(days=3) + # y = ExtraInfo.objects.all().select_related('user','department').get(id=comp_id) + #check if location given + if location!="": + user_details=User.objects.get(id=y.user_id) + obj1, created = StudentComplain.objects.get_or_create(complainer=y, + complaint_type=comp_type, + location=location, + specific_location=specific_location, + details=details, + status=status, + complaint_finish=complaint_finish, + upload_complaint=comp_file) + + historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') history = [] j = 1 k = 1 for i in historytemp: history.append(i) - # if j%2 == 1: + # if j%2 != 0: # history.append(i) # j = j+1 + + for h in history: h.serial_no = k - k=k+1 + k = k+1 + # if location == "hall1": + # dsgn = "hall1caretaker" + # elif location == "hall3": + # dsgn = "hall3caretaker" + # else : + # dsgn = "hall4caretaker" + if location == "hall-1": + dsgn ="hall1caretaker" + elif location =="hall-3": + dsgn ="hall3caretaker" + elif location =="hall-4": + dsgn ="hall4caretaker" + elif location =="CC1": + dsgn ="cc1convener" + elif location =="CC2": + dsgn ="CC2 convener" + elif location == "core_lab": + dsgn = "corelabcaretaker" + elif location =="LHTC": + dsgn ="lhtccaretaker" + elif location =="NR2": + dsgn ="nr2caretaker" + elif location =="Maa Saraswati Hostel": + dsgn ="mshcaretaker" + elif location =="Nagarjun Hostel": + dsgn ="nhcaretaker" + elif location =="Panini Hostel": + dsgn ="phcaretaker" + else: + dsgn = "rewacaretaker" + caretaker_name = HoldsDesignation.objects.select_related('user','working','designation').get(designation__name = dsgn) + print(caretaker_name.user.username) + print(user_details.username) + print(caretaker_name.designation) + user_details=User.objects.get(id=y.user_id) + des=HoldsDesignation.objects.filter(user=user_details).all() + file_id = create_file(uploader=user_details.username, + uploader_designation=des[0].designation, + receiver=caretaker_name.user.username, + receiver_designation=dsgn, + src_module="complaint", + src_object_id= str(obj1.id), + file_extra_JSON= {}, + attached_file = None) - total_worker = [] - total_workertemp = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').filter(caretaker_id=a) - j = 1 - # for i in total_workertemp: - # if j%2 != 0: - # total_worker.append(i) - # j = j + 1 - - for i in total_workertemp: - total_worker.append(i) + # This is to allow the student + student = 1 + message = "A New Complaint has been lodged" + complaint_system_notif(request.user, caretaker_name.user,'lodge_comp_alert',obj1.id,student,message) + + # return render(request, "complaintModule/complaint_user.html", + # {'history': history, 'comp_id': comp_id }) + # next = request.POST.get('next', '/') + + messages.success(request,message) + # return HttpResponseRedirect('/complaint/user') - complaint_assign_no = [] - for x in total_worker: - worker = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').get(id=x.id) - temp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(worker_id=worker).count() - worker.total_complaint = temp - complaint_assign_no.append(worker) + # for x in total_worker: + # worker = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').get(id=x.id) + # temp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(worker_id=worker).count() + # worker.total_complaint = temp + # complaint_assign_no.append(worker) notification = Notification.objects.filter(recipient=current_user.id) notification = notification.filter(data__exact={'url':'complaint:detail2','module':'Complaint System'}) return render(request, "complaintModule/complaint_caretaker.html", {'history': history, 'comp_id': y.id, - 'notification': notification, 'total_worker': - total_worker, 'complaint_assign_no': complaint_assign_no}) + 'notification': notification, 'complaint_assign_no': complaint_assign_no}) else: - y = ExtraInfo.objects.all().select_related('user','department').get(id=y.id) - a = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(staff_id=y) + # y = ExtraInfo.objects.all().select_related('user','department').get(id=y.id) + + a = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(staff_id=y.id) b = a.area history = [] historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(location=b).order_by('-id') - total_worker = [] - total_workertemp = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').filter(caretaker_id=a) - j = 1 - for i in total_workertemp: - total_worker.append(i) + # total_worker = [] + # total_workertemp = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').filter(caretaker_id=a) + # j = 1 + # for i in total_workertemp: + # total_worker.append(i) + # complaint_assign_no = [] complaint_assign_no = [] - complaint_assign_no = [] + user_details=User.objects.get(id=y.user_id) + # if user_details.username=="shyams": + # desgn="hall3caretaker" + # if user_details.username=="hall4caretaker": + # desgn="hall4caretaker" + # a = get_object_or_404(User, username=request.user.username) + # y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() + carehistorytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') + carehistory=[] + j = 1 + for i in carehistorytemp: + carehistory.append(i) + # if j%2 != 0: + # history.append(i) + # j = j+1 - for x in total_worker: - worker = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').get(id=x.id) - temp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(worker_id=worker).count() - worker.total_complaint = temp - complaint_assign_no.append(worker) + for i in carehistory: + i.serial_no = j + j = j+1 + # for x in total_worker: + # worker = Workers.objects.select_related('caretaker_id','caretaker_id__staff_id','caretaker_id__staff_id__user','caretaker_id__staff_id__department').get(id=x.id) + # temp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(worker_id=worker).count() + # worker.total_complaint = temp + # complaint_assign_no.append(worker) overduecomplaint = [] j = 1 @@ -658,14 +872,87 @@ def caretaker(request): notification = Notification.objects.filter(recipient=current_user.id) notification = notification.filter(data__exact={'url':'complaint:detail2','module':'Complaint System'}) + user_details=User.objects.get(id=y.user_id) + # print(y.user_type) + # print(user_details.username) + # print(user_details) - + des=HoldsDesignation.objects.filter(user=user_details).all() + # print(y.user_id) + # print(user_details) + # print(des[0].designation) + user_object = get_user_object_from_username(y.user.username) + user_des=HoldsDesignation.objects.filter(user=user_details).all() + # print(user_object) + # print(user_des) + outbox_files = view_outbox( + username=user_details.username, + designation=des[0].designation, + src_module="complaint" + ) + + outbox=[] + comp_list=set() + for i in outbox_files: + # print(i) + outbox.append(i) + for i in outbox: + file_history = view_history(file_id=i['id']) + + comp=File.objects.filter(uploader=file_history[0]['current_id']) + for j in comp: + c=StudentComplain.objects.all().filter(id=j.src_object_id) + comp_list.add(c) + # print(c[0]) + + break + complaint_final_list=[] + for i in comp_list: + complaint_final_list.append(i[0]) + print(user_details.username) + print(des[0].designation) + inbox_files = view_inbox( + username=user_details.username, + designation=des[0].designation, + src_module="complaint" + ) + print(inbox_files) + + inbox=[] + comp_list_in=set() + for i in inbox_files: + # print(i) + inbox.append(i) + file_history_list=[] + for i in inbox: + file_history = view_history(file_id=i['id']) + # print(file_history[0]) + file_history_list.append(file_history[0]) + # print(file_history[0]['file_id']) + comp=File.objects.filter(id=file_history[0]['file_id']) + print(comp[0].src_object_id) + for j in comp: + c=StudentComplain.objects.all().filter(id=j.src_object_id) + comp_list_in.add(c) + # print(c[0]) + + # break + # file_history_list_final=uniqueList(file_history_list) + # print(file_history_list) + complaint_final_list_in=[] + for i in comp_list_in: + complaint_final_list_in.append(i[0]) + + # print(complaint_final_list_in) + return render(request, "complaintModule/complaint_caretaker.html", - { 'history': history, 'comp_id': y.id, 'total_worker': total_worker, - 'complaint_assign_no': total_worker, + { 'history': complaint_final_list_in, + 'comp_id': y.id, + 'carehistory':complaint_final_list, 'notification':notification, - 'overduecomplaint': overduecomplaint, 'care_id': a}) + 'overduecomplaint': overduecomplaint, + 'care_id': a}) @login_required def remove_worker_from_complaint(request,complaint_id): @@ -711,6 +998,37 @@ def changestatus(request, complaint_id, status): return HttpResponseRedirect('/complaint/caretaker/') + + +@login_required +def changestatussuper(request, complaint_id, status): + """ + The function is used by caretaker to change the status of a complaint. + @param: + request - trivial. + complaint_id - used to get complaint_id registered. + status-used to get the current status of complaints + + @variables: + issue - The issue object. + supported - True if the user's intention is to support the issue. + support_count - Total supporters of the above issue. + context - Holds data needed to make necessary changes in the template. + """ + if status == '3': + StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=complaint_id).\ + update(status=status, worker_id='') + return HttpResponseRedirect('/complaint/supervisor/') + elif status == '2': + StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=complaint_id).\ + update(status=status, worker_id='') + return HttpResponseRedirect('/complaint/supervisor/') + else: + StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=complaint_id).\ + update(status=status) + return HttpResponseRedirect('/complaint/supervisor/') + + @login_required def removew(request, work_id): """ @@ -821,8 +1139,8 @@ def supervisor(request): # print("--------------------------") # testEntry() current_user = get_object_or_404(User, username=request.user.username) - y = ExtraInfo.objects.all().select_related('user','department').filter(user=current_user).first() + comp_id = y.id if request.method == 'POST' : try: y = ExtraInfo.objects.all().select_related('user','department').get(id=y.id) @@ -843,6 +1161,8 @@ def supervisor(request): # if j%2 != 0: # all_complaint.append(i) # j = j + 1 + + overduecomplaint = [] for i in all_complaint: if i.status != 2 and i.status != 3: @@ -850,44 +1170,255 @@ def supervisor(request): i.delay = date.today() - i.complaint_finish overduecomplaint.append(i) - return render(request, "complaintModule/supervisor1.html", - {'all_caretaker': all_caretaker, 'all_complaint': all_complaint, - 'overduecomplaint': overduecomplaint, 'area': area,'num':num}) - else: - print('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') - y = ExtraInfo.objects.all().select_related('user','department').get(id=y.id) - try: - a = get_object_or_404(Supervisor, sup_id=y) - except : - return HttpResponseRedirect('/') - - #print(a) - # if(len(a)==0) : - # return render('../dashboard/') - a = Supervisor.objects.select_related('sup_id','sup_id__user','sup_id__department').get(sup_id=y) - all_caretaker = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').filter(area=a.area).order_by('-id') - area = all_caretaker[0].area - numtemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(location = area).filter(status = 0).count() - num = int(numtemp/2+0.5) - all_complaint = [] - all_complainttemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(location=a.area).order_by('-id') - j = 1 - for i in all_complainttemp: - all_complaint.append(i) - # if j%2 != 0: - # all_complaint.append(i) - # j = j + 1 - overduecomplaint = [] - for i in all_complaint: - if i.status != 2 and i.status != 3: - if i.complaint_finish < date.today(): - i.delay = date.today() - i.complaint_finish - overduecomplaint.append(i) - - return render(request, "complaintModule/supervisor1.html", - {'all_caretaker': all_caretaker, 'all_complaint': all_complaint, - 'overduecomplaint': overduecomplaint, 'area': area, 'num' : num}) - + comp_type = request.POST.get('complaint_type', '') + location = request.POST.get('Location', '') + specific_location = request.POST.get('specific_location', '') + comp_file = request.FILES.get('myfile') + + details = request.POST.get('details', '') + status = 0 + # finish time is according to complaint type + complaint_finish = datetime.now() + timedelta(days=2) + if comp_type == 'Electricity': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'carpenter': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'plumber': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'garbage': + complaint_finish = datetime.now() + timedelta(days=1) + elif comp_type == 'dustbin': + complaint_finish = datetime.now() + timedelta(days=1) + elif comp_type == 'internet': + complaint_finish = datetime.now() + timedelta(days=4) + elif comp_type == 'other': + complaint_finish = datetime.now() + timedelta(days=3) + y = ExtraInfo.objects.all().select_related('user','department').get(id=comp_id) + #check if location given + if location!="": + # x = StudentComplain(complainer=y, + # complaint_type=comp_type, + # location=location, + # specific_location=specific_location, + # details=details, + # status=status, + # complaint_finish=complaint_finish, + # upload_complaint=comp_file) + + + # x.save() + obj1, created = StudentComplain.objects.get_or_create(complainer=y, + complaint_type=comp_type, + location=location, + specific_location=specific_location, + details=details, + status=status, + complaint_finish=complaint_finish, + upload_complaint=comp_file) + + + historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') + history = [] + j = 1 + k = 1 + for i in historytemp: + history.append(i) + # if j%2 != 0: + # history.append(i) + # j = j+1 + + + for h in history: + h.serial_no = k + k = k+1 + # if location == "hall1": + # dsgn = "hall1caretaker" + # elif location == "hall3": + # dsgn = "hall3caretaker" + # else : + # dsgn = "hall4caretaker" + if location == "hall-1": + dsgn ="hall1caretaker" + elif location =="hall-3": + dsgn ="hall3caretaker" + elif location =="hall-4": + dsgn ="hall4caretaker" + elif location =="CC1": + dsgn ="cc1convener" + elif location =="CC2": + dsgn ="CC2 convener" + elif location == "core_lab": + dsgn = "corelabcaretaker" + elif location =="LHTC": + dsgn ="lhtccaretaker" + elif location =="NR2": + dsgn ="nr2caretaker" + elif location =="Maa Saraswati Hostel": + dsgn ="mshcaretaker" + elif location =="Nagarjun Hostel": + dsgn ="nhcaretaker" + elif location =="Panini Hostel": + dsgn ="phcaretaker" + else: + dsgn = "rewacaretaker" + caretaker_name = HoldsDesignation.objects.select_related('user','working','designation').get(designation__name = dsgn) + user_details=User.objects.get(id=y.user_id) + c2=Supervisor.objects.all().filter(area=area) + print(caretaker_name.user.username) + print(user_details.username) + print(caretaker_name.designation) + + # sup = HoldsDesignation.objects.select_related('user','working','designation').get(user = y.id) + # print(sup.designation) + + user_details=User.objects.get(id=y.user_id) + des=HoldsDesignation.objects.filter(user=user_details).all() + + + file_id = create_file(uploader=user_details.username, + uploader_designation=des[0].designation, + receiver=caretaker_name.user.username, + receiver_designation=str(caretaker_name.designation), + src_module="complaint", + src_object_id= str(obj1.id), + file_extra_JSON= {}, + attached_file = None) + + + # This is to allow the student + student = 1 + message = "A New Complaint has been lodged" + complaint_system_notif(request.user, caretaker_name.user,'lodge_comp_alert',obj1.id,student,message) + + # return render(request, "complaintModule/complaint_user.html", + # {'history': history, 'comp_id': comp_id }) + # next = request.POST.get('next', '/') + + messages.success(request,message) + # return HttpResponseRedirect('/complaint/user') + + return render(request, "complaintModule/supervisor1.html", + {'all_caretaker': all_caretaker, 'all_complaint': all_complaint, + 'overduecomplaint': overduecomplaint, 'area': area,'num':num}) + else: + # y = ExtraInfo.objects.all().select_related('user','department').get(id=y.id).fi + # try: + # a = get_object_or_404(Supervisor, sup_id=y) + # except : + # return HttpResponseRedirect('/') + + #print(a) + # if(len(a)==0) : + # return render('../dashboard/') + a = get_object_or_404(User, username=request.user.username) + # y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() + historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') + history=[] + j = 1 + for i in historytemp: + history.append(i) + # if j%2 != 0: + # history.append(i) + # j = j+1 + + for i in history: + i.serial_no = j + j = j+1 + a = Supervisor.objects.select_related('sup_id','sup_id__user','sup_id__department').get(sup_id=y) + all_caretaker = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').filter(area=a.area).order_by('-id') + area = all_caretaker[0].area + # desgn=HoldsDesignation.objects.select_related('user','working','designation').get(user = y.id) + # desgn="hall3supervisor" + numtemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(location = area).filter(status = 0).count() + num = int(numtemp/2+0.5) + all_complaint = [] + user_details=User.objects.get(id=y.user_id) + all_complainttemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(location=a.area).order_by('-id') + j = 1 + for i in all_complainttemp: + all_complaint.append(i) + # if j%2 != 0: + # all_complaint.append(i) + # j = j + 1 + overduecomplaint = [] + for i in all_complaint: + if i.status != 2 and i.status != 3: + if i.complaint_finish < date.today(): + i.delay = date.today() - i.complaint_finish + overduecomplaint.append(i) + + # print(y.user_id) + # print(des[0].designation) + # u=ExtraInfo.objects.filter(user=y.user_id).all() + # print(u) + # des=HoldsDesignation.objects.filter(user=u[0].id).all() + # print(des[0].designation.name) + + + current_user = get_object_or_404(User, username=request.user.username) + y = ExtraInfo.objects.all().select_related('user','department').filter(user=current_user).first() + user_details=User.objects.get(id=y.user_id) + des=HoldsDesignation.objects.filter(user=user_details).all() + print(y.user_id) + print(user_details.username) + print(des[0].user) + outbox_files = view_outbox( + username=user_details.username, + designation=des[0].designation, + src_module="complaint" + ) + + outbox=[] + comp_list=set() + for i in outbox_files: + # print(i) + outbox.append(i) + + for i in outbox: + file_history = view_history(file_id=i['id']) + + comp=File.objects.filter(uploader=file_history[0]['current_id']) + for j in comp: + c=StudentComplain.objects.all().filter(id=j.src_object_id) + comp_list.add(c) + # print(c[0]) + + break + complaint_final_list=[] + for i in comp_list: + complaint_final_list.append(i[0]) + + inbox_files = view_inbox( + username=user_details.username, + designation=des[0].designation, + src_module="complaint" + ) + + inbox=[] + comp_list_in=set() + for i in inbox_files: + print(i) + inbox.append(i) + + for i in inbox: + file_history = view_history(file_id=i['id']) + + comp=File.objects.filter(uploader=file_history[0]['current_id']) + for j in comp: + c=StudentComplain.objects.all().filter(id=j.src_object_id) + comp_list_in.add(c) + print(c[0]) + + break + complaint_final_list_in=[] + for i in comp_list_in: + complaint_final_list_in.append(i[0]) + print(complaint_final_list_in) + return render(request, "complaintModule/supervisor1.html", + + {'history':complaint_final_list_in,'all_caretaker': all_caretaker, 'all_complaint': all_complaint,'outbox':complaint_final_list, + 'overduecomplaint': overduecomplaint, 'area': area, 'num' : num}) + @login_required def caretaker_id_know_more(request,caretaker_id): this_caretaker = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').get(id = caretaker_id) @@ -935,6 +1466,36 @@ def resolvepending(request, cid): # complainer_details = StudentComplain.objects.get(id=cid) # complaint_system_notif(request.user, complainer_details.complainer.user ,'comp_resolved_alert') return render(request,"complaintModule/resolve_pending.html",{"a" : a,"thiscomplaint" : thiscomplaint}) + + + + +@login_required +def resolvependingsuper(request, cid): + a = get_object_or_404(User, username=request.user.username) + y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() + thiscomplaint = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').get(id=cid) + if request.method == 'POST': + newstatus = request.POST.get('yesorno','') + comment = request.POST.get('comment') + intstatus = 0 + if newstatus == 'Yes': + intstatus = 2 + else: + intstatus = 3 + StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=cid).\ + update(status=intstatus) + StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=cid).\ + update(comment=comment) + complainer_details = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').get(id=cid) + student=0 + message = "Congrats! Your complaint has been resolved" + complaint_system_notif(request.user, complainer_details.complainer.user ,'comp_resolved_alert',complainer_details.id,student,message) + return HttpResponseRedirect("/complaint/supervisor/") + else: + # complainer_details = StudentComplain.objects.get(id=cid) + # complaint_system_notif(request.user, complainer_details.complainer.user ,'comp_resolved_alert') + return render(request,"complaintModule/resolve_pending.html",{"a" : a,"thiscomplaint" : thiscomplaint}) @@ -1033,3 +1594,456 @@ def detail3(request, detailcomp_id1): loc = detail3.location care = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').filter(area=loc).first() return render(request, "complaintModule/complaint_supervisor_detail.html", {"detail3": detail3,"comp_id":comp_id,"care":care,"num":num}) + + + + +@login_required + +def supervisorlodge(request): + """ + The function is used to register a complaint + @param: + request - trivial. + + + @variables: + issue - The issue object. + supported - True if the user's intention is to support the issue. + support_count - Total supporters of the above issue. + context - Holds data needed to make necessary changes in the template. + """ + a = get_object_or_404(User, username=request.user.username) + y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() + num = 1 + comp_id = y.id + if request.method == 'POST': + comp_type = request.POST.get('complaint_type', '') + location = request.POST.get('Location', '') + specific_location = request.POST.get('specific_location', '') + comp_file = request.FILES.get('myfile') + + details = request.POST.get('details', '') + status = 0 + # finish time is according to complaint type + complaint_finish = datetime.now() + timedelta(days=2) + if comp_type == 'Electricity': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'carpenter': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'plumber': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'garbage': + complaint_finish = datetime.now() + timedelta(days=1) + elif comp_type == 'dustbin': + complaint_finish = datetime.now() + timedelta(days=1) + elif comp_type == 'internet': + complaint_finish = datetime.now() + timedelta(days=4) + elif comp_type == 'other': + complaint_finish = datetime.now() + timedelta(days=3) + y = ExtraInfo.objects.all().select_related('user','department').get(id=comp_id) + #check if location given + if location!="": + # x = StudentComplain(complainer=y, + # complaint_type=comp_type, + # location=location, + # specific_location=specific_location, + # details=details, + # status=status, + # complaint_finish=complaint_finish, + # upload_complaint=comp_file) + + + # x.save() + obj1, created = StudentComplain.objects.get_or_create(complainer=y, + complaint_type=comp_type, + location=location, + specific_location=specific_location, + details=details, + status=status, + complaint_finish=complaint_finish, + upload_complaint=comp_file) + + + historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') + history = [] + j = 1 + k = 1 + for i in historytemp: + history.append(i) + # if j%2 != 0: + # history.append(i) + # j = j+1 + + + for h in history: + h.serial_no = k + k = k+1 + # if location == "hall1": + # dsgn = "hall1caretaker" + # elif location == "hall3": + # dsgn = "hall3caretaker" + # else : + # dsgn = "hall4caretaker" + if location == "hall-1": + dsgn ="hall1caretaker" + elif location =="hall-3": + dsgn ="hall3caretaker" + elif location =="hall-4": + dsgn ="hall4caretaker" + elif location =="CC1": + dsgn ="cc1convener" + elif location =="CC2": + dsgn ="CC2 convener" + elif location == "core_lab": + dsgn = "corelabcaretaker" + elif location =="LHTC": + dsgn ="lhtccaretaker" + elif location =="NR2": + dsgn ="nr2caretaker" + elif location =="Maa Saraswati Hostel": + dsgn ="mshcaretaker" + elif location =="Nagarjun Hostel": + dsgn ="nhcaretaker" + elif location =="Panini Hostel": + dsgn ="phcaretaker" + else: + dsgn = "rewacaretaker" + caretaker_name = HoldsDesignation.objects.select_related('user','working','designation').get(designation__name = dsgn) + + + # This is to allow the student + student = 1 + message = "A New Complaint has been lodged" + complaint_system_notif(request.user, caretaker_name.user,'lodge_comp_alert',obj1.id,student,message) + + # return render(request, "complaintModule/complaint_user.html", + # {'history': history, 'comp_id': comp_id }) + # next = request.POST.get('next', '/') + + messages.success(request,message) + return HttpResponseRedirect('/complaint/supervisor') + + else: + a = get_object_or_404(User, username=request.user.username) + y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() + historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') + history=[] + + notification = Notification.objects.filter(recipient=a.id) + notification = notification.filter(data__exact={'url':'complaint:detail','module':'Complaint System'}) + # notification_message = [] + # for notification in x: + # to = User.objects.get(id=notification.actor_object_id).username + # from django.utils.timesince import timesince as timesince_ + # duration = timesince_(notification.timestamp,None) + # notification_message.append(notification.verb+' by '+ to + ' ' + duration + ' ago ') + + + + + j = 1 + for i in historytemp: + history.append(i) + # if j%2 != 0: + # history.append(i) + # j = j+1 + + for i in history: + i.serial_no = j + j = j+1 + + # if location == "hall-1": + # dsgn ="hall1caretaker" + # elif location =="hall-3": + # dsgn ="hall3caretaker" + # elif location =="hall-4": + # dsgn ="hall4caretaker" + # elif location =="CC1": + # dsgn ="CC convenor" + # elif location =="CC2": + # dsgn ="CC2 convener" + # elif location == "core_lab": + # dsgn = "corelabcaretaker" + # elif location =="LHTC": + # dsgn ="lhtccaretaker" + # elif location =="NR2": + # dsgn ="nr2caretaker" + # else: + # dsgn = "rewacaretaker" + # caretaker_name = HoldsDesignation.objects.get(designation__name = dsgn) + + # complaint_system_notif(request.user, caretaker_name.user,'lodge_comp_alert') + return render(request, "complaintModule/supervisor1.html", + {'history': history,'notification':notification, 'comp_id': y.id}) + + return render(request, "complaintModule/complaint_user.html", + {'history': history, 'comp_id': comp_id }) + + + + +@login_required +def submitfeedbacksuper(request, complaint_id): + """ + The function is used by the complainant to enter feedback after the complaint has been resolved + @param: + request - trivial. + complaint_id - id of the registerd complaint. + + @variables: + issue - The issue object. + supported - True if the user's intention is to support the issue. + support_count - Total supporters of the above issue. + context - Holds data needed to make necessary changes in the template. + """ + + if request.method == 'POST': + feedback = request.POST.get('feedback', '') + rating = request.POST.get('rating', '') + StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=complaint_id).\ + update(feedback=feedback, flag=rating) + a = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=complaint_id).first() + care = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').filter(area=a.location).first() + rate = care.rating + newrate = 0 + if rate == 0: + newrate = rating + else: + a1 = int(rating) + b1 = int(rate) + c1 = int((a1+b1)/2) + newrate = c1 + + Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').filter(area=a.location).update(rating=newrate) + return HttpResponseRedirect('/complaint/supervisor/') + return render(request,"complaintModule/feedback.html",{'a' : a}) + + else: + a = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').get(id=complaint_id) + return render(request, "complaintModule/submit_feedback.html", {'a': a}) + + + +@login_required + +def caretakerlodge(request): + """ + The function is used to register a complaint + @param: + request - trivial. + + + @variables: + issue - The issue object. + supported - True if the user's intention is to support the issue. + support_count - Total supporters of the above issue. + context - Holds data needed to make necessary changes in the template. + """ + a = get_object_or_404(User, username=request.user.username) + y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() + num = 1 + comp_id = y.id + if request.method == 'POST': + comp_type = request.POST.get('complaint_type', '') + location = request.POST.get('Location', '') + specific_location = request.POST.get('specific_location', '') + comp_file = request.FILES.get('myfile') + + details = request.POST.get('details', '') + status = 0 + # finish time is according to complaint type + complaint_finish = datetime.now() + timedelta(days=2) + if comp_type == 'Electricity': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'carpenter': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'plumber': + complaint_finish = datetime.now() + timedelta(days=2) + elif comp_type == 'garbage': + complaint_finish = datetime.now() + timedelta(days=1) + elif comp_type == 'dustbin': + complaint_finish = datetime.now() + timedelta(days=1) + elif comp_type == 'internet': + complaint_finish = datetime.now() + timedelta(days=4) + elif comp_type == 'other': + complaint_finish = datetime.now() + timedelta(days=3) + y = ExtraInfo.objects.all().select_related('user','department').get(id=comp_id) + #check if location given + if location!="": + # x = StudentComplain(complainer=y, + # complaint_type=comp_type, + # location=location, + # specific_location=specific_location, + # details=details, + # status=status, + # complaint_finish=complaint_finish, + # upload_complaint=comp_file) + + + # x.save() + obj1, created = StudentComplain.objects.get_or_create(complainer=y, + complaint_type=comp_type, + location=location, + specific_location=specific_location, + details=details, + status=status, + complaint_finish=complaint_finish, + upload_complaint=comp_file) + + + historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') + history = [] + j = 1 + k = 1 + for i in historytemp: + history.append(i) + # if j%2 != 0: + # history.append(i) + # j = j+1 + + + for h in history: + h.serial_no = k + k = k+1 + # if location == "hall1": + # dsgn = "hall1caretaker" + # elif location == "hall3": + # dsgn = "hall3caretaker" + # else : + # dsgn = "hall4caretaker" + if location == "hall-1": + dsgn ="hall1caretaker" + elif location =="hall-3": + dsgn ="hall3caretaker" + elif location =="hall-4": + dsgn ="hall4caretaker" + elif location =="CC1": + dsgn ="cc1convener" + elif location =="CC2": + dsgn ="CC2 convener" + elif location == "core_lab": + dsgn = "corelabcaretaker" + elif location =="LHTC": + dsgn ="lhtccaretaker" + elif location =="NR2": + dsgn ="nr2caretaker" + elif location =="Maa Saraswati Hostel": + dsgn ="mshcaretaker" + elif location =="Nagarjun Hostel": + dsgn ="nhcaretaker" + elif location =="Panini Hostel": + dsgn ="phcaretaker" + else: + dsgn = "rewacaretaker" + caretaker_name = HoldsDesignation.objects.select_related('user','working','designation').get(designation__name = dsgn) + + + # This is to allow the student + student = 1 + message = "A New Complaint has been lodged" + complaint_system_notif(request.user, caretaker_name.user,'lodge_comp_alert',obj1.id,student,message) + + # return render(request, "complaintModule/complaint_user.html", + # {'history': history, 'comp_id': comp_id }) + # next = request.POST.get('next', '/') + + messages.success(request,message) + return HttpResponseRedirect('/complaint/caretaker') + + else: + a = get_object_or_404(User, username=request.user.username) + y = ExtraInfo.objects.all().select_related('user','department').filter(user=a).first() + historytemp = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(complainer=y).order_by('-id') + history=[] + + notification = Notification.objects.filter(recipient=a.id) + notification = notification.filter(data__exact={'url':'complaint:detail','module':'Complaint System'}) + # notification_message = [] + # for notification in x: + # to = User.objects.get(id=notification.actor_object_id).username + # from django.utils.timesince import timesince as timesince_ + # duration = timesince_(notification.timestamp,None) + # notification_message.append(notification.verb+' by '+ to + ' ' + duration + ' ago ') + + + + + j = 1 + for i in historytemp: + history.append(i) + # if j%2 != 0: + # history.append(i) + # j = j+1 + + for i in history: + i.serial_no = j + j = j+1 + + # if location == "hall-1": + # dsgn ="hall1caretaker" + # elif location =="hall-3": + # dsgn ="hall3caretaker" + # elif location =="hall-4": + # dsgn ="hall4caretaker" + # elif location =="CC1": + # dsgn ="CC convenor" + # elif location =="CC2": + # dsgn ="CC2 convener" + # elif location == "core_lab": + # dsgn = "corelabcaretaker" + # elif location =="LHTC": + # dsgn ="lhtccaretaker" + # elif location =="NR2": + # dsgn ="nr2caretaker" + # else: + # dsgn = "rewacaretaker" + # caretaker_name = HoldsDesignation.objects.get(designation__name = dsgn) + + # complaint_system_notif(request.user, caretaker_name.user,'lodge_comp_alert') + return render(request, "complaintModule/complaint_caretaker.html", + {'history': history,'notification':notification, 'comp_id': y.id}) + + return render(request, "complaintModule/complaint_user.html", + {'history': history, 'comp_id': comp_id }) + + +@login_required +def submitfeedbackcaretaker(request, complaint_id): + """ + The function is used by the complainant to enter feedback after the complaint has been resolved + @param: + request - trivial. + complaint_id - id of the registerd complaint. + + @variables: + issue - The issue object. + supported - True if the user's intention is to support the issue. + support_count - Total supporters of the above issue. + context - Holds data needed to make necessary changes in the template. + """ + + if request.method == 'POST': + feedback = request.POST.get('feedback', '') + rating = request.POST.get('rating', '') + StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=complaint_id).\ + update(feedback=feedback, flag=rating) + a = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').filter(id=complaint_id).first() + care = Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').filter(area=a.location).first() + rate = care.rating + newrate = 0 + if rate == 0: + newrate = rating + else: + a1 = int(rating) + b1 = int(rate) + c1 = int((a1+b1)/2) + newrate = c1 + + Caretaker.objects.select_related('staff_id','staff_id__user','staff_id__department').filter(area=a.location).update(rating=newrate) + return HttpResponseRedirect('/complaint/caretaker/') + return render(request,"complaintModule/feedback.html",{'a' : a}) + + else: + a = StudentComplain.objects.select_related('complainer','complainer__user','complainer__department','worker_id','worker_id__caretaker_id__staff_id','worker_id__caretaker_id__staff_id__user','worker_id__caretaker_id__staff_id__department').get(id=complaint_id) + return render(request, "complaintModule/submit_feedback.html", {'a': a}) \ No newline at end of file diff --git a/FusionIIIT/applications/filetracking/admin.py b/FusionIIIT/applications/filetracking/admin.py new file mode 100644 index 000000000..82b78df95 --- /dev/null +++ b/FusionIIIT/applications/filetracking/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin + +# Register your models here. +from applications.filetracking.models import File, Tracking + +admin.site.register(File) +admin.site.register(Tracking) diff --git a/FusionIIIT/applications/filetracking/api/serializers.py b/FusionIIIT/applications/filetracking/api/serializers.py new file mode 100644 index 000000000..bdae2024e --- /dev/null +++ b/FusionIIIT/applications/filetracking/api/serializers.py @@ -0,0 +1,24 @@ +from applications.filetracking.models import File, Tracking +from django.core.files import File as DjangoFile +from rest_framework import serializers + + +class FileSerializer(serializers.ModelSerializer): + class Meta: + model = File + fields = '__all__' + + +class TrackingSerializer(serializers.ModelSerializer): + class Meta: + model = Tracking + fields = '__all__' + + +class FileHeaderSerializer(serializers.ModelSerializer): + ''' + This serializes everything except the attachments of a file and whether it is read or not + ''' + class Meta: + model = File + exclude = ['upload_file', 'is_read'] diff --git a/FusionIIIT/applications/filetracking/api/urls.py b/FusionIIIT/applications/filetracking/api/urls.py new file mode 100644 index 000000000..90f03b2ef --- /dev/null +++ b/FusionIIIT/applications/filetracking/api/urls.py @@ -0,0 +1,22 @@ +from django.conf.urls import url +from .views import ( + CreateFileView, + ViewFileView, + DeleteFileView, + ViewInboxView, + ViewOutboxView, + ViewHistoryView, + ForwardFileView, + GetDesignationsView, +) + +urlpatterns = [ + url(r'^file/$', CreateFileView.as_view(), name='create_file'), + url(r'^file/(?P\d+)/$', ViewFileView.as_view(), name='view_file'), + url(r'^file/(?P\d+)/$', DeleteFileView.as_view(), name='delete_file'), + url(r'^inbox/$', ViewInboxView.as_view(), name='view_inbox'), + url(r'^outbox/$', ViewOutboxView.as_view(), name='view_outbox'), + url(r'^history/(?P\d+)/$', ViewHistoryView.as_view(), name='view_history'), + url(r'^file/(?P\d+)/$', ForwardFileView.as_view(), name='forward_file'), + url(r'^designations/(?P\w+)/$', GetDesignationsView.as_view(), name='get_designations'), +] diff --git a/FusionIIIT/applications/filetracking/api/views.py b/FusionIIIT/applications/filetracking/api/views.py new file mode 100644 index 000000000..6694e749f --- /dev/null +++ b/FusionIIIT/applications/filetracking/api/views.py @@ -0,0 +1,89 @@ +from rest_framework.views import APIView +from rest_framework.response import Response +from rest_framework import status, permissions +from rest_framework.authentication import TokenAuthentication +from ..sdk.methods import create_file, view_file, delete_file, view_inbox, view_outbox, view_history, forward_file, get_designations + + +class CreateFileView(APIView): + #authentication_classes = [TokenAuthentication] + #permission_classes = [permissions.IsAuthenticated] + + def post(self, request, *args, **kwargs): + file_id = create_file(**request.data) + return Response({'file_id': file_id}, status=status.HTTP_201_CREATED) + + +class ViewFileView(APIView): + #authentication_classes = [TokenAuthentication] + #permission_classes = [permissions.IsAuthenticated] + + def get(self, request, file_id, *args, **kwargs): + file_details = view_file(int(file_id)) + return Response(file_details) + + +class DeleteFileView(APIView): + #authentication_classes = [TokenAuthentication] + #permission_classes = [permissions.IsAuthenticated] + + def delete(self, request, file_id, *args, **kwargs): + success = delete_file(int(file_id)) + if success: + return Response({'message': 'File deleted successfully'}, + status=status.HTTP_204_NO_CONTENT) + else: + return Response({'error': 'File not found'}, + status=status.HTTP_404_NOT_FOUND) + + +class ViewInboxView(APIView): + #authentication_classes = [TokenAuthentication] + #permission_classes = [permissions.IsAuthenticated] + + def get(self, request, *args, **kwargs): + inbox_files = view_inbox( + request.user.username, + request.query_params.get('designation'), + request.query_params.get('src_module')) + return Response(inbox_files) + + +class ViewOutboxView(APIView): + #authentication_classes = [TokenAuthentication] + #permission_classes = [permissions.IsAuthenticated] + + def get(self, request, *args, **kwargs): + outbox_files = view_outbox( + request.user.username, + request.query_params.get('designation'), + request.query_params.get('src_module')) + return Response(outbox_files) + + +class ViewHistoryView(APIView): + #authentication_classes = [TokenAuthentication] + #permission_classes = [permissions.IsAuthenticated] + + def get(self, request, file_id, *args, **kwargs): + history = view_history(int(file_id)) + return Response(history) + + +class ForwardFileView(APIView): + #authentication_classes = [TokenAuthentication] + #permission_classes = [permissions.IsAuthenticated] + + def post(self, request, file_id, *args, **kwargs): + new_tracking_id = forward_file(int(file_id), **request.data) + return Response({'tracking_id': new_tracking_id}, + status=status.HTTP_201_CREATED) + + +class GetDesignationsView(APIView): + #authentication_classes = [TokenAuthentication] + #permission_classes = [permissions.IsAuthenticated] + + def get(self, request, username, *args, **kwargs): + user_designations = get_designations(username) + return Response({'designations': user_designations}) diff --git a/FusionIIIT/applications/filetracking/apps.py b/FusionIIIT/applications/filetracking/apps.py new file mode 100644 index 000000000..7e3d3b6d2 --- /dev/null +++ b/FusionIIIT/applications/filetracking/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class FileTrackingConfig(AppConfig): + name = 'applications.filetracking' diff --git a/FusionIIIT/applications/filetracking/models.py b/FusionIIIT/applications/filetracking/models.py new file mode 100644 index 000000000..9d78b24c9 --- /dev/null +++ b/FusionIIIT/applications/filetracking/models.py @@ -0,0 +1,51 @@ +from django.db import models +from django.contrib.auth.models import User +from applications.globals.models import ExtraInfo, HoldsDesignation, Designation + + +class File(models.Model): + """ + This is file table which contains the all the files created by user + """ + uploader = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE, related_name='uploaded_files') + designation = models.ForeignKey(Designation, on_delete=models.CASCADE, null=True, related_name='upload_designation') + subject = models.CharField(max_length=100, null=True, blank=True) + description = models.CharField(max_length=400, null=True, blank=True) + upload_date = models.DateTimeField(auto_now_add=True) + upload_file = models.FileField(blank=True) + is_read = models.BooleanField(default = False) + + + # additions for API + src_module = models.CharField(max_length=100, default='filetracking') + src_object_id = models.CharField(max_length=100,null=True) + file_extra_JSON = models.JSONField(null=True) + + class Meta: + db_table = 'File' + + #def __str__(self): + #return str(self.ref_id) + + +class Tracking(models.Model): + """ + This is File Tracing Table which contains the status of each individual file created by the user + """ + file_id = models.ForeignKey(File, on_delete=models.CASCADE, null=True) + current_id = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE) + current_design = models.ForeignKey(HoldsDesignation, null=True, on_delete=models.CASCADE) + receiver_id = models.ForeignKey(User,null = True, on_delete=models.CASCADE, related_name='receiver_id') + receive_design = models.ForeignKey(Designation, null=True, on_delete=models.CASCADE, related_name='rec_design') + + receive_date = models.DateTimeField(auto_now_add=True) + forward_date = models.DateTimeField(auto_now_add=True) + remarks = models.CharField(max_length=250, null=True, blank=True) + upload_file = models.FileField(blank=True) + is_read = models.BooleanField(default = False) + + # additions for API + tracking_extra_JSON = models.JSONField(null=True) + + class Meta: + db_table = 'Tracking' diff --git a/FusionIIIT/applications/filetracking/sdk/methods.py b/FusionIIIT/applications/filetracking/sdk/methods.py new file mode 100644 index 000000000..d85bc4755 --- /dev/null +++ b/FusionIIIT/applications/filetracking/sdk/methods.py @@ -0,0 +1,405 @@ +from django.contrib.auth.models import User +from applications.filetracking.models import Tracking, File +from applications.globals.models import Designation, HoldsDesignation, ExtraInfo +from applications.filetracking.api.serializers import FileSerializer, FileHeaderSerializer, TrackingSerializer +from django.core.exceptions import ValidationError +from typing import Any + + +def create_file( + uploader: str, + uploader_designation: str, + receiver: str, + receiver_designation: str, + src_module: str = "filetracking", + src_object_id: str = "", + file_extra_JSON: dict = {}, + attached_file: Any = None) -> int: + ''' + This function is used to create a file object corresponding to any object of a module that needs to be tracked + ''' + + ''' + Functioning: + create base file with params + create tracking with params + if both complete then return id of file + else raise error + + also, delete file object if tracking isnt created + ''' + uploader_user_obj = get_user_object_from_username(uploader) + uploader_extrainfo_obj = get_ExtraInfo_object_from_username(uploader) + uploader_designation_obj = Designation.objects.get( + name=uploader_designation) + receiver_obj = get_user_object_from_username(receiver) + receiver_designation_obj = Designation.objects.get( + name=receiver_designation) + + new_file = File.objects.create( + uploader=uploader_extrainfo_obj, + designation=uploader_designation_obj, + src_module=src_module, + src_object_id=src_object_id, + file_extra_JSON=file_extra_JSON, + ) + + if attached_file is not None: + new_file.upload_file.save(attached_file.name, attached_file, save=True) + + uploader_holdsdesignation_obj = HoldsDesignation.objects.get( + user=uploader_user_obj, designation=uploader_designation_obj) + + new_tracking = Tracking.objects.create( + file_id=new_file, + current_id=uploader_extrainfo_obj, + current_design=uploader_holdsdesignation_obj, + receiver_id=receiver_obj, + receive_design=receiver_designation_obj, + tracking_extra_JSON=file_extra_JSON, + remarks=f"File with id:{str(new_file.id)} created by {uploader} and sent to {receiver}" + # upload_file = None, dont add file for first tracking + ) + if new_tracking is None: + new_file.delete() + raise ValidationError('Tracking model data is incorrect') + else: + return new_file.id + + +def view_file(file_id: int) -> dict: + ''' + This function returns all the details of a given file + ''' + try: + requested_file = File.objects.get(id=file_id) + serializer = FileSerializer(requested_file) + file_details = serializer.data + return file_details + except File.DoesNotExist: + raise NotFound("File Not Found with provided ID") + + +def delete_file(file_id: int) -> bool: + ''' + This function is used to delete a file from being tracked, all the tracking history is deleted as well and returns true if the deletion was successful + ''' + try: + File.objects.filter(id=file_id).delete() + return True + except File.DoesNotExist: + return False + +# inbox and outbox could be sorted based on most recent linked tracking entry + +def view_inbox(username: str, designation: str, src_module: str) -> list: + ''' + This function is used to get all the files in the inbox of a particular user and designation + ''' + user_designation = Designation.objects.get(name=designation) + recipient_object = get_user_object_from_username(username) + received_files_tracking = Tracking.objects.select_related('file_id').filter( + receiver_id=recipient_object, + receive_design=user_designation, + file_id__src_module=src_module, + file_id__is_read=False) + received_files = [tracking.file_id for tracking in received_files_tracking] + + # remove duplicate file ids (from sending back and forth) + received_files_unique = uniqueList(received_files) + + received_files_serialized = list(FileHeaderSerializer( + received_files_unique, many=True).data) + + for file in received_files_serialized: + file['sent_by_user'] = get_last_file_sender(file['id']).username + file['sent_by_designation'] = get_last_file_sender_designation(file['id']).name + + return received_files_serialized + + +def view_outbox(username: str, designation: str, src_module: str) -> list: + ''' + This function is used to get all the files in the outbox of a particular user and designation + ''' + user_designation = get_designation_obj_from_name(designation=designation) + user_object = get_user_object_from_username(username) + user_HoldsDesignation_object = HoldsDesignation.objects.get( + user=user_object, designation=user_designation) + sender_ExtraInfo_object = get_ExtraInfo_object_from_username(username) + sent_files_tracking = Tracking.objects.select_related('file_id').filter( + current_id=sender_ExtraInfo_object, + current_design=user_HoldsDesignation_object, + file_id__src_module=src_module, + file_id__is_read=False) + sent_files = [tracking.file_id for tracking in sent_files_tracking] + + # remove duplicate file ids (from sending back and forth) + sent_files_unique = uniqueList(sent_files) + + sent_files_serialized = FileHeaderSerializer(sent_files_unique, many=True) + return sent_files_serialized.data + + +# need: view_archived, archive_file, (can get details of archived files by view_file, etc) +# view_drafts, create_draft, (delete_draft can be via delete_file), +# (forward_draft can be via forward_file, but lets implement a send draft that follows our remark convention) + +def view_archived(username: str, designation: str, src_module: str) -> dict: + ''' + This function is used to get all the files in the archive of a particular user and designation + Archived file mean those which the user has ever interacted with, and are now finished or archived + ''' + user_designation = Designation.objects.get(name=designation) + user_object = get_user_object_from_username(username) + received_archived_tracking = Tracking.objects.select_related('file_id').filter( + receiver_id=user_object, + receive_design=user_designation, + file_id__src_module=src_module, + file_id__is_read=True) + + user_HoldsDesignation_object = HoldsDesignation.objects.get( + user=user_object, designation=user_designation) + sender_ExtraInfo_object = get_ExtraInfo_object_from_username(username) + sent_archived_tracking = Tracking.objects.select_related('file_id').filter( + current_id=sender_ExtraInfo_object, + current_design=user_HoldsDesignation_object, + file_id__src_module=src_module, + file_id__is_read=True) + + archived_tracking = received_archived_tracking | sent_archived_tracking + archived_files = [tracking.file_id for tracking in archived_tracking] + + # remove duplicate file ids (from sending back and forth) + archived_files_unique = uniqueList(archived_files) + + archived_files_serialized = FileHeaderSerializer(archived_files_unique, many=True) + return archived_files_serialized.data + + + +def archive_file(file_id: int) -> bool: + ''' + This function is used to archive a file and returns true if the archiving was successful + ''' + try: + File.objects.filter(id=file_id).update(is_read=True) + return True + except File.DoesNotExist: + return False + + + +def create_draft( + uploader: str, + uploader_designation: str, + src_module: str = "filetracking", + src_object_id: str = "", + file_extra_JSON: dict = {}, + attached_file: Any = None) -> int: + ''' + This function is used to create a draft file object corresponding to any object of a module that needs to be tracked + It is similar to create_file but is not sent to anyone + Later this file can be sent to someone by forward_file by using draft file_id + ''' + uploader_extrainfo_obj = get_ExtraInfo_object_from_username(uploader) + uploader_designation_obj = Designation.objects.get( + name=uploader_designation) + + new_file = File.objects.create( + uploader=uploader_extrainfo_obj, + designation=uploader_designation_obj, + src_module=src_module, + src_object_id=src_object_id, + file_extra_JSON=file_extra_JSON, + upload_file=attached_file + ) + return new_file.id + + +def view_drafts(username: str, designation: str, src_module: str) -> dict: + ''' + This function is used to get all the files in the drafts (has not been sent) of a particular user and designation + ''' + user_designation = Designation.objects.get(name=designation) + user_ExtraInfo_object = get_ExtraInfo_object_from_username(username) + draft_files = File.objects.filter( + tracking__isnull=True, uploader=user_ExtraInfo_object, designation=user_designation, src_module=src_module) + draft_files_serialized = FileHeaderSerializer(draft_files, many=True) + return draft_files_serialized.data + + + +def forward_file( + file_id: int, + receiver: str, + receiver_designation: str, + file_extra_JSON: dict, + remarks: str = "", + file_attachment: Any = None) -> int: + ''' + This function forwards the file and inserts a new tracking history into the file tracking table + Note that only the current owner(with appropriate designation) of the file has the ability to forward files + ''' + # HoldsDesignation and ExtraInfo object are used instead + # of Designation and User object because of the legacy code being that way + + current_owner = get_current_file_owner(file_id) + current_owner_designation = get_current_file_owner_designation(file_id) + current_owner_extra_info = ExtraInfo.objects.get(user=current_owner) + current_owner_holds_designation = HoldsDesignation.objects.get( + user=current_owner, designation=current_owner_designation) + receiver_obj = User.objects.get(username=receiver) + receiver_designation_obj = Designation.objects.get( + name=receiver_designation) + tracking_data = { + 'file_id': file_id, + 'current_id': current_owner_extra_info.id, + 'current_design': current_owner_holds_designation.id, + 'receiver_id': receiver_obj.id, + 'receive_design': receiver_designation_obj.id, + 'tracking_extra_JSON': file_extra_JSON, + 'remarks': remarks, + } + if file_attachment is not None: + tracking_data['upload_file'] = file_attachment + + tracking_entry = TrackingSerializer(data=tracking_data) + if tracking_entry.is_valid(): + tracking_entry.save() + return tracking_entry.instance.id + else: + raise ValidationError('forward data is incomplete') + + +def view_history(file_id: int) -> dict: + ''' + This function is used to get the history of a particular file with the given file_id + ''' + Tracking_history = Tracking.objects.filter( + file_id=file_id).order_by('-receive_date') + Tracking_history_serialized = TrackingSerializer( + Tracking_history, many=True) + return Tracking_history_serialized.data + + +# HELPER FUNCTIONS + +def get_current_file_owner(file_id: int) -> User: + ''' + This functions returns the current owner of the file. + The current owner is the latest recipient of the file + ''' + latest_tracking = Tracking.objects.filter( + file_id=file_id).order_by('-receive_date').first() + latest_recipient = latest_tracking.receiver_id + return latest_recipient + + +def get_current_file_owner_designation(file_id: int) -> Designation: + ''' + This function returns the designation of the current owner of the file. + The current owner is the latest recipient of the file + ''' + latest_tracking = Tracking.objects.filter( + file_id=file_id).order_by('-receive_date').first() + latest_recipient_designation = latest_tracking.receive_design + return latest_recipient_designation + +def get_last_file_sender(file_id: int) -> User: + ''' + This Function returns the last file sender, + one who has last forwarded/sent the file + ''' + latest_tracking = Tracking.objects.filter( + file_id=file_id).order_by('-receive_date').first() + latest_sender_extra_info = latest_tracking.current_id + return latest_sender_extra_info.user + +def get_last_file_sender_designation(file_id: int) -> Designation: + ''' + This Function returns the last file sender's Designation, + one who has last forwarded/sent the file + ''' + latest_tracking = Tracking.objects.filter( + file_id=file_id).order_by('receive_date').first() + latest_sender_holds_designation = latest_tracking.current_design + return latest_sender_holds_designation.designation + +def get_designations(username: str) -> list: + ''' + This function is used to return a list of all the designation names of a particular user + ''' + user = User.objects.get(username=username) + designations_held = HoldsDesignation.objects.filter(user=user) + designation_name = [designation.name for designation in designations_held] + +def get_user_object_from_username(username: str) -> User: + user = User.objects.get(username=username) + return user + +def get_ExtraInfo_object_from_username(username: str) -> ExtraInfo: + user = User.objects.get(username=username) + extrainfo = ExtraInfo.objects.get(user=user) + return extrainfo + +def uniqueList(l: list) -> list: + ''' + This function is used to return a list with unique elements + O(n) time and space + ''' + s = set(l) + unique_list = (list(s)) + return unique_list + +def add_uploader_department_to_files_list(files: list) -> list: + ''' + This function is used to add the department of the uploader to the file + ''' + for file in files: + uploader_Extrainfo = file['uploader'] + file['uploader_department'] = (str(uploader_Extrainfo.department)).split(': ')[1] + + return files + +def get_designation_obj_from_name(designation: str) -> Designation: + des = Designation.objects.get(name = designation) + return des + +def get_HoldsDesignation_obj(username: str, designation:str) -> HoldsDesignation: + user_object = get_user_object_from_username(username=username) + user_designation = get_designation_obj_from_name(designation=designation) + obj = HoldsDesignation.objects.get( + user=user_object, designation=user_designation) + return obj + +def get_last_recv_tracking_for_user(file_id: int, username: str, designation: str)-> Tracking: + ''' + This returns the last tracking where username+designation recieved file_id + ''' + + recv_user_obj = get_user_object_from_username(username) + recv_design_obj = get_designation_obj_from_name(designation) + + last_tracking = Tracking.objects.filter(file_id=file_id, + receiver_id=recv_user_obj, + receive_design=recv_design_obj).order_by('-receive_date')[0] + return last_tracking + +def get_last_forw_tracking_for_user(file_id: int, username: str, designation: str) -> Tracking: + ''' + Returns the last tracking where the specified user forwarded the file. + ''' + + # Get user and designation objects + sender_user_obj = get_ExtraInfo_object_from_username(username) + sender_designation_obj = get_HoldsDesignation_obj(username=username, designation=designation) + + # Filter Tracking objects by file_id, sender_id, and sender_designation + last_tracking = Tracking.objects.filter(file_id=file_id, + current_id=sender_user_obj, + current_design=sender_designation_obj).order_by('-forward_date').first() + return last_tracking + +def get_extra_info_object_from_id(id: int): + return ExtraInfo.objects.get(id=id) \ No newline at end of file diff --git a/FusionIIIT/applications/filetracking/tests.py b/FusionIIIT/applications/filetracking/tests.py new file mode 100644 index 000000000..a79ca8be5 --- /dev/null +++ b/FusionIIIT/applications/filetracking/tests.py @@ -0,0 +1,3 @@ +# from django.test import TestCase + +# Create your tests here. diff --git a/FusionIIIT/applications/filetracking/urls.py b/FusionIIIT/applications/filetracking/urls.py new file mode 100644 index 000000000..01bc4d206 --- /dev/null +++ b/FusionIIIT/applications/filetracking/urls.py @@ -0,0 +1,42 @@ +from django.conf.urls import url, include + +from . import views +from .api import urls + +app_name = 'filetracking' + +urlpatterns = [ + + url(r'^$', views.filetracking, name='filetracking'), + url(r'^draftdesign/$', views.draft_design, name='draft_design'), + url(r'^drafts/(?P\d+)$', views.drafts_view, name='drafts_view'), + url(r'^outbox/(?P\d+)$', views.outbox_view, name='outbox_view'), + url(r'^inbox/(?P\d+)$', views.inbox_view, name='inbox_view'), + url(r'^outward/$', views.outward, name='outward'), + url(r'^inward/$', views.inward, name='inward'), + url(r'^confirmdelete/(?P\d+)$', + views.confirmdelete, name='confirm_delete'), + url(r'^archive/(?P\d+)/$', views.archive_view, name='archive_view'), + url(r'^finish/(?P\d+)/$', views.archive_file, name='finish_file'), + url(r'^viewfile/(?P\d+)/$', views.view_file, name='view_file_view'), + url(r'^forward/(?P\d+)/$', views.forward, name='forward'), + url(r'^ajax/$', views.AjaxDropdown1, name='ajax_dropdown1'), + url(r'^ajax_dropdown/$', views.AjaxDropdown, name='ajax_dropdown'), + url(r'^test/$', views.test, name='test'), + url(r'^delete/(?P\d+)$', views.delete, name='delete'), + url(r'^forward_inward/(?P\d+)/$', + views.forward_inward, name='forward_inward'), + + # correction team 24 + url(r'^finish_design/$', views.finish_design, name='finish_design'), + url(r'^finish_fileview/(?P\d+)$', + views.finish_fileview, + name='finish_fileview'), + url(r'^archive_design/$', views.archive_design, name='archive_design'), + url(r'^archive_finish/(?P\d+)/$', + views.archive_finish, name='archive_finish'), + + # REST api urls + url(r'^api/', include(urls)) + +] diff --git a/FusionIIIT/applications/filetracking/utils.py b/FusionIIIT/applications/filetracking/utils.py new file mode 100644 index 000000000..5ebd27374 --- /dev/null +++ b/FusionIIIT/applications/filetracking/utils.py @@ -0,0 +1,7 @@ +from .models import File, Tracking +from applications.globals.models import ExtraInfo, HoldsDesignation, Designation +from django.contrib.auth.models import User + +def get_designation(userid): + user_designation=HoldsDesignation.objects.select_related('user','working','designation').filter(user=userid) + return user_designation \ No newline at end of file diff --git a/FusionIIIT/applications/filetracking/views.py b/FusionIIIT/applications/filetracking/views.py new file mode 100644 index 000000000..fef932a9b --- /dev/null +++ b/FusionIIIT/applications/filetracking/views.py @@ -0,0 +1,727 @@ +from django.contrib import messages +from django.shortcuts import render, get_object_or_404, redirect +from .models import File, Tracking +from applications.globals.models import ExtraInfo, HoldsDesignation, Designation +from django.template.defaulttags import csrf_token +from django.http import HttpResponse, HttpResponseRedirect, JsonResponse +from django.contrib.auth.decorators import login_required +from django.db import IntegrityError +from django.core import serializers +from django.contrib.auth.models import User +from timeit import default_timer as time +from notification.views import office_module_notif, file_tracking_notif +from .utils import * +from django.utils.dateparse import parse_datetime +from .sdk.methods import * + +@login_required(login_url="/accounts/login/") +def filetracking(request): + """ + The function is used to create files by current user(employee). + It adds the employee(uploader) and file datails to a file(table) of filetracking(model) + if he intends to create file. + + @param: + request - trivial. + + @variables: + + + uploader - Employee who creates file. + subject - Title of the file. + description - Description of the file. + upload_file - Attachment uploaded while creating file. + file - The file object. + extrainfo - The Extrainfo object. + holdsdesignations - The HoldsDesignation object. + context - Holds data needed to make necessary changes in the template. + """ + if request.method == "POST": + try: + if 'save' in request.POST: + uploader = request.user.extrainfo + subject = request.POST.get('title') + description = request.POST.get('desc') + design = request.POST.get('design') + designation = Designation.objects.get(id=HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(id=design).designation_id) + upload_file = request.FILES.get('myfile') + if upload_file and upload_file.size / 1000 > 10240: + messages.error( + request, "File should not be greater than 10MB") + return redirect("/filetracking") + + File.objects.create( + uploader=uploader, + description=description, + subject=subject, + designation=designation, + upload_file=upload_file + ) + + messages.success(request, 'File Draft Saved Successfully') + + if 'send' in request.POST: + uploader = request.user.extrainfo + subject = request.POST.get('title') + description = request.POST.get('desc') + design = request.POST.get('design') + designation = Designation.objects.get(id=HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(id=design).designation_id) + + upload_file = request.FILES.get('myfile') + if upload_file and upload_file.size / 1000 > 10240: + messages.error( + request, "File should not be greater than 10MB") + return redirect("/filetracking") + + file = File.objects.create( + uploader=uploader, + description=description, + subject=subject, + designation=designation, + upload_file=upload_file + ) + + current_id = request.user.extrainfo + remarks = request.POST.get('remarks') + + sender = request.POST.get('design') + current_design = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(id=sender) + + receiver = request.POST.get('receiver') + try: + receiver_id = User.objects.get(username=receiver) + except Exception as e: + messages.error(request, 'Enter a valid Username') + return redirect('/filetracking/') + receive = request.POST.get('recieve') + try: + receive_design = Designation.objects.get(name=receive) + except Exception as e: + messages.error(request, 'Enter a valid Designation') + return redirect('/filetracking/') + + upload_file = request.FILES.get('myfile') + + Tracking.objects.create( + file_id=file, + current_id=current_id, + current_design=current_design, + receive_design=receive_design, + receiver_id=receiver_id, + remarks=remarks, + upload_file=upload_file, + ) + # office_module_notif(request.user, receiver_id) + file_tracking_notif(request.user, receiver_id, subject) + messages.success(request, 'File sent successfully') + + except IntegrityError: + message = "FileID Already Taken.!!" + return HttpResponse(message) + + file = File.objects.select_related( + 'uploader__user', 'uploader__department', 'designation').all() + extrainfo = ExtraInfo.objects.select_related('user', 'department').all() + holdsdesignations = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').all() + designations = get_designation(request.user) + + context = { + 'file': file, + 'extrainfo': extrainfo, + 'holdsdesignations': holdsdesignations, + 'designations': designations, + } + return render(request, 'filetracking/composefile.html', context) + + +@login_required(login_url="/accounts/login") +def draft_design(request): + """ + The function is used to get the designation of the user and renders it on draft template. + + @param: + request - trivial. + + @variables: + + + context - Holds data needed to make necessary changes in the template. + """ + designation = get_designation(request.user) + context = { + 'designation': designation, + } + return render(request, 'filetracking/draft_design.html', context) + + +@login_required(login_url="/accounts/login") +def drafts_view(request, id): + """ + This function is used to view all the drafts created by the user ordered by upload date.it collects all the created files from File object. + + @param: + request - trivial + id - user id + + @parameters + draft - file obeject containing all the files created by user + context - holds data needed to render the template + + + + """ + user_HoldsDesignation_obj = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(pk=id) + s = str(user_HoldsDesignation_obj).split(" - ") + designation = s[1] + draft_files = view_drafts( + username=user_HoldsDesignation_obj.user, + designation=user_HoldsDesignation_obj.designation, + src_module='filetracking' + ) + + # Correct upload_date type + for f in draft_files: + f['upload_date'] = parse_datetime(f['upload_date']) + f['uploader'] = get_extra_info_object_from_id(f['uploader']) + + draft_files = add_uploader_department_to_files_list(draft_files) + + context = { + 'draft_files': draft_files, + 'designations': designation, + } + return render(request, 'filetracking/drafts.html', context) + + +@login_required(login_url="/accounts/login") +def outbox_view(request, id): + """ + The function is used to get all the files sent by user(employee) to other employees + which are filtered from Tracking(table) objects by current user i.e. current_id. + It displays files sent by user to other employees of a Tracking(table) of filetracking(model) + in the 'Outbox' tab of template. + + @param: + request - trivial. + id - user id + + @variables: + outward_files - File objects filtered by current_id i.e, present working user. + context - Holds data needed to make necessary changes in the template. + + """ + user_HoldsDesignation_obj = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(pk=id) + s = str(user_HoldsDesignation_obj).split(" - ") + designation = s[1] + + # outward_files = Tracking.objects.select_related('file_id__uploader__user', 'file_id__uploader__department', 'file_id__designation', 'current_id__user', 'current_id__department', + # 'current_design__user', 'current_design__working', 'current_design__designation', 'receiver_id', 'receive_design').filter(current_id=request.user.extrainfo).order_by('-forward_date') + + # user_designation = HoldsDesignation.objects.select_related( + # 'user', 'working', 'designation').get(pk=id) + + outward_files = view_outbox(username=user_HoldsDesignation_obj.user, + designation=user_HoldsDesignation_obj.designation, + src_module='filetracking') + + for f in outward_files: + last_forw_tracking = get_last_forw_tracking_for_user(file_id=f['id'], + username=user_HoldsDesignation_obj.user, + designation=user_HoldsDesignation_obj.designation) + f['sent_to_user'] = last_forw_tracking.receiver_id + f['sent_to_design'] = last_forw_tracking.receive_design + f['last_sent_date'] = last_forw_tracking.forward_date + + f['upload_date'] = parse_datetime(f['upload_date']) + f['uploader'] = get_extra_info_object_from_id(f['uploader']) + + outward_files = add_uploader_department_to_files_list(outward_files) + + context = { + + 'out_files': outward_files, + 'viewer_designation': designation, + } + return render(request, 'filetracking/outbox.html', context) + + +@login_required(login_url="/accounts/login") +def inbox_view(request, id): + """ + The function is used to fetch the files received by the user form other employees. + These files are filtered by receiver id and ordered by receive date. + + @param: + request - trivial. + id - HoldsDesignation object id + + @variables: + inward_files - File object with additional sent by information + context - Holds data needed to make necessary changes in the template. + + """ + # inward_file = Tracking.objects.select_related('file_id__uploader__user', 'file_id__uploader__department', 'file_id__designation', 'current_id__user', 'current_id__department', + # 'current_design__user', 'current_design__working', 'current_design__designation', 'receiver_id', 'receive_design').filter(receiver_id=request.user).order_by('-receive_date') + + user_HoldsDesignation_obj = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(pk=id) + s = str(user_HoldsDesignation_obj).split(" - ") + designation = s[1] + inward_files = view_inbox( + username=user_HoldsDesignation_obj.user, + designation=user_HoldsDesignation_obj.designation, + src_module='filetracking' + ) + + # correct upload_date type and add recieve_date + for f in inward_files: + f['upload_date'] = parse_datetime(f['upload_date']) + + last_recv_tracking = get_last_recv_tracking_for_user(file_id=f['id'], + username=user_HoldsDesignation_obj.user, + designation=user_HoldsDesignation_obj.designation) + f['receive_date'] = last_recv_tracking.receive_date + f['uploader'] = get_extra_info_object_from_id(f['uploader']) + + inward_files = add_uploader_department_to_files_list(inward_files) + + + context = { + + 'in_file': inward_files, + 'designations': designation, + } + return render(request, 'filetracking/inbox.html', context) + + +@login_required(login_url="/accounts/login") +def outward(request): + """ + This function fetches the different designations of the user and renders it on outward template + @param: + request - trivial. + + @variables: + context - Holds the different designation data of the user + + """ + designation = get_designation(request.user) + + context = { + 'designation': designation, + } + return render(request, 'filetracking/outward.html', context) + + +@login_required(login_url="/accounts/login") +def inward(request): + """ + This function fetches the different designations of the user and renders it on inward template + + + @param: + request - trivial. + + @variables: + context - Holds the different designation data of the user + """ + designation = get_designation(request.user) + context = { + + 'designation': designation, + } + return render(request, 'filetracking/inward.html', context) + + +@login_required(login_url="/accounts/login") +def confirmdelete(request, id): + """ + The function is used to confirm the deletion of a file. + @param: + request - trivial. + id - user id + + @variables: + context - Holds data needed to make necessary changes in the template. + """ + file = File.objects.select_related( + 'uploader__user', 'uploader__department', 'designation').get(pk=id) + + context = { + 'j': file, + } + + return render(request, 'filetracking/confirmdelete.html', context) + +def view_file(request, id): + ''' + This function is used to view a particular file received by an employee from another. + This function also conditionally renders two forms 'forward_file' and 'archive_file' + based on if the user has necessary permissions or not. + The business permissions are as follows: + 1. User can forward file only if they are the last recipient of the file + 2. User can archive a file only if they have received it last and they are also the original owner of the file + + To forward the file and to archive the file separate views with POST request are called + + It displays the details file of a File and remarks as well as the attachments of all the users + who have been involved till that point of the workflow. + + @param: + request - Trivial. + id - ID of the file object which the user intends to forward to another employee. + + @variables: + file - The File object. + track - The Tracking object. + designation - the designations of the user + ''' + + file = get_object_or_404(File, id=id) + track = Tracking.objects.select_related('file_id__uploader__user', 'file_id__uploader__department', 'file_id__designation', 'current_id__user', 'current_id__department', + 'current_design__user', 'current_design__working', 'current_design__designation', 'receiver_id', 'receive_design').filter(file_id=file).order_by('receive_date') + designations = get_designation(request.user) + + forward_enable = False + archive_enable = False + + current_owner = get_current_file_owner(file.id) + file_uploader = get_user_object_from_username(file.uploader.user.username) + + + if current_owner == request.user and file.is_read is False: + forward_enable = True + if current_owner == request.user and file_uploader == request.user and file.is_read is False: + archive_enable = True + + context = { + 'designations': designations, + 'file': file, + 'track': track, + 'forward_enable': forward_enable, + 'archive_enable': archive_enable, + } + return render(request, 'filetracking/viewfile.html', context) + +@login_required(login_url="/accounts/login") +def archive_file(request, id): + '''This function is used to archive a file. + It returns unauthorized access if the user is not file uploader + and the current owner of the file + ''' + if request.method == "POST": + file = get_object_or_404(File, id=id); + current_owner = get_current_file_owner(file.id) + file_uploader = get_user_object_from_username(file.uploader.user.username) + if current_owner == request.user and file_uploader == request.user: + file.is_read = True + file.save() + messages.success(request, 'File Archived') + else: + messages.error(request, 'Unauthorized access') + + return render(request, 'filetracking/composefile.html') + +@login_required(login_url="/accounts/login") +def forward(request, id): + """ + The function is used to forward files received by user(employee) from other + employees which are filtered from Tracking(table) objects by current user + i.e. receiver_id to other employees. + It also gets track of file created by uploader through all users involved in file + along with their remarks and attachments + It displays details file of a File(table) and remarks and attachments of user involved + in file of Tracking(table) of filetracking(model) in the template. + + @param: + request - trivial. + id - id of the file object which the user intends to forward to other employee. + + @variables: + file - The File object. + track - The Tracking object. + remarks = Remarks posted by user. + receiver = Receiver to be selected by user for forwarding file. + receiver_id = Receiver_id who has been selected for forwarding file. + upload_file = File attached by user. + extrainfo = ExtraInfo object. + holdsdesignations = HoldsDesignation objects. + context - Holds data needed to make necessary changes in the template. + """ + + file = get_object_or_404(File, id=id) + track = Tracking.objects.select_related('file_id__uploader__user', 'file_id__uploader__department', 'file_id__designation', 'current_id__user', 'current_id__department', + 'current_design__user', 'current_design__working', 'current_design__designation', 'receiver_id', 'receive_design').filter(file_id=file).order_by('receive_date') + + if request.method == "POST": + if 'finish' in request.POST: + file.is_read = True + file.save() + if 'send' in request.POST: + current_id = request.user.extrainfo + remarks = request.POST.get('remarks') + track.update(is_read=True) + + sender = request.POST.get('sender') + current_design = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(id=sender) + + receiver = request.POST.get('receiver') + try: + receiver_id = User.objects.get(username=receiver) + except Exception as e: + messages.error(request, 'Enter a valid destination') + designations = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').filter(user=request.user) + + context = { + + 'designations': designations, + 'file': file, + 'track': track, + } + return render(request, 'filetracking/forward.html', context) + receive = request.POST.get('recieve') + try: + receive_design = Designation.objects.get(name=receive) + except Exception as e: + messages.error(request, 'Enter a valid Designation') + designations = get_designation(request.user) + + context = { + + 'designations': designations, + 'file': file, + 'track': track, + } + return render(request, 'filetracking/forward.html', context) + + upload_file = request.FILES.get('myfile') + + Tracking.objects.create( + file_id=file, + current_id=current_id, + current_design=current_design, + receive_design=receive_design, + receiver_id=receiver_id, + remarks=remarks, + upload_file=upload_file, + ) + messages.success(request, 'File sent successfully') + + designations = get_designation(request.user) + + context = { + + 'designations': designations, + 'file': file, + 'track': track, + } + + return render(request, 'filetracking/forward.html', context) + + +@login_required(login_url="/accounts/login") +def archive_design(request): + + designation = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').filter(user=request.user) + + context = { + 'designation': designation, + } + return render(request, 'filetracking/archive_design.html', context) + + +@login_required(login_url="/accounts/login") +def archive_view(request, id): + """ + The function is used to fetch the files in the user's archive + (those which have passed by user and been archived/finished) + + @param: + request - trivial. + id - HoldsDesignation object id + + @variables: + archive_files - File object with additional information + context - Holds data needed to make necessary changes in the template. + + """ + user_HoldsDesignation_obj = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(pk=id) + s = str(user_HoldsDesignation_obj).split(" - ") + designation = s[1] + + archive_files = view_archived( + username=user_HoldsDesignation_obj.user, + designation=user_HoldsDesignation_obj.designation, + src_module='filetracking' + ) + + # correct upload_date type and add receive_date + for f in archive_files: + f['upload_date'] = parse_datetime(f['upload_date']) + f['designation'] = Designation.objects.get(id=f['designation']) + f['uploader'] = get_extra_info_object_from_id(f['uploader']) + + archive_files = add_uploader_department_to_files_list(archive_files) + + context = { + 'archive_files': archive_files, + 'designations': designation, + } + return render(request, 'filetracking/archive.html', context) + + + +@login_required(login_url="/accounts/login") +def archive_finish(request, id): + # file = get_object_or_404(File, ref_id=id) + file1 = get_object_or_404(File, id=id) + track = Tracking.objects.filter(file_id=file1) + + return render(request, 'filetracking/archive_finish.html', {'file': file1, 'track': track}) + + +@login_required(login_url="/accounts/login") +def finish_design(request): + + designation = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').filter(user=request.user) + + context = { + 'designation': designation, + } + return render(request, 'filetracking/finish_design.html', context) + + +@login_required(login_url="/accounts/login") +def finish_fileview(request, id): + + out = Tracking.objects.select_related('file_id__uploader__user', 'file_id__uploader__department', 'file_id__designation', 'current_id__user', 'current_id__department', + 'current_design__user', 'current_design__working', 'current_design__designation', 'receiver_id', 'receive_design').filter(file_id__uploader=request.user.extrainfo, is_read=False).order_by('-forward_date') + + abcd = HoldsDesignation.objects.select_related( + 'user', 'working', 'designation').get(pk=id) + + context = { + + 'out': out, + 'abcd': abcd, + } + return render(request, 'filetracking/finish_fileview.html', context) + + +@login_required(login_url="/accounts/login") +def finish(request, id): + # file = get_object_or_404(File, ref_id=id) + file1 = get_object_or_404(File, id=id) + track = Tracking.objects.filter(file_id=file1) + + if request.method == "POST": + if 'Finished' in request.POST: + File.objects.filter(pk=id).update(is_read=True) + track.update(is_read=True) + messages.success(request, 'File Archived') + + return render(request, 'filetracking/finish.html', {'file': file1, 'track': track, 'fileid': id}) + + +def AjaxDropdown1(request): + """ + This function returns the designation of receiver on the forward or compose file template. + + @param: + request - trivial. + + + @variables: + context - return the httpresponce containing the matched designation of the user + """ + if request.method == 'POST': + value = request.POST.get('value') + + hold = Designation.objects.filter(name__startswith=value) + holds = serializers.serialize('json', list(hold)) + context = { + 'holds': holds + } + + return HttpResponse(JsonResponse(context), content_type='application/json') + + +def AjaxDropdown(request): + """ + This function returns the usernames of receiver on the forward or compose file template. + + @param: + request - trivial. + + + @variables: + context - return the httpresponce containing the matched username + """ + if request.method == 'POST': + value = request.POST.get('value') + users = User.objects.filter(username__startswith=value) + users = serializers.serialize('json', list(users)) + + context = { + 'users': users + } + return HttpResponse(JsonResponse(context), content_type='application/json') + + +def test(request): + return HttpResponse('success') + + +@login_required(login_url="/accounts/login") +def delete(request, id): + """ + The function is used the delete of a file and it returns to the drafts page. + + @param: + request - trivial. + id - id of the file that is going to be deleted + + """ + file = File.objects.get(pk=id) + file.delete() + return redirect('/filetracking/draftdesign/') + + +def forward_inward(request, id): + """ This function is used forward the files which are available in the inbox of the user . + + @param: + request - trivial + id - id of the file that is going to forward + + @variables: + file - file object + track - tracking object of the file + context - necessary data to render + + """ + + file = get_object_or_404(File, id=id) + file.is_read = True + track = Tracking.objects.select_related('file_id__uploader__user', 'file_id__uploader__department', 'file_id__designation', 'current_id__user', 'current_id__department', + 'current_design__user', 'current_design__working', 'current_design__designation', 'receiver_id', 'receive_design').filter(file_id=file) + designations = get_designation(request.user) + + context = { + + 'designations': designations, + 'file': file, + 'track': track, + } + return render(request, 'filetracking/forward.html', context) diff --git a/FusionIIIT/templates/complaintModule/add_workers.html b/FusionIIIT/templates/complaintModule/add_workers.html index 842d4397a..4ea009064 100644 --- a/FusionIIIT/templates/complaintModule/add_workers.html +++ b/FusionIIIT/templates/complaintModule/add_workers.html @@ -2,16 +2,16 @@ {% block lodgecomplaint %} {% comment %}The tab menu starts here!{% endcomment %} -