The following seems to work. The filename is the document ID (docID)
and an extention of .pdf. The first three characters of the docID are
hashed to create a directory tree.
class PdfviewController(BasePlusController):
def index(self, a, b, c, docID):
if auth:
path = os.path.join(g.pdfdocs_dir,a,b,c,docID + '.pdf')
f = open(path, 'rb')
content = f.read()
f.close()
response.headers['Content-Type'] = 'application/pdf'
return content
Thanks.
Edgar
On Jul 14, 2:35 pm, edgarsmolow <[email protected]> wrote:
> Last step is how to deliver the PDF document from the pdfview
> controller.
>
> Thanks!
> Edgar
>
> On Jul 14, 1:28 pm, kochhar <[email protected]> wrote:
>
> > edgarsmolow wrote:
> > > On Jul 14, 12:17 pm, kochhar <[email protected]> wrote:
> > >> edgarsmolow wrote:
> > >>> Our website generates PDF documents on-the-fly based upon database
> > >>> content. The user who created the document should be able to view it,
> > >>> but not other users, since the documents often contain private
> > >>> information. A web page on a Pylons site will contain link(s) to the
> > >>> user's document, where each link is an anchor element.
> > >>> Where should the documents be stored on disk: outside of the Pylons
> > >>> directory tree? If outside, configure a system variable or an Apache
> > >>> setting (alias)?
>
> > >> I'd store them on disk outside the pylons directory and add
> > >> configuration your
> > >> app for their locations.
>
> > > Excellent!
> > > One more question:
>
> > > Where / how is that configuration set up?
>
> > The config is set in the development.ini or production.ini files. Under the
> > [app:main] section, you can add another entry like:
>
> > myapp.pdfdocs_dir = /path/to/pdf/docs
>
> > Then in lib/app_globals.py store the config:
> > class Globals:
> > def __init__(self):
> > self.pdfdocs_dir = config['myapp.pdfdocs_dir']
>
> > Finally, in your pdfview controller you can access the location using,
> > g.pdfdocs_dir
>
> > >>> What is the best way to construct the anchor elements? Something like
> > >>> this (where pdfdocs is aliased)?
> > >>> <a href="/pdfdocs/ABC12345.pdf">My Special Document</a>
> > >>> Or, perhaps like this?
> > >>> <a href="/viewer.py?docid=ABC12345">My Special Document</a>
> > >>> and let viewer.py return the contents of ABC12345,pdf if the user is
> > >>> authorized to view it?
>
> > >> How about adding a pdfview controller and creating a route which maps
> > >> /pdfdocs/:docid to pdfview? Your links will look like the former but
> > >> you'll get
> > >> the functionality of the latter.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---