Пример #1
0
def download(model, request):
    check_submitter_access(model, request)
    a_type = model.attrs['attachment_type']
    payload = model.attrs['payload']
    response = Response()
    if a_type == 'text':
        response.text = html_2_text(payload)
        response.headers['Content-Type'] = 'text/plain'
        response.headers['Content-Disposition'] = \
            'attachment;filename={0}.txt'.format(model.name)
    elif a_type == 'file':
        payload = pickle.loads(payload)
        file_data = payload['file']
        file_data.seek(0)
        response.body = file_data.read()
        response.headers['Content-Type'] = payload['mimetype']
        response.headers['Content-Disposition'] = \
            'attachment;filename={0}'.format(
                payload['filename'].encode('utf-8'))
    elif a_type == 'image':
        payload = pickle.loads(payload)
        scale = request.params.get('scale')
        filename = payload['filename']
        if scale:
            image_data = payload['scales'][scale]
            filename = '{0}_{1}.{2}'.format(
                filename[:filename.rfind('.')], scale,
                filename[filename.rfind('.') + 1:])
        else:
            image_data = payload['image']
        image_data.seek(0)
        response.body = image_data.read()
        response.headers['Content-Type'] = payload['mimetype']
        response.headers['Content-Disposition'] = \
            'attachment;filename={0}'.format(filename)
    return response
Пример #2
0
def payload_index_transform(instance, value):
    if instance.attachment_type == 'text':
        return html_2_text(value)
    return u''