List Info

Thread: Outputting MS word-friendly format




Outputting MS word-friendly format
user name
2007-12-19 09:13:02
Like the title says, I'd like to output a word-friendly
format.
Obviously plain text is trivial, but I'd like to have a doc
or at
least rtf format. Can anyone point me in the right
direction?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Outputting MS word-friendly format
user name
2007-12-19 11:12:00
A quick google returned this:
http://pyrtf.sourceforg
e.net/

On Dec 19, 3:13 pm, "bax...gretschpages.com"
<mail.bax...gmail.com>
wrote:
> Like the title says, I'd like to output a word-friendly
format.
> Obviously plain text is trivial, but I'd like to have a
doc or at
> least rtf format. Can anyone point me in the right
direction?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Outputting MS word-friendly format
user name
2007-12-19 11:18:41
The short answer is that Django templates are format
agnostic. They
don't know anything about HTML so you can output pretty much
anything
that looks like text from a template.

But if what you are returning is *not* HTML, remember to set
the
optional 'mimetype' param to HttpResponse. For example, I
have a class
called Taconite (which works very nicely for doing AJAX via
jQuery.taconite). It returns XML, so its response method
is:
            def response(self):
                return HttpResponse(self.render(),
mimetype='application/xml')

Generating non-text-format responses is a different matter,
and it
takes you away from the in-the-box template mechanism
altogether. I
would suggest returning RTF and letting the user do their
own
conversion to whatever.

One last comment: Django's templating system is not tightly
bound to
the rest of Django (with the exception of the admin/forms
modules). As
long as a view returns an HttpResponse object, then you can
do
anything that solves your problem. That means you can create
your own
universe of templates and templating languages and still use
Django
for the overall framework. This also means it's trivial to
mix-and-
match, with each view using the templating mechanism that is
most
suited to the task.

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


