Code Monkey home page Code Monkey logo

templated-docs's People

Contributors

alexmorozov avatar dudanogueira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

templated-docs's Issues

where is TEMPLATED_DOCS_LIBREOFFICE_PATH for MAC?

  • Templated-docs version: 0.3.1
  • Python version: 3.5
  • Operating System: osx 10.12
  • OpenOffice5.3

Description

Hi, I am trying to test this package on local mac machine. I found that it needs pylokit
from pylokit import Office
But it seems pylokit only support linux.
[https://github.com/xrmx/pylokit/blob/master/pylokit/lokit.py]

What I Did

I am trying add:
`/Applications/OpenOffice.app/Contents/program` in TEMPLATED_DOCS_LIBREOFFICE_PATH,
but there are no `TARGET_LIB = ("libsofficeapp.so", "libmergedlo.so")`,
in mac, there is only  `libsofficeapp.dylib`.
I do not know how to set TEMPLATED_DOCS_LIBREOFFICE_PATH for environment var.
Any suggestions?

pylokit.lokit.LoKitInitializeError: Failed to initialize LibreOfficeKit

  • Templated-docs version: 0.3.1
  • Python version: 3.5.2
  • Operating System: ubuntu16.04 LTS or windows10

Description

Error message:
raise LoKitInitializeError("Failed to initialize LibreOfficeKit") pylokit.lokit.LoKitInitializeError: Failed to initialize LibreOfficeKit

What I Did

I have installed  LibreOffice 5, and added some data in database
`python manage.py runserver `
after I input information, I clicked the button, then I got that error.
Why this happen? How to solve this ?

File generation works in development but times out on the server

  • Templated-docs version: 0.3.1
  • Python version: 2.7.6
  • Operating System: Ubuntu 14.04.5

Description

I can successfully generate .docx files in development (Ubuntu 16.04), but it hangs/times out on when deployed to the server (Ubuntu 14.04).
I have tried LO versions 5.1.6.2 and 5.3.2.2.
Nginx & Gunicorn timeouts are 120s. It will successfully generate the templates in 2-3 seconds on my laptop, so the timeout is not the issue. The processor is idle throughout.

Edit:
It seems I am able to create .odt files, but not .doc. or .docx on the server.

What I Did

I've added logging to every step of process and discovered that it doesn't seem to get past

https://github.com/alexmorozov/templated-docs/blob/master/templated_docs/__init__.py#L92

This would indicate a problem with LO.

On the server, I can successfully convert an .odt file to .docx with the pylokit example...

>>> import os
>>> lo_path = "/usr/lib/libreoffice/program"
>>> with Office(lo_path) as lo:
...     with lo.documentLoad("report_end_of_course.odt") as doc:
...         doc.saveAs("myNewFile.docx")


Is there anything I can try to debug this further?

Thanks

May provide corrupted document

When coding Django's tags via LibreOffice window, we are practically unable to control the way LibreOffice stores them in its messy zipped od* archive. One may happen that Django's tags are messed up with xml tags as shown below:

    <text:p text:style-name="P21">Lorem ipsum {{
        <text:span text:style-name="T12">element.el0 }</text:span>}
        <text:span text:style-name="T12">and {{ element.el1 }} and {{ element.el2 }} and </text:span>{{
        <text:span text:style-name="T12">element.eln }</text:span>}
    </text:p>

So templated-docs unzips template and Django replaces its tags with data. But how it works with markup like this }</text:span>}? Obviously, source xml will be broken and, furthermore, od* corrupted.

Maybe here is the explanation of the issue #8

I don't know if there's any way to fix the issue except programming source xml.

Issue with reflecting the same "Type" (such as int,float) in the output .xls

  • Templated-docs version: latest
  • Python version: 2.7
  • Operating System: Ubuntu 16:04 LTS

Description

I have passed a dictionary of context which I had to display in the excel.
Most of them were numbers but in the excel created as the output of templated_docs, these numbers were seen as text and I was not able to do math operations such as "SUM"

Expected result: The type of variable in the Excel as "Integer"

What I Did

No crash. The data was coming as it is exact. But only the "type" is different.

I tried making a template with default Format as "Number" still the same output is repeated

Is safe filter really supported

From docs

Django templating language is fully supported, including filters and tags.

Is that really true? At least safe filter does not seem to work?

Feature: hyperlinks

We should be able to make a certain part of a document a hyperlink. At the first glance, a custom template tag will suffice:

{% hyperlink 'http://site.com' %}
here goes a part of a document
{% endhyperlink %}

Generates corrupted file

  • Templated-docs version: 0.3.1
  • Python version: 2.7.10
  • Operating System: OSX 10.12

Description

When i generate odt from odt template that is filled with data i get
corrupted file libreoffice says:
Read-Error.
Format error discovered in the file in sub-document content.xml at 2,199655(row,col).

undefined symbol: libreofficekit_hook

  • Templated-docs version:
    templated-docs==0.3.1
  • Python version:
    Python3.4
  • Operating System:
    Ubuntu 16.04

What I Did

  • Tried to update LO (current version 5.2.6)
  • output from locate libmergedlo.so is nothing
  • tried to change path in settings.py
