Beispiel #1
0
 def is_owner (self, user):
     """
     user is the owner of the current SubTask if
     - user is a Core in the department which created the Task
       which SubTask is related to
     - user is a Core in the department to which SubTask is assigned
     """
     print 'User Dept : ', user.get_profile ().get_dept ()
     print 'Is Core : ', is_core (user)
     print 'Task Dept : ', self.task.creator.get_profile ().get_dept ()
     print 'SubTask Dept : ', self.department
     user_dept = user.get_profile().get_dept ()
     return is_core (user) and (
         (user_dept == self.task.creator.get_profile ().get_dept ()) or
         (user_dept == self.department))
Beispiel #2
0
 def is_owner (self, user):
     """
     user is the owner of the current Task if
     - user is a Core in the Task's department
     """
     print 'User Dept : ', user.get_profile ().get_dept ().name
     print 'Is Core : ', is_core (user)
     print 'Task Dept : ', self.creator.get_profile ().get_dept ().name
     return user.get_profile ().get_dept () == self.creator.get_profile ().get_dept () and is_core (user)
Beispiel #3
0
def display_portal(request, owner_name=None):
    """
    Display owner's portal.
    """
    page_owner = get_page_owner(request, owner_name)
    request.session['page_owner'] = page_owner
    print page_owner, "/n/n/n/n"
    if is_core(page_owner):
        return display_core_portal(request, page_owner)
    else:
        return display_coord_portal(request, page_owner)
Beispiel #4
0
def display_portal (request, owner_name = None):
    """
    Display owner's portal.
    """
    page_owner = get_page_owner (request, owner_name)
    request.session['page_owner']=page_owner;
    print page_owner , "/n/n/n/n"
    if is_core (page_owner):
        return display_core_portal (request, page_owner)
    else:
        return display_coord_portal (request, page_owner)
Beispiel #5
0
def get_timeline(user):
    """
    If user is a Core, return all Tasks created by user.
    Else, return all Tasks for user's Department

    Should it be based on Department instead of Core?
    """
    # Get user's department name
    user_dept = user.get_profile().get_dept()
    if is_core(user):
        return Task.objects.filter(creator=user)
    else:
        return Task.objects.filter(creator__group=user_dept)
Beispiel #6
0
def get_timeline (user):
    """
    If user is a Core, return all Tasks created by user.
    Else, return all Tasks for user's Department

    Should it be based on Department instead of Core?
    """
    # Get user's department name
    user_dept = user.get_profile ().get_dept ()
    if is_core (user):
        return Task.objects.filter (creator = user)
    else:
        return Task.objects.filter (creator__group = user_dept)
