示例#1
0
 def _render(self, formatter, cols, name_pat, size, header, limit):
     #noinspection PyArgumentList
     icon = Icons(self.env)
     icon_dir = icon.icon_location(size)[1]
     files = fnmatch.filter(os.listdir(icon_dir), '%s.png' % name_pat)
     icon_names = [os.path.splitext(p)[0] for p in files]
     if limit:
         displayed_icon_names = reduce_names(icon_names, limit)
     else:
         displayed_icon_names = icon_names
     icon_table = render_table(displayed_icon_names, cols,
                               lambda name: icon._render_icon(formatter,
                                                              name, size))
     if not len(icon_names):
         message = 'No %s icon matches %s' % (SIZE_DESCR[size], name_pat)
     elif len(icon_names) == 1:
         message = 'Showing the only %s icon matching %s' % \
                   (SIZE_DESCR[size], name_pat)
     elif len(displayed_icon_names) == len(icon_names):
         message = 'Showing all %d %s icons matching %s' % \
                   (len(icon_names), SIZE_DESCR[size], name_pat)
     else:
         message = 'Showing %d of %d %s icons matching %s' % \
                   (len(displayed_icon_names), len(icon_names),
                    SIZE_DESCR[size], name_pat)
     return tag.div(tag.p(tag.small(message)) if header else '', icon_table)
示例#2
0
 def _render(self, formatter, cols, name_pat, size, header, limit):
     #noinspection PyArgumentList
     icon = Icons(self.env)
     icon_dir = icon.icon_location(size)[1]
     files = fnmatch.filter(os.listdir(icon_dir), name_pat + '.png')
     icon_names = [os.path.splitext(p)[0] for p in files]
     if limit:
         displayed_icon_names = reduce_names(icon_names, limit)
     else:
         displayed_icon_names = icon_names
     icon_table = render_table(displayed_icon_names, cols,
                               lambda name: icon._render_icon(formatter,
                                                              name, size))
     if not len(icon_names):
         message = 'No %s icon matches %s' % (SIZE_DESCR[size], name_pat)
     elif len(icon_names) == 1:
         message = 'Showing the only %s icon matching %s' % \
                   (SIZE_DESCR[size], name_pat)
     elif len(displayed_icon_names) == len(icon_names):
         message = 'Showing all %d %s icons matching %s' % \
                   (len(icon_names), SIZE_DESCR[size], name_pat)
     else:
         message = 'Showing %d of %d %s icons matching %s' % \
                   (len(displayed_icon_names), len(icon_names),
                    SIZE_DESCR[size], name_pat)
     return tag.div(tag.p(tag.small(message)) if header else '', icon_table)
示例#3
0
    def expand_macro(self, formatter, name, content):
        prefix = limit = None
        if content:
            argv = [arg.strip() for arg in content.split(',')]
            if len(argv) > 0:
                prefix = argv[0]
                if len(argv) > 1:
                    limit = int(argv[1])

        cursor = formatter.db.cursor()

        sql = 'SELECT name, ' \
              '  max(version) AS max_version, ' \
              '  max(time) AS max_time ' \
              'FROM wiki'
        args = []
        if prefix:
            sql += ' WHERE name LIKE %s'
            args.append(prefix + '%')
        sql += ' GROUP BY name ORDER BY max_time DESC'
        if limit:
            sql += ' LIMIT %s'
            args.append(limit)
        cursor.execute(sql, args)

        entries_per_date = []
        prevdate = None
        for name, version, ts in cursor:
            if not 'WIKI_VIEW' in formatter.perm('wiki', name, version):
                continue
            time = datetime.fromtimestamp(ts, utc)
            date = format_date(time)
            if date != prevdate:
                prevdate = date
                entries_per_date.append((date, []))
            version = int(version)
            diff_href = None
            if version > 1:
                diff_href = formatter.href.wiki(name, action='diff',
                                                version=version)
            page_name = formatter.wiki.format_page_name(name)
            entries_per_date[-1][1].append((page_name, name, version,
                                            diff_href))

        return tag.div([tag.h3(date) +
                        tag.ul([tag.li(tag.a(page_name,
                                             href=formatter.href.wiki(name)),
                                       ' ',
                                       diff_href and 
                                       tag.small('(', tag.a('diff',
                                                            href=diff_href),
                                                 ')') or
                                       None)
                                for page_name, name, version, diff_href
                                in entries])
                        for date, entries in entries_per_date])
