Example #1
0
def download_spss_labels(request, username, form_id_string):
    xform = get_object_or_404(XForm,
                              user__username__iexact=username,
                              id_string__exact=form_id_string)
    owner = User.objects.get(username__iexact=username)
    helper_auth_helper(request)

    if not has_permission(xform, owner, request, xform.shared):
        return HttpResponseForbidden('Not shared.')

    try:
        xlsform_io= xform.to_xlsform()
        if not xlsform_io:
            messages.add_message(request, messages.WARNING,
                                 _(u'No XLS file for your form '
                                   u'<strong>%(id)s</strong>')
                                 % {'id': form_id_string})
            return HttpResponseRedirect("/%s" % username)
    except:
        return HttpResponseServerError('Error retrieving XLSForm.')

    survey= survey_from.xls(filelike_obj=xlsform_io)
    zip_filename= '{}_spss_labels.zip'.format(xform.id_string)
    zip_io= survey_to_spss_label_zip(survey, xform.id_string)

    response = StreamingHttpResponse(FileWrapper(zip_io),
                                     content_type='application/zip; charset=utf-8')
    response['Content-Disposition'] = 'attachment; filename={}'.format(zip_filename)
    return response
Example #2
0
def download_spss_labels(request, username, form_id_string):
    xform = get_object_or_404(XForm,
                              user__username__iexact=username,
                              id_string__exact=form_id_string)
    owner = User.objects.get(username__iexact=username)
    helper_auth_helper(request)

    if not has_permission(xform, owner, request, xform.shared):
        return HttpResponseForbidden('Not shared.')

    try:
        xlsform_io = xform.to_xlsform()
        if not xlsform_io:
            messages.add_message(
                request, messages.WARNING,
                _(u'No XLS file for your form '
                  u'<strong>%(id)s</strong>') % {'id': form_id_string})
            return HttpResponseRedirect("/%s" % username)
    except:
        return HttpResponseServerError('Error retrieving XLSForm.')

    survey = survey_from.xls(filelike_obj=xlsform_io)
    zip_filename = '{}_spss_labels.zip'.format(xform.id_string)
    zip_io = survey_to_spss_label_zip(survey, xform.id_string)

    response = StreamingHttpResponse(
        FileWrapper(zip_io), content_type='application/zip; charset=utf-8')
    response['Content-Disposition'] = 'attachment; filename={}'.format(
        zip_filename)
    return response
Example #3
0
def download_spss_labels(request, username, form_id_string):
    xform = get_object_or_404(XForm, user__username__iexact=username, id_string__exact=form_id_string)
    xlsform_io = _get_xlsform(request, username, form_id_string)
    # FIXME: Really don't like this overloading...
    if isinstance(xlsform_io, HttpResponse):
        return xlsform_io

    survey = survey_from.xls(filelike_obj=xlsform_io)
    zip_filename = "{}_spss_labels.zip".format(xform.id_string)
    zip_io = survey_to_spss_label_zip(survey, xform.id_string)

    response = StreamingHttpResponse(FileWrapper(zip_io), content_type="application/zip; charset=utf-8")
    response["Content-Disposition"] = "attachment; filename={}".format(zip_filename)
    return response
Example #4
0
def download_spss_labels(request, username, form_id_string):
    xform = get_object_or_404(XForm,
                              user__username__iexact=username,
                              id_string__exact=form_id_string)
    xlsform_io= _get_xlsform(request, username, form_id_string)
    # FIXME: Really don't like this overloading...
    if isinstance(xlsform_io, HttpResponse):
        return xlsform_io

    survey= survey_from.xls(filelike_obj=xlsform_io)
    zip_filename= '{}_spss_labels.zip'.format(xform.id_string)
    zip_io= survey_to_spss_label_zip(survey, xform.id_string)

    response = StreamingHttpResponse(FileWrapper(zip_io),
                                     content_type='application/zip; charset=utf-8')
    response['Content-Disposition'] = 'attachment; filename={}'.format(zip_filename)
    return response