Beispiel #7
0
def eventcoord(request, event="", request_id=-1, owner_name=None, Edit=False):
    """
    Function called when an event coord logs in. Displays his requests.
    Allows him to add new requests for his event.
    Each event has a separate page
    """

    event_name = event
    event_coord = True
    user = request.user
    coordinating = Group.objects.filter(label__name='Events', members=user)
    page_owner = get_page_owner(request, owner_name)

    for item in coordinating:
        if event in str(item.name):
            allow_adding_request = True
    Form = BudgetFormEvent
    if str(user.get_profile().get_dept()) == "Finance":
        finance_coord = True
        allow_adding_request = True
        all_events_data = get_all_events()
        all_department_data = get_all_departments()
        Form = BudgetFormCoordEvent
    else:
        finance_coord = False
    if (str(user) != str(page_owner)):
        allow_adding_request = False
    if event == "":
        event_list = []
        for item in coordinating:

            event_list.append(item.name)
        return render_to_response('finance/select_event.html',
                                  locals(),
                                  context_instance=global_context(request))
    finance_form = Form()
    advance_portal_finance_data = get_all_eventsadvanceportal()
    # Get requests created by an event
    self_requests = Budget_Event.objects.filter(
        event=Group.objects.filter(label__name='Events', name=event))
    accepted_requests_A = Budget_Event.objects.filter(
        event=Group.objects.filter(label__name='Events', name=event),
        status='A')
    required_items = Budget_Event.objects.filter(
        event=Group.objects.get(label__name='Event', name=event))
    advance_payment_objs = []
    for item in accepted_requests_A:
        advance_payment_objs += Advance_Payment.objects.filter(
            link=item, finance_approval=True)

    total_budget, balance_budget_total = calculate_budget(
        accepted_requests_A, advance_payment_objs)

    accepted_requests_A_list = accepted_requests_A.values_list(
        'id', 'amount_revised')
    string_r_A = {}
    status_A = {}
    form_tuple = []
    ids_A = []
    try:
        buffer_exist = Buffer.objects.get(
            event=Group.objects.get(label__name='Event', name=event))
        if buffer_exist.finance_approval == True:
            buffer_approved = True
    except:
        pass
    for i in range(0, len(accepted_requests_A_list)):
        # Get data to be displayed on advance payment portal
        all_approved_requests = Advance_Payment.objects.filter(
            link=Budget_Event.objects.get(id=accepted_requests_A_list[i][0]),
            finance_approval=True)
        balance_budget = accepted_requests_A_list[i][1] - sum([
            x[0] for x in all_approved_requests.values_list('amount_request')
        ])
        not_approved_objs = Advance_Payment.objects.filter(
            link=Budget_Event.objects.get(id=accepted_requests_A_list[i][0]),
            finance_approval=False)
        all_objs_for_item = Advance_Payment.objects.filter(
            link=Budget_Event.objects.get(id=accepted_requests_A_list[i][0]))
        not_approved_amt = sum(
            [x[0] for x in not_approved_objs.values_list('amount_request')])
        temp = []
        ids_A.append(accepted_requests_A_list[i][0])
        #        money[accepted_requests_A_list[i][0]] = AdvancePortalForm(prefix=str(accepted_requests_A_list[i][0]))
        money = AdvancePortalForm(prefix=str(accepted_requests_A_list[i][0]))

        boolformfin = BoolForm(prefix=str(accepted_requests_A_list[i][0]) +
                               "fin")
        boolformeven = BoolForm(prefix=str(accepted_requests_A_list[i][0]) +
                                "even")
        temp.append(accepted_requests_A[i])
        temp.append(money)

        try:
            filteritem = Budget_Event.objects.get(
                id=accepted_requests_A_list[i][0])
            exist = Advance_Payment.objects.get(link=filteritem)
            Advance_object = exist
        except:
            exist = Advance_Payment(amount_request=0, link=filteritem)
        try:
            if exist:
                status_A = accepted_requests_A_list[i][1] - exist.amount_request
            else:
                status_A = accepted_requests_A_list[i][1]
        except:
            pass
        temp.append(status_A)
        try:
            temp.append(exist.amount_request)
        except:
            temp.append(0)
        if (is_core(user) and finance_coord):
            d = {}
            user_is_core = True
            try:
                if (exist.finance_approval == False):
                    temp.append(boolformfin)
                else:
                    d['bool_val'] = "Approved"
                    temp.append(d)
                    d = {}

                if (exist.events_approval == False):
                    d['bool_val'] = "Not yet Approved"
                    temp.append(d)
                    d = {}

                else:
                    d['bool_val'] = "Approved"
                    temp.append(d)
                    d = {}
            except:
                temp.append(boolformfin)
                d['bool_val'] = "Not yet Approved"
                temp.append(d)
                d = {}

        elif (is_core(user)):
            d = {}
            user_is_core = True
            try:
                if (exist.finance_approval == False):
                    d['bool_val'] = "Not yet Approved"
                    temp.append(d)
                    d = {}
                else:
                    d['bool_val'] = "Approved"
                    temp.append(d)
                    d = {}
                if (exist.events_approval == False):
                    temp.append(boolformeven)
                else:
                    d['bool_val'] = "Approved"
                    temp.append(d)
                    d = {}
            except:
                temp.append("Not yet Approved")
                temp.append(boolformeven)
        else:
            d = {}
            if (exist.finance_approval == False):
                d['bool_val'] = "Not yet Approved"
                temp.append(d)
                d = {}
            else:
                d['bool_val'] = "Approved"
                temp.append(d)
                d = {}
            if (exist.events_approval == False):
                d['bool_val'] = "Not yet Approved"
                temp.append(d)
                d = {}
            else:
                d['bool_val'] = "Approved"
                temp.append(d)
                d = {}
        now = datetime.date.today()
        due = filteritem.requirement_date
        try:
            if Advance_object.finance_approval:
                temp.append("Accepted")
            else:
                temp.append("Available")
            Advance_object = []
        except:
            if (now > due):
                temp.append("Rejected")
            else:
                temp.append("Available")

        temp.append(not_approved_amt)

        temp3 = []
        for item in all_objs_for_item:
            temp2 = []
            temp2.append(item)
            if item.finance_approval == True:
                dicta = {}
                dicta['bool_val'] = "Approved"
                temp2.append(dicta)
            else:
                if (is_core(user)):
                    temp2.append(BoolForm(prefix=str(item.id)))
                else:
                    dicta = {}
                    dicta['bool_val'] = "Not Approved"
                    temp2.append(dicta)
            if (item.finance_approval == True):
                temp2.append("Accepted")
            elif (now > due):
                temp2.append("Rejected")
            else:
                temp2.append("Available")
            temp3.append(temp2)
        temp.append(temp3)
        temp.append(balance_budget)
        form_tuple.append(temp)

    temp = []
    # For Buffer in Advance payment Portal
    bufferform = []
    bufferform.append(BufferForm())
    # For Buffer
    temp = []
    buffer_A = []
    try:
        exist = Buffer.objects.get(
            event=Group.objects.get(label__name='Event', name=event))
    except:
        exist = Buffer(
            event=Group.objects.get(label__name='Event', name=event))
    buffer_A = []
    buffer_A.append(exist)
    # If core, then allow him to approve requests.
    if (is_core(user) and finance_coord):
        d = {}
        user_is_core = True
        try:
            if (exist.finance_approval == False):
                temp.append(BoolForm(prefix=str("bufferfin")))
            else:
                d['bool_val'] = "Approved"
                temp.append(d)
                d = {}
            if (exist.events_approval == False):
                d['bool_val'] = "Not yet Approved"
                temp.append(d)
                d = {}
            else:
                d['bool_val'] = "Approved"
                temp.append(d)
                d = {}
        except:
            temp.append(boolformfin)
            d['bool_val'] = "Not yet Approved"
            temp.append(d)
    elif (is_core(user)):
        d = {}
        user_is_core = True
        try:
            if (exist.finance_approval == False):
                d['bool_val'] = "Not yet Approved"
                temp.append(d)
                d = {}
            else:
                d['bool_val'] = "Approved"
                temp.append(d)
                d = {}
            if (exist.events_approval == False):
                temp.append(BoolForm(prefix=str("buffereven")))
            else:
                d['bool_val'] = "Approved"
                temp.append(d)
                d = {}
        except:
            temp.append("Not yet Approved")
            temp.append(BoolForm(prefix=str("buffereven")))
    else:
        d = {}
        if (exist.finance_approval == False):
            d['bool_val'] = "Not yet Approved"
            temp.append(d)
            d = {}
        else:
            d['bool_val'] = "Approved"
            temp.append(d)
            d = {}
        if (exist.events_approval == False):
            d['bool_val'] = "Not yet Approved"
            temp.append(d)
            d = {}
        else:
            d['bool_val'] = "Approved"
            temp.append(d)
            d = {}