示例#4
0
    def expand_macro(self, formatter, name, content):
        args, kw = parse_args(content)
        prefix = args[0].strip() if args else None
        limit = _arg_as_int(args[1].strip(), min=1) if len(args) > 1 else None
        group = kw.get('group', 'date')

        sql = """SELECT name, max(version) AS max_version,
                        max(time) AS max_time FROM wiki"""
        args = []
        if prefix:
            with self.env.db_query as db:
                sql += " WHERE name %s" % db.prefix_match()
                args.append(db.prefix_match_value(prefix))
        sql += " GROUP BY name ORDER BY max_time DESC"
        if limit:
            sql += " LIMIT %s"
            args.append(limit)

        entries_per_date = []
        prevdate = None
        for name, version, ts in self.env.db_query(sql, args):
            if not 'WIKI_VIEW' in formatter.perm('wiki', name, version):
                continue
            req = formatter.req
            date = user_time(req, format_date, from_utimestamp(ts))
            if date != prevdate:
                prevdate = date
                entries_per_date.append((date, []))
            version = int(version)
            diff_href = None
            if version > 1:
                diff_href = formatter.href.wiki(name, action='diff',
                                                version=version)
            page_name = formatter.wiki.format_page_name(name)
            entries_per_date[-1][1].append((page_name, name, version,
                                            diff_href))

        items_per_date = (
            (date, (tag.li(tag.a(page, href=formatter.href.wiki(name)),
                           tag.small(' (', tag.a(_("diff"), href=diff_href),
                                     ')') if diff_href else None,
                           '\n')
                    for page, name, version, diff_href in entries))
            for date, entries in entries_per_date)

        if group == 'date':
            out = ((tag.h3(date), tag.ul(entries))
                   for date, entries in items_per_date)
        else:
            out = tag.ul(entries for date, entries in items_per_date)
        return tag.div(out)
示例#5
0
文件: macros.py 项目: exocad/exotrac
    def expand_macro(self, formatter, name, content):
        args, kw = parse_args(content)
        prefix = args[0].strip() if args else None
        limit = int(args[1].strip()) if len(args) > 1 else None
        group = kw.get('group', 'date')

        sql = """SELECT name, max(version) AS max_version,
                        max(time) AS max_time FROM wiki"""
        args = []
        if prefix:
            with self.env.db_query as db:
                sql += " WHERE name %s" % db.prefix_match()
                args.append(db.prefix_match_value(prefix))
        sql += " GROUP BY name ORDER BY max_time DESC"
        if limit:
            sql += " LIMIT %s"
            args.append(limit)

        entries_per_date = []
        prevdate = None
        for name, version, ts in self.env.db_query(sql, args):
            if not 'WIKI_VIEW' in formatter.perm('wiki', name, version):
                continue
            req = formatter.req
            date = user_time(req, format_date, from_utimestamp(ts))
            if date != prevdate:
                prevdate = date
                entries_per_date.append((date, []))
            version = int(version)
            diff_href = None
            if version > 1:
                diff_href = formatter.href.wiki(name, action='diff',
                                                version=version)
            page_name = formatter.wiki.format_page_name(name)
            entries_per_date[-1][1].append((page_name, name, version,
                                            diff_href))

        items_per_date = (
            (date, (tag.li(tag.a(page, href=formatter.href.wiki(name)),
                           tag.small(' (', tag.a(_("diff"), href=diff_href),
                                     ')') if diff_href else None,
                           '\n')
                    for page, name, version, diff_href in entries))
            for date, entries in entries_per_date)

        if group == 'date':
            out = ((tag.h3(date), tag.ul(entries))
                   for date, entries in items_per_date)
        else:
            out = tag.ul(entries for date, entries in items_per_date)
        return tag.div(out)
