Beispiel #1
0
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 department_name is None:
        department = page_owner.get_profile ().department
    else:
        department = Department.objects.get (department_name)
    display_dict = dict ()
    display_dict['shouts']=shouts#by vivek
    display_dict['shout_form']=shout_form#by vivek
    display_dict['all_Tasks'] = get_timeline (page_owner)
    display_dict['updates'] = get_all_updates (department)
    display_dict ['dept_cores_list'] = User.objects.filter (
        groups__name = 'Cores',
        userprofile__department = department)
    display_dict ['dept_coords_list'] = User.objects.filter (
        groups__name = 'Coords',
        userprofile__department = department)
    return render_to_response('tasks/department_portal.html',
                              display_dict,
                              context_instance = global_context (request))
Beispiel #2
0
def search(request, search_term=None):  
    print request.method
    page_owner = get_page_owner (request, None)                               
    if request.method == "POST":
        query = request.POST['searchbar']
        search_term = '/search/'+str(urllib.urlencode({'':query}))
        print search_term
        return HttpResponseRedirect(search_term)         
    if not search_term:
            return render_to_response('search/search.html', locals(),RequestContext(request))     
    results = handle_search(request,search_term)
    if spelling(search_term) is not '':
        spelling_suggestion = spelling(search_term)
    tasks = results['tasks']
    users = results['users']
    subtasks = results['subtasks']
    
    #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('search/search.html', locals(),RequestContext(request))
Beispiel #3
0
def approval_portal(request):
    date_list = []
    date_list = range(5, len(DATE_CHOICES) + 5)
    page_owner = get_page_owner(request, owner_name=request.user)
    curr_userprofile = userprofile.objects.get(user=request.user)
    department = page_owner.get_profile().department
    departments = Department.objects.filter(is_event=True).order_by("Dept_Name")
    changed_objects = []

    new_objects = []
    exists_objects = []
    special_req_dept = Department.objects.get(id=58)
    exist_dept = []
    for dept in departments:
        a = EventRound.objects.filter(department=dept)
        if len(a) != 0:
            exist_dept.append(dept)
    """for dept in departments:
        a=FacilitiesObject.objects.filter(creator__department=dept,department=curr_userprofile.department)
        b=FacilitiesObject.objects.filter(creator__department=dept,name__department=special_req_dept)
        if len(a.filter(request_status=0)) + len(b.filter(request_status=0)) != 0:       
            new_objects.append(dept.Dept_Name)   
        elif len(a.filter(request_status=1)) + len(b.filter(request_status=1)) != 0 :       
            changed_objects.append(dept.Dept_Name) 
        elif len(a) + len(b) !=0:
            exists_objects.append(dept.Dept_Name)"""

    return render_to_response("facilities/approval_portal.html", locals(), context_instance=global_context(request))
Beispiel #4
0
def add_round(request, event_id):
    curr_userprofile = userprofile.objects.get(user=request.user)
    page_owner = get_page_owner(request, owner_name=request.user)
    department = Department.objects.get(id=event_id)
    e = EventRound()
    try:
        print "c"
        exist = EventRound.objects.get(department=department, number=1)
        print "x"
        allround = EventRound.objects.filter(department=department).order_by("-number")
        print allround[0].number
        e.number = allround[0].number + 1
        e.department = department
        e.name = "Round " + str(e.number)
        p = e.id
        e.save()
        print "f"
    except:
        print "b"
        e.number = 1
        e.department = department
        e.name = "Round " + str(e.number)
        p = e.id
        e.save()
    items = ItemList.objects.all()
    for item in items:
        a = FacilitiesObject(department=department, event_round=e, name=item)
        a.save()

    return HttpResponseRedirect(SITE_URL + "erp/facilities/round_home/" + str(department.id))
