witten
/
luminotes
Archived
1
0
Fork 0

No longer hard-coding list of supported export plugins.

This commit is contained in:
Dan Helfman 2009-02-20 14:05:48 -08:00
parent e778c354d1
commit 67162b9ec8
1 changed files with 17 additions and 11 deletions

View File

@ -44,6 +44,7 @@ class Notebooks( object ):
LINK_PATTERN = re.compile( u'<a\s+((?:[^>]+\s)?href="([^"]+)"(?:\s+target="([^"]*)")?[^>]*)>(<img [^>]+>)?([^<]*)</a>', re.IGNORECASE ) LINK_PATTERN = re.compile( u'<a\s+((?:[^>]+\s)?href="([^"]+)"(?:\s+target="([^"]*)")?[^>]*)>(<img [^>]+>)?([^<]*)</a>', re.IGNORECASE )
FILE_PATTERN = re.compile( u'/files/' ) FILE_PATTERN = re.compile( u'/files/' )
NEW_FILE_PATTERN = re.compile( u'/files/new' ) NEW_FILE_PATTERN = re.compile( u'/files/new' )
EXPORT_FORMAT_PATTERN = re.compile( u"^[a-zA-Z0-9_]+$" )
""" """
Controller for dealing with notebooks and their notes, corresponding to the "/notebooks" URL. Controller for dealing with notebooks and their notes, corresponding to the "/notebooks" URL.
@ -1210,10 +1211,10 @@ class Notebooks( object ):
@rtype: unicode or generator (for streaming files) @rtype: unicode or generator (for streaming files)
@return: exported file with appropriate headers to trigger a download @return: exported file with appropriate headers to trigger a download
@raise Access_error: the current user doesn't have access to the given notebook @raise Access_error: the current user doesn't have access to the given notebook
@raise Validation_error: one of the arguments is invalid @raise Validation_error: one of the arguments is invalid or the format is unknown
""" """
if format not in ( "html", "csv" ): if not self.EXPORT_FORMAT_PATTERN.search( format ):
raise Access_error() raise Validation_error( u"format", format, Valid_string, message = u"is invalid" )
notebook = self.__users.load_notebook( user_id, notebook_id ) notebook = self.__users.load_notebook( user_id, notebook_id )
@ -1226,14 +1227,19 @@ class Notebooks( object ):
from plugins.Invoke import invoke from plugins.Invoke import invoke
return invoke( try:
plugin_type = u"export", return invoke(
plugin_name = format, plugin_type = u"export",
database = self.__database, plugin_name = format,
notebook = notebook, database = self.__database,
notes = startup_notes + other_notes, notebook = notebook,
response_headers = cherrypy.response.headerMap, notes = startup_notes + other_notes,
) response_headers = cherrypy.response.headerMap,
)
except ImportError:
import traceback
traceback.print_exc()
raise Validation_error( u"format", format, Valid_string, message = u"is unknown" )
@expose( view = Json ) @expose( view = Json )
@end_transaction @end_transaction