示例#6
0
    def expand_macro(self, formatter, name, content):
        prefix = limit = None
        if content:
            argv = [arg.strip() for arg in content.split(',')]
            if len(argv) > 0:
                prefix = argv[0]
                if len(argv) > 1:
                    limit = int(argv[1])

        cursor = formatter.db.cursor()

        sql = 'SELECT name, ' \
              '  max(version) AS max_version, ' \
              '  max(time) AS max_time ' \
              'FROM wiki'
        args = []
        if prefix:
            sql += ' WHERE name LIKE %s'
            args.append(prefix + '%')
        sql += ' GROUP BY name ORDER BY max_time DESC'
        if limit:
            sql += ' LIMIT %s'
            args.append(limit)
        cursor.execute(sql, args)

        entries_per_date = []
        prevdate = None
        for name, version, ts in cursor:
            if not 'WIKI_VIEW' in formatter.perm('wiki', name, version):
                continue
            date = format_date(from_utimestamp(ts))
            if date != prevdate:
                prevdate = date
                entries_per_date.append((date, []))
            version = int(version)
            diff_href = None
            if version > 1:
                diff_href = formatter.href.wiki(name, action='diff',
                                                version=version)
            page_name = formatter.wiki.format_page_name(name)
            entries_per_date[-1][1].append((page_name, name, version,
                                            diff_href))
        return tag.div(
            (tag.h3(date),
             tag.ul(
                 tag.li(tag.a(page, href=formatter.href.wiki(name)), ' ',
                        diff_href and
                        tag.small('(', tag.a('diff', href=diff_href), ')') or
                        None)
                 for page, name, version, diff_href in entries))
            for date, entries in entries_per_date)
示例#7
0
    def expand_macro(self, formatter, name, content):
        prefix = limit = None
        if content:
            argv = [arg.strip() for arg in content.split(',')]
            if len(argv) > 0:
                prefix = argv[0]
                if len(argv) > 1:
                    limit = int(argv[1])

        sql = """SELECT name, max(version) AS max_version, 
                        max(time) AS max_time FROM wiki"""
        args = []
        if prefix:
            sql += " WHERE name LIKE %s"
            args.append(prefix + '%')
        sql += " GROUP BY name ORDER BY max_time DESC"
        if limit:
            sql += " LIMIT %s"
            args.append(limit)

        entries_per_date = []
        prevdate = None
        for name, version, ts in self.env.db_query(sql, args):
            if not 'WIKI_VIEW' in formatter.perm('wiki', name, version):
                continue
            req = formatter.req
            date = user_time(req, format_date, from_utimestamp(ts))
            if date != prevdate:
                prevdate = date
                entries_per_date.append((date, []))
            version = int(version)
            diff_href = None
            if version > 1:
                diff_href = formatter.href.wiki(name, action='diff',
                                                version=version)
            page_name = formatter.wiki.format_page_name(name)
            entries_per_date[-1][1].append((page_name, name, version,
                                            diff_href))
        return tag.div(
            (tag.h3(date),
             tag.ul(
                 tag.li(tag.a(page, href=formatter.href.wiki(name)), ' ',
                        diff_href and
                        tag.small('(', tag.a('diff', href=diff_href), ')') or
                        None)
                 for page, name, version, diff_href in entries))
            for date, entries in entries_per_date)