Re: Outputting MS word-friendly format
country flaguser name
United States
2007-12-19 12:17:36
baxtergretschpages.com wrote:
> Thanks.. that's close, but I can't seem to get it to
work properly
> from within Django;
>
> They give an example like this:
> def MakeExample1() :
> 	doc     = Document()
> 	ss      = doc.StyleSheet
> 	section = Section()
> 	doc.Sections.append( section )
>
> 	section.append( 'A lot of useful documents can be
created '
> 					'in this way, more advance formating is available
'
> 					'but a lot of users just want to see their data
come out '
> 					'in something other than a text file.' )
> 	return doc
>
> I have:
> def rtf(request, slug):
>     release = Release.objects.get(slug=slug)
>     response =
HttpResponse(mimetype='application/rtf')
>     response['Content-Disposition'] = 'attachment;
> filename='+release.slug+'.rtf'
>
>     doc     = Document()
>     ss      = doc.StyleSheet
>     section = Section()
>     doc.Sections.append( section )
>
>     section.append( 'A lot of useful documents can be
created '
> 					'in this way, more advance formating is available
'
> 					'but a lot of users just want to see their data
come out '
> 					'in something other than a text file.' )
>     response.write(doc.Sections)
>     return response
>
> But it looks like I'm returning a list or something:
> [['A lot of useful documents can be created in this
way, more advance
> formating is available but a lot of users just want to
see their data
> come out in something other than a text file.']]
>   
The example returns doc--you are returning doc.Sections. 
Most likely
that is a list, or a list-like object.  I've never used
pyrtf, fwiw.


Cheers,
Cliff


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


Re: Outputting MS word-friendly format
user name
2007-12-19 12:25:22


On Dec 19, 6:52 pm, "bax...gretschpages.com"
<mail.bax...gmail.com>
wrote:
> Thanks.. that's close, but I can't seem to get it to
work properly
> from within Django;
>
> They give an example like this:
> def MakeExample1() :
>         doc     = Document()
>         ss      = doc.StyleSheet
>         section = Section()
>         doc.Sections.append( section )
>
>         section.append( 'A lot of useful documents can
be created '
>                                         'in this way,
more advance formating is available '
>                                         'but a lot of
users just want to see their data come out '
>                                         'in something
other than a text file.' )
>         return doc
>
> I have:
> def rtf(request, slug):
>     release = Release.objects.get(slug=slug)
>     response =
HttpResponse(mimetype='application/rtf')
>     response['Content-Disposition'] = 'attachment;
> filename='+release.slug+'.rtf'
>
>     doc     = Document()
>     ss      = doc.StyleSheet
>     section = Section()
>     doc.Sections.append( section )
>
>     section.append( 'A lot of useful documents can be
created '
>                                         'in this way,
more advance formating is available '
>                                         'but a lot of
users just want to see their data come out '
>                                         'in something
other than a text file.' )
>     response.write(doc.Sections)
>     return response
>
> But it looks like I'm returning a list or something:
> [['A lot of useful documents can be created in this
way, more advance
> formating is available but a lot of users just want to
see their data
> come out in something other than a text file.']]
>

Judging by the examples it looks like you need that Renderer
class,
e.g.:

DR = Renderer()
DR.Write(doc, response)

> On Dec 19, 11:12 am, "Jökull"
<jokullsolb...gmail.com> wrote:
>
> > A quick google returned this:http://pyrtf.sourceforg
e.net/
>
> > On Dec 19, 3:13 pm, "bax...gretschpages.com" <mail.bax...gmail.com>
> > wrote:
>
> > > Like the title says, I'd like to output a
word-friendly format.
> > > Obviously plain text is trivial, but I'd like
to have a doc or at
> > > least rtf format. Can anyone point me in the
right direction?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Outputting MS word-friendly format
user name
2007-12-19 11:52:38
Thanks.. that's close, but I can't seem to get it to work
properly
from within Django;

They give an example like this:
def MakeExample1() :
	doc     = Document()
	ss      = doc.StyleSheet
	section = Section()
	doc.Sections.append( section )

	section.append( 'A lot of useful documents can be created
'
					'in this way, more advance formating is available '
					'but a lot of users just want to see their data come
out '
					'in something other than a text file.' )
	return doc

I have:
def rtf(request, slug):
    release = Release.objects.get(slug=slug)
    response = HttpResponse(mimetype='application/rtf')
    response['Content-Disposition'] = 'attachment;
filename='+release.slug+'.rtf'

    doc     = Document()
    ss      = doc.StyleSheet
    section = Section()
    doc.Sections.append( section )

    section.append( 'A lot of useful documents can be
created '
					'in this way, more advance formating is available '
					'but a lot of users just want to see their data come
out '
					'in something other than a text file.' )
    response.write(doc.Sections)
    return response

But it looks like I'm returning a list or something:
[['A lot of useful documents can be created in this way,
more advance
formating is available but a lot of users just want to see
their data
come out in something other than a text file.']]


On Dec 19, 11:12 am, "Jökull"
<jokullsolb...gmail.com> wrote:
> A quick google returned this:http://pyrtf.sourceforg
e.net/
>
> On Dec 19, 3:13 pm, "bax...gretschpages.com"
<mail.bax...gmail.com>
> wrote:
>
> > Like the title says, I'd like to output a
word-friendly format.
> > Obviously plain text is trivial, but I'd like to
have a doc or at
> > least rtf format. Can anyone point me in the right
direction?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Outputting MS word-friendly format
user name
2007-12-19 13:26:42


> Judging by the examples it looks like you need that
Renderer class,
> e.g.:
>
> DR = Renderer()
> DR.Write(doc, response)
>
That got it. Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Outputting MS word-friendly format
user name
2007-12-20 13:14:42
Hi Baxter,

On Dec 19, 3:13 pm, "bax...gretschpages.com"
<mail.bax...gmail.com>
wrote:
> Like the title says, I'd like to output a word-friendly
format.
> Obviously plain text is trivial, but I'd like to have a
doc or at
> least rtf format. Can anyone point me in the right
direction?

I've been messing around with OOXML and came up with this:
http://code.djangopr
oject.com/wiki/NewformsHOWTO#Q:Okay.Thisisatrickyone.Notsure
ifyoullbeabletohelpbutdoyouknowhowtogenerateaDOCXorODFfilefr
omintheadmin
(http://tinyurl.com/28w3t3)

I basically render a load of XML and zip it and any binaries
into a
docx (works with odf as well, hippie).

You'll need to learn yourself some OOXML but, yu know, it's
an open
standard so you can download the specs. Editing the
templates is a
fiddle but that's why God (aka Bram Moolenaar) invented
Vim.

I've been using this method for a while and it's worked
really well
for me.

Regards,

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


[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )