ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Django: using ConTeXT mkiv to output PDF
@ 2018-01-24 14:15 kaddour kardio
  2018-01-25 10:47 ` Henning Hraban Ramm
  0 siblings, 1 reply; 10+ messages in thread
From: kaddour kardio @ 2018-01-24 14:15 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 3280 bytes --]

i have a small Django app <https://bitbucket.org/kaddourkardio/kardiology> to
manage my patients data, and use LaTeX to output reports. It consists un a
*parent* model called Patients and child models Consultation , StressEcho and
so on. With LaTex this works without problems

def courrier_pdf(request, pk2, pk1):
entry = Courrier.objects.get(pk=pk2)
source = Patient.objects.get(pk=pk1)
context = dict({'courrier': entry, 'patient': source})#buffer =
BytesIO()template = get_template('courrier/courrier.tex')
rendered_tpl = template.render(context,
request).encode('utf-8')#Python3 only. For python2 check out the
docs!with tempfile.TemporaryDirectory() as tempdir:
  # Create subprocess, supress output with PIPE and
  # run latex twice to generate the TOC properly.
  # Finally read the generated pdf.
    for i in range(2):
        process = Popen(
            ['xelatex', '-output-directory', tempdir],
            stdin=PIPE,
            stdout=PIPE,
        )
        process.communicate(rendered_tpl)
    with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
        pdf = f.read()
r = HttpResponse(content_type='application/pdf')
r.write(pdf)return r

i tried with this view in order to use ConTeXT but without success

def courrier_mkiv(request, pk2, pk1):

entry = Courrier.objects.get(pk=pk2)
cource = Patient.objects.get(pk=pk1)
context = dict({'courrier': entry, 'patient': cource})# buffer =
BytesIO()template = get_template('courrier/courrier.mkiv')
rendered_tpl = template.render(context, request).encode('utf-8')with
tempfile.TemporaryDirectory() as tempdir:
    process = Popen(['context', '--result', tempdir],
                    stdin=PIPE,
                    stdout=PIPE,
                    )
    process.communicate(rendered_tpl)
    with open(os.path.join(tempdir, 'textput.pdf'), 'rb') as f:
        pdf = f.read()
r = HttpResponse(content_type='application/pdf')
r.write(pdf)return r

My feeling is that the problem is in the workspace since i get logfiles in
the root of my app Here is log file from ConTeXT:

open source     > level 1, order 1, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-yes.mkiv'
system          >
system          > ConTeXt  ver: 2018.01.04 17:37 MKIV beta  fmt:
2018.1.4  int: english/english
system          >
system          > 'cont-new.mkiv' loaded
open source     > level 2, order 2, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-new.mkiv'
close source    > level 2, order 2, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-new.mkiv'
system          > files > jobname 'tmpy82c5j7i', input
'/tmp/tmpy82c5j7i', result 'tmpy82c5j7i'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active

tex error       > tex error on line 8 in file /home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-yes.mkiv: ! I can't find file
`/tmp/tmpy82c5j7i'.

l.8 }

I tried this in my view

os.chdirw(tempdir)

just before process without success.

My guess is that ConTeXT option --result= does not behave exactly like
LaTeX's -output-directoryAny help is welcome i really need ConTeXT for my
work and this problem is driving me mad!

-- 
Dr YAHYAOUI Mohamed Kaddour, cardiologue -- Clinique KARDIA.

[-- Attachment #1.2: Type: text/html, Size: 133036 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-02-02 12:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-24 14:15 Django: using ConTeXT mkiv to output PDF kaddour kardio
2018-01-25 10:47 ` Henning Hraban Ramm
2018-01-25 13:58   ` kaddour kardio
2018-01-25 14:19     ` Hans Hagen
2018-01-26 18:41       ` kaddour kardio
2018-01-27 10:18         ` Hans Hagen
2018-01-28 17:59         ` Pablo Rodriguez
2018-01-28 23:33           ` kaddour kardio
2018-02-02 12:22             ` kaddour kardio
2018-02-02 12:49               ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).