Traceback (most recent call last):
  File "/usr/lib/python3.4/multiprocessing/process.py", line 254, in _bootstrap
    self.run()
  File "/usr/lib/python3.4/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.4/dist-packages/templated_docs/__init__.py", line 92, in _convert_subprocess
    with Office(lo_path) as lo:
  File "/usr/local/lib/python3.4/dist-packages/pylokit/lokit.py", line 110, in __init__
    self.lokit = lo.libreofficekit_hook(six.b(lo_path))
  File "/usr/local/lib/python3.4/dist-packages/cffi/api.py", line 866, in __getattr__
    make_accessor(name)
  File "/usr/local/lib/python3.4/dist-packages/cffi/api.py", line 862, in make_accessor
    accessors[name](name)
  File "/usr/local/lib/python3.4/dist-packages/cffi/api.py", line 792, in accessor_function
    value = backendlib.load_function(BType, name)
AttributeError: function/symbol 'libreofficekit_hook' not found in library '/usr/lib/libreoffice/program/libmergedlo.so': /usr/lib/libreoffice/program/libmergedlo.so: undefined symbol: libreofficekit_hook

get_template_sources() takes 2 positional arguments but 3 were given

  • Templated-docs version:0.3.1
  • Python version: 3.7
  • Django : 2.1
  • Operating System: Debian (Docker image : python:3.7.3-stretch )

Description

Im trying to pass fill_template('dashboard/report/word/invoice.odt', context, output_format='pdf')

What I Did

def report_html_view(request,project_id):
    try :
        context = {'number':'93333333'}  # Just an example
        filename = fill_template('dashboard/report/word/invoice.odt', context, output_format='pdf')
        visible_filename = 'greeting.pdf'
    except Exception as e:
        print('Something Went Wrong.!'+ str(e))
    return FileResponse(filename, visible_filename)

Output / Error

get_template_sources() takes 2 positional arguments but 3 were given

Support of flat xml document format

Description

when trying to use a template of .fodt format, it throws error that it is not a valid zip file. Upon inspecting code, the fill_template method is written to take only zip file into consideration. I wrote code to consider both kind flat/archive formatted documents. I will create a PR with that.

image not displayed correctly in pdf

  • Templated-docs version: 0.3.1
  • Python version: 2.7.13
  • Operating System: Debian 9.0

Description

When I generate the pdf with images, in the generated PDF only a white image with a border instead of the original image appears

What I Did

VIEWS.PY
context = {}
attach = Attachment()
soup = BeautifulSoup(description)
descriptions = soup.findAll('p')
for d in descriptions:
token = str(d)[3:-4]
if token[:9] == '<img src=':
format, imgstr = token.split(';base64,')
ext = format.split('/')[-1]
data = ContentFile(base64.b64decode(imgstr), name='temp.' + ext)
attach.attach = data
attach.save()
dd.append(attach.attach)
context['dd'] = dd
filename = fill_template('invoice/invoice2.odt', context, output_format='pdf')
visible_filename = 'invoice.{}'.format('pdf')
return FileResponse(filename, visible_filename)

INVOICE2.ODT
{% load templated_docs_tags %}
{% for d in dd %}
{% image d %}
{% endfor %}

Templated-docs crashes server with exit codes 139, 77

  • Templated-docs version: 0.2.9
  • Python version: 2.7.12
  • Operating System: Ubuntu 16.04

Description

I faced a critical bug which kills Django server with exit codes 139, 77.

I have an API which handles .docx render. I will show one of views, as an example, they are pretty similar:

@permission_classes((permissions.IsAdminUser,))
class BookDocxViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
    def retrieve(self, request, *args, **kwargs):
        queryset = Pupils.objects.get(id=kwargs['pk'])
        serializer = StudentSerializer(queryset)
        context = dict(serializer.data)
        doc = fill_template('crm/docs/book.ott', context, output_format='docx')
        p = u'docs/books/%s/%s_%s_%s.doc' % (datetime.now().date(), context[u'surname'], context[u'name'], datetime.now().date())
        with open(doc, 'rb') as f:
            content = f.read()
            path = default_storage.save(p, ContentFile(content))
            f.close()
        return response.Response(u'/media/' + path)

When I call it the first time, it creates a .docx file, saves it to my default_storage and then returns me a download link. But when I try to do it again, or do it with another method (which works with another template and context), my server just crashes without any logs. The last thing I see is either

Process finished with exit code 77 if I call it with a little delay (more then one second)
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) if call my method for the second time right away (in less than one second)
I tried to use debuger -- it said that my server crashes on this line:

doc = fill_template('crm/docs/book.ott', context, output_format='docx')

I bet what happens is:

  1. When I call my method the first time templated_docs starts LibreOffice backend, and then does not stop it
  2. When I call my method the second time templated_docs tries to start LibreOffice backend again, but it is already busy.

According to this documentation, the process that used pylockt should be killed after. But we cannot kill Django server.

What I Did

I made some changes to __init__.py to add multiprocessing. Pull request is attached.

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Django 2.0.2 and python 3.5 problem

  • Templated-docs version: 0.3.1
  • Python version: 3.5
  • Operating System: ubuntu 16.04

