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. exations - The HoldsDesignation object. context - Hotrainfo - The Extrainfo object. holdsdesignlds data needed to make necessary changes in the template. """ if request.method == "POST": try: if 'save' in request.POST: print("********************") uploader = request.user.extrainfo print(uploader) #ref_id = request.POST.get('fileid') subject = request.POST.get('title') description = request.POST.get('desc') design = request.POST.get('design') designation = Designation.objects.get(id=design) upload_file = request.FILES.get('myfile') File.objects.create( uploader=uploader, #ref_id=ref_id, description=description, subject=subject, designation=designation, upload_file=upload_file) if 'send' in request.POST: uploader = request.user.extrainfo print(uploader) #ref_id = request.POST.get('fileid') subject = request.POST.get('title') description = request.POST.get('desc') design = request.POST.get('design') print("designation is ", design) designation = Designation.objects.get( id=HoldsDesignation.objects.get(id=design).designation_id) upload_file = request.FILES.get('myfile') file = File.objects.create( uploader=uploader, #ref_id=ref_id, 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.get(id=sender) receiver = request.POST.get('receiver') receiver_id = User.objects.get(username=receiver) print("Receiver_id = ") print(receiver_id) receive = request.POST.get('recieve') print("recieve = ") print(receive) receive_designation = Designation.objects.filter(name=receive) print("receive_designation = ") print(receive_designation) receive_design = receive_designation[0] upload_file = request.FILES.get('myfile') # return HttpResponse ("success") 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) messages.success(request, 'File sent successfully') except IntegrityError: message = "FileID Already Taken.!!" return HttpResponse(message) file = File.objects.all() extrainfo = ExtraInfo.objects.all() holdsdesignations = HoldsDesignation.objects.all() designations = HoldsDesignation.objects.filter(user=request.user) context = { 'file': file, 'extrainfo': extrainfo, 'holdsdesignations': holdsdesignations, 'designations': designations, } return render(request, 'filetracking/composefile.html', context)
def ps1(request): """ The function is used to create indents by faculty. It adds the indent datails to the indet_table of Purchase and Store module @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. item_name- Name of the item to be procured quantity - Qunat of the item to be procured present_stock=request.POST.get('present_stock') estimated_cost=request.POST.get('estimated_cost') purpose=request.POST.get('purpose') specification=request.POST.get('specification') indent_type=request.POST.get('indent_type') nature=request.POST.get('nature') indigenous=request.POST.get('indigenous') replaced =request.POST.get('replaced') budgetary_head=request.POST.get('budgetary_head') expected_delivery=request.POST.get('expected_delivery') sources_of_supply=request.POST.get('sources_of_supply') head_approval=False director_approval=False financial_approval=False purchased =request.POST.get('purchased') """ des = HoldsDesignation.objects.all().select_related().filter( user=request.user).first() if str(des.designation) == "student": return redirect('/dashboard') if request.user.extrainfo.id == '132': return redirect("/purchase-and-store/entry/") 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') item_name = request.POST.get('item_name') quantity = request.POST.get('quantity') present_stock = request.POST.get('present_stock') estimated_cost = request.POST.get('estimated_cost') purpose = request.POST.get('purpose') specification = request.POST.get('specification') indent_type = request.POST.get('indent_type') nature = request.POST.get('nature') indigenous = request.POST.get('indigenous') replaced = request.POST.get('replaced') budgetary_head = request.POST.get('budgetary_head') expected_delivery = request.POST.get('expected_delivery') sources_of_supply = request.POST.get('sources_of_supply') head_approval = False director_approval = False financial_approval = False purchased = False file = File.objects.create(uploader=uploader, description=description, subject=subject, designation=designation, upload_file=upload_file) IndentFile.objects.create( file_info=file, item_name=item_name, quantity=quantity, present_stock=present_stock, estimated_cost=estimated_cost, purpose=purpose, specification=specification, indent_type=indent_type, nature=nature, indigenous=indigenous, replaced=replaced, budgetary_head=budgetary_head, expected_delivery=expected_delivery, sources_of_supply=sources_of_supply, head_approval=head_approval, director_approval=director_approval, financial_approval=financial_approval, purchased=purchased, ) 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') item_name = request.POST.get('item_name') quantity = request.POST.get('quantity') present_stock = request.POST.get('present_stock') estimated_cost = request.POST.get('estimated_cost') purpose = request.POST.get('purpose') specification = request.POST.get('specification') indent_type = request.POST.get('indent_type') nature = request.POST.get('nature') indigenous = request.POST.get('indigenous') replaced = request.POST.get('replaced') budgetary_head = request.POST.get('budgetary_head') expected_delivery = request.POST.get('expected_delivery') sources_of_supply = request.POST.get('sources_of_supply') head_approval = False director_approval = False financial_approval = False purchased = False file = File.objects.create(uploader=uploader, description=description, subject=subject, designation=designation, upload_file=upload_file) IndentFile.objects.create( file_info=file, item_name=item_name, quantity=quantity, present_stock=present_stock, estimated_cost=estimated_cost, purpose=purpose, specification=specification, indent_type=indent_type, nature=nature, indigenous=indigenous, replaced=replaced, budgetary_head=budgetary_head, expected_delivery=expected_delivery, sources_of_supply=sources_of_supply, head_approval=head_approval, director_approval=director_approval, financial_approval=financial_approval, purchased=purchased, ) 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('/ps1/') 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) messages.success(request, 'Indent Filed Successfully!') finally: message = "FileID Already Taken.!!" 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 = HoldsDesignation.objects.select_related( 'user', 'working', 'designation').filter(user=request.user) context = { 'file': file, 'extrainfo': extrainfo, 'holdsdesignations': holdsdesignations, 'designations': designations, } return render(request, 'ps1/composeIndent.html', context)