def is_assignee (self, user): """ Return True if user is a Coord who has been assigned this subtask. """ print 'User Dept : ', user.get_profile ().department print 'Is Coord : ', is_coord (user) user_dept = user.get_profile().department return is_coord (user) and (self.coords.filter (id = user.id).exists ())
def is_assignee(self, user): """ Return True if user is a Coord who has been assigned this subtask. """ print 'User Dept : ', user.get_profile().department print 'Is Coord : ', is_coord(user) user_dept = user.get_profile().department return is_coord(user) and (self.coords.filter(id=user.id).exists())
def remainder(request): """ Here we check if the user is a coord. Then we get all the subtasks assigned to the coord which are only 3 days away from overdue. If it is the case we send them a mail, stating the subject of the subtask which is not yet completed and only 3 days from overdue along with its deadline and status This is automated using cron and calling the respective url of this view everday. """ users=userprofile.objects.all() t=get_template('mail_template.html') today=date.today() datatuple=() for user1 in users: if is_coord(user1.user): subtasks=SubTask.objects.filter(coords=user1.user).filter(deadline=today+relativedelta(days=+3)) if subtasks: work_pending=False for subtask in subtasks: if subtask.status != 'C': work_pending=True if work_pending: body=t.render(Context({'name':user1.user.username ,'subtasks':subtasks})) msg=EmailMessage('Remainder',body,'*****@*****.**',[user1.user.email]) msg.content_subtype="html" datatuple+= ( (msg), ) connection=mail.get_connection() connection.send_messages(datatuple) return HttpResponse("remainder sent!")
def edit_task_wrapper (*__args, **__kwargs): request = __args[0] curr_task_id = __kwargs.get('task_id', None) curr_page_owner = User.objects.get( username = __kwargs.get('owner_name', None)) if curr_task_id is None: # Creation of Task if not is_coord (request.user): if request.user == curr_page_owner: # Go ahead return func (*__args, **__kwargs) else: # You can't create Tasks while visiting some # other user's pages # (use case : manually typing erp/coord_name/edit/) print 'Go create Tasks in your own page, dude.' print 'Redirecting... to visited User\'s portal' return redirect ( 'erp.tasks.views.display_portal', owner_name = __kwargs.get('owner_name', request.user.username)) else: # User is not a Core print 'You aren\'t authorized to create Tasks.' print 'Redirecting... to visited User\'s portal' return redirect ('erp.tasks.views.display_portal', owner_name = __kwargs.get('owner_name', request.user.username)) return handle_existing_object (Task, curr_task_id, request.user, curr_page_owner, func, __args, __kwargs)
def ReportGen(request, owner_name): buff=StringIO() response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=ReportOnShaastra.pdf' sno=1 elements=[] toc = TableOfContents() # For conciseness we use the same styles for headings and TOC entries toc.levelStyles = [h1, h2] elements.append(Paragraph('Shaastra Report',centered)) elements.append(Paragraph('Table Of Contents',centered)) elements.append(toc) elements.append(PageBreak()) position_on_page=PAGE_HEIGHT-FRAME_BORDER users_in_department=userprofile.objects.filter(department = request.user.get_profile().department ) if is_core(request.user): tasks=Task.objects.filter(creator__in = users_in_department ).order_by('creation_date') elements.append(Paragraph('Tasks made by your Department',h1)) elements.append(big_spacer) position_on_page = position_on_page - h1.fontSize - big_spacer_height for task in tasks: position_on_page,sno=ShowTask(request,elements,position_on_page,sno,task) elements.append(PageBreak()) position_on_page=PAGE_HEIGHT-FRAME_BORDER elements.append(Paragraph('SubTasks given to your Department',h1)) elements.append(big_spacer) tasks=SubTask.objects.filter(department = request.user.get_profile().department ).order_by('creation_date') position_on_page = position_on_page - h1.fontSize - big_spacer_height for task in tasks: position_on_page,sno=ShowSubTask(request,elements,position_on_page,sno,task) elements.append(PageBreak()) position_on_page=PAGE_HEIGHT-FRAME_BORDER sno=1 if is_core(request.user): subtasks=SubTask.objects.filter(creator__in = users_in_department).order_by('creation_date') elements.append(Paragraph('Sub-Tasks given to your coords',h1)) elements.append(big_spacer) position_on_page = position_on_page - h1.fontSize - big_spacer_height elif is_coord(request.user): subtasks = request.user.subtask_set.all().order_by('creation_date') elements.append(Paragraph('Sub-Tasks given to you',h1)) elements.append(big_spacer) position_on_page = position_on_page - h1.fontSize - big_spacer_height for subtask in subtasks: position_on_page,sno=ShowSubTask(request,elements,position_on_page,sno,subtask) doc = MyDocTemplate(buff) doc.multiBuild(elements) response.write(buff.getvalue()) return response
def read(request, request_id): curr_userprofile=userprofile.objects.get(user=request.user) department = curr_userprofile.department if department.is_event: if is_coord(request.user): curr_request=Request.objects.get(id=request_id) if curr_request.read_status==False: curr_request.read_status=True curr_request.save() return HttpResponseRedirect(reverse('erp.finance.views.advance', kwargs={'dept': '0',}))
def display_portal (request, owner_name = None): """ Display owner's portal. """ page_owner = get_page_owner (request, owner_name) if is_multiple_user (page_owner): return display_multiple_portal (request, page_owner) elif is_core (page_owner): return display_core_portal (request, page_owner) elif is_supercoord(page_owner): return display_supercoord_portal (request, page_owner) elif is_coord(page_owner): return display_coord_portal (request, page_owner)
def is_owner (self, user): """ user is the owner of the current SubTask if - user is a Core in the department which created the Task which SubTask is related to - user is a Core in the department to which SubTask is assigned """ print 'User Dept : ', user.get_profile ().department print 'Is Core : ', is_core (user) print 'Task Dept : ', self.task.creator.get_profile ().department print 'SubTask Dept : ', self.department user_dept = user.get_profile().department return (not is_coord (user)) and ( (user_dept == self.task.creator.get_profile ().department) or (user_dept == self.department))
def question_for(request, owner_name = None): feedback_tab=True curr_user=request.user curr_userprofile=userprofile.objects.get(user=request.user) owner_name=None page_owner = get_page_owner (request, owner_name) Core='Core' Coord='Coord' if str(curr_userprofile.department) == "QMS": if is_core(curr_user): qms_core=True is_core1=True is_visitor1=False if is_supercoord(curr_user): qms_supercoord=True is_visitor1=False if is_coord(curr_user): qms_coord=True is_visitor1=False else: return Http404 #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) return render_to_response('feedback/questions_for.html',locals(),context_instance=global_context(request))
def delete_question(request, question_id, question_for, owner_name = None): feedback_tab=True if not is_coord(request.user): curr_userprofile=userprofile.objects.get(user=request.user) owner_name=None page_owner = get_page_owner (request, owner_name) if str(curr_userprofile.department) == "QMS": q = Question.objects.get(id=question_id) answers = q.answer_set.all() answeraverages = q.answeravg_set.all() if answers: for ans in answers: ans.delete() if answeraverages: for avg in answeraverages: avg.delete() q.delete() return redirect('erp.feedback.views.display', question_for=question_for, permanent=True, owner_name = request.user) else: raise Http404 else: raise Http404
def is_owner (self, user): """ user is the owner of the current Task if - user is a Core in the Task's department """ print 'User Dept : ', user.get_profile ().department print 'Is Core : ', is_core (user) print 'Task Dept : ', self.creator.get_profile ().department return user.get_profile ().department == self.creator.get_profile ().department and (not is_coord (user))
def display(request,question_for, owner_name = None): feedback_tab=True curr_user=request.user curr_userprofile=userprofile.objects.get(user=request.user) users_profile=userprofile.objects.all() owner_name=None page_owner = get_page_owner (request, owner_name) Core='Core' Coord='Coord' #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) if is_core(curr_user): if str(curr_userprofile.department) == "QMS": is_core1=True is_visitor1=False qms_core=True if question_for=='Core': question_for_core=True questions=Question.objects.filter(feedback_for='Core') else: questions=Question.objects.filter(feedback_for='Coord') question_for_coord=True else: raise Http404 if is_supercoord(curr_user): if str(curr_userprofile.department) == "QMS": is_core1=True is_visitor1=False qms_core=True if question_for=='Core': question_for_core=True questions=Question.objects.filter(feedback_for='Core') else: questions=Question.objects.filter(feedback_for='Coord') question_for_coord=True else: raise Http404 if is_coord(curr_user): if str(curr_userprofile.department) == "QMS": qms_coord=True if question_for=='Core': question_for_core=True questions=Question.objects.filter(feedback_for='Core') else: question_for_coord=True questions=Question.objects.filter(feedback_for='Coord') else: raise Http404 return render_to_response('feedback/display.html',locals(),context_instance=global_context(request))
def global_context(request): # The try...except blocks are there for the case when an anonymous # user visits any page (esp the login page) try: user_dept_name = request.user.get_profile ().department.Dept_Name except: user_dept_name = False try: user_name = request.user.get_profile ().name except: user_name = False try: photo_list=userphoto.objects.filter() except: photo_list=False page_owner = request.session.get ('page_owner', request.user) try: po_dept_name = page_owner.get_profile ().department.Dept_Name except: po_dept_name = False try: po_name = page_owner.get_profile ().name except: po_name = False try: if (request.user.get_profile().department.owner.all()): supercore = True else: supercore = False except: supercore = False try: department = request.user.get_profile().department if request.user.username.endswith(department.Dept_Name.replace(' ','').lower()): multiple_coord = True else: multiple_coord = False except: multiple_coord = False qms_core = False qms_supercoord = False qms_coord = False finance_tab=False facilities_tab=False hospi=False finance=False if page_owner != request.user: is_visitor = True else: is_visitor = False try: po_name = page_owner.get_profile ().name curr_user=request.user curr_userprofile=userprofile.objects.get(user=request.user) department = page_owner.get_profile ().department if is_core(curr_user): if str(curr_userprofile.department) == 'QMS': qms_core= True finance_tab=True facilities_tab=True if str(curr_userprofile.department) == 'Finance': finance_tab=True finance=True if str(curr_userprofile.department) == 'Hospitality': hospi=True if is_facilities_coord(curr_user): facilities_tab=True if department.is_event: facilities_tab=True finance_tab=True if is_supercoord(curr_user): if str(curr_userprofile.department) == 'QMS': qms_supercoord= True finance_tab=True facilities_tab=True if str(curr_userprofile.department) == 'Finance': finance_tab=True finance=True if str(curr_userprofile.department) == 'Hospitality': hospi=True if is_facilities_coord(curr_user): facilities_tab=True if department.is_event: finance_tab=True facilities_tab=True if is_coord(curr_user): if str(curr_userprofile.department) == 'QMS': qms_coord= True finance_tab=True facilities_tab=True if str(curr_userprofile.department) == 'Finance': finance=True if str(curr_userprofile.department) == 'Hospitality': hospi=True if is_facilities_coord(curr_user): facilities_tab=True if department.is_event: finance_tab=True print "foo" facilities_tab=True if str(curr_userprofile.department) == 'Finance': finance_tab=True if request.user.username=="ee11b075": facilities_tab=True except: qms_core = False qms_supercoord = False qms_coord = False finance_tab=False facilities_tab=False qms=qms_coord or qms_core or qms_supercoord context = RequestContext (request, {'user':request.user, 'SITE_URL':settings.SITE_URL, 'user_dept_name': user_dept_name, 'user_name': user_name, 'is_core' : is_core (request.user), 'is_multiple_user' : is_multiple_user (request.user), 'is_supercoord' : is_supercoord (request.user), 'is_coord' : is_coord (request.user), 'po_is_core' : is_core (page_owner), 'po_is_supercoord' : is_supercoord (page_owner), 'po_is_coord' : is_coord (page_owner), 'is_visitor' : is_visitor, 'page_owner' : page_owner, 'po_name' : po_name, 'po_dept_name' : po_dept_name, 'photo_list':photo_list, 'supercore':supercore, 'multiple_coord':multiple_coord, 'qms_core':qms_core, 'qms_coord':qms_coord, 'qms_supercoord':qms_supercoord, 'finance_tab':finance_tab, 'facilities_tab':facilities_tab, 'hospi':hospi, 'finance':finance, 'qms':qms, }) return context
def permissions(request): curr_userprofile=userprofile.objects.get(user=request.user) feedback_tab=True page_owner = get_page_owner (request, owner_name=request.user) #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) #To display Add Tasks and Feedback options if is_core(request.user): is_core1=True is_visitor1=False if str(department) == "QMS": qms_core=True qms_dept=True if str(department) == "Finance": finance_core=True finance=True if is_supercoord(request.user): user_supercoord=True if str(department) == "QMS": qms_supercoord=True qms_dept=True if str(department) == "Finance": finance=True if is_coord(request.user): user_coord=True if str(department) == "QMS": qms_coord=True qms_dept=True if str(department) == "Finance": finance=True """ Get instances already created of Permission model create instances of Permission model with coord name and permission Note: There will be as many objects as finance coords. """ if is_core(request.user) and str(department) == "Finance": coords=Permission.objects.all() if coords: print 'coords exist' finance_coords=Permission.objects.all() else: finance_coords=userprofile.objects.filter(department=department) for eachcoord in finance_coords: if is_coord(eachcoord.user): curr_coord=Permission(coord=eachcoord.name) curr_coord.save() PermissionFormset=modelformset_factory(Permission, extra=0, form=PermissionForm) qset = Permission.objects.all() perms = False if request.method == 'POST': permissionformset=PermissionFormset(request.POST, queryset=qset) if permissionformset.is_valid(): for form in permissionformset.forms: if form.has_changed: form.save() qset = Permission.objects.all() permissionformset=PermissionFormset(queryset=qset) perms=True return render_to_response('finance/permissions.html',locals(),context_instance=global_context(request)) else: permissionformset=PermissionFormset(queryset=qset) else: raise Http404 return render_to_response('finance/permissions.html',locals(),context_instance=global_context(request))
def display_department_portal (request, owner_name = None, department_name = None): """ Display all basic info about user's Department. """ print 'Department name :', department_name # #added by vivek print "departmental portal here" shout_form=shout_box_form() shouts=shout_box.objects.all() print "done" page_owner = get_page_owner (request, owner_name) if request.method == 'POST': shout_form=shout_box_form (request.POST) if shout_form.is_valid(): new_shout = shout_form.save (commit = False) new_shout.user=page_owner new_shout.nickname=page_owner.get_profile ().nickname new_shout.timestamp=datetime.datetime.now() new_shout.save () shout_form = shout_box_form () if department_name is None: department = page_owner.get_profile ().department else: department = Department.objects.get (department_name) display_dict = dict () display_dict['shouts']=shouts display_dict['shout_form']=shout_form display_dict['all_Tasks'] = get_timeline (page_owner) display_dict['updates'] = get_all_updates (department) #Get Department Members' image thumbnails display_dict ['dept_cores_list'] = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) display_dict ['dept_supercoords_list'] = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) display_dict ['dept_coords_list'] = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) qms_core=False if is_core(request.user): if str(department) == 'QMS': display_dict['qms_core']=True display_dict['finance_tab']=True qms_supercoord = False if is_supercoord(request.user): if str(department) == 'QMS': display_dict['qms_supercoord']= True display_dict['finance_tab']=True qms_coord=False if is_coord(request.user): if str(department) == 'QMS': display_dict['qms_coord']=True display_dict['finance_tab']=True finance_tab=False if department.is_event: display_dict['finance_tab']=True return render_to_response('tasks/department_portal.html', display_dict, context_instance = global_context (request))
def answer(request, owner_name=None): feedback_tab=True curr_user=request.user curr_userprofile=userprofile.objects.get(user=request.user) users_profile=userprofile.objects.all() owner_name=None page_owner = get_page_owner (request, owner_name) yes='yes' no='no' #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) if is_core(curr_user): is_core1=True is_visitor1=False if str(curr_userprofile.department) == "QMS": qms_core=True qms_dept=True if is_supercoord(curr_user): user_supercoord=True if str(curr_userprofile.department) == "QMS": qms_supercoord=True qms_dept=True if is_coord(curr_user): user_coord=True if str(curr_userprofile.department) == "QMS": qms_coord=True qms_dept=True openfeedback=OpenFeedback.objects.filter(id=1) if openfeedback: curr_feedback=OpenFeedback.objects.get(id=1) else: curr_feedback=OpenFeedback(feedback=False) curr_feedback.save() openreview=OpenReview.objects.filter(id=1) if openreview: curr_review=OpenReview.objects.get(id=1) else: curr_review=OpenReview(review=False) curr_review.save() if curr_feedback.feedback==True: if is_core(curr_user): is_core1=True is_visitor1=False if str(curr_userprofile.department) == "QMS": qms_core=True qms_dept=True curr_department=curr_userprofile.department coord_profiles = userprofile.objects.filter (department= curr_department,user__groups__name = 'Coords') questions=Question.objects.filter(departments=curr_department).exclude(answered_by='Coord').exclude(answered_by='Vol') answers=Answer.objects.filter(creator=curr_userprofile) if is_coord(curr_user): user_coord=True if str(curr_userprofile.department) == "QMS": qms_coord=True qms_dept=True curr_department=curr_userprofile.department core_profiles=userprofile.objects.filter(department=curr_department,user__groups__name='Cores') coord_profiles = userprofile.objects.filter (department= curr_department,user__groups__name = 'Coords').exclude(user=request.user) questions=Question.objects.filter(departments=curr_department).exclude(answered_by='Core').exclude(answered_by='Vol') answers=Answer.objects.filter(creator=curr_userprofile) return render_to_response('feedback/feedback.html',locals(),context_instance=global_context(request)) return render_to_response('feedback/feedback.html',locals(),context_instance=global_context(request))
def qms_review(request, dept_id, is_all, owner_name = None): feedback_tab=True owner_name=None curr_userprofile=userprofile.objects.get(user=request.user) qms_department=curr_userprofile.department all_departments=Department.objects.all().order_by('Dept_Name') page_owner = get_page_owner (request, owner_name) curr_department = Department.objects.get(id=dept_id) yes='yes' no='no' #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) if is_core(request.user): is_core1=True is_visitor1=False if str(qms_department) == "QMS": qms_core=True qms_dept=True if is_supercoord(request.user) and str(qms_department) == "QMS": qms_dept=True qms_supercoord=True if is_coord(request.user) and str(qms_department) == "QMS": qms_dept=True qms_coord=True if is_coord(request.user) or is_supercoord(request.user) or is_core(request.user) and str(qms_department) == "QMS": core_profiles=userprofile.objects.filter(department=curr_department,user__groups__name='Cores') coord_profiles = userprofile.objects.filter (department= curr_department,user__groups__name = 'Coords') for coord in coord_profiles: questions=Question.objects.filter(departments=curr_department).filter(feedback_for='Coord') for q in questions: answers = Answer.objects.filter(owner=coord).filter(question=q) if answers: existing = Answeravg.objects.filter(owner=coord).filter(question=q) if existing: for i in existing: curr_id = i.id existing_average = Answeravg.objects.get(id=curr_id) add=0 number=0 for a in answers: number +=1 add += a.rating average=Decimal(add/number) existing_average.avg = average existing_average.num = number existing_average.save() else: add=0 number=0 for a in answers: number +=1 add += a.rating average=Decimal(add/number) saveavg = Answeravg(question=q,owner=coord,avg=average, num=number) saveavg.save() for core in core_profiles: questions=Question.objects.filter(departments=curr_department).filter(feedback_for='Core') for q in questions: answers = Answer.objects.filter(owner=core).filter(question=q) if answers: existing = Answeravg.objects.filter(owner=core).filter(question=q) if existing: for i in existing: curr_id = i.id existing_average = Answeravg.objects.get(id=curr_id) add=0 number=0 for a in answers: number +=1 add += a.rating average=Decimal(add/number) existing_average.avg = average existing_average.num = number existing_average.save() else: add=0 number=0 for a in answers: number +=1 add += a.rating average=Decimal(add/number) saveavg = Answeravg(question=q,owner=core,avg=average, num=number) saveavg.save() questions=Question.objects.filter(departments=curr_department) averages = Answeravg.objects.all() else: raise Http404 return render_to_response('feedback/qms_review.html',locals(),context_instance=global_context(request))
def review(request, owner_name = None): feedback_tab=True curr_userprofile=userprofile.objects.get(user=request.user) curr_department=curr_userprofile.department owner_name=None page_owner = get_page_owner (request, owner_name) qms_core=False owner_answers=Answer.objects.filter(owner=curr_userprofile) curr_averages = Answeravg.objects.filter(owner=curr_userprofile) #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) if is_core(request.user): is_core1=True is_visitor1=False if str(curr_department) == "QMS": qms_core=True questions=Question.objects.filter(departments=curr_department).filter(feedback_for='Core') if is_coord(request.user): is_coord1=True if str(curr_userprofile.department) == "QMS": qms_coord=True questions=Question.objects.filter(departments=curr_department).filter(feedback_for='Coord') openfeedback=OpenFeedback.objects.filter(id=1) if openfeedback: curr_feedback=OpenFeedback.objects.get(id=1) else: curr_feedback=OpenFeedback(feedback=False) curr_feedback.save() openreview=OpenReview.objects.filter(id=1) if openreview: curr_review=OpenReview.objects.get(id=1) else: curr_review=OpenReview(review=False) curr_review.save() illegal=True if curr_review.review==True: if is_core(request.user) or is_coord(request.user): for q in questions: answers = Answer.objects.filter(owner=curr_userprofile).filter(question=q) if answers: existing = Answeravg.objects.filter(owner=curr_userprofile).filter(question=q) if existing: for i in existing: curr_id = i.id existing_average = Answeravg.objects.get(id=curr_id) add=0 number=0 for a in answers: number +=1 add += a.rating average=Decimal(add/number) existing_average.avg = average existing_average.num = number existing_average.save() else: add=0 number=0 for a in answers: number +=1 add += a.rating average=Decimal(add/number) saveavg = Answeravg(question=q,owner=curr_userprofile,avg=average, num=number) saveavg.save() averages = Answeravg.objects.filter(owner=curr_userprofile) return render_to_response('feedback/review.html',locals(),context_instance=global_context(request)) else: raise Http404 return render_to_response('feedback/feedback.html',locals(),context_instance=global_context(request))
def advance(request, dept): feedback_tab=True finance_core=False total_amount1=0 curr_userprofile=userprofile.objects.get(user=request.user) page_owner = get_page_owner (request, owner_name=request.user) qms_dept=False events_core=False advance=False #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) #To display Add Tasks and Feedback options if is_core(request.user): is_core1=True is_visitor1=False if str(department) == "QMS": qms_core=True qms_dept=True if str(department) == "Finance": finance_core=True if is_supercoord(request.user): user_supercoord=True if str(department) == "QMS": qms_supercoord=True qms_dept=True if is_coord(request.user): user_coord=True if str(department) == "QMS": qms_coord=True qms_dept=True #Check if instance of open portal present. Otherwise make one. openportal=OpenBudgetPortal.objects.filter(id=1) if openportal: curr_portal=OpenBudgetPortal.objects.get(id=1) else: curr_portal=OpenBudgetPortal(opened=False) curr_portal.save() curr_user=request.user event=False finance=False event_chosen=False if (department.is_event): event=True if is_core(request.user): events_core=True """ if is_core(request.user): events_core=True item_exist=False submitted = False plans = Budget.objects.filter(department=department) items = Item.objects.filter(department=department) if items: item_exist=True if curr_portal.opened == True: budgets = plans.exclude(name='F') if curr_portal.opened == False: plan_finance = Budget.objects.get(name='F',department=department) if plan_finance.submitted == True: submitted = True budgets = plans.exclude(name='F') return render_to_response('finance/event_core_view.html',locals(),context_instance=global_context(request)) else: return render_to_response('finance/event_core_view.html',locals(),context_instance=global_context(request)) """ if curr_portal.opened==False: items=Item.objects.all() curr_plans = Budget.objects.filter(department=department) if curr_plans: item_exist=True plan_finance=Budget.objects.get(name='F',department=department) if plan_finance.submitted == True: submitted=True """ Create an instance of request model associated with each item in the finance department approved plan """ advance=True curr_items = Item.objects.filter(budget=plan_finance,department=department) request_items = Request.objects.filter(department=department) for item in curr_items: request_item1=Request.objects.filter(item=item) if not request_item1: new_request=Request(request_amount=0.0, granted_amount=0.0, balance_amount=item.original_amount, item=item, department=department) new_request.save() request_items = Request.objects.filter(department=department) """ADVANCE PORTAL FORM""" if request.method == 'POST': request_error=False requested_amount = request.POST['request'] if requested_amount: try: requested_amount1=float(requested_amount) curr_request = Request.objects.get(id=request.POST['id']) curr_request.request_amount=requested_amount curr_request.request_status=True curr_request.granted_status=False curr_request.read_status=False curr_request.history = str(curr_request.history) + 'requested: '+str(requested_amount)+' on '+str(datetime.date.today())+'<br>' curr_request.save() except: request_error=True else: request_error=True #return HttpResponseRedirect(reverse('erp.finance.views.advance', kwargs={'dept': dept,})) #check for error request_items = Request.objects.filter(department=department) return render_to_response('finance/advance_portal.html',locals(),context_instance=global_context(request)) elif str(department) == "Finance": no_request=False finance=True event=False departments=Department.objects.filter(is_event=True).order_by('Dept_Name') has_perms = False """ Checking is the finance coord logged in has permission to update plan from finance department. """ finance_coords=Permission.objects.all() for eachcoord in finance_coords: if curr_userprofile.name == eachcoord.coord: if eachcoord.budget_sanction==True: has_perms = True if is_core(request.user): has_perms=True """ Make a list of all the budget plans which have already been approved. Note that this happens only when the portal is closed. """ if curr_portal.opened == False: plans = Budget.objects.all() if plans: submitted_plans=Budget.objects.filter(name='F', submitted=True) if submitted_plans: advance=True pending_approval = [] if dept!='0': for plan in submitted_plans: if str(plan.department.id)==dept: event_chosen = True request_items = Request.objects.all() if request_items: for req in request_items: if req.request_status: pending_approval.append(req.department.Dept_Name) if event_chosen: event_name = Department.objects.get(id=dept) plan_finance = Budget.objects.get(name='F',department=event_name) items=Item.objects.filter(department=event_name) curr_items = Item.objects.filter(budget=plan_finance,department=event_name) request_items = Request.objects.filter(department=event_name) if request_items: if request.method == 'POST': approved_error=False approved_amount = request.POST['request'] if approved_amount: try: approved_amount1=float(approved_amount) curr_request = Request.objects.get(id=request.POST['id']) curr_request.granted_amount=approved_amount curr_request.balance_amount=float(curr_request.balance_amount)-float(curr_request.granted_amount) curr_request.request_status=False curr_request.granted_status=True curr_request.read_status=False #new line not happening? curr_request.history = str(curr_request.history)+'approved: '+str(approved_amount)+' on '+str(date.today())+ '<br>' curr_request.save() #if Response Redirect is not given then the history will be lagging #return HttpResponseRedirect(reverse('erp.finance.views.advance', kwargs={'dept': dept,})) except: approved_error=True else: approved_error=True else: no_request=True request_items = Request.objects.filter(department=event_name) if request_items: pending_approval = [] for req in request_items: if req.request_status: pending_approval.append(req.department.Dept_Name) return render_to_response('finance/advance_portal.html',locals(),context_instance=global_context(request)) if qms_dept: if curr_portal.opened == False: plans = Budget.objects.all() if plans: submitted_plans=Budget.objects.filter(name='F', submitted=True) if submitted_plans: advance=True if dept!='0': for plan in submitted_plans: if str(plan.department.id)==dept: event_chosen = True request_items = Request.objects.all() if request_items: pending_approval = [] for req in request_items: if req.request_status: pending_approval.append(req.department.Dept_Name) if event_chosen: event_name = Department.objects.get(id=dept) plan_finance = Budget.objects.get(name='F',department=event_name) request_items = Request.objects.filter(department=event_name) items=Item.objects.all() return render_to_response('finance/advance_portal.html',locals(),context_instance=global_context(request)) """
def budget_portal(request, plan="None"): feedback_tab=True finance_core=False total_amount1=0 curr_userprofile=userprofile.objects.get(user=request.user) page_owner = get_page_owner (request, owner_name=request.user) qms_dept=False events_core=False advance=False #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) #To display Add Tasks and Feedback options if is_core(request.user): is_core1=True is_visitor1=False if str(department) == "QMS": qms_core=True qms_dept=True if str(department) == "Finance": finance_core=True if is_supercoord(request.user): user_supercoord=True if str(department) == "QMS": qms_supercoord=True qms_dept=True if is_coord(request.user): user_coord=True if str(department) == "QMS": qms_coord=True qms_dept=True #Check if instance of open portal present. Otherwise make one. openportal=OpenBudgetPortal.objects.filter(id=1) if openportal: curr_portal=OpenBudgetPortal.objects.get(id=1) else: curr_portal=OpenBudgetPortal(opened=False) curr_portal.save() curr_user=request.user event=False finance=False deadline=Deadline.objects.filter(id=1) if deadline: deadline=Deadline.objects.get(id=1) if not deadline: deadline=Deadline(budget_portal_deadline=date.today()) if finance_core: deadlines=Deadline.objects.all() if not deadlines: deadline1=Deadline(budget_portal_deadline=date.today()) deadline1.save() deadline=Deadline.objects.get(id=1) if (department.is_event): event=True if is_core(request.user): events_core=True item_exist=False submitted = False plans = Budget.objects.filter(department=department) items = Item.objects.filter(department=department) if items: item_exist=True if curr_portal.opened == True: budgets = plans.exclude(name='F') if curr_portal.opened == False: plan_finance = Budget.objects.get(name='F',department=department) if plan_finance.submitted == True: submitted = True budgets = plans.exclude(name='F') return render_to_response('finance/event_core_view.html',locals(),context_instance=global_context(request)) else: return render_to_response('finance/event_core_view.html',locals(),context_instance=global_context(request)) if curr_portal.opened==True: """ First check if plans exist in database for the particular department else create three plans. """ plans = Budget.objects.filter(department=department) if plans: print "plans exist" else: curr_plan = Budget(name='A', total_amount=0, department=department) curr_plan.save() curr_plan = Budget(name='B', total_amount=0, department=department) curr_plan.save() curr_plan = Budget(name='C', total_amount=0, department=department) curr_plan.save() curr_plan = Budget(name='F', total_amount=0, department=department) curr_plan.save() plans = Budget.objects.filter(department=department) description='Description' form_selected = False """ Let the user choose the Plan to be updated and accordingly prepopulate the form with the data. """ if plan=='A' or plan=='B' or plan=='C': for p in plans: if p.name == plan: curr_plan = Budget.objects.get(id=p.id) form_selected=True qset = Item.objects.filter(department=department, budget=curr_plan) if len(qset)<5: extra1=5-len(qset) else: extra1=2 ItemFormset=modelformset_factory(Item, fields=('name', 'description','quantity', 'original_amount'),extra=extra1, can_delete=True) if request.method == 'POST': budgetclaimform=BudgetClaimForm(request.POST, instance=curr_plan) itemformset=ItemFormset(request.POST, queryset=qset) form_saved = False if itemformset.is_valid(): for form in itemformset.forms: if form.has_changed(): if not form in itemformset.deleted_forms: tempform = form.save(commit=False) tempform.department=department tempform.budget=curr_plan tempform.save() if form in itemformset.deleted_forms: if item.objects.filter(id=form.instance.id): curr_item = Item.objects.get(id=form.instance.id) curr_item.delete() form_saved = True qset = Item.objects.filter(department=department, budget=curr_plan) if 'add_more_items' in request.POST: if len(qset)<5: extra1=5-len(qset) else: extra1=2 else: if len(qset)<5: extra1=5-len(qset) else: extra1=0 ItemFormset=modelformset_factory(Item, fields=('name', 'description','quantity','original_amount'),extra=extra1, can_delete=True) itemformset=ItemFormset(queryset=qset) else: error=True if budgetclaimform.is_valid(): budgetclaimform1=budgetclaimform.save(commit=False) for qset1 in qset: total_amount1+=qset1.original_amount budgetclaimform1.total_amount=float(total_amount1) budgetclaimform1.save() else: error=True else: budgetclaimform=BudgetClaimForm(instance=curr_plan) itemformset=ItemFormset(queryset=qset) else: items=Item.objects.all() curr_plans = Budget.objects.filter(department=department) if curr_plans: item_exist=True plan_finance=Budget.objects.get(name='F',department=department) if plan_finance.submitted == True: submitted=True """ADVANCE""" """ Create an instance of request model associated with each item in the finance department approved plan """ advance=True curr_items = Item.objects.filter(budget=plan_finance,department=department) request_items = Request.objects.filter(department=department) if not request_items: for item in curr_items: new_request=Request(request_amount=0.0, granted_amount=0.0, balance_amount=item.original_amount, item=item, department=department) new_request.save() request_items = Request.objects.filter(department=department) """ADVANCE PORTAL FORM""" if request.method == 'POST': requested_amount = request.POST['request'] if requested_amount: try: requested_amount1=float(requested_amount) curr_request = Request.objects.get(id=request.POST['id']) curr_request.request_amount=requested_amount curr_request.request_status=True #new line not happening? curr_request.history = str(curr_request.history) + '\n' +'requested amount: '+str(requested_amount)+' on '+str(datetime.date.today()) curr_request.save() #if Response Redirect is not given then the history will be lagging #return HttpResponseRedirect(reverse('erp.finance.views.budget_portal', kwargs={'plan': 'budget',})) except: request_error=True request_items = Request.objects.filter(department=department) return render_to_response('finance/budget_portal.html',locals(),context_instance=global_context(request)) elif str(department) == "Finance": finance=True event=False departments=Department.objects.filter(is_event=True).order_by('Dept_Name') has_perms = False """ Checking is the finance coord logged in has permission to update plan from finance department. """ finance_coords=Permission.objects.all() for eachcoord in finance_coords: if curr_userprofile.name == eachcoord.coord: if eachcoord.budget_sanction==True: has_perms = True if is_core(request.user): has_perms=True """ Make a list of all the budget plans which have already been approved. Note that this happens only when the portal is closed. """ if curr_portal.opened == False: submittedplans = [] plans = Budget.objects.all() if plans: for dept in departments: curr_plans = Budget.objects.filter(department=dept) if curr_plans: plan_finance=Budget.objects.get(name='F',department=dept) if plan_finance.submitted == True: submittedplans.append(dept.Dept_Name) submitted_plans=Budget.objects.filter(name='F', submitted=True) if submitted_plans: advance=True curr_items = Item.objects.filter(budget=plan_finance,department=department) request_items = Request.objects.filter(department=department) if not request_items: for item in curr_items: new_request=Request(request_amount=0.0, granted_amount=0.0, balance_amount=item.original_amount, item=item, department=department) new_request.save() request_items = Request.objects.filter(department=department) """ADVANCE PORTAL FORM if request.method == 'POST': requested_amount = request.POST['request'] curr_request = Request.objects.get(id=request.POST['id']) curr_request.request_amount=requested_amount curr_request.request_status=True #new line not happening? curr_request.history = str(curr_request.history) + '\n' +'requested amount: '+str(requested_amount)+' on '+str(datetime.date.today()) curr_request.save() #if Response Redirect is not given then the history will be lagging return HttpResponseRedirect(reverse('erp.finance.views.budget_portal', kwargs={'plan': 'budget',}))""" """ Finance core has the option to set deadline. """ if finance_core: form_saved=False if request.method=='POST': deadlineform=DeadlineForm(request.POST,instance=deadline) if deadlineform.is_valid(): deadlineform.save() form_saved=True else: deadlineform=DeadlineForm(instance=deadline) return render_to_response('finance/budget_portal.html',locals(),context_instance=global_context(request)) """ If user is part of QMS department then, he/she has the pemission to view all plans from all departments, like a finance coord without permission. """ if qms_dept or events_core: departments=Department.objects.filter(is_event=True).order_by('Dept_Name') has_perms=False if curr_portal.opened == False: submittedplans = [] plans = Budget.objects.all() if plans: for dept in departments: curr_plans = Budget.objects.filter(department=dept) if curr_plans: plan_finance=Budget.objects.get(name='F',department=dept) if plan_finance.submitted == True: submittedplans.append(dept.Dept_Name) return render_to_response('finance/budget_portal.html',locals(),context_instance=global_context(request)) else: raise Http404
def edit_question(request,question_id, question_for, owner_name = None): feedback_tab=True q = Question.objects.get(id=question_id) #Get Department Members' image thumbnails page_owner = get_page_owner (request, owner_name=None) department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) if is_core(request.user): curr_userprofile=userprofile.objects.get(user=request.user) if str(curr_userprofile.department) == "QMS": is_core1=True is_visitor1=False qms_core=True if question_for== 'Coord': if request.method == 'POST': questionform=QuestionFormCoord(request.POST, instance=q) question_added=False if questionform.is_valid(): questionform1=questionform.save(commit=False) questionform1.edited_last=curr_userprofile questionform1.feedback_for='Coord' questionform1.save() questionform.save_m2m() question_added= True return redirect('erp.feedback.views.display', question_for=question_for, permanent=True, owner_name = request.user) else: error=True questionform=QuestionFormCoord(instance=q) return render_to_response('feedback/question.html',locals(),context_instance=global_context(request)) if question_for== 'Core': if request.method == 'POST': questionform=QuestionFormCore(request.POST, instance=q) question_added=False if questionform.is_valid(): questionform1=questionform.save(commit=False) questionform1.edited_last=curr_userprofile questionform1.feedback_for='Core' questionform1.answered_by='Coord' questionform1.save() questionform.save_m2m() question_added= True return redirect('erp.feedback.views.display', question_for=question_for, permanent=True, owner_name = request.user) else: error=True questionform=QuestionFormCore(instance=q) return render_to_response('feedback/question.html',locals(),context_instance=global_context(request)) else: raise Http404 if is_supercoord(request.user): curr_userprofile=userprofile.objects.get(user=request.user) if str(curr_userprofile.department) == "QMS": is_core1=True is_visitor1=False qms_core=True if question_for== 'Coord': if request.method == 'POST': questionform=QuestionFormCoord(request.POST, instance=q) question_added=False if questionform.is_valid(): questionform1=questionform.save(commit=False) questionform1.edited_last=curr_userprofile questionform1.feedback_for='Coord' questionform1.save() questionform.save_m2m() question_added= True return redirect('erp.feedback.views.display', question_for=question_for, permanent=True, owner_name = request.user) else: error=True questionform=QuestionFormCoord(instance=q) return render_to_response('feedback/question.html',locals(),context_instance=global_context(request)) if question_for== 'Core': if request.method == 'POST': questionform=QuestionFormCore(request.POST, instance=q) question_added=False if questionform.is_valid(): questionform1=questionform.save(commit=False) questionform1.edited_last=curr_userprofile questionform1.feedback_for='Core' questionform1.answered_by='Coord' questionform1.save() questionform.save_m2m() question_added= True return redirect('erp.feedback.views.display', question_for=question_for, permanent=True, owner_name = request.user) else: error=True questionform=QuestionFormCore(instance=q) return render_to_response('feedback/question.html',locals(),context_instance=global_context(request)) else: raise Http404 if is_coord(request.user): owner_name=None page_owner = get_page_owner (request, owner_name) curr_userprofile=userprofile.objects.get(user=request.user) if str(curr_userprofile.department) == "QMS": qms_coord=True if question_for== 'Coord': if request.method == 'POST': questionform=QuestionFormCoord(request.POST,instance=q) question_added=False if questionform.is_valid(): questionform1=questionform.save(commit=False) questionform1.edited_last=curr_userprofile questionform1.feedback_for='Coord' questionform1.save() questionform.save_m2m() question_added= True return redirect('erp.feedback.views.display', question_for=question_for, permanent=True, owner_name = request.user) else: error=True questionform=QuestionFormCoord(instance=q) return render_to_response('feedback/question.html',locals(),context_instance=global_context(request)) else: if request.method == 'POST': questionform=QuestionFormCore(request.POST, instance=q) question_added=False if questionform.is_valid(): questionform1=questionform.save(commit=False) questionform1.edited_last=curr_userprofile questionform1.feedback_for='Core' questionform1.answered_by='Coord' questionform1.save() questionform.save_m2m() question_added= True return redirect('erp.feedback.views.display', question_for=question_for, permanent=True, owner_name = request.user) else: error=True questionform=QuestionFormCore(instance=q) return render_to_response('feedback/question.html',locals(),context_instance=global_context(request)) else: raise Http404
def display(request, event_name): """ Display the plans and items. """ display=True finance=False feedback_tab=True form_saved=False total_amount1=0 page_owner = get_page_owner (request, owner_name=request.user) curr_userprofile=userprofile.objects.get(user=request.user) #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) #To display Add Tasks and Feedback options if is_core(request.user): is_core1=True is_visitor1=False if str(department) == "QMS": qms_core=True qms_dept=True if is_supercoord(request.user): user_supercoord=True if str(department) == "QMS": qms_supercoord=True qms_dept=True if is_coord(request.user): user_coord=True if str(department) == "QMS": qms_coord=True qms_dept=True #Check if instance of open portal present. Otherwise make one. openportal=OpenBudgetPortal.objects.filter(id=1) if openportal: curr_portal=OpenBudgetPortal.objects.get(id=1) else: curr_portal=OpenBudgetPortal(opened=False) curr_portal.save() if(department.is_event): event=True budgets = Budget.objects.filter(department=department) items = Item.objects.all() item_exist = False if items: item_exist = True return render_to_response('finance/budget_display.html',locals(),context_instance=global_context(request)) first_time=False item_exist=False event1 = Department.objects.get(id=event_name) if str(department) == "Finance" or "QMS": finance_core=False if str(department) == "Finance": finance=True else: qms_dept=True event1 = Department.objects.get(id=event_name) plans = Budget.objects.filter(department=event1) if plans: item_exist=True budgets=Budget.objects.filter(department=event1) items = Item.objects.all() planF = False has_perms = False if curr_portal.opened==False: finance_coords=Permission.objects.all() for eachcoord in finance_coords: if curr_userprofile.name == eachcoord.coord: if eachcoord.budget_sanction==True: has_perms = True if is_core(request.user) and str(department) == "Finance": has_perms=True finance_core=True planF = True plan_finance=Budget.objects.get(name='F',department=event1) submitted = False if plan_finance.submitted ==False: qset = Item.objects.filter(department=event1, budget=plan_finance) for qset1 in qset: total_amount1+=qset1.original_amount if len(qset)<5: extra1=5-len(qset) else: extra1=0 ItemFormset=modelformset_factory(Item, fields=('name', 'description','quantity', 'original_amount'), extra=extra1, can_delete=True) if request.method== "POST": budgetclaimform=BudgetClaimForm(request.POST, instance=plan_finance) itemformset=ItemFormset(request.POST, queryset=qset) form_saved = False if itemformset.is_valid(): for form in itemformset.forms: if form.has_changed(): if not form in itemformset.deleted_forms: tempform = form.save(commit=False) tempform.department=event1 tempform.budget=plan_finance tempform.save() if form in itemformset.deleted_forms: if Item.objects.filter(id=form.instance.id): curr_item = Item.objects.get(id=form.instance.id) curr_item.delete() form_saved = True qset = Item.objects.filter(department=event1, budget=plan_finance) else: error=True if budgetclaimform.is_valid(): total_amount1=0 budgetclaimform1=budgetclaimform.save(commit=False) for qset1 in qset: total_amount1+=qset1.original_amount budgetclaimform1.total_amount=float(total_amount1) budgetclaimform1.save() else: error=True if 'add_more_items' in request.POST: if len(qset)<5: extra1=5-len(qset) else: extra1=2 else: if len(qset)<5: extra1=5-len(qset) else: extra1=0 ItemFormset=modelformset_factory(Item, fields=('name', 'description','quantity','original_amount'),extra=extra1, can_delete=True) itemformset=ItemFormset(queryset=qset) else: budgetclaimform=BudgetClaimForm(instance=plan_finance) itemformset=ItemFormset(queryset=qset) return render_to_response('finance/budget_display.html',locals(),context_instance=global_context(request)) else: submitted = True return render_to_response('finance/budget_display.html',locals(),context_instance=global_context(request)) else: return render_to_response('finance/budget_display.html',locals(),context_instance=global_context(request)) else: first_time = True return render_to_response('finance/budget_display.html',locals(),context_instance=global_context(request))
def answer_questions(request,userprofile_id,question_id,rating=None, owner_name = None): feedback_tab=True if str(rating) == '20': rating=None rating_choice=[i for i in range(11)] curr_user=request.user curr_userprofile=userprofile.objects.get(user=request.user) owner_name=None is_core1=False qms_core=False page_owner = get_page_owner (request, owner_name) #Get Department Members' image thumbnails department = page_owner.get_profile ().department dept_cores_list = User.objects.filter ( groups__name = 'Cores', userprofile__department = department) dept_supercoords_list = User.objects.filter ( groups__name = 'Supercoords', userprofile__department = department) dept_coords_list = User.objects.filter ( groups__name = 'Coords', userprofile__department = department) if is_core(curr_user): is_core1=True is_visitor1=False if str(curr_userprofile.department) == "QMS": qms_core=True if is_supercoord(curr_user): user_supercoord=True if str(curr_userprofile.department) == "QMS": qms_supercoord=True if is_coord(curr_user): user_coord=True if str(curr_userprofile.department) == "QMS": qms_coord=True openfeedback=OpenFeedback.objects.filter(id=1) if openfeedback: curr_feedback=OpenFeedback.objects.get(id=1) else: curr_feedback=OpenFeedback(feedback=False) curr_feedback.save() if curr_feedback.feedback==True: curr_department=curr_userprofile.department answers=Answer.objects.filter(creator=curr_userprofile) question1=Question.objects.filter(id=question_id) if question1: question2=Question.objects.get(id=question_id) curr_feedbackuser_userprofile=userprofile.objects.get(id=userprofile_id) if is_core(curr_user): question_no_answer=[] if str(curr_userprofile.department) == "QMS": is_core1=True is_visitor1=False qms_core=True questions=Question.objects.filter(departments=curr_department).exclude(answered_by='Coord').exclude(answered_by='Vol') if rating != None: answer=Answer.objects.filter(question = question2).filter(creator=curr_userprofile).filter(owner=curr_feedbackuser_userprofile) if answer: for answer1 in answer: answer1.rating=rating answer1.save() else: answer1=Answer(rating=rating,question=question2,owner=curr_feedbackuser_userprofile,creator=curr_userprofile,answered=True) answer1.save() for question_one in questions: answer_present=False for answer_one in answers: if answer_one.question==question_one and answer_one.creator==curr_userprofile and answer_one.owner==curr_feedbackuser_userprofile: answer_present=True if not answer_present: question_no_answer.append(question_one) return render_to_response('feedback/answer_questions.html',locals(),context_instance=global_context(request)) if is_coord(curr_user): if str(curr_userprofile.department) == "QMS": qms_coord=True question_no_answer=[] if is_coord(curr_feedbackuser_userprofile.user): questions=Question.objects.filter(departments=curr_department).filter(feedback_for='Coord').exclude(answered_by='Core').exclude(answered_by='Vol') else: questions=Question.objects.filter(departments=curr_department).filter(feedback_for='Core') if rating != None: answer=Answer.objects.filter(question=question2).filter(creator=curr_userprofile).filter(owner=curr_feedbackuser_userprofile) if answer: for answer1 in answer: answer1.rating=rating answer1.save() else: answer1=Answer(rating=rating,question=question2,owner=curr_feedbackuser_userprofile,creator=curr_userprofile,answered=True) answer1.save() for question_one in questions: answer_present=False for answer_one in answers: if answer_one.question==question_one and answer_one.creator==curr_userprofile and answer_one.owner==curr_feedbackuser_userprofile: answer_present=True if not answer_present: question_no_answer.append(question_one) return render_to_response('feedback/answer_questions.html',locals(),context_instance=global_context(request)) return render_to_response('feedback/feedback.html',locals(),context_instance=global_context(request))