Changeset 744:3a967f693570 in hatta-dev for hatta.py


Ignore:
Timestamp:
01/24/10 15:19:13 (2 years ago)
Author:
sheep@…
Branch:
default
Message:

implemet the subdirectory storage, more tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • hatta.py

    r743 r744  
    682682    """ 
    683683 
    684     # XXX Override required methods here. 
     684    periods_re = re.compile(r'^[.]|(?<=/)[.]') 
     685    slashes_re = re.compile(r'^[/]|(?<=/)[/]') 
     686 
     687    def _title_to_file(self, title): 
     688        """Modified escaping to allow slashes and spaces.""" 
     689 
     690        title = unicode(title).strip() 
     691        escaped = werkzeug.url_quote(title, safe='/ ') 
     692        path = os.path.join(self.repo_prefix, escaped) 
     693        path = self.periods_re.sub('%2E', path) 
     694        path = self.slashes_re.sub('%2F', path) 
     695        return path 
     696 
     697    def save_file(self, title, file_name, author=u'', comment=u'', parent=None): 
     698        """Make the subdirectories if needed.""" 
     699 
     700        file_path = self._file_path(title) 
     701        self._check_path(file_path) 
     702        dir_path = os.path.dirname(file_path) 
     703        try: 
     704            os.makedirs(dir_path) 
     705        except OSError: 
     706            pass 
     707        super(WikiSubdirectoryStorage, self).save_file(title, file_name, 
     708                                                       author, comment, parent) 
    685709 
    686710 
     
    19331957            comment = _(u'created') 
    19341958            rev = -1 
    1935         except werkzeug.exceptions.Forbidden: 
     1959        except werkzeug.exceptions.Forbidden, e: 
    19361960            yield werkzeug.html.p( 
    1937                 werkzeug.html(_(u"Can't edit symbolic links or directories"))) 
     1961                werkzeug.html(_(unicode(e)))) 
    19381962            return 
    19391963        if preview: 
Note: See TracChangeset for help on using the changeset viewer.