Description

django 2.0.2

What I Did

does not generate files ... ;-/ even demo project does not work

Allow Absolute Path for Odt Models, not only from template folder.

Not really a Issue, but more a feature: Allow absolute path for template odt, as I would like to not use a template from template folder.

One might be able to get a file from a Model FileField and use it as the odt model. This may be accomplished by trying to get the template from the provided path first, if it fails, try loading from the template folder (or vice versa).

I'll try to implement this on my fork and pull request it later.

Thanks for this awesome project, by the way. Also saw a nice jabber related project of yours. I am also interested on that one as I have some solution that sends. I'll test it later against the latest Spark Server.

Support for templates from MEDIA_ROOT

  • Templated-docs version: 0.3.1
  • Python version: Python 3.6.6rc1+
  • Operating System: Debian testing (buster)

Description

I'm writing an application where users can provide there own templates, via uploading them.

What I Did

from templated_docs import fill_template
from templated_docs.http import FileResponse

template_path = "/home/.../template.odt"
context = {... my pretty context ...}
filename = fill_template(template_path, context, "pdf")
pretty_name = "my_pretty_name.pdf"
return FileResponse(filename, pretty_name)

which raises a "TemplateDoesNotExist" exception.

I could use an external app to load the template (django-dbtemplate for instance), but loading the template right from the full path should be simpler.

Thanks !

Template generation hangs after first request

  • Templated-docs version: templated-docs==0.2.10
  • Python version: 2.7.9
  • Operating System: Debian 8.0
  • Django version: 1.9.10
  • LibreOffice version: 4.3.3.2 430m0(Build:2)

Description

I'm trying to use a base case example filling a receipt with data from my database in a Django App.
Everything seems to be working as expected, no errors in the Django development server nor requests, but I only get the file the first time that I make the GET request to the method that I'm using to generate de DOCX file with my data. Then if I call this method for second time and so on, the GET remains waiting for a response from server that nevers is produced.

It's sounds to me like if the first request is not ending correctly de libreoffice proccess being used to generate the template output, but I'm just guessing.

DEBUG SERVER SAMPLE OUTPUT:

Django version 1.9.10, using settings 'extrematic.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
create libreoffice object
Uno initialized 1
initialized
[29/Sep/2016 14:13:36] "GET /expediente/398/solicitud_pago/ HTTP/1.1" 200 62645
create libreoffice object

METHOD THAT I'M USING TO PASS DATA TO TEMPLATE:

@csrf_exempt
@staff_member_required
@require_http_methods(["GET",])
def solicitud_pago(request, expediente):
  expediente = Expediente.objects.get(pk=expediente)
  servicios = Servicio.objects.filter(expediente=expediente)
  context = {'user': request.user, 'expediente': expediente, 'servicios': servicios, 'fecha': datetime.date.today() }
  filename = fill_template('solicitud_pago.odt', context, output_format='docx')
  visible_filename = 'solicitud_pago.docx'
  return FileResponse(filename, visible_filename)

Thanks in advance for your help and for all the effort building this app.

Regards,

Javier Civantos

DjangoUnicodeEncodeError when trying to get data from database

  • Templated-docs version: 0.2.9
  • Python version: 3.5.2
  • Operating System: Linux Mint 18 in VirtualBox 5.1.4

Description

I'm getting DjangoUnicodeEncodeError for no apparrent reason.

Here's the error page code: http://dpaste.com/3QBF0F7

What I Did

I'm trying to get some data from my database to a .pdf file for printing. I can't get this module to produce a pdf file at all. The django debug error site gives a hint for a .png and I can't locate any png files in my data request.

The only place I can find a mention for a png file is in the __init__.py file line 99.
data = smart_str(source.read(name)) where a variable of name has a value of Thumbnails/thumbnail.png when the site is trying to produce the aforementioned file with the data I need.

Image / ImageField not expanded correctly

  • Templated-docs version: 0.3.1
  • Python version: 2.7.x
  • Operating System: Mac OSX 10.11

Description

While trying to expand an ImageField inside a template, we don't get the image in the resulting OpenOffice file.

What I Did

we create a Django ImageField object, and insert into the context, then we expand the template (an ODS) to another ODS. Everything is expanded (variables and objects) but not the image (sort of)

What we get

we unzip the resulting ODS, we see the image tag with the link to the subdir "Pictures/<ourfile.jpg>" but there is no "Pictures/" subdir in the resulting zip file, so this to us explains why it doesn't work as expected.
We have looked at the source code of the image tag, and indeed there doesn't seem to be an instruction to write anything to the Pictures subdir.

There is something in the init.py file, that seems to write in the Pictures/ subdir but it doesn't work for us.

We are pretty ignorant of the ODT/S format, but to us it seems it could not work if there is no embedded file in the zip. Is this assumption correct? If so, could we propose a patch?

Thanks
Z

No Issue

Hello, thank you very much for your contribution, hes a great help.
how I can load a template from a model?
Example: model templates with a filefield, I need to take this file as a template
Thank you for your cooperation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.