def convert_attachment(att):
    from filingcabinet.pdf_utils import convert_to_pdf
    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()
def convert_attachment(att):
    from filingcabinet.pdf_utils import convert_to_pdf
    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()