Hi:

natebeacham: Yup, using item.category.name works fine =).

Using string interpolation on item.category also works - I was silly,
forgot to restart the gunicorn process (I suppose you have to restart
it after any changes to views.py, right? Or does it pick it up
automatically after a while?).

So between the two approaches, using item.category.name, and using
string interpolation is one preferable to the other?

Jikra: Thanks for the tip =). I did try Pisa for a bit, but for some
reason, it was just timing out when I tried to integrate it into
Django.

The reason I didn't push harder to investigate the issue was that
firstly, the command-line utility seemed to have pretty poor
performance anyway.

And secondly, Pisa itself seems to have been discontinued:

http://groups.google.com/group/xhtml2pdf/browse_thread/thread/32dcee769245fc8f

Finally, Pisa (and other approaches wkhtmltopdf) seem to require a lot
more dependencies installed/setup - reportlab is just a single package
to compile.

But  yeah, I'd still love if there was a separate template I could use
to generate the PDF. It just feels very weird building up the PDF line
by line in views.py.

Cheers,
Victor

On Nov 18, 8:14 pm, Jirka Vejrazka <[email protected]> wrote:
> Hi Victor,
>
>   It really depends on complexity of your PDF. I needed to do
> something similar some time ago and used ReportLab addon called "pisa"
> and used standard Django template language to define the PDF contents.
>
>   You might want to take a look, it worked well enough for simple PDF pages.
>
>   Cheers
>
>     Jirka
>
> On 18/11/2010, Victor Hooi <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm trying to use ReportLab to produce a PDF output for one of my
> > views.
>
> > My first question is - at the moment, I'm building up the PDF inside
> > my view. Is this really the recommended way of doing it? It's like
> > I've got presentation code inside my view (controller). Isn't there a
> > cleaner way of doing it, or going from a template to PDF somehow? (I
> > know ReportLab offers a commercial package using RML templates,
> > however I was hoping for an opensource/free method).
>
> > Second question, I have a model with several FK fields. E.g.
>
> >     class Article(models.Model):
> >         category = models.ForeignKey(Category)
> >         subject = models.ForeignKey(Subject)
>
> > Both the category and subject classes have fields called "name", and
> > __unicode__ methods defined which return name.
>
> > I'm trying to refer to these fields in my PDF output. I have a list of
> > items in article_list (i.e. queryset):
>
> >     for item in article_list:
> >         text = item.category
> >         category = Paragraph(text, styles['Heading2'])
> >         story.append(category)
>
> >         text = '%s' % item.subject
> >         subject = Paragraph(text, styles['Heading3'])
> >         story.append(subject)
>
> > When I try to run this code, I get:
>
> >     'Category' object has no attribute 'split'
>
> > and the same error with subject, obviously, once it gets to that bit
> > of the code.
>
> > Any idea why this might be, or how to fix it? Any help is much
> > appreciated.
>
> > Cheers,
> > Victor
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to