Пример #1
0
    def render(self):
        queryset = self.project.values.filter(snapshot=None)
        data = []

        for question in Question.objects.order_by_catalog(
                self.project.catalog):
            if question.questionset.is_collection and question.questionset.attribute:
                if question.questionset.attribute.uri.endswith('/id'):
                    set_attribute_uri = question.questionset.attribute
                else:
                    set_attribute_uri = question.questionset.attribute.uri.rstrip(
                        '/') + '/id'

                for value_set in queryset.filter(
                        attribute__uri=set_attribute_uri):
                    values = queryset.filter(attribute=question.attribute, set_index=value_set.set_index) \
                                     .order_by('set_prefix', 'set_index', 'collection_index')
                    data.append((self.stringify(question.text),
                                 self.stringify(value_set.value),
                                 self.stringify_values(values)))
            else:
                values = queryset.filter(
                    attribute=question.attribute).order_by(
                        'set_prefix', 'set_index', 'collection_index')

                data.append((self.stringify(question.text), '',
                             self.stringify_values(values)))

        return render_to_csv(self.project.title, data, self.delimiter)
Пример #2
0
    def render(self):
        data = []
        answer_sections = get_answers_tree(self.project).get('sections')
        for section in answer_sections:
            questionsets = section.get('questionsets')
            for questionset in questionsets:
                questions = questionset.get('questions')
                for question in questions:
                    text = self.stringify(question.get('text'))
                    answers = self.stringify_answers(question.get('answers'))
                    data.append((text, answers))

        return render_to_csv(self.project.title, data, self.delimiter)
Пример #3
0
 def render_to_response(self, context, **response_kwargs):
     format = self.kwargs.get('format')
     if format == 'xml':
         serializer = AttributeExportSerializer(context['attributes'],
                                                many=True)
         xml = AttributeRenderer().render(serializer.data)
         return XMLResponse(xml, name='domain')
     elif format[:3] == 'csv':
         if format == 'csvcomma':
             delimiter = ','
         else:
             delimiter = ';'
         rows = []
         for attribute in context['attributes']:
             rows.append((attribute.key, attribute.comment, attribute.uri))
         return render_to_csv(_('Domain'), rows, delimiter)
     else:
         return render_to_format(self.request, format, _('Domain'),
                                 'domain/domain_export.html', context)
Пример #4
0
    def render_to_response(self, context, **response_kwargs):

        if self.kwargs.get('format') == 'csvsemicolon':
            delimiter = ';'
        else:
            delimiter = ','

        data = []
        answer_sections = get_answers_tree(context['project']).get('sections')
        for section in answer_sections:
            questionsets = section.get('questionsets')
            for questionset in questionsets:
                questions = questionset.get('questions')
                for question in questions:
                    text = self.stringify(question.get('text'))
                    answers = self.stringify_answers(question.get('answers'))
                    data.append((text, answers))

        return render_to_csv(context['project'].title, data, delimiter)
Пример #5
0
 def render_to_response(self, context, **response_kwargs):
     format = self.kwargs.get('format')
     if format == 'xml':
         serializer = ExportSerializer(context['attributes'], many=True)
         xmldata = XMLRenderer().render(serializer.data)
         response = HttpResponse(prettify_xml(xmldata),
                                 content_type="application/xml")
         response['Content-Disposition'] = 'filename="domain.xml"'
         return response
     elif format[:3] == 'csv':
         if format == 'csvcomma':
             delimiter = ','
         else:
             delimiter = ';'
         rows = []
         for attribute in context['attributes']:
             rows.append((attribute.key, attribute.comment, attribute.uri))
         return render_to_csv(self.request, _('Domain'), rows, delimiter)
     else:
         return render_to_format(self.request, format, _('Domain'),
                                 'domain/domain_export.html', context)
Пример #6
0
 def render_to_response(self, context, **response_kwargs):
     format = self.kwargs.get('format')
     if format == 'xml':
         serializer = ExportSerializer(context['entities'], many=True)
         xmldata = XMLRenderer().render(serializer.data)
         response = HttpResponse(prettify_xml(xmldata),
                                 content_type="application/xml")
         response['Content-Disposition'] = 'filename="domain.xml"'
         return response
     elif format == 'csv':
         rows = []
         for entity in context['entities']:
             rows.append(
                 (_('Attribute') if entity.is_attribute else _('Entity'),
                  _('collection') if entity.is_collection else '',
                  entity.key, entity.comment, entity.uri,
                  entity.attribute.value_type if entity.is_attribute else
                  '', entity.attribute.unit if entity.is_attribute else ''))
         return render_to_csv(self.request, _('Domain'), rows)
     else:
         return render_to_format(self.request, format, _('Domain'),
                                 'domain/domain_export.html', context)