# Amount Requested

    buffer_A.append(temp)
    sum_amount_a, sum_amount_b, sum_amount_r = calculate_sums(self_requests)

    if request_id >= 0:
        request_to_edit = Budget_Event.objects.get(id=request_id)
        Edit = True
        finance_form = Form(
            initial={
                'particular': request_to_edit.particular,
                'requirement_date': request_to_edit.requirement_date,
                'amount_a': request_to_edit.amount_a,
                'amount_b': request_to_edit.amount_b,
                'amount_revised': request_to_edit.amount_revised,
                'status': request_to_edit.status
            })
        if request.method == 'POST':
            finance_form = Form(request.POST)
            if finance_form.is_valid():
                request_to_edit.particular = finance_form.cleaned_data[
                    'particular']
                request_to_edit.requirement_date = finance_form.cleaned_data[
                    'requirement_date']
                request_to_edit.amount_a = finance_form.cleaned_data[
                    'amount_a']
                request_to_edit.amount_b = finance_form.cleaned_data[
                    'amount_b']
                success = True
                if finance_coord:
                    request_to_edit.amount_revised = finance_form.cleaned_data[
                        'amount_revised']
                    request_to_edit.status = finance_form.cleaned_data[
                        'status']
                request_to_edit.save()
                request_id = -1
                return HttpResponseRedirect("./")
        return render_to_response('finance/budget_portal.html',
                                  locals(),
                                  context_instance=global_context(request))


