Exemple #1
0
def dashboard(request):
    
    base_facilities = SupplyPoint.objects.filter(active=True, type__code="hsa")
    em_group = None
    if request.location:
        valid_facilities = get_facilities().filter(parent_id=request.location.pk)
        base_facilities = base_facilities.filter(location__parent_id__in=[f.pk for f in valid_facilities])
        em_group = (group_for_location(request.location) == config.Groups.EM)
    # reporting info

    month = MonthPager(request)

    if em_group:
        report = ReportingBreakdown(base_facilities, month.datespan, include_late = True, MNE=False, days_for_late=settings.LOGISTICS_DAYS_UNTIL_LATE_PRODUCT_REPORT)#(group == config.Groups.EM))
    else:
        report = ReportingBreakdown(base_facilities)

    return render_to_response("malawi/dashboard.html",
                              {"reporting_data": report,
                               "hsas_table": MalawiContactTable(Contact.objects.filter(is_active=True,
                                                                                       role__code="hsa"), request=request),
                               "graph_width": 200,
                               "graph_height": 200,
                               "month_pager": month,
                               "districts": get_districts().order_by("code"),
                               "location": request.location},
                               
                              context_instance=RequestContext(request))
Exemple #2
0
def facility(request, code, context={}):
    facility = get_object_or_404(SupplyPoint, code=code)
    assert(facility.type.code == config.SupplyPointCodes.FACILITY)
    em = group_for_location(facility.location) == config.Groups.EM
    mp = MonthPager(request)
    context["location"] = facility.location
    facility.location.supervisors = facility.contact_set.filter\
        (is_active=True, role__code=config.Roles.HSA_SUPERVISOR)
    facility.location.in_charges = facility.contact_set.filter\
        (is_active=True, role__code=config.Roles.IN_CHARGE)
    if em:
        context["stockrequest_table"] = HSAStockRequestTable\
            (StockRequest.objects.filter(supply_point__supplied_by=facility,
                                         requested_on__gte=mp.datespan.startdate,
                                         requested_on__lte=mp.datespan.enddate)\
                                 .exclude(status=StockRequestStatus.CANCELED), request)
    else:
        context["stockrequest_table"] = HSAStockRequestTable\
            (StockRequest.objects.filter(supply_point__supplied_by=facility,
                                         requested_on__gte=request.datespan.startdate,
                                         requested_on__lte=request.datespan.enddate)\
                                 .exclude(status=StockRequestStatus.CANCELED), request)
    context["em"] = em
    context["month_pager"] = mp
    
    return render_to_response("malawi/single_facility.html",

        context, context_instance=RequestContext(request))