示例#8
0
    def filter_stream(self, req, method, filename, stream, data):
        if filename == "ticket.html":
            ##Check Permissions
            enchants = self.config.get('blackmagic', 'tweaks', '')
            for field in (x.strip() for x in enchants.split(',')):
                self.env.log.debug("Checking %s:" % field)
                disabled = False
                hidden = False
                #Get a list of the permissions from the config, split them on commas and remove spaces
                perms = self.config.get('blackmagic', '%s.permission' % field, '').upper()
                #Default to not having permissions
                hasPerm = True
                if perms:
                    hasPerm = False
                    #If there are permissions
                    self.env.log.debug("perm: %s" % len(perms))
                    perms = perms.split(',')
                    #walk the list we got back and check the request for the permission
                    for perm in perms:
                        perm = perm.strip()
                        self.env.log.debug("Checking perm: %s" % perm)
                        if perm in req.perm:
                            self.env.log.debug("User has perm: %s" % perm)
                            hasPerm = True
                    if hasPerm == False:
                        denial = self.config.get('blackmagic', '%s.ondenial' % field, None)
                        if denial:
                            if denial == "disable":
                                disabled = True
                            elif denial == "hide":
                                hidden = True
                            else:
                                disabled = True
                        else:
                            disabled = True

                self.env.log.debug('hasPerm: %s' % hasPerm)
                if hidden == False:
                    if self.config.get('blackmagic', '%s.label' % field, None):
                        labelTXT = self.config.get('blackmagic', '%s.label' % field)
                        label = tag.label("%s:" %labelTXT, for_="field-%s" % field)
                        stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(label)

                if hasPerm == False:   
                    if istrue(self.config.get('blackmagic', '%s.hide' % field, None)):
                        hidden = True
                        
                    if disabled or istrue(self.config.get('blackmagic', '%s.disable' % field, False)):
                        stream = stream | Transformer('//*[@id="field-%s"]' % field).attr("disabled", "disabled")
                        label = self.config.get('blackmagic', '%s.label' % field)
                        if not label:
                            label = field.capitalize()
                        if not self.gray_disabled:
                            stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(
                                tag.strike()('%s:' % label)
                            )
                        else:
                            stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(
                                tag.span(style="color:%s" % self.gray_disabled)('%s:' % label)
                            )
                    
                    if hidden or istrue(self.config.get('blackmagic', '%s.hide' % field, None)):
                        stream = stream | Transformer('//th[@id="h_%s"]' % field).replace(" ") 
                        stream = stream | Transformer('//td[@headers="h_%s"]' % field).replace(" ")
                        stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(" ")
                        stream = stream | Transformer('//*[@id="field-%s"]' % field).replace(" ")

                    
                if hidden == False:
                    if self.config.get('blackmagic', '%s.notice' % field, None):
                        stream = stream | Transformer('//*[@id="field-%s"]' % field).after(
                            tag.br() + tag.small(class_="notice-%s" %field)(
                                tag.em()(
                                    Markup(self.config.get('blackmagic', '%s.notice' % field))
                                )
                            )
                        )
                    
                tip = self.config.get('blackmagic', '%s.tip' % field, None)
                if tip:
                    stream = stream | Transformer('//div[@id="banner"]').before(
                        tag.script(type="text/javascript", 
                        src=req.href.chrome("blackmagic", "js", "wz_tooltip.js"))()
                    )
                    
                    stream = stream | Transformer('//*[@id="field-%s"]' % field).attr(
                        "onmouseover", "Tip('%s')" % tip.replace(r"'", r"\'")
                    )
                        
                    
        return stream
