Esempio n. 1
0
 def set_report_headers(self):
     header = list(LocationTypeDetails.get_ordered_types().exclude(
         name__iexact="country").values_list('name', flat=True))
     other_headers = [
         'Household ID', 'Name', 'Age', 'Month of Birth', 'Year of Birth',
         'Gender'
     ]
     header.extend(other_headers)
     header.extend(self.question_headers())
     return header
Esempio n. 2
0
 def clean_headers_location_type_order(self, headers):
     headers = UploadService.remove_trailing('Name',
                                             in_array=headers,
                                             exclude='Code')
     ordered_types = [
         type.name
         for type in LocationTypeDetails.get_ordered_types().exclude(
             name__iexact='country')
     ]
     if not ordered_types == headers:
         raise ValidationError(
             'Location types not in order. Please refer to input file format.'
         )
Esempio n. 3
0
def list_weights(request):
    location_weights = LocationWeight.objects.all()
    surveys = Survey.objects.all()
    survey = None
    selected_location = None
    params = request.GET
    if contains_key(params, 'survey'):
        survey = Survey.objects.get(id=params['survey'])
        location_weights = location_weights.filter(survey=survey)
    if contains_key(params, 'location'):
        selected_location = Location.objects.get(id=params['location'])
        location_weights = location_weights.filter(location=selected_location)

    location_types = LocationTypeDetails.get_ordered_types().exclude(name__iexact="country")
    context = {'location_weights': location_weights,
               'location_types': location_types,
               'location_data': LocationWidget(selected_location),
               'surveys': surveys,
               'selected_survey': survey,
               'action': 'list_weights_page',
               'request': request}
    return render(request, 'locations/weights/index.html', context)
Esempio n. 4
0
 def selected_type_is_second_lowest(self):
     return self.selected_location.type == LocationTypeDetails.get_second_lowest_level_type(
     )
 def forwards(self, orm):
     the_country = LocationTypeDetails.the_country()
     if the_country:
         the_country.order = 0
     LocationTypeDetails.objects.all().delete()
     self.generate_location_type_details(the_country, the_country)
Esempio n. 6
0
 def parent_location(self):
     location = self.locations.all()[0]
     from survey.models import LocationTypeDetails
     second_lowest_level_type = LocationTypeDetails.get_second_lowest_level_type()
     return location.get_ancestors().filter(type=second_lowest_level_type)[0]
Esempio n. 7
0
 def selected_type_is_second_lowest(self):
     return self.selected_location.type == LocationTypeDetails.get_second_lowest_level_type()
Esempio n. 8
0
 def forwards(self, orm):
     the_country = LocationTypeDetails.the_country()
     if the_country:
         the_country.order = 0
     LocationTypeDetails.objects.all().delete()
     self.generate_location_type_details(the_country, the_country)
Esempio n. 9
0
 def clean_headers_location_type_order(self, headers):
     headers = UploadService.remove_trailing('Name', in_array=headers, exclude='Code')
     ordered_types = [type.name for type in LocationTypeDetails.get_ordered_types().exclude(name__iexact='country')]
     if not ordered_types == headers:
         raise ValidationError('Location types not in order. Please refer to input file format.')
 def set_report_headers(self):
     header = list(LocationTypeDetails.get_ordered_types().exclude(name__iexact="country").values_list('name', flat=True))
     other_headers = ['Household ID', 'Name', 'Age', 'Month of Birth', 'Year of Birth', 'Gender']
     header.extend(other_headers)
     header.extend(self.question_headers())
     return header