Exemple #1
0
 def __init__(self, *args, **kwargs):
     self.username = kwargs.pop('username', '')
     if 'instance' in kwargs:
         self.facility = kwargs.pop('instance')
         if not 'data' in kwargs:
             initial = { \
                 'name':self.facility.name, \
                 'code':self.facility.code, \
                 'type':self.facility.type, \
                 'owner':self.facility.owner, \
                 'authority':self.facility.authority, \
                 'catchment_areas':self.facility.catchment_areas.all(), \
             }
             district = get_district_for_facility(self.facility)
             if district:
                 initial.update({'facility_district':district})
             kwargs.update({'initial':initial})
     else:
         chars = '1234567890_QWERTYUOPASDFGHJKLZXCVBNM'
         self.code = u"gen" + u"".join([choice(chars) \
                                       for i in range(10)]).lower()
         initial = {'code':self.code}
         kwargs.update({'initial':initial})
         self.facility = None
     forms.Form.__init__(self, *args, **kwargs)
     self.fields['facility_district'] = forms.ModelChoiceField(queryset=self.get_districts_for_form(self.username), empty_label='----', required=False, \
                                   widget=forms.Select({'onchange':'update_facility_district(this)'}))
def editFacilityLocations(request, facility_pk=None, district_pk=None):
    if facility_pk:
        facility = get_object_or_404(HealthFacilityBase, pk=facility_pk)
        areas = facility.catchment_areas.all()
    else: areas = None
    if district_pk:
        district = get_object_or_404(Location, pk=district_pk)
    else:
        district = get_district_for_facility(facility)
    locations = district.get_descendants(include_self=True)
    return render_to_response(
      'cvs/facility/partials/edit_facility_locations.html',
      {
          'catchment_areas':areas,
          'locations':locations
      },
      context_instance=RequestContext(request))