def resolvepending(request, cid): a = get_object_or_404(User, username=request.user.username) y = ExtraInfo.objects.all().filter(user=a).first() thiscomplaint = StudentComplain.objects.get(id=cid) if request.method == 'POST': newstatus = request.POST.get('yesorno', '') intstatus = 0 if newstatus == 'Yes': intstatus = 2 else: intstatus = 3 StudentComplain.objects.filter(id=cid).\ update(status=intstatus) complainer_details = StudentComplain.objects.get(id=cid) complaint_system_notif(request.user, complainer_details.complainer.user, 'comp_resolved_alert') return HttpResponseRedirect("/complaint/caretaker/") 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 })
def user(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().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') print("ooooeee") print("Attachment : ",comp_file) 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.get(id=comp_id) #check if location given print(location) if location!="": print("huaaaaa") # 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) print(obj1) print(created) historytemp = StudentComplain.objects.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" else: dsgn = "rewacaretaker" caretaker_name = HoldsDesignation.objects.get(designation__name = dsgn) print('lets chcek') # 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', '/') return HttpResponseRedirect('/complaint/user') else: print("oooo!!!") a = get_object_or_404(User, username=request.user.username) y = ExtraInfo.objects.all().filter(user=a).first() historytemp = StudentComplain.objects.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 # 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_user.html", {'history': history, 'comp_id': y.id}) return render(request, "complaintModule/complaint_user.html", {'history': history, 'comp_id': comp_id })
def complaint_reassign(request,wid,iid): current_user = get_object_or_404(User, username=request.user.username) y = ExtraInfo.objects.all().filter(user=current_user).first() if request.method == 'POST': type = request.POST.get('submit', '') a = get_object_or_404(User, username=request.user.username) y = ExtraInfo.objects.all().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.get(id=worker_id) StudentComplain.objects.select_for_update().filter(id=iid).\ update(worker_id=w, status=1) url = '/complaint/caretaker/worker_id_know_more/'+wid; complainer_details = StudentComplain.objects.get(id=iid) student=0 message = "Your complaint has been re-assigned" complaint_system_notif(request.user, complainer_details.complainer.user ,'reassign_worker_alert',complainer_details.id,student,message) return HttpResponseRedirect(url) elif type == 'redirect': assign_caretaker = request.POST.get('assign_caretaker', '') c = Caretaker.objects.get(id=assign_caretaker) c1 = Caretaker.objects.get(id=iid) remark = 'Redirect complaint from ' + c1.area StudentComplain.objects.select_for_update().filter(id=iid).\ update(location=c.area, remarks=remark) url = '/complaint/caretaker/worker_id_know_more/'+wid; complainer_details = StudentComplain.objects.get(id=iid) 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(url) else: y = ExtraInfo.objects.get(id=y.id) a = Caretaker.objects.get(staff_id=y) b = a.area comp_id = y.id try: detail = StudentComplain.objects.filter(id=iid).first() total_caretaker = Caretaker.objects.all() total_caretakers_in_area = Caretaker.objects.filter(area=b) worker = [] workertemp = [] flag = '' temp = detail.location try: if Workers.objects.filter(caretaker_id=a).count() == 0: flag = 'no_worker' else: workertemp = Workers.objects.filter(caretaker_id=a) j = 1 for i in workertemp: worker.append(i) # if j%2 != 0: # worker.append(i) # j = j + 1 except Caretaker.DoesNotExist: flag = 'no_worker' except StudentComplain.DoesNotExist: return HttpResponse("<H1>Not a valid complaint </H1>") return render(request, "complaintModule/reassignworker.html", {'detail': detail, 'worker': worker, 'flag': flag, 'total_caretaker': total_caretaker,'a':a, 'wid':wid, 'total_caretakers_in_area':total_caretakers_in_area})
def assign_worker(request, comp_id1): current_user = get_object_or_404(User, username=request.user.username) y = ExtraInfo.objects.all().filter(user=current_user).first() """ The function is used to assign workers to complaints. @param: request - trivial. comp_idl - id of the complaint which the user intends to support/unsupport. @variables: type - takes the value either assign or redirect. a - To handle error. y - Foreign key . context - Holds data needed to make necessary changes in the template. """ if request.method == 'POST': type = request.POST.get('submit', '') a = get_object_or_404(User, username=request.user.username) y = ExtraInfo.objects.all().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.get(id=worker_id) StudentComplain.objects.select_for_update().filter(id=comp_id1).\ update(worker_id=w, status=1) complainer_details = StudentComplain.objects.get(id=comp_id1) print(complainer_details.id) 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.get(id=assign_caretaker) c1 = Caretaker.objects.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.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/') else: y = ExtraInfo.objects.get(id=y.id) a = Caretaker.objects.get(staff_id=y) b = a.area comp_id = y.id try: detail = StudentComplain.objects.filter(id=comp_id1).first() total_caretaker = Caretaker.objects.all() total_caretakers_in_area = Caretaker.objects.filter(area=b) workertemp = [] worker = [] flag = '' temp = detail.location try: #care = Caretaker.objects.filter(area=temp).first() if Workers.objects.filter(caretaker_id=a).count() == 0: flag = 'no_worker' else: workertemp1 = Workers.objects.filter(caretaker_id=a) workertemp = workertemp1.filter(worker_type=detail.complaint_type) j = 1 print('worker asign') for i in workertemp: worker.append(i) # if j%2 != 0: # worker.append(i) # j = j + 1 except Caretaker.DoesNotExist: flag = 'no_worker' except StudentComplain.DoesNotExist: return HttpResponse("<H1>Not a valid complaint </H1>") 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})