예제 #1
0
def convert_attachment(att):
    result_file = convert_to_pdf(
        att.file.path,
        binary_name=settings.FROIDE_CONFIG.get('doc_conversion_binary'),
        construct_call=settings.FROIDE_CONFIG.get('doc_conversion_call_func'))
    if result_file is None:
        return

    result_filename = os.path.basename(result_file)
    result_name, result_ext = os.path.splitext(result_filename)

    if att.converted:
        new_att = att.converted
    else:
        name, ext = os.path.splitext(att.name)
        name = _('{name}_converted{ext}').format(name=name, ext=result_ext)

        new_att = FoiAttachment(name=name,
                                belongs_to=att.belongs_to,
                                approved=False,
                                filetype='application/pdf',
                                is_converted=True)

    with open(result_file, 'rb') as f:
        new_file = File(f)
        new_att.size = new_file.size
        new_att.file.save(new_att.name, new_file)
    new_att.save()
    att.converted = new_att
    att.save()
예제 #2
0
def convert_attachment(att):
    output_bytes = convert_to_pdf(
        att.file.path,
        binary_name=settings.FROIDE_CONFIG.get('doc_conversion_binary'),
        construct_call=settings.FROIDE_CONFIG.get('doc_conversion_call_func'))
    if output_bytes is None:
        return

    if att.converted:
        new_att = att.converted
    else:
        name, ext = os.path.splitext(att.name)
        name = _('{name}_converted{ext}').format(name=name, ext='.pdf')

        new_att = FoiAttachment(name=name,
                                belongs_to=att.belongs_to,
                                approved=False,
                                filetype='application/pdf',
                                is_converted=True,
                                can_approve=att.can_approve)

    new_file = ContentFile(output_bytes)
    new_att.size = new_file.size
    new_att.file.save(new_att.name, new_file)
    new_att.save()
    att.converted = new_att
    att.can_approve = False
    att.approved = False
    att.save()
예제 #3
0
def convert_attachment(att):
    result_file = convert_to_pdf(
        att.file.path,
        binary_name=settings.FROIDE_CONFIG.get('doc_conversion_binary'),
        construct_call=settings.FROIDE_CONFIG.get('doc_conversion_call_func'))
    if result_file is None:
        return

    path, filename = os.path.split(result_file)

    if att.converted:
        new_att = att.converted
    else:
        if FoiAttachment.objects.filter(belongs_to=att.belongs_to,
                                        name=filename).exists():
            name, extension = filename.rsplit('.', 1)
            filename = '%s_converted.%s' % (name, extension)

        new_att = FoiAttachment(belongs_to=att.belongs_to,
                                approved=False,
                                filetype='application/pdf',
                                is_converted=True)

    new_att.name = filename
    with open(result_file, 'rb') as f:
        new_file = File(f)
        new_att.size = new_file.size
        new_att.file.save(filename, new_file)
    new_att.save()
    att.converted = new_att
    att.save()
예제 #4
0
파일: tasks.py 프로젝트: stefanw/froide
def convert_attachment(att):
    output_bytes = convert_to_pdf(
        att.file.path,
        binary_name=settings.FROIDE_CONFIG.get(
            'doc_conversion_binary'
        ),
        construct_call=settings.FROIDE_CONFIG.get(
            'doc_conversion_call_func'
        )
    )
    if output_bytes is None:
        return

    if att.converted:
        new_att = att.converted
    else:
        name, ext = os.path.splitext(att.name)
        name = _('{name}_converted{ext}').format(name=name, ext='.pdf')

        new_att = FoiAttachment(
            name=name,
            belongs_to=att.belongs_to,
            approved=False,
            filetype='application/pdf',
            is_converted=True,
            can_approve=att.can_approve
        )

    new_file = ContentFile(output_bytes)
    new_att.size = new_file.size
    new_att.file.save(new_att.name, new_file)
    new_att.save()
    att.converted = new_att
    att.can_approve = False
    att.approved = False
    att.save()