Beispiel #5
0
def facilities_home(request):
    curr_userprofile = userprofile.objects.get(user=request.user)
    page_owner = get_page_owner(request, owner_name=request.user)
    department = page_owner.get_profile().department

    special_req_dept = Department.objects.get(id=58)
    """if is_facilities_coord(request.user):
    	if is_core(request.user):
            return HttpResponseRedirect(SITE_URL + "erp/facilities/approval_portal/")
        if is_supercoord(request.user):
            return HttpResponseRedirect(SITE_URL + "erp/facilities/approval_portal/")
        if request.user.username == "ch10b090":
            return HttpResponseRedirect(SITE_URL + "erp/facilities/approval_portal/")
        if request.user.username == "ce10b084":
            return HttpResponseRedirect(SITE_URL + "erp/facilities/approval_portal/")

        
        
        return HttpResponseRedirect(SITE_URL + "erp/facilities/approval_portal/")"""
    # if department.Dept_Name=="QMS":
    #     return HttpResponseRedirect(SITE_URL + "erp/facilities/qms_visible_portal/")
    if request.user.username == "ee11b075":
        return HttpResponseRedirect(SITE_URL + "erp/facilities/approval_portal/")
    if curr_userprofile.department.is_event:
        return HttpResponseRedirect(SITE_URL + "erp/facilities/round_home/" + str(curr_userprofile.department.id))

    return HttpResponseRedirect(SITE_URL + "erp/facilities/approval_portal/")
Beispiel #6
0
def display_task (request, task_id, owner_name = None):
    """
    Display full details of a Task.
    TODO :
    Validation
    Back Button to go back
    """
    page_owner = get_page_owner (request, owner_name)
    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)
    
    print 'Display Task - Task ID : ', task_id
    curr_task = Task.objects.get (id = task_id)
    comments = TaskComment.objects.filter (task__id = task_id)


    return render_to_response('tasks/display_task.html',
                              locals(),
                              context_instance = global_context (request))
Beispiel #7
0
def submit(request, event):
    feedback_tab=True
    page_owner = get_page_owner (request, owner_name=request.user)
    department = page_owner.get_profile ().department 
    if is_core(request.user) and str(department) == "Finance":
        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 curr_portal.opened==False:
            event1 = Department.objects.get(id=event)
            plans = Budget.objects.filter(department=event1)
            if plans:
                plan_finance=Budget.objects.get(name='F',department=event1)
                
                if plan_finance.submitted==False:
                    plan_finance.submitted=True
                    plan_finance.save()
                    return HttpResponseRedirect(reverse('erp.finance.views.display', kwargs={'event_name': event,}))
                if plan_finance.submitted==True:
                    plan_finance.submitted=False
                    plan_finance.save()
                    return HttpResponseRedirect(reverse('erp.finance.views.budget_portal', kwargs={'plan': 'budget',}))
    else:
        raise Http404
Beispiel #8
0
def edit_subtask (request, subtask_id, owner_name = None):
    """
    Display full details of a SubTask.

    Note :
    Only owners of a subtask can (fully) edit the subtask (and that too only
    in their own page, ie. not while visiting some other user's page)

    Coords who have been assigned the SubTask can change only the Status.

    TODO :
    Validation
    Have an Edit Subtask view (like for Tasks)?
    """
    page_owner = get_page_owner (request, owner_name)

    user = request.user
    curr_subtask = SubTask.objects.get (id = subtask_id)
    curr_subtask_form = SubTaskForm (instance = curr_subtask)

    if curr_subtask.is_owner (user):
        is_owner = True
    else:
        # User is a Coord
        is_owner = False

    has_updated = False
    other_errors = False
    if request.method == 'POST':
        if is_owner:
            # Let the Core save the SubTask
            curr_subtask_form = SubTaskForm (request.POST, instance = curr_subtask)
            if curr_subtask_form.is_valid ():
                curr_subtask_form.save ()
                has_updated = True
            else:
                other_errors = True
        elif 'status' in request.POST:
            # Coord - allowed to change only the status
            curr_subtask.status = request.POST.get ('status', 'O') 
            curr_subtask.save ()
            has_updated = True
            # Reinstantiate the form
            curr_subtask_form = SubTaskForm (instance = curr_subtask)
            print 'SubTask updated'
    comments, comment_form, comment_status = handle_comment (
        request = request,
        is_task_comment = False,
        object_id = subtask_id,
        other_errors = other_errors)
    if has_updated:
        return redirect ('erp.tasks.views.display_portal',
                         owner_name = owner_name)
    else:
        return render_to_response('tasks/edit_subtask.html',
                              locals(),
                              context_instance = global_context (request))
