Attachment 'request_ors.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Data associated with a single Request
   4 
   5     @copyright: 2001-2003 by Jürgen Hermann <jh@web.de>
   6     @copyright: 2003-2004 by Thomas Waldmann
   7     @license: GNU GPL, see COPYING for details.
   8     ORS specific request classes    
   9 """
  10 import sys,os, mimetypes, time, urllib,shutil
  11 from MoinMoin import config, search, wikiutil
  12 from MoinMoin.Page import Page
  13 from MoinMoin.request import RequestCGI,RequestCLI
  14 from MoinMoin.util import MoinMoinNoFooter, filesys, web
  15 
  16 from MoinMoin.action import AttachFile
  17 
  18 
  19 
  20 class RequestORSCGI(RequestCGI):
  21     """
  22     specialized on CGI requests
  23     if self.ors_mod_active is 0, behaves just like RequestCGI but allows extended call syntax
  24     """
  25 
  26     def __init__(self, properties={}):
  27         RequestCGI.__init__(self, properties)
  28         self.keywords={}
  29         self.export_mode=0
  30         self.pagevars=[]
  31         self.ors_mod_active=1
  32 
  33     def exportAttachments(self,pagename):
  34         """
  35         export all attachments for page
  36         """
  37         return
  38     
  39         files=AttachFile._get_files(self, pagename)
  40         attach_dir = AttachFile.getAttachDir(self, pagename, create=1)
  41         pname = wikiutil.quoteWikinameFS(pagename)
  42         attach_dir = os.path.join(self.export_dir, pname, "attachments")
  43         if len(files)==0:
  44             return
  45         if not os.path.isdir(attach_dir): 
  46             filesys.makeDirs(attach_dir)
  47         for filename in files:
  48             if filename.endswith('.chm'):
  49                 continue
  50             fpath = AttachFile.getFilename(self, pagename, filename)
  51             tpath=os.path.join(attach_dir,filename)
  52             shutil.copyfile( fpath, tpath) 
  53 
  54 class RequestExportCLI(RequestCLI):
  55     """ specialized on export requests """
  56 
  57     def __init__(self, properties={}):
  58         RequestCLI.__init__(self, properties)
  59         self.export_mode=1
  60         self.export_dir="."
  61         self.keywords={}
  62         self.pagevars=[]
  63         self.loadTheme('modern')
  64 
  65         d = {'title_text': None, 'title_link': None, 'page': None,}
  66         self.themedict = d
  67         self.setPragma('section-numbers', '0')
  68 
  69     def getPragma(self, key, defval=None):
  70         """ Query a pragma value (#pragma processing instruction)
  71 
  72             Keys are not case-sensitive.
  73         """
  74         if key=='section-numbers':
  75             return '0'
  76         return self.pragma.get(key.lower(), defval)
  77 
  78     def http_redirect(self, url):
  79         """ Redirect to a fully qualified, or server-rooted URL """
  80         raise Exception("Redirect to #%s# not handled by exporter!" % url)
  81 
  82     def setup_args(self, form=None):
  83         args = {
  84             'action':['print'],
  85             'media':['projection'],
  86             }
  87         return args
  88 
  89     def getAttachUrl(self,pagename, filename,addts=0, escaped=0):
  90 
  91         attach_dir = AttachFile.getAttachDir(self, pagename, create=0)
  92         pname = wikiutil.quoteWikinameFS(pagename)
  93         attach_dir = os.path.join(".", pname, "attachments")
  94 
  95         url = "%s/%s" % (attach_dir,
  96             urllib.quote(filename.encode(config.charset)))
  97         return url
  98 
  99 
 100     def exportAttachments(self,pagename):
 101         """
 102         export all attachments for page
 103         """
 104         files=AttachFile._get_files(self, pagename)
 105         attach_dir = AttachFile.getAttachDir(self, pagename, create=1)
 106         pname = wikiutil.quoteWikinameFS(pagename)
 107         attach_dir = os.path.join(self.export_dir, pname, "attachments")
 108         if len(files)==0:
 109             return
 110         if not os.path.isdir(attach_dir): 
 111             filesys.makeDirs(attach_dir)
 112         for filename in files:
 113             if filename.endswith('.chm'):
 114                 continue
 115             fpath = AttachFile.getFilename(self, pagename, filename)
 116             tpath=os.path.join(attach_dir,filename)
 117             shutil.copyfile( fpath, tpath) 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-10-24 16:41:36, 3.6 KB) [[attachment:FrontPage.pdf]]
  • [get | view] (2005-10-20 23:45:56, 124.5 KB) [[attachment:SyntaxReference.doc]]
  • [get | view] (2005-10-20 23:27:53, 19.0 KB) [[attachment:moin_export.py]]
  • [get | view] (2005-10-24 14:06:32, 3.9 KB) [[attachment:request_ors.py]]
  • [get | view] (2005-10-27 14:27:18, 81.6 KB) [[attachment:text_pdf.py]]
  • [get | view] (2005-10-20 23:29:45, 66.2 KB) [[attachment:text_word.py]]
  • [get | view] (2005-11-03 17:30:17, 53.9 KB) [[attachment:wiki_word.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.