Exemplo n.º 1
0
 def check_syntax(self, kind, content):
     try:
         diag.get_builder(kind)().parse_string(content)
         return True
     except:
         msg = kind + 'diag: an error occurred while parsing source text.'
         msg = html.strong(msg)
         pre = html.pre(content)
         return html.div(msg, pre)
Exemplo n.º 2
0
    def expand_macro(self, formatter, name, content):
        if name == 'ViewTopic':
            self.log.debug("Rendering ViewTopic macro...")

            # Determine topic subject
            page_name = formatter.req.path_info[6:] or 'WikiStart'
            subject = content or page_name

            # Create request context.
            context = Context.from_request(formatter.req)
            context.realm = 'discussion-wiki'

            # Get database access.
            db = self.env.get_db_cnx()
            context.cursor = db.cursor()

            # Get API object.
            api = self.env[DiscussionApi]

            # Get topic by subject
            topic = api.get_topic_by_subject(context, subject)
            self.log.debug('subject: %s' % (subject,))
            self.log.debug('topic: %s' % (topic,))

            # Prepare request and resource object.
            if topic:
                context.req.args['topic'] = topic['id']
                context.resource = Resource('discussion', 'topic/%s' % (
                  topic['id'],))

            # Process discussion request.
            template, data = api.process_discussion(context)

            # Return rendered template.
            data['discussion']['mode'] = 'message-list'
            data['discussion']['page_name'] = page_name
            if context.redirect_url:
                # Generate HTML elements for redirection.
                href = context.req.href(context.redirect_url[0]) + \
                  context.redirect_url[1]
                self.log.debug("Redirecting to %s" % (href))
                return html.div(html.strong('Redirect: '),
                  ' This page redirects to ', html.a(href, href = href),
                  html.script("window.location = '" + context.req.href(
                  'discussion', 'redirect', redirect_url = href) + "'",
                  language = "JavaScript"), class_ = "system-message")
            else:
                # Render template.
                return to_unicode(Chrome(self.env).render_template(
                  formatter.req, template, data, 'text/html', True))
        else:
            raise TracError('Not implemented macro %s' % (name))
Exemplo n.º 3
0
def render_tag_changes(old_tags, new_tags):
    old_tags = split_into_tags(old_tags or '')
    new_tags = split_into_tags(new_tags or '')
    added = sorted(new_tags - old_tags)
    added = added and \
            tagn_("%(tags)s added", "%(tags)s added",
                  len(added), tags=builder.em(', '.join(added)))
    removed = sorted(old_tags - new_tags)
    removed = removed and \
              tagn_("%(tags)s removed", "%(tags)s removed",
                    len(removed), tags=builder.em(', '.join(removed)))
    # TRANSLATOR: How to delimit added and removed tags.
    delim = added and removed and _("; ")
    return builder(builder.strong(_("Tags")), ' ', added, delim, removed)
Exemplo n.º 4
0
 def expand_macro(self, formatter, name, content):
     env = formatter.env
     req = formatter.req
     if not content:
         args = []
         kw = {}
     else:
         args, kw = parse_args(content)
     if name == 'ProjectStats':
         if 'wiki' in kw.keys():
             prefix = 'prefix' in kw.keys() and kw['prefix'] or None
             wiki = WikiSystem(env)
             if kw['wiki'] == 'count' or 'count' in args:
                 return tag(len(list(wiki.get_pages(prefix))))
     elif name == 'UserQuery':
         msg_no_perm = tag.p(tag_("(required %(perm)s missing)",
                                  perm=tag.strong('USER_VIEW')),
                             class_='hint')
         if 'perm' in kw.keys():
             perm_sys = PermissionSystem(self.env)
             users = perm_sys.get_users_with_permission(kw['perm'].upper())
         else:
             acct_mgr = AccountManager(env)
             users = list(set(acct_mgr.get_users()))
         if 'locked' in kw.keys() or 'locked' in args:
             guard = AccountGuard(env)
             locked = []
             for user in users:
                 if guard.user_locked(user):
                     locked.append(user)
             if kw.get('locked', 'True').lower() in ('true', 'yes', '1'):
                 users = locked
             else:
                 users = list(set(users) - set(locked))
         elif 'visit' in kw.keys() or 'visit' in args:
             if 'USER_VIEW' not in req.perm:
                 return msg_no_perm
             cols = []
             data = {'accounts': fetch_user_data(env, req), 'cls': 'wiki'}
             for col in ('email', 'name'):
                 if col in args:
                     cols.append(col)
             data['cols'] = cols
             return Chrome(env).render_template(req, 'user_table.html',
                                                data, 'text/html', True)
         if kw.get('format') == 'count' or 'count' in args:
             return tag(len(users))
         if 'USER_VIEW' not in req.perm:
             return msg_no_perm
         if 'email' in args or 'name' in args:
             # Replace username with full name, add email if available.
             for username, name, email in self.env.get_known_users():
                 if username in users:
                     if 'name' not in args or name is None:
                         name = username
                     if 'email' in args and email is not None:
                         email = ''.join(['<', email, '>'])
                         name = ' '.join([name, email])
                     if not username == name:
                         users.pop(users.index(username))
                         users.append(name)
         if not users and 'nomatch' in kw.keys():
             return format_to_oneliner(env, formatter.context,
                                       kw['nomatch'])
         users = sorted(users)
         if kw.get('format') == 'list':
             return tag.ul([
                 tag.li(Chrome(env).format_author(req, user))
                 for user in users
             ])
         else:
             # Default output format: comma-separated list.
             return tag(', '.join(
                 [Chrome(env).format_author(req, user) for user in users]))