Beispiel #9
0
def display(request, roundno):
    curr_userprofile = userprofile.objects.get(user=request.user)
    page_owner = get_page_owner(request, owner_name=request.user)
    department = page_owner.get_profile().department
    items = FacilitiesObject.objects.filter(creator__department=curr_userprofile.department, roundno=roundno).order_by(
        "name", "request_status"
    )

    return render_to_response("facilities/display.html", locals(), context_instance=global_context(request))
Beispiel #10
0
def display_portal (request, owner_name = None):
    """
    Display owner's portal.
    """
    page_owner = get_page_owner (request, owner_name)

    if page_owner=='Invalid':
        return HttpResponseRedirect('/erp/home/login')
    if is_core (page_owner):
        return display_core_portal (request, page_owner)
    else:
        return display_coord_portal (request, page_owner)
Beispiel #11
0
def display_task (request, task_id, owner_name = None):
    """
    Display full details of a Task.
    TODO :
    Validation
    Back Button to go back
    """
    page_owner = get_page_owner (request, owner_name)
    print 'Display Task - Task ID : ', task_id
    curr_task = Task.objects.get (id = task_id)
    comments = TaskComment.objects.filter (task__id = task_id)
    return render_to_response('tasks/display_task.html',
                              locals(),
                              context_instance = global_context (request))
Beispiel #12
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)       
Beispiel #13
0
def display_subtask (request, subtask_id, owner_name = None):
    """
    Display full details of a SubTask.
    TODO :
    Validation
    Have an Edit Subtask view (like for Tasks)?
    """
    page_owner = get_page_owner (request, owner_name)
    user = request.user
    curr_subtask = SubTask.objects.get (id = subtask_id)
    comments = SubTaskComment.objects.filter (subtask__id = subtask_id)

    return render_to_response('tasks/display_subtask.html',
                              locals(),
                              context_instance = global_context (request))
Beispiel #14
0
def display_subtask (request, subtask_id, owner_name = None):
    """
    Display full details of a SubTask.
    TODO :
    Validation
    Have an Edit Subtask view (like for Tasks)?
    """
    page_owner = get_page_owner (request, owner_name)
    user = request.user
    curr_subtask = SubTask.objects.get (id = subtask_id)
    comments = SubTaskComment.objects.filter (subtask__id = subtask_id)

    return render_to_response('tasks/display_subtask.html',
                              locals(),
                              context_instance = global_context (request))
Beispiel #15
0
def handle_updates (request, owner_name = None):
    """
    Used by coords to send updates to Core.
    Cores will just see the updates they have received.

    Return a dict containing update variables.
    """
    page_owner = get_page_owner (request, owner_name)

    update_dict = dict ()
    if page_owner.groups.filter (name = 'Coords'):
        # For Coords
        update_form = UpdateForm ()
        update_status = "Blank"
        update_dict['updates'] = Update.objects.filter (author = page_owner)
        update_dict['update_form'] = update_form
        update_dict['update_status'] = update_status
    else:
        if page_owner.groups.filter (name = 'Supercoords'):
            # For Supercoords
            update_form = UpdateForm ()
            update_status = "Blank"
            update_dict['updates'] = get_all_updates (page_owner.get_profile ().department)
            update_dict['update_form'] = update_form
            update_dict['update_status'] = update_status
        else:
            # For Core, just display all updates for his dept
            update_dict['updates'] = get_all_updates (
                page_owner.get_profile ().department)

    if request.method == 'POST':
        update_form = UpdateForm (request.POST)            
        if update_form.is_valid():
            new_update = update_form.save (commit = False)
            new_update.author = page_owner
            new_update.save ()
            update_form = UpdateForm ()
            update_status = "Success"
            update_dict['update_status'] = update_status
            return update_dict
        else:
            update_status = "Failed"
            update_dict['update_status'] = update_status
            update_dict['update_form'] = update_form
            return update_dict
    return update_dict
