Exemplo n.º 1
0
    def get(self, request):
        leads = Lead.objects.all()

        event = request.GET.get('event')
        if event:
            leads = leads.filter(event__pk=event)
            if not Event.objects.get(pk=event).allow(self.request.user):
                leads = Lead.objects.none()

        lead_id = request.GET.get('id')
        if lead_id:
            leads = leads.filter(pk=lead_id)

        has_entries = request.GET.get('has_entries')
        if has_entries:
            leads = leads.filter(entry__isnull=False)

        index = request.GET.get('index')
        if index:
            leads = leads[int(index):]
        count = request.GET.get('count')
        if count:
            leads = leads[:int(count)]

        data = []
        for lead in leads:
            data.append(LeadSerializer(lead).serialize())

        response = JsonResult(data=data)
        if request.GET.get('file') == '1':
            response[
                'Content-Disposition'] = 'attachment; filename="{}.json"'.format(
                    generate_filename('Leads Export'))
        return response
Exemplo n.º 2
0
    def get(self, request):
        countries = Country.objects.all()

        code = request.GET.get('code')
        if code:
            countries = countries.filter(
                Q(code=code) | Q(reference_country__code=code))

        index = request.GET.get('index')
        if index:
            countries = countries[int(index):]
        count = request.GET.get('count')
        if count:
            countries = countries[:int(count)]

        data = []
        for country in countries:
            data.append(CountrySerializer(country).serialize())

        response = JsonResult(data=data)
        if request.GET.get('file') == '1':
            response[
                'Content-Disposition'] = 'attachment; filename="{}.json"'.format(
                    generate_filename('Countries Export'))
        return response
Exemplo n.º 3
0
    def get(self, request):
        soses = SurveyOfSurvey.objects.all()

        event = request.GET.get('event')
        if event:
            soses = soses.filter(lead__event__pk=event)
            if not Event.objects.get(pk=event).allow(self.request.user):
                soses = SurveyOfSurvey.objects.none()

        sos_id = request.GET.get('id')
        if sos_id:
            soses = soses.filter(pk=sos_id)

        index = request.GET.get('index')
        if index:
            soses = soses[int(index):]
        count = request.GET.get('count')
        if count:
            soses = soses[:int(count)]

        data = []
        for sos in soses:
            data.append(SosSerializer(sos).serialize())

        response = JsonResult(data=data)
        if request.GET.get('file') == '1':
            response[
                'Content-Disposition'] = 'attachment; filename="{}.json"'.format(
                    generate_filename('Assessment Registry Export'))
        return response
Exemplo n.º 4
0
    def get(self, request):
        events = Event.get_events_for(request.user)

        event_id = request.GET.get('id')
        if event_id:
            events = events.filter(pk=event_id)

        index = request.GET.get('index')
        if index:
            events = events[int(index):]
        count = request.GET.get('count')
        if count:
            events = events[:int(count)]

        data = []
        for event in events:
            data.append(EventSerializer(event).serialize())

        response = JsonResult(data=data)
        if request.GET.get('file') == '1':
            response[
                'Content-Disposition'] = 'attachment; filename="{}.json"'.format(
                    generate_filename('Events Export'))
        return response