Exemplo n.º 5
0
 def expand_macro(self, formatter, name, content):
     env = formatter.env
     req = formatter.req
     if not content:
         args = []
         kw = {}
     else:
         args, kw = parse_args(content)
     if name == 'ProjectStats':
         if 'wiki' in kw.keys():
             prefix = 'prefix' in kw.keys() and kw['prefix'] or None
             wiki = WikiSystem(env)
             if kw['wiki'] == 'count' or 'count' in args:
                 return tag(len(list(wiki.get_pages(prefix))))
     elif name == 'UserQuery':
         msg_no_perm = tag.p(tag_("(required %(perm)s missing)",
                                  perm=tag.strong('USER_VIEW')),
                             class_='hint')
         if 'perm' in kw.keys():
             perm_sys = PermissionSystem(self.env)
             users = perm_sys.get_users_with_permission(kw['perm'].upper())
         else:
             acct_mgr = AccountManager(env)
             users = list(set(acct_mgr.get_users()))
         if 'locked' in kw.keys() or 'locked' in args:
             guard = AccountGuard(env)
             locked = []
             for user in users:
                 if guard.user_locked(user):
                     locked.append(user)
             if kw.get('locked', 'True').lower() in ('true', 'yes', '1'):
                 users = locked
             else:
                 users = list(set(users) - set(locked))
         elif 'visit' in kw.keys() or 'visit' in args:
             if 'USER_VIEW' not in req.perm:
                 return msg_no_perm
             cols = []
             data = {'accounts': fetch_user_data(env, req), 'cls': 'wiki'}
             for col in ('email', 'name'):
                 if col in args:
                     cols.append(col)
             data['cols'] = cols
             return Chrome(env).render_template(
                 req, 'user_table.html', data, 'text/html', True)
         if kw.get('format') == 'count' or 'count' in args:
             return tag(len(users))
         if 'USER_VIEW' not in req.perm:
             return msg_no_perm
         if 'email' in args or 'name' in args:
             # Replace username with full name, add email if available.
             for username, name, email in self.env.get_known_users():
                 if username in users:
                     if 'name' not in args or name is None:
                         name = username
                     if 'email' in args and email is not None:
                         email = ''.join(['<', email, '>'])
                         name = ' '.join([name, email])
                     if not username == name:
                         users.pop(users.index(username))
                         users.append(name)
         if not users and 'nomatch' in kw.keys():
             return format_to_oneliner(env, formatter.context,
                                       kw['nomatch'])
         users = sorted(users)
         if kw.get('format') == 'list':
             return tag.ul([tag.li(Chrome(env).format_author(req, user))
                            for user in users])
         else:
             # Default output format: comma-separated list.
             return tag(', '.join([Chrome(env).format_author(req, user)
                                   for user in users]))
Exemplo n.º 6
0
 def render_groups(groups):
     return tag.ul(
         [tag.li(isinstance(elt, tuple) and 
                 tag(tag.strong(elt[0]), render_groups(elt[1])) or
                 render_one(elt, pagelangs.get(elt)))
          for elt in groups])