def filter_stream(self, req, method, filename, stream, data): """ Adds project total count information in project summary block:: Downloads: 288 """ # TODO: Make interface for the project summary box and implement it here # Filter only the summary table wiki macro if filename != 'multiproject_summary.html': return stream # Load project and followers info project = Project.get(self.env) count = ProjectDownloadEntry.total_download_count(project.id) if count == 0: return stream # Add following information into project summary block trans = Transformer('//div[@class="summary"]/table').append( tag.tr( tag.th('Downloads:'), tag.td(count) ) ) return stream | trans
def filter_stream(self, req, method, filename, stream, data): """ Adds project total count information in project summary block:: Downloads: 288 """ # TODO: Make interface for the project summary box and implement it here # Filter only the summary table wiki macro if filename != "multiproject_summary.html": return stream # Load project and followers info project = Project.get(self.env) count = ProjectDownloadEntry.total_download_count(project.id) if count == 0: return stream # Add following information into project summary block trans = Transformer('//div[@class="summary"]/table').append(tag.tr(tag.th("Downloads:"), tag.td(count))) return stream | trans
def expand_macro(self, formatter, name, content, args=None): # Parse optional arguments if args is None: args = parse_args(content) if len(args) > 1: args = args[1] files_core = FilesCoreComponent(self.env) node_factory, download_config = files_core.files_node_factory_and_config(formatter.req) if 'FILES_DOWNLOADS_VIEW' not in formatter.req.perm: return '' if name == 'FilesDownloadsCount': count = ProjectDownloadEntry.total_download_count(node_factory.project_id) return html.span(count, class_="files_downloads_count") elif name == 'FilesDownloads' or name == 'FilesDownloadsNarrow': is_narrow = True if name == 'FilesDownloads': is_narrow = False no_hide = False if args.has_key('no_hide') and args['no_hide'].lower() == 'true': no_hide = True only_featured = False if args.has_key('only_featured') and args['only_featured'].lower() == 'true': only_featured = True title = _('Featured downloads') if only_featured else _('Downloads') try: title = _(args['title']) except KeyError: title = _('Featured downloads') if only_featured else _('Downloads') except ValueError as e: title = _('Invalid title: %(reason)s', reason=str(e)) download_entries = ProjectDownloadEntry.get_all_download_entries(node_factory.project_id, only_featured=only_featured) downloads = [] user_store = None user_by_id = {} if not is_narrow: user_store = get_userstore() for download_entry in download_entries: if not is_narrow and not user_by_id.has_key(download_entry.uploader_id): user = user_store.getUserWhereId(download_entry.uploader_id) user_by_id[download_entry.uploader_id] = user # This doesn't check whether the node really exists node = MappedFileNode.from_download_entry(download_entry, node_factory) downloads.append(node) add_stylesheet(formatter.req, 'multiproject/css/files.css') add_script(formatter.req, 'multiproject/js/files.js') return Chrome(self.env).render_template(formatter.req, 'multiproject_files_wiki.html', {'downloads' : downloads, 'downloads_dir': download_config.downloads_dir, 'is_narrow': is_narrow, 'no_hide': no_hide, 'only_featured': only_featured, 'user_by_id': user_by_id, 'title': title, 'format_filename': format_filename}, 'text/html', True)