示例#9
0
    def filter_stream(self, req, method, filename, stream, data):
        #remove matches from custom queries due to the fact ticket permissions are checked after this stream is manipulated so the count cannot be updated.
        if filename == "query.html":
            stream |= Transformer('//div[@class="query"]/h1/span[@class="numrows"]/text()').replace("")

        if filename == "ticket.html":
            for field,e in self.enchants.items():
                disabled = e["disable"]
                hidden = e["hide"]
                #permissions are set for field
                if e["permission"] != "" and not hidden and not (disabled or disabled and e["ondenial"]=="hide"):
                    self.env.log.debug("Permissions %s" % e["permission"])
                    #default set to denied
                    denied = True
                    #iterate through permissions
                    for perm in (x.strip() for x in e["permission"].split(',')):
                        self.env.log.debug("Checking permission %s" % perm)
                        #user has permission no denied
                        if perm and perm in req.perm(data.get("ticket").resource):
                            self.env.log.debug("Has %s permission" % perm)
                            denied = False
                    #if denied is true hide/disable dpending on denial setting
                    if denied:
                        denial = self.config.get('blackmagic', '%s.ondenial' % field, None)
                        if denial:
                            if denial == "disable":
                                disabled = True
                            elif denial == "hide":
                                hidden = True
                            else:
                                disabled = True
                        else:
                                disabled = True

                #hide fields
                if hidden:
                    #replace th and td in previews with empty tags
                    stream = stream | Transformer('//th[@id="h_%s"]' % field).replace(tag.th(" "))
                    stream = stream | Transformer('//td[@headers="h_%s"]' % field).replace(tag.td(" "))
                    #replace labels and fields with blank space
                    stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(" ")
                    stream = stream | Transformer('//*[@id="field-%s"]' % field).replace(" ")

                #change label
                if e["label"] is not None:
                    stream |= Transformer('//th[@id="h_%s"]/text()' % field).replace(e["label"] + ":")
                    stream = stream | Transformer('//label[@for="field-%s"]/text()' % field).replace(e["label"] + ":")

                if disabled:
                    buffer = StreamBuffer()
                    #copy input to buffer then disable original
                    stream |= Transformer('//*[@id="field-%s" and (@checked) and @type="checkbox"]' % field).copy(buffer).after(buffer).attr("disabled","disabled")
                    #change new element to hidden field instead of checkbox and remove check
                    stream |= Transformer('//*[@id="field-%s" and not (@disabled) and (@checked) and @type="checkbox"]' % field).attr("type","hidden").attr("checked",None).attr("id",None)
                    #disable non-check boxes / unchecked check boxes
                    stream = stream | Transformer('//*[@id="field-%s" and not (@checked)]' % field).attr("disabled", "disabled")

                    if not self.gray_disabled:
                        #cut label content into buffer then append it into the label with a strike tag around it
                        stream = stream | Transformer('//label[@for="field-%s"]/text()' % field).cut(buffer).end().select('//label[@for="field-%s"]/' % field).append(tag.strike(buffer))
                    else:
                        #cut label and replace with coloured span
                        stream = stream | Transformer('//label[@for="field-%s"]/text()' % field).cut(buffer).end().select('//label[@for="field-%s"]/' % field).append(tag.span(buffer, style="color:%s" % self.gray_disabled))

                if self.config.get('blackmagic', '%s.notice' % field, None):
                    stream = stream | Transformer('//*[@id="field-%s"]' % field).after(
                        tag.br() + tag.small()(
                            tag.em()(
                                Markup(self.config.get('blackmagic', '%s.notice' % field))
                            )
                        )
                    )

                tip = self.config.get('blackmagic', '%s.tip' % field, None)
                if tip:
                    stream = stream | Transformer('//div[@id="banner"]').before(
                        tag.script(type="text/javascript",
                        src=req.href.chrome("blackmagic", "js", "wz_tooltip.js"))()
                    )

                    stream = stream | Transformer('//*[@id="field-%s"]' % field).attr(
                        "onmouseover", "Tip('%s')" % tip.replace(r"'", r"\'")
                    )


        return stream
