Beispiel #1
0
    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)
Beispiel #2
0
    def expand_macro(self, formatter, name, content, args=None):
        class_list = ['wikiextras', 'box']
        style_list = []
        if args is None:
            content, args = parse_args(content)

        #noinspection PyArgumentList
        if not Icons(self.env).shadowless:
            class_list.append('shadow')

        class_arg = args.get('class', '')
        if class_arg:
            class_list.append(class_arg)

        align = 'right' if name in ['newsbox', 'rbox'] else \
                'center' if name=='imagebox' else ''
        align = args.get('align', align)
        if align:
            class_list.append(align)

        if name == 'newsbox':
            type = 'news'
        elif name == 'imagebox':
            type = 'image'
        else:
            type = args.get('type')
            if not type:
                for flag, value in args.iteritems():
                    if value is True:
                        type = flag
                        break
            type = self._get_type(type)
        if type in self.types:
            td = self.types[type]  # type data
            if td[1]:  #icon
                class_list += ['icon', td[1]]
            else:
                class_list.append(type)
            bg = self.urgency_bg.get(td[0])
            if bg:
                class_list.append(bg)
            del td
        elif type:
            class_list.append(type)

        style = args.get('style', '')
        if style:
            style_list.append(style)

        width = args.get('width', '')
        if width:
            if width.isdigit():
                width = '%spx' % width
            if width.endswith('px'):
                # compensate for padding
                if self._has_icon(type):
                    width = '%dpx' % (int(width[:-2]) - 57)
                else:
                    width = '%dpx' % (int(width[:-2]) - 22)
            style_list.append('width:%s' % width)

        html = format_to_html(self.env, formatter.context, content)
        class_ = ' '.join(class_list)
        style = ';'.join(style_list)

        return tag.div(html, class_=class_, style=style)
    def expand_macro(self, formatter, name, content, args=None):
        class_list = ['wikiextras', 'box']
        style_list = []
        if args is None:
            content, args = parse_args(content)

        #noinspection PyArgumentList
        if not Icons(self.env).shadowless:
            class_list.append('shadow')

        class_arg = args.get('class', '')
        if class_arg:
            class_list.append(class_arg)

        align = 'right' if name in ['newsbox', 'rbox'] else \
                'center' if name=='imagebox' else ''
        align = args.get('align', align)
        if align:
            class_list.append(align)

        if name == 'newsbox':
            type = 'news'
        elif name == 'imagebox':
            type = 'image'
        else:
            type = args.get('type')
            if not type:
                for flag, value in args.iteritems():
                    if value is True:
                        type = flag
                        break
            type = self._get_type(type)
        if type in self.types:
            td = self.types[type] # type data
            if td[1]: #icon
                class_list += ['icon', td[1]]
            else:
                class_list.append(type)
            bg = self.urgency_bg.get(td[0])
            if bg:
                class_list.append(bg)
            del td
        elif type:
            class_list.append(type)

        style = args.get('style', '')
        if style:
            style_list.append(style)

        width = args.get('width', '')
        if width:
            if width.isdigit():
                width = '%spx' % width
            if width.endswith('px'):
                # compensate for padding
                if self._has_icon(type):
                    width = '%dpx' % (int(width[:-2]) - 57)
                else:
                    width = '%dpx' % (int(width[:-2]) - 22)
            style_list.append('width:%s' % width)

        html = format_to_html(self.env, formatter.context, content)
        class_ = ' '.join(class_list)
        style = ';'.join(style_list)

        return tag.div(html, class_=class_, style=style)