Пример #1
0
 def render_timeline_event(self, context, field, event):
     # Decompose event data.
     title, description, path = event[3]
     # Return apropriate content.
     if field == 'url':
         if not path:
             # method is DELETE
             return ''
         files_core = FilesCoreComponent(self.env)
         req = None
         try:
             req = context.req
         except AttributeError as e:
             pass
         download_config = files_core.files_download_config(req=req)
         node = FileSystemNode(download_config.base_path)
         node.populate_file_data(
             get_normalized_relative_path(node.base_path,
                                          path,
                                          assume_relative_path=True))
         if node.exists():
             return context.href.files(node.relative_path)
         else:
             return ""
     elif field == 'title':
         return tag(title)
     elif field == 'description':
         return tag(description)
Пример #2
0
 def render_timeline_event(self, context, field, event):
     # Decompose event data.
     title, description, path = event[3]
     # Return apropriate content.
     if field == 'url':
         if not path:
             # method is DELETE
             return ''
         files_core = FilesCoreComponent(self.env)
         req = None
         try:
             req = context.req
         except AttributeError as e:
             pass
         download_config = files_core.files_download_config(req=req)
         node = FileSystemNode(download_config.base_path)
         node.populate_file_data(get_normalized_relative_path(node.base_path, path,
             assume_relative_path=True))
         if node.exists():
             return context.href.files(node.relative_path)
         else:
             return ""
     elif field == 'title':
         return tag(title)
     elif field == 'description':
         return tag(description)
Пример #3
0
    def validate_dir(self, downloads_dir):
        if not downloads_dir:
            return ''

        try:
            downloads_dir = filesystem.get_normalized_relative_path(self.base_path,
                downloads_dir, assume_relative_path=True)
        except filesystem.InvalidFilenameOrPath:
            raise DownloadDirValidationException(_('Download dir is invalid'))

        if '/' in downloads_dir or '\\' in downloads_dir:
            raise DownloadDirValidationException(_('Download directory is invalid'))
        return downloads_dir
Пример #4
0
    def validate_dir(self, downloads_dir):
        if not downloads_dir:
            return ''

        try:
            downloads_dir = filesystem.get_normalized_relative_path(
                self.base_path, downloads_dir, assume_relative_path=True)
        except filesystem.InvalidFilenameOrPath:
            raise DownloadDirValidationException(_('Download dir is invalid'))

        if '/' in downloads_dir or '\\' in downloads_dir:
            raise DownloadDirValidationException(
                _('Download directory is invalid'))
        return downloads_dir
Пример #5
0
    def get_delete_event(self, req, download_str, dir_or_file,
                         type_to_can_view, show_downloads_events,
                         show_files_events, filename, path):
        target_path = '/' + path
        target_type = download_str
        can_view_target = type_to_can_view[target_type]
        if not can_view_target:
            return
        if target_type == 'download':
            if not show_downloads_events:
                return
            event_class = 'downloadsevent-rm'
        else:
            if not show_files_events:
                return
            event_class = 'filesevent-rm'

        parent_path = get_normalized_relative_path('base_path_not_used',
                                                   os.path.join(
                                                       target_path[1:], '..'),
                                                   assume_relative_path=True)
        if dir_or_file == 'dir':
            title = _("Directory %(filename)s deleted", filename=filename)
            description = tag_(
                "Directory %(filename)s deleted from %(target_path)s",
                filename=filename,
                target_path=tag.a(target_path,
                                  href=req.href.files(parent_path)))
        else:
            if target_type == 'download':
                title = _("Download %(filename)s deleted", filename=filename)
                description = tag_(
                    "Download %(filename)s deleted from %(target_path)s",
                    filename=filename,
                    target_path=tag.a(target_path,
                                      href=req.href.files(parent_path)))
            else:
                title = _("File %(filename)s deleted", filename=filename)
                description = tag_(
                    "File %(filename)s deleted from %(target_path)s",
                    filename=filename,
                    target_path=tag.a(target_path,
                                      href=req.href.files(parent_path)))
        return event_class, title, description
Пример #6
0
    def get_delete_event(self, req, download_str, dir_or_file, type_to_can_view,
                         show_downloads_events, show_files_events, filename, path):
        target_path = '/' + path
        target_type = download_str
        can_view_target = type_to_can_view[target_type]
        if not can_view_target:
            return
        if target_type == 'download':
            if not show_downloads_events:
                return
            event_class = 'downloadsevent-rm'
        else:
            if not show_files_events:
                return
            event_class = 'filesevent-rm'

        parent_path = get_normalized_relative_path(
            'base_path_not_used', os.path.join(target_path[1:], '..'),
            assume_relative_path=True)
        if dir_or_file == 'dir':
            title = _("Directory %(filename)s deleted", filename=filename)
            description = tag_("Directory %(filename)s deleted from %(target_path)s",
                filename=filename, target_path=tag.a(target_path,
                    href=req.href.files(parent_path)))
        else:
            if target_type == 'download':
                title = _("Download %(filename)s deleted", filename=filename)
                description = tag_("Download %(filename)s deleted from %(target_path)s",
                    filename=filename, target_path=tag.a(target_path,
                        href=req.href.files(parent_path)))
            else:
                title = _("File %(filename)s deleted", filename=filename)
                description = tag_("File %(filename)s deleted from %(target_path)s",
                    filename=filename, target_path=tag.a(target_path,
                        href=req.href.files(parent_path)))
        return event_class, title, description