#    return redirect ('finance.views.finance', locals())
    print "nearing"
    if request.method == 'POST':
        finance_form = Form(request.POST)
        print "saving"
        if finance_form.is_valid():
            new_request = finance_form.save(commit=False)
            success = True
            new_request.requester = user
            if not new_request.amount_revised:
                new_request.amount_revised = 0
            new_request.event = Group.objects.filter(label__name='Events',
                                                     name=event)[0]
            new_request.save()
            print "saved"
            return render_to_response('finance/budget_portal.html',
                                      locals(),
                                      context_instance=global_context(request))
    return render_to_response('finance/budget_portal.html',
                              locals(),
                              context_instance=global_context(request))
Beispiel #8
0
def eventcoord(request,event="",request_id=-1,owner_name=None,Edit=False):
    """
    Function called when an event coord logs in. Displays his requests.
    Allows him to add new requests for his event.
    Each event has a separate page
    """
    
    event_name = event
    event_coord = True
    user = request.user
    coordinating = Group.objects.filter(label__name = 'Events', members = user)
    page_owner = get_page_owner (request, owner_name)    
    
    for item in coordinating:
        if event in str(item.name):
            allow_adding_request = True
    Form = BudgetFormEvent
    if str(user.get_profile().get_dept ()) == "Finance":
        finance_coord=True
        allow_adding_request = True
        all_events_data = get_all_events()
        all_department_data = get_all_departments()
        Form = BudgetFormCoordEvent
    else:
        finance_coord=False
    if (str(user) != str(page_owner)):
        allow_adding_request = False
    if event == "":
        event_list = []
        for item in coordinating:
            
            event_list.append(item.name)
        return render_to_response('finance/select_event.html',locals(), context_instance = global_context (request))        
    finance_form = Form()
    advance_portal_finance_data = get_all_eventsadvanceportal()
    # Get requests created by an event
    self_requests = Budget_Event.objects.filter(event = Group.objects.filter(label__name = 'Events', name = event))
    accepted_requests_A = Budget_Event.objects.filter(event = Group.objects.filter(label__name = 'Events', name = event), status='A')
    required_items = Budget_Event.objects.filter(event=Group.objects.get (label__name = 'Event',
name = event))
    advance_payment_objs = []
    for item in accepted_requests_A:
        advance_payment_objs += Advance_Payment.objects.filter(link = item, finance_approval=True)

    total_budget, balance_budget_total = calculate_budget(accepted_requests_A, advance_payment_objs)
    
    accepted_requests_A_list = accepted_requests_A.values_list('id', 'amount_revised')
    string_r_A = {}
    status_A = {}
    form_tuple = []
    ids_A = []
    try:
        buffer_exist = Buffer.objects.get(event=Group.objects.get (label__name = 'Event',
name = event))
        if buffer_exist.finance_approval == True:
            buffer_approved=True
    except:
        pass
    for i in range(0, len(accepted_requests_A_list)):
        # Get data to be displayed on advance payment portal
        all_approved_requests = Advance_Payment.objects.filter(link=Budget_Event.objects.get(id=accepted_requests_A_list[i][0]), finance_approval=True)
        balance_budget = accepted_requests_A_list[i][1] - sum([x[0] for x in all_approved_requests.values_list('amount_request')])
        not_approved_objs = Advance_Payment.objects.filter(link=Budget_Event.objects.get(id=accepted_requests_A_list[i][0]), finance_approval=False)
        all_objs_for_item = Advance_Payment.objects.filter(link=Budget_Event.objects.get(id=accepted_requests_A_list[i][0]))
        not_approved_amt = sum([x[0] for x in not_approved_objs.values_list('amount_request')])
        temp = []
        ids_A.append(accepted_requests_A_list[i][0])
