Exemple #1
0
def login(request):
    context = {}
    context["msg"] = messages.get(request.GET.get("msg", None))
    
    if request.method == "POST":
        form = LoginForm(request.POST)
        if not request.user.is_authenticated():
            if form.is_valid():
                user = auth.authenticate(
                    username=form.cleaned_data["username"], 
                    password=form.cleaned_data["password"])
                if user:
                    if user.is_active:
                        auth.login(request, user)
                        if has_roles(user, ["gmc",]):
                            try:
                                facility = user.get_profile().facility.id
                                return HttpResponseRedirect("/facility/%s/" % facility)
                            except (ObjectDoesNotExist, AttributeError):
                                pass 
                                
                        return HttpResponseRedirect("/")
                        
                return HttpResponseRedirect("/accounts/login/?msg=login_failed")
    else:
        form = LoginForm()
        
    context["form"] = form
    return as_html(request, "login.html", context)
Exemple #2
0
def processor(self):
    user = self.user
    tabs = []
    if has_roles(user, ["partner", "national", "district"]):
        tabs.append({ "link": "/", "title": "National" })
        tabs.append({ "link": "/district/", "title": "District"})
    if has_roles(user, ["partner", "national", "district", "clinic"]):
        tabs.append({ "link": "/clinic/", "title": "Clinic"})
        tabs.append({ "link": "/child/", "title": "Child"})
        tabs.append({ "link": "/hsa/", "title": "HSA"})
    if has_roles(user, ["partner", "national", "district"]):
        tabs.append({ "link": "/setup/", "title": "Setup"})
    context = {
        "site": { "title": "RapidResponse",
                  "tabs": tabs },
        "settings": settings,
    }
    return context
Exemple #3
0
def processor(self):
    user = self.user
    tabs = []
    if has_roles(user, ["partner", "national", "district"]):
        tabs.append({ "link": "/", "title": "National" })
        tabs.append({ "link": "/district/", "title": "District"})
    if has_roles(user, ["partner", "national", "district", "gmc"]):
        tabs.append({ "link": "/gmc/", "title": "GMC"})
        tabs.append({ "link": "/child/", "title": "Child"})
        tabs.append({ "link": "/hsa/", "title": "HSA"})
    if has_roles(user, ["partner", "national", "district"]):
        tabs.append({ "link": "/setup/", "title": "Setup"})
    tabs.append({ "link": "/background/", "title": "Background"})
    context = {
        "site": { "title": "Malawi",
                  "tabs": tabs },
        "settings": settings,
    }
    return context
Exemple #4
0
def hsa(request):
    q = Q()
    if not has_roles(request.user, "partner"):
        q = Q(id__in=get_providers(request.user))
    nonhtml, tables = get_dict(request, [
        ["providers", q],
    ])
    if nonhtml:
        return nonhtml

    context = {}
    context.update(tables)

    return as_html(request, "hsa.html", context)
Exemple #5
0
def child_list(request):
    q = Q()
    if not has_roles(request.user, "partner"):
        q = Q(provider__in=get_providers(request.user))

    nonhtml, tables = get(request, [
        ["case", q & Q(active=True)],
        ["reports", q],
        ["case", q & Q(active=False)]
    ])
    if nonhtml:
        return nonhtml

    context = {}
    context["active"] = tables[0]
    context["reports"] = tables[1]
    context["inactive"] = tables[2]

    return as_html(request, "child_list.html", context)
Exemple #6
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", {})