def update(self, instance, validated_data):
        displayfields_data = validated_data.pop('displayfield_set')
        filterfields_data = validated_data.pop('filterfield_set')

        with transaction.atomic():
            instance.name = validated_data.get('name', instance.name)
            instance.description = validated_data.get('description', instance.description)
            instance.distinct = validated_data.get(
                'distinct', instance.distinct)
            instance.modified = datetime.date.today()
            instance.save()

            for displayfield_data in instance.displayfield_set.all():
                 if displayfield_data.aggregate == "Filter":
                    displayfield_data.filter_field.delete()

            instance.displayfield_set.all().delete()

            for displayfield_data in displayfields_data:
                display_field = DisplayField()
                for key, value in displayfield_data.items():
                    setattr(display_field, key, value)

                display_field.save()
            instance.filterfield_set.all().delete()

            for filterfield_data in filterfields_data:
                filter_field = FilterField()
                for key, value in filterfield_data.items():
                    setattr(filter_field, key, value)
                filter_field.save()

        return instance
Ejemplo n.º 2
0
    def update(self, instance, validated_data):
        displayfields_data = validated_data.pop('displayfield_set')
        filterfields_data = validated_data.pop('filterfield_set')

        with transaction.atomic():
            instance.name = validated_data.get('name', instance.name)
            instance.description = validated_data.get('description',
                                                      instance.description)
            instance.distinct = validated_data.get('distinct',
                                                   instance.distinct)
            instance.modified = datetime.date.today()
            instance.save()
            instance.displayfield_set.all().delete()
            for displayfield_data in displayfields_data:
                display_field = DisplayField()
                for key, value in displayfield_data.items():
                    setattr(display_field, key, value)
                display_field.save()
            instance.filterfield_set.all().delete()
            for filterfield_data in filterfields_data:
                filter_field = FilterField()
                for key, value in filterfield_data.items():
                    setattr(filter_field, key, value)
                filter_field.save()
        return instance
 def validate(self, data):
     if 'filterfield_set' in data:
         for filter_field_data in data['filterfield_set']:
             filter_field = FilterField()
             for key, value in filter_field_data.items():
                 setattr(filter_field, key, value)
             filter_field.clean()
             filter_field_data['filter_value'] = filter_field.filter_value
     return data
Ejemplo n.º 4
0
 def validate(self, data):
     if 'filterfield_set' in data:
         for filter_field_data in data['filterfield_set']:
             filter_field = FilterField()
             for key, value in filter_field_data.items():
                 setattr(filter_field, key, value)
             filter_field.clean()
             filter_field_data['filter_value'] = filter_field.filter_value
     return data
Ejemplo n.º 5
0
def ajax_get_choices(request):
    path_verbose = request.GET.get('path_verbose')
    label = request.GET.get('label')
    root_model = request.GET.get('root_model')
    choices = FilterField().get_choices(path_verbose or root_model, label)
    select_widget = forms.Select(choices=[('', '---------')] + list(choices))
    options_html = select_widget.render_options([], [0])
    return HttpResponse(options_html)
Ejemplo n.º 6
0
    def update(self, instance, validated_data):
        displayfields_data = validated_data.pop('displayfield_set')
        filterfields_data = validated_data.pop('filterfield_set')

        with transaction.atomic():
            instance.name = validated_data.get('name', instance.name)
            instance.chart_categories = validated_data.get(
                'chart_categories', instance.chart_categories)
            instance.chart_series = validated_data.get('chart_series',
                                                       instance.chart_series)
            instance.chart_values = validated_data.get('chart_values',
                                                       instance.chart_values)
            instance.chart_type = validated_data.get('chart_type',
                                                     instance.chart_type)
            instance.chart_style = validated_data.get('chart_style',
                                                      instance.chart_style)
            instance.chart_stacked = validated_data.get(
                'chart_stacked', instance.chart_stacked)
            instance.chart_labels = validated_data.get('chart_labels',
                                                       instance.chart_labels)
            instance.chart_total = validated_data.get('chart_total',
                                                      instance.chart_total)
            instance.description = validated_data.get('description',
                                                      instance.description)
            instance.distinct = validated_data.get('distinct',
                                                   instance.distinct)
            instance.modified = datetime.date.today()
            instance.save()
            instance.displayfield_set.all().delete()
            for displayfield_data in displayfields_data:
                display_field = DisplayField()
                for key, value in displayfield_data.items():
                    setattr(display_field, key, value)
                display_field.save()
            instance.filterfield_set.all().delete()
            for filterfield_data in filterfields_data:
                filter_field = FilterField()
                for key, value in filterfield_data.items():
                    setattr(filter_field, key, value)
                filter_field.save()
        return instance
Ejemplo n.º 7
0
def ajax_get_choices(request):
    path_verbose = request.GET.get('path_verbose')
    label = request.GET.get('label')
    root_model = request.GET.get('root_model')
    app_label = request.GET.get('app_label')
    model_name = path_verbose or root_model
    model_name = model_name.split(':')[-1]
    model = ContentType.objects.get(model=model_name, app_label=app_label).model_class()
    choices = FilterField().get_choices(model, label)
    select_widget = forms.Select(choices=[('','---------')] + list(choices))
    options_html = select_widget.render_options([], [0])
    return HttpResponse(options_html)
Ejemplo n.º 8
0
    def get_query(self):
        """
        Builds the report's queryset
        :return: QuerySet Object, Error messages
        """
        report = self
        model_class = report.root_model.model_class()

        # Check for report_builder_model_manger property on the model
        if getattr(model_class, 'report_builder_model_manager', False):
            objects = getattr(model_class, 'report_builder_model_manager').all()
        else:
            # Get global model manager
            manager = get_model_manager()
            objects = getattr(model_class, manager).all()

        # Filters & exclude
        and_filters, or_filters, excludes, message = FilterField.get_report_filters(report)

        if and_filters:
            and_filters = [Q(x) for x in and_filters]
            objects = objects.filter(reduce(operator.and_, and_filters))
        if or_filters:
            or_filters = [Q(x) for x in or_filters]
            objects = objects.filter(reduce(operator.or_, or_filters))
        if excludes:
            objects = objects.exclude(**excludes)

        # Aggregates
        objects = self.add_aggregates(objects)

        # Distinct
        if report.distinct:
            objects = objects.distinct()

        return objects, message
Ejemplo n.º 9
0
    def add_filter_fields_to_report(self, report):
        """Adds default filters to the given report"""

        award_acceptance_filter = FilterField(
            report=report,
            path='awardacceptance__',
            path_verbose='awardacceptance',
            field='current_modification',
            field_verbose='current modification [BooleanField]',
            filter_type='exact',
            filter_value='True',
        )
        award_acceptance_filter.save()

        award_negotiation_filter = FilterField(
            report=report,
            path='awardnegotiation__',
            path_verbose='awardnegotiation',
            field='current_modification',
            field_verbose='current modification [BooleanField]',
            filter_type='exact',
            filter_value='True',
        )
        award_negotiation_filter.save()

        first_proposal_filter = FilterField(
            report=report,
            path='proposal__',
            path_verbose='proposal',
            field='is_first_proposal',
            field_verbose='is first proposal [BooleanField]',
            filter_type='exact',
            filter_value='True',
        )
        first_proposal_filter.save()