代码之家  ›  专栏  ›  技术社区  ›  Epaga Alex Reynolds

NameError:未定义全局名称“没有更改集”

  •  1
  • Epaga Alex Reynolds  · 技术社区  · 16 年前

    好吧,这里是Python新手,我想我正在做一些非常愚蠢的事情,你能告诉我这是什么吗,这样我们就可以继续我们的生活了?

    NameError: global name 'has_no_changeset' is not defined 在第55行(我尝试调用函数 has_no_changeset ).

    from genshi.builder import tag
    
    from trac.core import implements,Component
    from trac.ticket.api import ITicketManipulator
    from trac.ticket.default_workflow import ConfigurableTicketWorkflow
    from trac.perm import IPermissionRequestor
    from trac.config import Option, ListOption
    import re
    
    revision = "$Rev$"
    url = "$URL$"
    
    class CloseActionController(Component):
        """Support for close checking.
    
        If a ticket is closed, it is NOT allowed if ALL the following conditions apply: 
         a) ticket is 'bug' ticket
         b) resolution status is 'fixed'
         c) none of the ticket's changes include a comment containing a changeset, i.e. regex "\[\d+\]"
         d) the ticket does not have the keyword 'web'
        """
    
        implements(ITicketManipulator)
    
        # ITicketManipulator methods
    
        def prepare_ticket(req, ticket, fields, actions):
            """Not currently called, but should be provided for future
            compatibility."""
            return
    
    
        def has_no_changeset(ticket):
            db = self.env.get_db_cnx()
            cursor = db.cursor()
    
            cursor.execute("SELECT newvalue FROM ticket_change WHERE ticket=%s AND field='comment'", (str(ticket.id).encode('ascii','replace'),))
    
            for newvalue, in cursor:
                if re.search("\[\d{5,}\]", newvalue):
                    return False
    
            return True
    
        def validate_ticket(me, req, ticket):
            """Validate a ticket after it's been populated from user input.
    
            Must return a list of `(field, message)` tuples, one for each problem
            detected. `field` can be `None` to indicate an overall problem with the
    
            ticket. Therefore, a return value of `[]` means everything is OK."""
    
            if ticket['type'] == 'bug' and ticket['resolution'] == 'fixed':
              if ticket['keywords'] == None or ticket['keywords'].find('web') == -1:
                if has_no_changeset(ticket):
                  return [(None, 'You can only close a bug ticket as "fixed" if you refer to a changeset somewhere within the ticket, e.g. with [12345]!')]
    
            return[]
    
    1 回复  |  直到 16 年前
        1
  •  4
  •   RichieHindle    16 年前

    您需要明确指定 self me )当引用当前类的方法时:

    if me.has_no_changeset(ticket):
    

    你正在使用 自己 -这是合法的,但强烈反对。应该调用成员函数的第一个参数 自己

    def validate_ticket(self, req, ticket):
        # [...]
        if self.has_no_changeset(ticket):