Exemplo n.º 5
0
    def get(self, request, event):
        # Get filtered informations from token
        informations = None
        request_data = None

        if request.GET.get('token'):
            try:
                export_token = ExportToken.objects.get(token=request.GET['token'])
                data = json.loads(export_token.data)
                informations = data['informations']
                request_data = data['post_data']
            except:
                pass

        if informations is None:
            informations = filter_informations(request.GET, Event.objects.get(pk=event)).values_list('id', flat=True)
        if request_data is None:
            request_data = dict(request.GET)

        # Excel export
        if request.GET.get('export-xls') == 'xls':
            if request.GET.get('export-format') == 'analysis-generic':
                return export_analysis_xls(generate_filename('Entries Export'), event, informations, request_data=request_data)
            else:
                return export_xls(generate_filename('Entries Export'), event, informations)

        # Docx and pdf export

        format_name = ''
        file_format = 'pdf' if (request.GET.get('export-pdf') == 'pdf') else 'docx'

        content_type = 'application/pdf' if (request.GET.get('export-pdf') == 'pdf') else\
                       'application/vnd.openxmlformats'\
                       '-officedocument.wordprocessingml.document'

        response = HttpResponse(content_type=content_type)

        if request.GET.get('export-format') == 'analysis-generic':
            format_name = 'Generic Export'
            if request.GET.get('export-pdf') == 'pdf':
                response.write(export_analysis_pdf(int(event), informations, data=request_data))
            else:
                export_analysis_docx(int(event), informations, data=request_data).save(response)

        elif request.GET.get('export-format') == 'geo':
            format_name = 'Geo Export'
            if request.GET.get('export-pdf') == 'pdf':
                response.write(export_pdf(int(event), informations, data=request_data, export_geo=True))
            else:
                export_docx(int(event), informations, data=request_data, export_geo=True).save(response)

        elif request.GET.get('export-format') == 'briefing':
            format_name = 'Briefing Note'
            if request.GET.get('export-pdf') == 'pdf':
                response.write(export_pdf_new_format(int(event), informations))
            else:
                export_docx_new_format(int(event), informations).save(response)
        else:
            format_name = 'Generic Export'
            if request.GET.get('export-pdf') == 'pdf':
                response.write(export_pdf(int(event), informations, data=request_data))
            else:
                export_docx(int(event), informations, data=request_data).save(response)

        response['Content-Disposition'] = 'attachment; filename = "{}.{}"'.format(
            generate_filename('Entries ' + format_name), file_format)

        return response
Exemplo n.º 6
0
 def get(self, request, event):
     return export_xls_weekly(generate_filename('Weekly Snapshot Export'))
Exemplo n.º 7
0
 def get(self, request, event):
     if request.GET.get('global') == '1':
         return export_xls(generate_filename('Entries Global Export'))
     else:
         return export_xls(generate_filename('Entries Export'))
Exemplo n.º 8
0
 def get(self, request):
     data, extra = ReportApiView.get_json(request.GET)
     response = JsonResult(data=data, extra=extra)
     if request.GET.get('file') == '1':
         response['Content-Disposition'] = 'attachment; filename="{}.json"'.format(generate_filename('Weekly Snapshot Export'))
     return response
Exemplo n.º 9
0
    def get(self, request):
        entries = Entry.objects.all().order_by('-created_at')

        event = request.GET.get('event')
        if event:
            entries = entries.filter(lead__event__pk=event)
            if not Event.objects.get(pk=event).allow(self.request.user):
                entries = Entry.objects.none()

        entry_id = request.GET.get('id')
        if entry_id:
            entries = entries.filter(pk=entry_id)

        index = request.GET.get('index')
        if index:
            entries = entries[int(index):]
        count = request.GET.get('count')
        if count:
            entries = entries[:int(count)]

        data = []
        for entry in entries:
            if event and entry.lead.event.entry_template:
                if entry.template:
                    data.append(TemplateEntrySerializer(entry).serialize())
            else:
                if not entry.template:
                    data.append(EntrySerializer(entry).serialize())

        # Extra requests
        extra = None
        extra_requests = request.GET.get('extra')
        if extra_requests:
            extra_requests = extra_requests.split(',')
            extra = {}

            if 'pillars' in extra_requests:
                extra['pillars'] = []
                for pillar in InformationPillar.objects.all():
                    extra['pillars'].append(PillarSerializer(pillar).serialize())

            if 'subpillars' in extra_requests:
                extra['subpillars'] = []
                for subpillar in InformationSubpillar.objects.all():
                    extra['subpillars'].append(SubpillarSerializer(subpillar).serialize())

            if 'sectors' in extra_requests:
                extra['sectors'] = []
                for sector in Sector.objects.all():
                    extra['sectors'].append(SectorSerializer(sector).serialize())

            if 'subsectors' in extra_requests:
                extra['subsectors'] = []
                for subsector in Subsector.objects.all():
                    extra['subsectors'].append(SubsectorSerializer(subsector).serialize())

        response = JsonResult(data=data, extra=extra)
        if request.GET.get('file') == '1':
            response['Content-Disposition'] = 'attachment; filename="{}.json"'.format(generate_filename('Entries Export'))
        return response