示例#10
0
    def filter_stream(self, req, method, filename, stream, data):
        #remove matches from custom queries due to the fact ticket permissions are checked after this stream is manipulated so the count cannot be updated.
        if filename == "query.html":
            stream |= Transformer(
                '//div[@class="query"]/h1/span[@class="numrows"]/text()'
            ).replace("")

        if filename == "ticket.html":
            for field, e in self.enchants.items():
                disabled = e["disable"]
                hidden = e["hide"]
                #permissions are set for field
                if e["permission"] != "" and not hidden and not (
                        disabled or disabled and e["ondenial"] == "hide"):
                    self.env.log.debug("Permissions %s" % e["permission"])
                    #default set to denied
                    denied = True
                    #iterate through permissions
                    for perm in (x.strip()
                                 for x in e["permission"].split(',')):
                        self.env.log.debug("Checking permission %s" % perm)
                        #user has permission no denied
                        if perm and perm in req.perm(
                                data.get("ticket").resource):
                            self.env.log.debug("Has %s permission" % perm)
                            denied = False
                    #if denied is true hide/disable dpending on denial setting
                    if denied:
                        denial = self.config.get('blackmagic',
                                                 '%s.ondenial' % field, None)
                        if denial:
                            if denial == "disable":
                                disabled = True
                            elif denial == "hide":
                                hidden = True
                            else:
                                disabled = True
                        else:
                            disabled = True

                #hide fields
                if hidden:
                    #replace th and td in previews with empty tags
                    stream = stream | Transformer(
                        '//th[@id="h_%s"]' % field).replace(tag.th(" "))
                    stream = stream | Transformer(
                        '//td[@headers="h_%s"]' % field).replace(tag.td(" "))
                    #replace labels and fields with blank space
                    stream = stream | Transformer(
                        '//label[@for="field-%s"]' % field).replace(" ")
                    stream = stream | Transformer(
                        '//*[@id="field-%s"]' % field).replace(" ")

                #change label
                if e["label"] is not None:
                    stream |= Transformer('//th[@id="h_%s"]/text()' %
                                          field).replace(e["label"] + ":")
                    stream = stream | Transformer(
                        '//label[@for="field-%s"]/text()' %
                        field).replace(e["label"] + ":")

                if disabled:
                    buffer = StreamBuffer()
                    #copy input to buffer then disable original
                    stream |= Transformer(
                        '//*[@id="field-%s" and (@checked) and @type="checkbox"]'
                        % field).copy(buffer).after(buffer).attr(
                            "disabled", "disabled")
                    #change new element to hidden field instead of checkbox and remove check
                    stream |= Transformer(
                        '//*[@id="field-%s" and not (@disabled) and (@checked) and @type="checkbox"]'
                        % field).attr("type",
                                      "hidden").attr("checked",
                                                     None).attr("id", None)
                    #disable non-check boxes / unchecked check boxes
                    stream = stream | Transformer(
                        '//*[@id="field-%s" and not (@checked)]' % field).attr(
                            "disabled", "disabled")

                    if not self.gray_disabled:
                        #cut label content into buffer then append it into the label with a strike tag around it
                        stream = stream | Transformer(
                            '//label[@for="field-%s"]/text()' %
                            field).cut(buffer).end().select(
                                '//label[@for="field-%s"]/' % field).append(
                                    tag.strike(buffer))
                    else:
                        #cut label and replace with coloured span
                        stream = stream | Transformer(
                            '//label[@for="field-%s"]/text()' %
                            field).cut(buffer).end().select(
                                '//label[@for="field-%s"]/' % field).append(
                                    tag.span(
                                        buffer,
                                        style="color:%s" % self.gray_disabled))

                if self.config.get('blackmagic', '%s.notice' % field, None):
                    stream = stream | Transformer(
                        '//*[@id="field-%s"]' % field
                    ).after(tag.br() + tag.small()(tag.em()(Markup(
                        self.config.get('blackmagic', '%s.notice' % field)))))

                tip = self.config.get('blackmagic', '%s.tip' % field, None)
                if tip:
                    stream = stream | Transformer(
                        '//div[@id="banner"]').before(
                            tag.script(type="text/javascript",
                                       src=req.href.chrome(
                                           "blackmagic", "js",
                                           "wz_tooltip.js"))())

                    stream = stream | Transformer(
                        '//*[@id="field-%s"]' % field).attr(
                            "onmouseover",
                            "Tip('%s')" % tip.replace(r"'", r"\'"))

        return stream
示例#11
0
    def filter_stream(self, req, method, filename, stream, data):
        self.log.debug('IN BlackMagic')
        if not filename == "ticket.html":
            self.log.debug('Not a ticket returning')
            return stream
        fields = self.config.getlist(csection, 'fields', [])
        self.log.debug('read enchants = %r' % fields)
        for field in fields:
            self.log.debug('starting : %s' % field)
            disabled = False
            hidden = False
            hide_summary = False
            remove = False
            perms = self.config.getlist(csection, '%s.permission' % field, [])
            self.log.debug('read permission config: %s has %s' % (field, perms))
            for (perm, denial) in [s.split(":") for s in perms] :
                perm = perm.upper()
                self.log.debug('testing permission: %s:%s should act= %s' %
                               (field, perm, (not req.perm.has_permission(perm) or perm == "ALWAYS")))
                if (not req.perm.has_permission(perm) or perm == "ALWAYS"): 
                    if denial:
                        denial = denial.lower()
                        if denial == "disable":
                            disabled = True
                        elif denial == "hide":
                            hidden = True
                        elif denial == "remove":
                            remove = True
                        else:
                            disabled = True
                    else:
                        disabled = True
                    
                if disabled or istrue(self.config.get(csection, '%s.disable' % field, False)):
                    self.log.debug('disabling: %s' % field)
                    stream = disable_field(stream, field)

                if self.config.get(csection, '%s.label' % field, None):
                    self.log.debug('labeling: %s' % field)
                    stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(
                        self.config.get(csection, '%s.label' % field)
                    )
                    
                if self.config.get(csection, '%s.notice' % field, None):
                    self.log.debug('noticing: %s' % field)
                    stream = stream | Transformer('//*[@id="field-%s"]' % field).after(
                        tag.br() + tag.small()(
                            tag.em()(
                                Markup(self.config.get(csection, '%s.notice' % field))
                            )
                        )
                    )
                    
                tip = self.config.get(csection, '%s.tip' % field, None)
                if tip:
                    self.log.debug('tipping: %s' % field)
                    stream = stream | Transformer('//div[@id="banner"]').before(
                        tag.script(type="text/javascript", 
                        src=req.href.chrome("blackmagic", "js", "wz_tooltip.js"))()
                    )
                    
                    stream = stream | Transformer('//*[@id="field-%s"]' % field).attr(
                        "onmouseover", "Tip('%s')" % tip.replace(r"'", r"\'")
                    )
                    
                if remove or istrue(self.config.get(csection, '%s.remove' % field, None)):
                    self.log.debug('removing: %s' % field)
                    stream = remove_field(stream, field)

                if hidden or istrue(self.config.get(csection, '%s.hide' % field, None)):
                    self.log.debug('hiding: %s' % field)
                    stream = hide_field(stream, field)
                    
        return stream
