def add_redressal(request, id_no): ''' Adds redressal to the thread. ''' if request.user.is_staff: thread = Thread.get_thread(request, id_no) member = get_object(request) if thread is not None and member is not None: if thread.redressal is None or thread.redressal.action != 'APPROVE': if request.method == 'POST': thread.init_for_redressal(request, member) if thread.is_redress_valid(): thread.redress() messages.success( request, f' Thread { thread } is redressed successfully. ') else: messages.info( request, ' Please fill out full form first, before submitting it. ' ) else: messages.info(request, ' Thread is already redressed. ') else: messages.error(request, f' Thread { id_no } does not exist. ') return HttpResponseRedirect(request.META.get('HTTP_REFERER')) return render(request, 'permission_denied.html')
def select_to_solve(request, id_no): if request.user.is_staff: #add code for checking for date member = get_object(request) thread = Thread.get_thread(request, id_no) if thread is not None and member is not None: if thread.redressal is None or not thread.redressal.action == 'APPROVE': curr_date = date.today() if thread.solving_date != curr_date: thread.solver = member thread.solving_date = curr_date thread.save(update_fields=['solver', 'solving_date']) messages.success( request, f" Thread { thread } is selected for solving. ") else: if thread.solver.user == request.user: return redirect(f'/thread/{ thread }/') messages.info( request, f" Thread { id_no } is already selected by other member for solving. " ) else: messages.info( request, f" Thread { id_no } is approved. Now, it can't be solved. " ) return redirect(f'/thread/{ thread }/') return redirect('/permission-denied/')
def deselect_to_solve(request, id_no): if request.user.is_staff: thread = Thread.get_thread(request, id_no) member = get_object(request) if thread is not None and member is not None: if thread.redressal is None or not thread.redressal.action == 'APPROVE': curr_date = date.today() if thread.solver != None and thread.solver.user == request.user: if thread.solving_date == curr_date: thread.solving_date = None thread.solver = None thread.save(update_fields=['solver', 'solving_date']) messages.success( request, f' Thread { thread } is deselected for solving. ') else: messages.info( request, f" Thread { thread } is not selected by no one. ") else: messages.info( request, f" Thread { thread } is selected by different user, you can't deselect it." ) else: messages.info( request, f" Thread { thread } is already approved. Now, it can't be solved. " ) return redirect(f'/thread/{ thread }/') return render(request, 'permisssion_denied.html')
def redress( request, id_no ) : ''' Adds Redress to complaint. ''' if request.user.is_staff : member = get_object( request ) print( 'reached') complain = Complain.get_complain( request, id_no ) if member is not None : if complain is not None : if complain.redressal is None or not complain.redressal.action == 'APPROVE' : complain.init_for_redressal( request, member ) if complain.is_redress_valid() : complain.save_redress() print( complain.redressal ) messages.success( request, f" Complaint { complain } is Redressed successfully. " ) else : messages.error( request, " Please type redressal in given section before submitting it. ") context = { 'complain' : complain, 'member' : member, 'redressal' : complain.redressal } return render( request, 'complain/solve_detail.html', context ) else : messages.error( request, f" Complaint { complain } is already redressed. " ) return redirect( f'/complain/{ complain }/' ) else : messages.error( request, f" There was problem in fetching details of Complaint { id_no }. ") else : messages.error( request, f" There is problem in fetching your access details. " ) return render( request, 'permission_denied.html' )
def edit( request, id_no ): ''' Grants edit access to complainer(student) id complain is rejected. ''' if request.user.is_authenticated: student = get_object( request ) complain = Complain.get_complain( request, id_no ) if student is not None and complain is not None: if student == complain.complainer: if complain.action_by_sorter == 'REJECTED': context = { 'complain' : complain, 'categories' : Complain.categories, 'sub_categories' : Complain.sub_categories } if request.method == "POST": complain.init_for_edit( request ) if complain.is_edit_valid(): complain.save_edit() messages.success( request, f'Complain { complain } edit successfully saved and sent for approval. ' ) return redirect( f'/complain/{ complain }/' ) else: messages.error( request, f'Please fill out all required columns of form then submit it, ') return render( request, 'complain/edit.html', context ) else: messages.info( request, 'You can only edit complain only if it is rejected by committee. ' ) else: messages.info( f"You don't have edit access to required Complain { complain }. " ) return redirect( f'/complain/{ complain }/' ) return render( request, 'permission_denied.html' )
def init_for_thread(request, thread): ''' Initialize the Note as required for the Thread. ''' note = Note() note.note = request.POST.get('note') note.file = request.FILES.get('file') note.solver = get_object(request) note.thread = thread if request.POST.get('pin_it') == 'Yes' and note.solver: note.pinned = True note.pinned_by = note.solver note.pinned_at = timezone.now() return note
def accept( request, id_no ): ''' Accepts Complain object for solving. ''' if request.user.is_staff: member = get_object( request ) complain = Complain.get_complain( request, id_no ) if member is not None and complain is not None: if complain.action_by_sorter == '' or complain.action_by_sorter == 'REJECTED' : complain.accept( member ) messages.success( request, f' Complain { complain } is ACCEPTED for solving. ' ) else: messages.info( request, f' Complain { complain } is already Accepted. ' ) return HttpResponseRedirect( request.META.get( 'HTTP_REFERER' ) ) return render( request, 'permission_denied.html' )
def approve_redressal( request, id_no ) : ''' Approves redressal of a complain ''' if request.user.is_staff : member = get_object( request ) complain = Complain.get_complain( request, id_no ) if member is not None and complain is not None : if complain.redressal and complain.redressal.action != 'Approve' : complain.redressal.approve( member ) messages.success( request, f" Redressal of Complaint { complain } is accepted successfully. " ) else : messages.info( request, f" Redressal of Complaint { complian } is already redressed. ") return redirect( f'/complain/{ complain }/' ) return render( request, 'permission_denied.html' )
def approve_redressal(request, id_no): ''' Function for approval in redressal of Thread. ''' if request.user.is_staff: member = get_object(request) thread = Thread.get_thread(request, id_no) if member is not None and thread is not None: if thread.redressal.action == '' or thread.redressal.action == 'REJECT': thread.redressal.approve(member) messages.success( request, f' Redressal of Thread { id_no } is approved. ') else: messages.info( request, f' Redressal of Thread { id_no } is already approved. ') return HttpResponseRedirect(request.META.get('HTTP_REFERER')) return render(request, 'permission_thread.html')
def reject( request, id_no ): ''' Rejects Complain object and sents for editing to student( complainer ). ''' if request.user.is_staff: member = get_object( request ) complain = Complain.get_complain( request, id_no ) if member is not None and complain is not None: if complain.action_by_sorter != 'REJECTED' : if request.method == "POST" : complain.init_for_reject( request, member ) if complain.is_reject_valid(): complain.save_reject() messages.success( request, f'Complaint { complain } is REJECTED and sent back to student for editing. ') else: messages.error( request, ' Please fill a message for rejection of a complaint. ' ) else : messages.info( request, f' Complaint { complain } is ALREADY REJECTED. ' ) return redirect( f'/complain/{ complain }/' ) return render( request, 'permission_denied.html' )
def detail(request, id_no): complain = Complain.get_complain( request, id_no ) obj = get_object( request ) if request.user.is_staff : if obj.role != 'Sorter' : page = detail_for_solve( request, obj, complain ) print( 1 ) else: page = detail_for_sort( request, obj, complain ) print( 3 ) return page elif request.user.is_authenticated: if complain.complainer == obj: context = { 'complain' : complain } return render( request, 'complain/stu_detail.html', context ) else: messages.info( request, 'This complain is registered by other student, it cannot be accessed.' ) return redirect( '/permission-denied/' )
def pin_note( request, id_no ): ''' Pins Note in the Complain / Thread. ''' if request.user.is_staff: note = Note.get_note( request, id_no ) member = get_object( request ) if note is not None: if not note.pinned == True: note.pin( member ) if note.thread: messages.success( request, f'Note { note } id is pinned in Thread { note.thread }. ') else: messages.success( request, f'Note {note } is pinned in Complain { note.complain }. ') else: if note.thread: messages.info( request, f'Note { note } is already pinned. ') else: messaged.info( request, f'Note {note } is already pinned in Complain { note.complain }. ' ) return HttpResponseRedirect( request.META.get( 'HTTP_REFERER' ) ) return render( request, 'permission_denied.html' )
def list(request) : if request.user.is_authenticated: obj = get_object( request ) # Member / Student object if obj is not None : if request.user.is_staff: if obj.role == 'Solver' : complain_list = Complain.objects.filter( action_by_sorter = 'ACCEPTED' ) elif obj.role == 'Sorter' : complain_list = Complain.objects.filter( action_by_sorter = '' ) else : complain_list = Complain.objects.all() else : complain_list = Complain.objects.filter( complainer = obj ) messages.info( request, f' Complain count : { len(complain_list) }' ) context = { 'complain_list' : complain_list, 'search_options' : Complain.search_options, 'filter_options' : Complain.filter_options } return render(request, 'complain/list.html', context) return render( request, 'permission_denied.html' )
def reject_redressal(request, id_no): if request.user.is_staff: thread = Thread.get_thread(request, id_no) member = get_object(request) if member is not None and thread is not None: if thread.redressal.action == '' or thread.redressal.action == 'APPROVE': thread.redressal.init_for_reject(request, member) if thread.redressal.is_reject_valid(): thread.redressal.reject() messages.success( request, f' Redressal of Thread { thread } is rejected. ') else: messages.info( 'Please fill rejection message first then submit it. ') else: messages.info( request, f' Redressal of Thread { id_no } is already rejected. ') return HttpResponseRedirect(request.META.get('HTTP_REFERER')) return render(request, 'permission_detnied.html')
def attach_complain(request, id_no, complain_id): ''' Attaches Complain of same category and sub_category to thread. ''' if request.user.is_staff: thread = Thread.get_thread(request, id_no) complain = Complain.get_complain(request, complain_id) member = get_object(request) if thread is not None and complain is not None and member is not None: if member.role == 'Sorter': if complain.thread == None: if thread.category == complain.category: if thread.sub_category == complain.sub_category: complain.init_for_thread(request, member, thread) complain.thread_it() thread.increase_complain_count() messages.success( request, f' Complain { complain } is attached to Thread { thread }. ' ) else: messages.error( request, f" Sub category doesn't match for Complaint { complain } and Thread { thread }. " ) else: messages.error( request, f" Category doesn't match for Complaint { complain } and Thread { thread }. " ) else: messages.error( request, f" Complaint { complain } id already attached to Thread { complain.thread }. " ) else: messages.info( request, f" You don't have access to attach Complaint to a Thread. " ) return redirect(f'/complain/{ complain_id }/') return render(request, 'permission_denied.html')
def add_thread(request): '''Handles requests for adding new Thread. ''' if request.user.is_staff: member = get_object(request) if member is not None: context = {'categories': Category.get_list()} print(Category.get_list()) print(Category.get_code_name_list()) print(SubCategory.get_code_name_list()) if request.method == 'POST': thread = Thread.init_for_add(request, member) if thread.category != 'Select Category': context.update({ 'thread': thread, 'sub_categories': SubCategory.get_list(request, thread.category) }) if thread.is_add_valid(request): if thread.id != '': thread.save() messages.success(request, f'Thread { thread.id } is added. ') return redirect(f'/thread/{ thread.id }/') else: messages.error( request, ' Thread Creation Limit reached for this subcatgory. ' ) else: if thread.sub_category != 'Select Sub Category': messages.error( request, ' Please fill form before submitting it. ') else: messages.info(request, ' Please select Sub Category. ') context.update({'thread': thread}) return render(request, 'threads/add.html', context) return render(request, 'permission_denied.html')
def add(request): if request.user.is_authenticated: if request.user.is_staff: messages.info( 'Members are not allowed to add complaint.' ) return render( request, 'permission-denied.html' ) student = get_object( request ) if student is not None: print( Category.get_list() ) today_date = date.today() context = { 'categories' : Category.get_list() } if student.count_date != today_date: student.reinitialize_count() if student.complain_count < 5: if request.method == "POST": complain = Complain.init( request ) if complain.category != 'Select Category' : context.update( { 'sub_categories' : SubCategory.get_list( request, complain.category ), 'complain' : complain } ) if complain.is_valid(): print( complain.id, complain.category, complain.sub_category ) complain.save() student.increase_count() # Increases Complain count messages.success( request, 'Complaint registered. Track it on dashboard . ' ) messages.info( request, f' You can register { str( 5 - student.complain_count ) } more complaints') return redirect( f'/complain/{ complain }' ) else: context.update( { 'complain' : complain } ) if complain.sub_category != 'Select Sub Category' : messages.error( request, ' Please fill full form, before submitting it. ' ) else : messages.info( request, ' Please select Sub Category for Complain. ' ) else: messages.info( request, 'Complaint registration limit reached for today. You have used all your 5 registrations. ') return render( request, 'permission_denied.html') return render(request, 'complain/add.html', context) return redirect('/permission-denied.html/')
def add_note(request, id_no): if request.user.is_staff: # checking if user if member complain = Complain.get_complain( request, id_no ) member = get_object( request ) if member is not None and complain is not None : if member != complain.solver : # verifying if user is solver messages.info( request, f' Complaint { id_no } is already selected by other member. So, note cannot be added.' ) return render(request, 'permission_denied.html', context) else: note = Note() note.init_all( request, member, complain ) if note.is_valid(): note.save() messages.success( request, f' Note { note.id } is added in Complaint.{ id_no }. ' ) else: messages.error( request, ' Please type your note before adding it. ' ) context = { 'note' : note, 'complain' : complain, 'member' : member } return render( request, 'complain/solve_detail.html', context ) return redirect( f'/complain/{ complain.id }/' ) return redirect('/permission-denied/')
def detail(request, id_no): if request.user.is_staff: thread = Thread.get_thread(request, id_no) member = get_object(request) pinned_complain_list = Complain.objects.filter(thread=thread, pinned_in_thread=True) unpinned_complain_list = Complain.objects.filter( thread=thread, pinned_in_thread=False) pinned_note_list = Note.objects.filter(thread=thread, pinned=True) unpinned_note_list = Note.objects.filter(thread=thread, pinned=False) curr_date = date.today() context = { 'thread': thread, 'member': member, 'pinned_complain_list': pinned_complain_list, 'unpinned_complain_list': unpinned_complain_list, 'pinned_note_list': pinned_note_list, 'unpinned_note_list': unpinned_note_list, 'curr_date': curr_date } return render(request, 'threads/detail.html', context) return render(request, 'permission_denied.html')
def reject_redressal( request, id_no ) : ''' Rejects the redressal of Complain object. ''' if request.user.is_staff : member = get_object( request ) complain = Complain.get_complain( request, id_no ) if member is not None and complain is not None : if complain.redressal and complain.redressal != 'Reject' : complain.redressal.init_for_reject( request, member ) if complain.redressal.is_reject_valid() : complain.redressal.reject() messages.success( request, f" Redressal of Complaint { complain } is rejected. ") else : messages.error( request, " Please fill rejecion reason before submitting form. " ) notes = Note.get_list( complain = complain ) complain = Complain.get_complain( request, complain.id ) reject = True # parameter for showing rejection form context = { 'complain' : complain, 'member' : member, 'reject' : reject, 'notes' : notes } return render( request, 'complain/solve_detail.html', context ) else : messages.info( request, f" Redressal of Complaint { complain } is rejected already. ") return redirect( f'/complain/{ complain }/' ) return render( request, 'permission_denied.html' )