Beispiel #16
0
def qms_visible_portal(request):
    curr_userprofile = userprofile.objects.get(user=request.user)
    curr_user = request.user
    page_owner = get_page_owner(request, owner_name=request.user)
    department = page_owner.get_profile().department
    departments = Department.objects.filter(is_event=True).order_by("Dept_Name")
    changed_objects = []
    new_objects = []
    exists_objects = []

    """'for dept in departments:
        a=FacilitiesObject.objects.filter(creator__department=dept)
        if len(a.filter(request_status=0)) != 0:       
            new_objects.append(dept.Dept_Name)   
        elif len(a.filter(request_status=1)) != 0 :       
            changed_objects.append(dept.Dept_Name) 
        elif len(a) !=0:
            exists_objects.append(dept.Dept_Name)"""

    return render_to_response("facilities/approval_portal.html", locals(), context_instance=global_context(request))
Beispiel #17
0
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))
Beispiel #18
0
def handle_updates (request, owner_name = None):
    """
    Used by coords to send updates to Core.
    Cores will just see the updates they have received.

    Return a dict containing update variables.
    """
    page_owner = get_page_owner (request, owner_name)

    update_dict = dict ()
    if page_owner.groups.filter (name = 'Coords'):
        # For Coords
        update_form = UpdateForm ()
        update_status = "Blank"
        update_dict['updates'] = Update.objects.filter (author = page_owner)
        update_dict['update_form'] = update_form
        update_dict['update_status'] = update_status
    else:
        # For Core, just display all updates for his dept
        update_dict['updates'] = get_all_updates (
            page_owner.get_profile ().department)

    if request.method == 'POST':
        update_form = UpdateForm (request.POST)            
        if update_form.is_valid():
            new_update = update_form.save (commit = False)
            new_update.author = page_owner
            new_update.save ()
            update_form = UpdateForm ()
            update_status = "Success"
            update_dict['update_status'] = update_status
            return update_dict
        else:
            update_status = "Failed"
            update_dict['update_status'] = update_status
            update_dict['update_form'] = update_form
            return update_dict
    return update_dict
Beispiel #19
0
def toggle(request):
    feedback_tab=True
    page_owner = get_page_owner (request, owner_name=request.user)
    department = page_owner.get_profile ().department 
    if is_core(request.user) and str(department) == "Finance":
        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 curr_portal.opened==False:
            curr_portal.opened=True
            curr_portal.save() 
            return HttpResponseRedirect(reverse('erp.finance.views.budget_portal', kwargs={'plan': 'budget',}))
    
        if curr_portal.opened==True:
            curr_portal.opened=False
            curr_portal.save()
            return HttpResponseRedirect(reverse('erp.finance.views.budget_portal', kwargs={'plan': 'budget',}))       
    else:
        raise Http404  