#        money[accepted_requests_A_list[i][0]] = AdvancePortalForm(prefix=str(accepted_requests_A_list[i][0]))
        money = AdvancePortalForm(prefix=str(accepted_requests_A_list[i][0]))

        boolformfin = BoolForm(prefix=str(accepted_requests_A_list[i][0])+"fin")
        boolformeven = BoolForm(prefix=str(accepted_requests_A_list[i][0])+"even")        
        temp.append(accepted_requests_A[i])
        temp.append(money)

        try:
            filteritem = Budget_Event.objects.get(id=accepted_requests_A_list[i][0])
            exist = Advance_Payment.objects.get(link=filteritem)
            Advance_object = exist
        except:
            exist = Advance_Payment(amount_request=0, link=filteritem)
        try:
            if exist:
                status_A = accepted_requests_A_list[i][1] - exist.amount_request
            else:
                status_A = accepted_requests_A_list[i][1]
        except:
            pass
        temp.append(status_A)
        try:
            temp.append(exist.amount_request)
        except:
            temp.append(0)
        if (is_core(user) and finance_coord):
            d = {}            
            user_is_core = True
            try:
                if(exist.finance_approval == False):
                    temp.append(boolformfin)
                else:
                    d['bool_val']="Approved"                    
                    temp.append(d)
                    d = {}
                    
                if(exist.events_approval == False):
                    d['bool_val']="Not yet Approved"                    
                    temp.append(d)
                    d = {}                    
                    
                else:
                    d['bool_val']="Approved"                                        
                    temp.append(d)
                    d = {}                    
            except:
                temp.append(boolformfin)
                d['bool_val']="Not yet Approved"                
                temp.append(d)
                d = {}                

        elif (is_core(user)):
            d = {}
            user_is_core = True
            try:
                if(exist.finance_approval == False):
                    d['bool_val']="Not yet Approved"
                    temp.append(d)
                    d = {}                    
                else:
                    d['bool_val']="Approved"
                    temp.append(d)
                    d = {}                                        
                if (exist.events_approval == False):
                    temp.append(boolformeven)                
                else:
                    d['bool_val']="Approved"                    
                    temp.append(d)
                    d = {}                    
            except:
                temp.append("Not yet Approved")
                temp.append(boolformeven)
        else:
            d = {}
            if(exist.finance_approval == False):
                d['bool_val']="Not yet Approved"                                    
                temp.append(d)
                d = {}                                    
            else:
                d['bool_val']="Approved"                                    
                temp.append(d)
                d = {}                                    
            if (exist.events_approval == False):
                d['bool_val']="Not yet Approved"                                                    
                temp.append(d)
                d = {}                                    
            else:
                d['bool_val']="Approved"                                    
                temp.append(d)
                d = {}
        now = datetime.date.today()
        due = filteritem.requirement_date
        try:
            if Advance_object.finance_approval:
                temp.append("Accepted")
            else:
                temp.append("Available")
            Advance_object = []
        except:
            if (now > due):
                temp.append("Rejected")
            else:
                temp.append("Available")
            
        temp.append(not_approved_amt)

        temp3 = []
        for item in all_objs_for_item:
            temp2 = []
            temp2.append(item)
            if item.finance_approval == True:
                dicta = {}
                dicta['bool_val'] = "Approved"
                temp2.append(dicta)
            else:
                if (is_core(user)):
                    temp2.append( BoolForm(prefix=str(item.id)))
                else:
                    dicta = {}
                    dicta['bool_val'] = "Not Approved"
                    temp2.append(dicta)
            if (item.finance_approval == True):
                temp2.append("Accepted")
            elif (now > due):
                temp2.append("Rejected")
            else:
                temp2.append("Available")
            temp3.append(temp2)
        temp.append(temp3)
        temp.append(balance_budget)
        form_tuple.append(temp)
        
    temp = []
    # For Buffer in Advance payment Portal
    bufferform = []
    bufferform.append(BufferForm())
    # For Buffer
    temp = []
    buffer_A = []
    try:
        exist = Buffer.objects.get(event=Group.objects.get (label__name = 'Event',
name = event))
    except:
        exist = Buffer(event=Group.objects.get (label__name = 'Event',
name = event))	
    buffer_A = []
    buffer_A.append(exist)
    # If core, then allow him to approve requests.
    if (is_core(user) and finance_coord):
        d = {}            
        user_is_core = True
        try:
            if(exist.finance_approval == False):
                temp.append(BoolForm(prefix=str("bufferfin")))                                    
            else:
                d['bool_val']="Approved"                    
                temp.append(d)
                d = {}                                        
            if(exist.events_approval == False):
                d['bool_val']="Not yet Approved"                    
                temp.append(d)
                d = {}                                        
            else:
                d['bool_val']="Approved"                                        
                temp.append(d)
                d = {}                                        
        except:
            temp.append(boolformfin)
            d['bool_val']="Not yet Approved"                
            temp.append(d)
    elif (is_core(user)):
        d = {}
        user_is_core = True
        try:
            if(exist.finance_approval == False):
                d['bool_val']="Not yet Approved"
                temp.append(d)
                d = {}                                        
            else:
                d['bool_val']="Approved"                    
                temp.append(d)
                d = {}                                        
            if (exist.events_approval == False):
                temp.append(BoolForm(prefix=str("buffereven")))                
            else:
                d['bool_val']="Approved"                    
                temp.append(d)
                d = {}                                        
        except:
            temp.append("Not yet Approved")
            temp.append(BoolForm(prefix=str("buffereven")))                                                
    else:
        d = {}
        if(exist.finance_approval == False):
            d['bool_val']="Not yet Approved"                                    
            temp.append(d)
            d = {}                                                        
        else:
            d['bool_val']="Approved"                                    
            temp.append(d)
            d = {}                                                        
        if (exist.events_approval == False):
            d['bool_val']="Not yet Approved"                                                    
            temp.append(d)
            d = {}                                                        
        else:
            d['bool_val']="Approved"                                    
            temp.append(d)
            d = {}


