diff options
| author | ianb <devnull@localhost> | 2005-07-20 03:35:27 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-07-20 03:35:27 +0000 |
| commit | 2090d0909e990711867e8acb7ab584fa0f8b6a3c (patch) | |
| tree | 6a0df0da0f167312fdfda421648e0a73f32e5316 /examples/filebrowser/pathobj.py | |
| parent | 81a7e69742b2720381f89b356af9fb3416854b4d (diff) | |
| download | paste-2090d0909e990711867e8acb7ab584fa0f8b6a3c.tar.gz | |
Made the WYSIWYG editor more customizable; added cancel links; added delete function; added search function; added function to add new pages based on 'blank' templates
Diffstat (limited to 'examples/filebrowser/pathobj.py')
| -rw-r--r-- | examples/filebrowser/pathobj.py | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/examples/filebrowser/pathobj.py b/examples/filebrowser/pathobj.py index bee2628..aeda780 100644 --- a/examples/filebrowser/pathobj.py +++ b/examples/filebrowser/pathobj.py @@ -27,8 +27,9 @@ class PathContext(object): path_classes = {} - def __init__(self, root): + def __init__(self, root, config): self.root = root + self.config = config def path(self, path): filename = self.root + '/' + path.lstrip('/') @@ -57,6 +58,23 @@ class PathContext(object): ptype)) cls.path_classes[ptype] = path_class + def stylesheets(self): + if self.config.get('stylesheet'): + value = self.config['stylesheet'] + else: + value = [] + if isinstance(value, (str, unicode)): + value = [value] + return [self.path(p) for p in value] + + def translate_path(self, path): + possible = self.config.get('live_web_translation', {}).items() + possible.sort(lambda a, b: cmp(len(a[0]), len(b[0]))) + for source, dest in possible: + if path.startswith(source): + return dest + path[len(source):] + return None + class Path(sitepage.SitePage): extensions = ['*'] @@ -126,6 +144,12 @@ class Path(sitepage.SitePage): self.write(f.read()) f.close() + def action_delete(self): + parent = self.pathurl.up() + os.unlink(self.filename) + self.message.write('%s deleted' % self.basename) + self.redirect(parent, action='view') + def join(self, name): parts = name.split('/') for part in parts: @@ -147,6 +171,9 @@ class Path(sitepage.SitePage): new_path += name return self.pathcontext.path(new_path) + def live_url(self): + return self.pathcontext.translate_path(self.path) + bad_regexes = [ re.compile(r'<script.*?</script>', re.I+re.S), re.compile(r'style="[^"]*position:.*?"', re.I+re.S), @@ -441,6 +468,26 @@ class Dir(Path): self.message.write('Created directory %s' % dest) self.redirect(self.pathurl(dest.path, action='view')) + def action_create_from_blank(self): + tmpl = self.fields.template + filename = self.fields.filename + good = True + if not tmpl: + self.message.write('You must select a blank template') + good = False + if not filename: + self.message.write('You must give a filename') + good = False + if not good: + self.redirect(self.pathurl(action='view')) + if not os.path.splitext(filename)[1]: + filename += os.path.splitext(tmpl)[1] + source = self.pathcontext.path(tmpl) + dest = self.join(filename) + dest.write_text(source.read()) + self.message.write('%s created' % dest.basename) + self.redirect(self.pathurl(dest.path, action='edit')) + def listdir(self): result = [] for fn in os.listdir(self.filename): |