示例#12
0
    def filter_stream(self, req, method, filename, stream, data):
        self.log.debug('IN BlackMagic')
        if not filename == "ticket.html":
            self.log.debug('Not a ticket returning')
            return stream
        fields = self.config.getlist(csection, 'fields', [])
        self.log.debug('read enchants = %r' % fields)
        for field in fields:
            self.log.debug('starting : %s' % field)
            disabled = False
            hidden = False
            hide_summary = False
            remove = False
            perms = self.config.getlist(csection, '%s.permission' % field, [])
            self.log.debug('read permission config: %s has %s' %
                           (field, perms))
            for (perm, denial) in [s.split(":") for s in perms]:
                perm = perm.upper()
                self.log.debug(
                    'testing permission: %s:%s should act= %s' %
                    (field, perm,
                     (not req.perm.has_permission(perm) or perm == "ALWAYS")))
                if (not req.perm.has_permission(perm) or perm == "ALWAYS"):
                    if denial:
                        denial = denial.lower()
                        if denial == "disable":
                            disabled = True
                        elif denial == "hide":
                            hidden = True
                        elif denial == "remove":
                            remove = True
                        else:
                            disabled = True
                    else:
                        disabled = True

                if disabled or istrue(
                        self.config.get(csection, '%s.disable' % field,
                                        False)):
                    self.log.debug('disabling: %s' % field)
                    stream = disable_field(stream, field)

                if self.config.get(csection, '%s.label' % field, None):
                    self.log.debug('labeling: %s' % field)
                    stream = stream | Transformer(
                        '//label[@for="field-%s"]' % field).replace(
                            self.config.get(csection, '%s.label' % field))

                if self.config.get(csection, '%s.notice' % field, None):
                    self.log.debug('noticing: %s' % field)
                    stream = stream | Transformer(
                        '//*[@id="field-%s"]' %
                        field).after(tag.br() + tag.small()(tag.em()(Markup(
                            self.config.get(csection, '%s.notice' % field)))))

                tip = self.config.get(csection, '%s.tip' % field, None)
                if tip:
                    self.log.debug('tipping: %s' % field)
                    stream = stream | Transformer(
                        '//div[@id="banner"]').before(
                            tag.script(type="text/javascript",
                                       src=req.href.chrome(
                                           "blackmagic", "js",
                                           "wz_tooltip.js"))())

                    stream = stream | Transformer(
                        '//*[@id="field-%s"]' % field).attr(
                            "onmouseover",
                            "Tip('%s')" % tip.replace(r"'", r"\'"))

                if remove or istrue(
                        self.config.get(csection, '%s.remove' % field, None)):
                    self.log.debug('removing: %s' % field)
                    stream = remove_field(self, stream, field)

                if hidden or istrue(
                        self.config.get(csection, '%s.hide' % field, None)):
                    self.log.debug('hiding: %s' % field)
                    stream = hide_field(self, stream, field)

        return stream