# Amount Requested

            
    buffer_A.append(temp)
    sum_amount_a,sum_amount_b,sum_amount_r = calculate_sums(self_requests)    

    if request_id >= 0:
        request_to_edit = Budget_Event.objects.get (id = request_id)
        Edit = True
        finance_form = Form(initial={'particular':request_to_edit.particular, 'requirement_date':request_to_edit.requirement_date, 'amount_a':request_to_edit.amount_a, 'amount_b':request_to_edit.amount_b, 'amount_revised':request_to_edit.amount_revised, 'status':request_to_edit.status})
        if request.method == 'POST':        
            finance_form = Form(request.POST)
            if finance_form.is_valid():
                request_to_edit.particular = finance_form.cleaned_data['particular']
                request_to_edit.requirement_date = finance_form.cleaned_data['requirement_date']
                request_to_edit.amount_a = finance_form.cleaned_data['amount_a']
                request_to_edit.amount_b = finance_form.cleaned_data['amount_b']
                success = True
                if finance_coord:
                    request_to_edit.amount_revised = finance_form.cleaned_data['amount_revised']
                    request_to_edit.status = finance_form.cleaned_data['status']                    
                request_to_edit.save()
                request_id = -1
                return HttpResponseRedirect("./")
        return render_to_response('finance/budget_portal.html',locals(), context_instance = global_context (request))
#    return redirect ('finance.views.finance', locals())
    print "nearing"
    if request.method == 'POST':
        finance_form = Form(request.POST)
        print "saving"
        if finance_form.is_valid():
            new_request = finance_form.save (commit = False)
            success = True
            new_request.requester = user
            if not new_request.amount_revised:
                new_request.amount_revised = 0            
            new_request.event = Group.objects.filter(label__name = 'Events', name = event)[0]
            new_request.save()
            print "saved"
            return render_to_response('finance/budget_portal.html',locals(), context_instance = global_context (request))
    return render_to_response('finance/budget_portal.html',locals(), context_instance = global_context (request))