Beispiel #20
0
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
Beispiel #21
0
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))
Beispiel #22
0
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 
Beispiel #23
0
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))
         
    """
Beispiel #24
0
def portal(request, roundno):
    curr_userprofile = userprofile.objects.get(user=request.user)
    page_owner = get_page_owner(request, owner_name=request.user)
    department = page_owner.get_profile().department
    special_req_dept = Department.objects.get(id=58)

    if department.is_event:
        qset = FacilitiesObject.objects.filter(creator__department=curr_userprofile.department, roundno=roundno)
        if len(qset) < 5:
            extra1 = 5 - len(qset)
        else:
            extra1 = 2
        ItemFormset = modelformset_factory(
            FacilitiesObject, fields=("name", "description", "quantity"), extra=extra1, can_delete=True
        )
        if request.method == "POST":
            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:
                            try:
                                curr_item = FacilitiesObject.objects.get(id=form.instance.id)
                                if curr_item.request_status == 0:
                                    tempform = form.save(commit=False)
                                    if tempform.quantity < 0:
                                        tempform.quantity = 0
                                    tempform.roundno = roundno
                                    tempform.creator = curr_userprofile
                                    if form.instance.name.department == special_req_dept:
                                        tempform.department = None
                                    else:
                                        tempform.department = form.instance.name.department
                                    tempform.request_date = datetime.date.today()
                                    tempform.save()
                                    form_saved = True
                                elif curr_item.request_status == 1:
                                    tempform = form.save(commit=False)
                                    tempform.creator = curr_userprofile
                                    tempform.request_date = datetime.date.today()
                                    if form.instance.name.department == special_req_dept:
                                        tempform.department = None
                                    else:
                                        tempform.department = form.instance.name.department
                                    tempform.department = form.instance.name.department
                                    tempform.roundno = roundno
                                    if tempform.quantity <= curr_item.approved_quantity:
                                        tempform.request_status = 2
                                    tempform.save()
                                    form_saved = True
                                elif curr_item.request_status == 2:
                                    tempform = form.save(commit=False)
                                    tempform.creator = curr_userprofile
                                    if form.instance.name.department == special_req_dept:
                                        tempform.department = None
                                    else:
                                        tempform.department = form.instance.name.department
                                    tempform.department = form.instance.name.department
                                    tempform.roundno = roundno
                                    tempform.request_date = datetime.date.today()
                                    if tempform.quantity > curr_item.approved_quantity:
                                        tempform.request_status = 1
                                    tempform.save()
                                    form_saved = True
                            except:
                                tempform = form.save(commit=False)
                                tempform.creator = curr_userprofile
                                if form.instance.name.department == special_req_dept:
                                    tempform.department = None
                                else:
                                    tempform.department = form.instance.name.department
                                tempform.roundno = roundno
                                tempform.department = form.instance.name.department
                                tempform.request_date = datetime.date.today()
                                tempform.save()
                                form_saved = True
                        if form in itemformset.deleted_forms:
                            if FacilitiesObject.objects.filter(id=form.instance.id):
                                curr_item = FacilitiesObject.objects.get(id=form.instance.id)
                                if curr_item.request_status == 0:
                                    curr_item.delete()
                                    form_saved = True
                                else:
                                    error2 = 1

                qset = FacilitiesObject.objects.filter(creator__department=curr_userprofile.department, roundno=roundno)
                # 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(
                    FacilitiesObject, fields=("name", "description", "quantity"), extra=extra1, can_delete=True
                )
                itemformset = ItemFormset(queryset=qset)
            else:
                items = FacilitiesObject.objects.filter(roundno=roundno)
                error = True
        else:
            itemformset = ItemFormset(queryset=qset)

    return render_to_response("facilities/portal.html", locals(), context_instance=global_context(request))
Beispiel #25
0
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))
Beispiel #26
0
def edit_subtask (request, subtask_id, owner_name = None):
    """
    Display full details of a SubTask.

    Note :
    Only owners of a subtask can (fully) edit the subtask (and that too only
    in their own page, ie. not while visiting some other user's page)

    Coords who have been assigned the SubTask can change only the Status.

    TODO :
    Validation
    Have an Edit Subtask view (like for Tasks)?
    """
    page_owner = get_page_owner (request, owner_name)
    user = request.user
    curr_subtask = SubTask.objects.get (id = subtask_id)
    curr_subtask_form = SubTaskForm (instance = curr_subtask,editor=request.user)

    if curr_subtask.is_owner (user):
        is_owner = True
    else:
        # User is a Coord
        is_owner = False

    if(curr_subtask.status=='C'):
        closed_task=1                     # The SubTask Was closed prior to editing
    else:
        closed_task=0                     # The SubTask is not closed prior to editing
    has_updated = False
    other_errors = 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)

    if request.method == 'POST':
        if is_owner:
            # Let the Core save the SubTask
            curr_subtask_form = SubTaskForm (request.POST, instance = curr_subtask)
            if curr_subtask_form.is_valid ():
                if 'status' in request.POST:                
                    if(curr_subtask_form.cleaned_data['status']=='C')and(closed_task == 0):
                        curr_subtask_form.completion_date=datetime.date.today()                    
                    elif(closed_task == 1):
                        curr_subtask_form.completion_date=None
                curr_subtask_form.save ()
                has_updated = True
            else:
                other_errors = True
        elif 'status' in request.POST:
            # Coord - allowed to change only the status
            curr_subtask.status = request.POST.get ('status', 'O') 
            if(curr_subtask.status=='C')and(closed_task == 0):
                curr_subtask.completion_date=datetime.date.today()                    
            elif(closed_task == 1):
                curr_subtask.completion_date=None
            curr_subtask.save ()
            has_updated = True
            # Reinstantiate the form
            curr_subtask_form = SubTaskForm (instance = curr_subtask)
            print 'SubTask updated'
    comments, comment_form, comment_status = handle_comment (
        request = request,
        is_task_comment = False,
        object_id = subtask_id,
        other_errors = other_errors)
    
   

    if has_updated:
        return redirect ('erp.tasks.views.display_portal',
                         owner_name = owner_name)
    else:
        return render_to_response('tasks/edit_subtask.html',
                              locals(),
                              context_instance = global_context (request))
Beispiel #27
0
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
Beispiel #28
0
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))    
Beispiel #29
0
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))
Beispiel #30
0
def edit_task (request, task_id = None, owner_name = None):
    """
    Edit existing Task.

    TODO :
    Do user validation (should have permission)
    Allow delete Task facility (?)
    Cancel Edit
    Save Draft
    """

    page_owner = get_page_owner (request, owner_name)
    user = request.user
    dept_names = [name for name, description in DEP_CHOICES]
    if task_id:
        # Existing Task
        curr_task = Task.objects.get (id = task_id)
        is_new_task = False
    else:
        # New Task
        curr_task = Task (creator = user)
        is_new_task = True
    if(curr_task.status=='C'):
        closed_task=1                     # The SubTask Was closed prior to editing
    else:
        closed_task=0                     # The SubTask is not closed prior to editing


    # curr_object = Task.objects.get (id = task_id)
    is_task_comment = True
    other_errors = False

    #Get all subtasks for task, if task exists
    if task_id:
        curr_subtasks = SubTask.objects.filter(task = curr_task)
        
    #Get Department Members' image thumbnails
    display_dict = dict ()
    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)

    SubTaskFormSet = inlineformset_factory (Task,
                                            SubTask,
                                            form = SubTaskForm,
                                            exclude = subtask_exclusion_tuple,
                                            extra = 0,
                                            can_delete = True)

    SubTaskFormSet.form = staticmethod(curry(SubTaskForm, editor=request.user))
                                           
    if request.method == 'POST':
        # Get the submitted formset
        subtaskfs = SubTaskFormSet (request.POST,
                                    instance = curr_task)
        template_form = subtaskfs.empty_form
        task_form = TaskForm (request.POST, instance = curr_task)
        if task_form.is_valid () and subtaskfs.is_valid ():
            curr_task = task_form.save (commit = False)
            
            if(curr_task.status=='C')and(closed_task == 0):
                curr_task.completion_date=datetime.date.today()                    
            elif(closed_task == 1):
                curr_task.completion_date=None
            curr_task.save()
            print 'Task : ', curr_task

#            comments, comment_form, comment_status = handle_comment (
#                request = request,
#                is_task_comment = True,
#                object_id = task_id)

            # Only the filled forms will be stored in subtasks
            # Also, subtasks marked for deletion are deleted here.
            subtasks = subtaskfs.save (commit = False)
            for subtask in subtasks:
                print 'Subtask : ', subtask
                subtask.creator = user
                subtask.status = DEFAULT_STATUS
                # In case it's a new form (inline formset won't
                # fill in the task in that case)
                subtask.task = curr_task
                #subtask.department=request.user.get_profile().department
                subtask.save ()
            subtaskfs.save_m2m () # Necessary, since we used commit = False
            return redirect ('erp.tasks.views.display_portal',
                             owner_name = owner_name)
        else:
            # One or more Forms are invalid
            other_errors = True
    else:
        task_form = TaskForm (instance = curr_task)
        subtaskfs = SubTaskFormSet (instance = curr_task)
        template_form = subtaskfs.empty_form
        comments, comment_form, comment_status = handle_comment (
        request = request,
        is_task_comment = True,
        object_id = task_id,

        other_errors = other_errors)
        print "atleast here" 
    


    return render_to_response('tasks/edit_task.html',
                              locals(),
                              context_instance = global_context (request))
Beispiel #31
0
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)) 
Beispiel #32
0
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))    
Beispiel #33
0
def edit_task (request, task_id = None, owner_name = None):
    """
    Edit existing Task.

    TODO :
    Do user validation (should have permission)
    Allow delete Task facility (?)
    Cancel Edit
    Save Draft
    """

    page_owner = get_page_owner (request, owner_name)
    user = request.user
    dept_names = [name for name, description in DEP_CHOICES]
    if task_id:
        # Existing Task
        curr_task = Task.objects.get (id = task_id)
        is_new_task = False
    else:
        # New Task
        curr_task = Task (creator = user)
        is_new_task = True

    # curr_object = Task.objects.get (id = task_id)
    is_task_comment = True
    other_errors = False

    SubTaskFormSet = inlineformset_factory (Task,
                                            SubTask,
                                            form = SubTaskForm,
                                            exclude = subtask_exclusion_tuple,
                                            extra = 0,
                                            can_delete = True)
    if request.method == 'POST':
        # Get the submitted formset
        subtaskfs = SubTaskFormSet (request.POST,
                                    instance = curr_task)
        template_form = subtaskfs.empty_form
        task_form = TaskForm (request.POST, instance = curr_task)
        if task_form.is_valid () and subtaskfs.is_valid ():
            curr_task = task_form.save (commit = False)
            curr_task.save()
            print 'Task : ', curr_task

            comments, comment_form, comment_status = handle_comment (
                request = request,
                is_task_comment = True,
                object_id = task_id)

            # Only the filled forms will be stored in subtasks
            # Also, subtasks marked for deletion are deleted here.
            subtasks = subtaskfs.save (commit = False)
            for subtask in subtasks:
                print 'Subtask : ', subtask
                subtask.creator = user
                subtask.status = DEFAULT_STATUS
                # In case it's a new form (inline formset won't
                # fill in the task in that case)
                subtask.task = curr_task
                subtask.save ()
            subtaskfs.save_m2m () # Necessary, since we used commit = False
            return redirect ('erp.tasks.views.display_portal',
                             owner_name = owner_name)
        else:
            # One or more Forms are invalid
            other_errors = True
    else:
        task_form = TaskForm (instance = curr_task)
        subtaskfs = SubTaskFormSet (instance = curr_task)
        template_form = subtaskfs.empty_form
    comments, comment_form, comment_status = handle_comment (
        request = request,
        is_task_comment = True,
        object_id = task_id,
        other_errors = other_errors)
    return render_to_response('tasks/edit_task.html',
                              locals(),
                              context_instance = global_context (request))
Beispiel #34
0
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))    
Beispiel #35
0
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))