コード例 #1
0
def editReporterFacilities(request, reporter_pk=None, district_pk=None, district=None):
    """ 
    This view renders only the select box for facilities, which is filtered
    to only those health facilities that have catchment areas within all the descendants 
    of the district that the reporter belongs to
    (or all heatlh facilities, if the district is de-selected)
    """
    if district: district_pk = Location.objects.filter(type='district').get(name__iexact=district).pk
    facilities = None
    if reporter_pk:
        reporter = get_object_or_404(HealthProviderBase, pk=reporter_pk)
        locations = reporter.reporting_location or reporter.location
        if not locations:
            return HttpResponse(status=404)
        facilities = get_user_district_facilities(request.user)
        locations = locations.get_descendants(include_self=True)
    else: reporter = None
    if district_pk:
        district = get_object_or_404(Location, pk=district_pk)
        locations = district.get_descendants(include_self=True)
        facilities = HealthFacility.objects.filter(catchment_areas__in=locations).distinct().values('pk', 'name', 'type__name').order_by('name')
    return render_to_response('cvs/reporter/partials/edit_reporter_facilities.html',
                              {'facilities': facilities,
                               'reporter': reporter},
                              context_instance=RequestContext(request))
コード例 #2
0
def newReporter(request):
    if request.method == 'POST':
        reporter_form = ReporterForm(data=request.POST, request=request)
        if reporter_form.is_valid():
            reporter_form.reporter = HealthProvider.objects.create(active=True)
            reporter_form.save()
            reporter = reporter_form.reporter
            return render_to_response('cvs/reporter/partials/new_reporter.html',
                                      {'added_reporter':reporter},
                                      context_instance=RequestContext(request))
        else:
            return render_to_response('cvs/reporter/partials/new_reporter.html',
                                      {'report_form':reporter_form},
                                      context_instance=RequestContext(request))
    else:
        reporter_form = ReporterForm(request=request)
        facilities = get_user_district_facilities(request.user)
        toret = render_to_response('cvs/reporter/partials/new_reporter.html',
                           {'reporter_form':reporter_form,
                            'facilities':facilities},
                           context_instance=RequestContext(request))
        return toret