2009-06-19 39 views
1

OK - Python newbie here - 私は本当に馬鹿なことをしていると思います。NameError:グローバル名 'has_no_changeset'が定義されていません

私はエラー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[] 

答えて

4

あなたは現在のクラスのメソッドを参照するときに、明示的にself(または、あなたのケースで、me)を指定する必要があります。

if me.has_no_changeset(ticket): 

あなたはme代わりのselfを使用している - それは法的なのですが、強く落胆した。メンバ関数の最初のパラメータは、self

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

と呼ばれます。これは問題でした... – Epaga

関連する問題