diff --git a/FusionIIIT/applications/filetracking/views.py b/FusionIIIT/applications/filetracking/views.py index a3c0a94ee..c720ad699 100644 --- a/FusionIIIT/applications/filetracking/views.py +++ b/FusionIIIT/applications/filetracking/views.py @@ -11,70 +11,37 @@ from timeit import default_timer as time from notification.views import office_module_notif,file_tracking_notif from .utils import * - +from . import config +from rest_framework.parsers import JSONParser +import json @login_required(login_url = "/accounts/login/") -### - -def errorCheck(request): - return render(request, 'filetracking/contactUs.html') - -#### -def user_check(request): - """ - This function is used to check if the user is a student or not - Its return type is bool - @param: - request - contains metadata about the requested page - - @Variables: - current_user - get user from request - user_details - extract details of the user from the database - desig_id - check for designation - student - designation for a student - final_user - final designation of the request(our user) - - - """ - try: - current_user = get_object_or_404(User, username=request.user.username) - - #extra info details , user id used as main id - user_details = ExtraInfo.objects.select_related('user','department').get(user = request.user) +def check_user(request): + designation = get_designation(request.user) - des = HoldsDesignation.objects.all().select_related().filter(user = request.user).first() - print(str(des.designation)) - if str(des.designation) == "student": - return True - else: - return False - - except Exception as e: - return False + context = { + 'designation': designation, + } + print(context) - - ################################### +def get_forward_to(request): + if request.method == 'POST': + jsonData = JSONParser().parse(request) + rcv = jsonData['des'] + return rcv def filetracking(request): - if user_check(request): - return render(request, 'filetracking/fileTrackingNotAllowed.html') - - """ 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. @@ -84,6 +51,19 @@ def filetracking(request): holdsdesignations - The HoldsDesignation object. context - Holds data needed to make necessary changes in the template. """ + + if request.method == "GET": + try: + if 'reciever_submit' in request.POST: + print("get was calleed") + rcv = request.POST.get('receiver') + + except IntegrityError: + message = "FileID Already Taken.!!" + return HttpResponse(message) + + + if request.method =="POST": try: if 'save' in request.POST: @@ -135,14 +115,23 @@ def filetracking(request): current_design = HoldsDesignation.objects.select_related('user','working','designation').get(id=sender) receiver = request.POST.get('receiver') + print(receiver) + try: receiver_id = User.objects.get(username=receiver) + print(receiver_id) except Exception as e: messages.error(request, 'Enter a valid Username') return redirect('/filetracking/') receive = request.POST.get('recieve') + print("receive is: ", receive) + s =receive.split(" - ") + try: - receive_design = Designation.objects.get(name=receive) + + receive_design = Designation.objects.get(name=s[1]) + print(receive_design) + except Exception as e: messages.error(request, 'Enter a valid Designation') return redirect('/filetracking/') @@ -158,7 +147,6 @@ def filetracking(request): 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') @@ -168,38 +156,37 @@ def filetracking(request): - file = File.objects.select_related('uploader__user','uploader__department','designation').all() + 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) - + print(designations) + + all_recievers = get_all_designation() context = { 'file': file, 'extrainfo': extrainfo, 'holdsdesignations': holdsdesignations, 'designations': designations, + 'all_recievers': all_recievers, + + + + } return render(request, 'filetracking/composefile.html', context) - @login_required(login_url = "/accounts/login") - def drafts(request): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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, @@ -209,21 +196,16 @@ def drafts(request): @login_required(login_url = "/accounts/login") def fileview(request,id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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') @@ -260,19 +242,15 @@ def fileview(request,id): @login_required(login_url = "/accounts/login") def fileview1(request,id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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. @@ -294,21 +272,16 @@ def fileview1(request,id): @login_required(login_url = "/accounts/login") def fileview2(request,id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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') @@ -327,13 +300,10 @@ def fileview2(request,id): @login_required(login_url = "/accounts/login") def outward(request): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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 @@ -348,15 +318,11 @@ def outward(request): @login_required(login_url = "/accounts/login") def inward(request): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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 """ @@ -370,15 +336,12 @@ def inward(request): @login_required(login_url = "/accounts/login") def confirmdelete(request,id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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. """ @@ -393,8 +356,6 @@ def confirmdelete(request,id): @login_required(login_url = "/accounts/login") def forward(request, id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ The function is used to forward files received by user(employee) from other employees which are filtered from Tracking(table) objects by current user @@ -403,11 +364,9 @@ def forward(request, id): 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. @@ -444,6 +403,7 @@ def forward(request, id): messages.error(request, 'Enter a valid destination') designations = HoldsDesignation.objects.select_related('user','working','designation').filter(user=request.user) + context = { 'designations': designations, @@ -452,8 +412,9 @@ def forward(request, id): } return render(request, 'filetracking/forward.html', context) receive = request.POST.get('recieve') + s =receive.split(" - ") try: - receive_design = Designation.objects.get(name=receive) + receive_design = Designation.objects.get(name=s[1]) except Exception as e: messages.error(request, 'Enter a valid Designation') designations = get_designation(request.user) @@ -482,12 +443,13 @@ def forward(request, id): designations = get_designation(request.user) - + all_recievers = get_all_designation() context = { 'designations':designations, 'file': file, 'track': track, + 'all_recievers': all_recievers, } return render(request, 'filetracking/forward.html', context) @@ -495,8 +457,6 @@ def forward(request, id): @login_required(login_url = "/accounts/login") def archive_design(request): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## designation = HoldsDesignation.objects.select_related('user','working','designation').filter(user=request.user) @@ -511,21 +471,14 @@ def archive_design(request): @login_required(login_url = "/accounts/login") def archive(request , id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## 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 = { @@ -542,8 +495,6 @@ def archive(request , id): @login_required(login_url = "/accounts/login") def archive_finish(request, id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## file1 = get_object_or_404(File, id=id) ##file = get_object_or_404(File, ref_id=id) track = Tracking.objects.filter(file_id=file1) @@ -556,8 +507,6 @@ def archive_finish(request, id): @login_required(login_url = "/accounts/login") def finish_design(request): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## designation = HoldsDesignation.objects.select_related('user','working','designation').filter(user=request.user) @@ -569,8 +518,6 @@ def finish_design(request): @login_required(login_url = "/accounts/login") def finish_fileview(request, id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## 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') @@ -593,8 +540,6 @@ def finish_fileview(request, id): @login_required(login_url = "/accounts/login") def finish(request, id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## file1 = get_object_or_404(File, id=id) ##file = get_object_or_404(File, ref_id=id) track = Tracking.objects.filter(file_id=file1) @@ -617,15 +562,11 @@ def finish(request, id): def AjaxDropdown1(request): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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 """ @@ -642,16 +583,12 @@ def AjaxDropdown1(request): def AjaxDropdown(request): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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 """ @@ -673,12 +610,9 @@ def test(request): @login_required(login_url = "/accounts/login") def delete(request,id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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 @@ -692,15 +626,11 @@ def delete(request,id): def forward_inward(request,id): - if user_check(request):## - return render(request, 'filetracking/fileTrackingNotAllowed.html')## """ 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 @@ -723,3 +653,12 @@ def forward_inward(request,id): return render(request, 'filetracking/forward.html', context) + + + +# todo_items = [] +# from fastapi import FastAPI +# app = FastAPI() +# @app.get("/health") +# def health(): +# return {"status": "ok"}