Beispiel #1
0
def district(request):
    districts = []
    for district in Zone.objects.filter(category=5).order_by("name"):
        if has_access(request, zone=district):
            districts.append(district)
            
    return as_html(request, "district.html", {"districts": districts})
Beispiel #2
0
def gmc(request):
    gmcs = []
    for gmc in Facility.objects.filter().order_by("name"):
        if has_access(request, facility=gmc):
            gmcs.append(gmc)

    return as_html(request, "gmc.html", {"facilities": gmcs})
Beispiel #3
0
def view(request, zone_id=None, facility_id=None):
    """ This is the main view that is a pretty magic view
    it figures out if you are looking for a facility, a zone
    or none at all. It then sets up the graph and passess on
    to a view to do the real work"""
    dct = {
        "classes": { "ReportMalnutrition": ReportMalnutrition, "Zone": Zone, "Case": Case },
        "limit": "",
    }
    access = False
    
    if not zone_id and not facility_id:
        # right so here are at the root of the site
        access = has_access(request)
        if not access:
            # according to the docs, district has access to the national page
            access = has_roles(request.user, ["district",])
            
        # we are at the root, so we set the root to non
        root = None
        # this is malawi specific, give us the districts
        zones = Q(category=4)
        facilities = None
        # to setup the SQL, use the _zones method
        sql_setup = _zones
    elif facility_id:
        # here we are looking at a facility
        root = Facility.objects.get(id=facility_id)
        access = has_access(request, facility=root)
        
        zones = None
        facilities = Q(id=facility_id)
        # use the right sql method for the setup
        sql_setup = _facilities
    elif zone_id:
        # this gets a little more complicated
        # because the sub zones could be zones or facilites
        root = Zone.objects.get(id=zone_id)
        access = has_access(request, zone=root)
        facilities = Q(zone=root)
        if not root.get_child_ids():
            # then we need to look for facilities
            sql_setup = _facilities
        else:
            sql_setup = _zones
            
        zones = Q(head=root)

    # do we need to filter
    filter_zone = request.GET.get("filter_zone")

    # this is used to show the filters on the right of the screen
    dct["zones_unfiltered"] = zones

    if filter_zone:
        zones = Q(id=filter_zone)
    
    dct["zones"] = zones
    dct["sql_setup"] = sql_setup
    dct["root"] = root
    dct["facilities"] = facilities

    graphs = Graphs(**dct)
    if access:
        return _view(request, graphs, root) 
    else:
        return as_html(request, "no_access.html", {})