Exemplo n.º 1
0
    def field_values(self, request, **kwargs):
        # Get a list of unique values for the field passed in kwargs.
        if kwargs['field_name'] == 'year':
            qs = Bushfire.objects.all().distinct().order_by(
                'year').values_list('year', flat=True)[::1]
            year_list = qs if current_finyear(
            ) in qs else qs + [current_finyear()]
            return self.create_response(request, data=year_list)
        elif kwargs['field_name'] == 'fire_number':
            # Get a list of fire_numbers and names for the field passed in kwargs and request.GET params.
            if request.GET.get('include_final_report') == 'true':
                qs = Bushfire.objects.filter(
                    report_status__in=(Bushfire.STATUS_INITIAL_AUTHORISED,
                                       Bushfire.STATUS_FINAL_AUTHORISED,
                                       Bushfire.STATUS_REVIEWED))
            else:
                qs = Bushfire.objects.filter(
                    report_status=Bushfire.STATUS_INITIAL_AUTHORISED)
            if request.GET.get('region_id'):
                qs = qs.filter(region_id=request.GET.get('region_id'))
            if request.GET.get('district_id'):
                qs = qs.filter(district_id=request.GET.get('district_id'))
            if request.GET.get('year'):
                qs = qs.filter(year=request.GET.get('year'))

            qs = qs.order_by('fire_number').values('fire_number', 'name',
                                                   'tenure__name')

            return self.create_response(request, data=list(qs))

        return super(BushfireResource, self).field_values(request, **kwargs)
Exemplo n.º 2
0
    def field_values(self, request, **kwargs):
        # Get a list of unique values for the field passed in kwargs.
        if kwargs['field_name'] == 'year':
            qs = Bushfire.objects.all().distinct().order_by('year').values_list('year', flat=True)[::1]
            year_list = qs if current_finyear() in qs else qs + [current_finyear()]
            return self.create_response(request, data=year_list)
        elif kwargs['field_name'] == 'fire_number':
        # Get a list of fire_numbers and names for the field passed in kwargs and request.GET params.
            qs = Bushfire.objects.filter(report_status=Bushfire.STATUS_INITIAL_AUTHORISED)
            if request.GET.get('region_id'):
                qs = qs.filter(region_id=request.GET.get('region_id'))
            if request.GET.get('district_id'):
                qs = qs.filter(district_id=request.GET.get('district_id'))
            if request.GET.get('year'):
                qs = qs.filter(year=request.GET.get('year'))

            qs = qs.order_by('fire_number').values('fire_number', 'name', 'tenure__name', 'other_tenure')

            for i in qs:
                if i['other_tenure']:
                    if i['other_tenure'] == Bushfire.IGNITION_POINT_CROWN:
                        i['other_tenure'] = 'Other - Crown'
                    elif i['other_tenure'] == Bushfire.IGNITION_POINT_PRIVATE:
                        i['other_tenure'] = 'Other - Private'
                    else:
                        i['other_tenure'] = 'Other'

            return self.create_response(request, data=list(qs))


        return super(BushfireResource, self).field_values(request, **kwargs)
Exemplo n.º 3
0
def fin_year(year):
    """
    Usage::

        {{ object.year|fin_year }}
    """
    if not year:
        year = current_finyear()
    return str(year) + '/' + str(int(year)+1)
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super(BushfireUpdateForm, self).__init__(*args, **kwargs)
     # order alphabetically, but with username='******', as first item in list
     active_users = User.objects.filter(groups__name='Users').filter(
         is_active=True).exclude(username__icontains='admin').extra(
             select={
                 'other': "CASE WHEN username='******' THEN 0 ELSE 1 END"
             }).order_by('other', 'username')
     self.fields['field_officer'].queryset = active_users
     self.fields['duty_officer'].queryset = active_users.exclude(
         username='******')
     self.fields['reporting_year'].initial = current_finyear()