Changeset 3334

Show
Ignore:
Timestamp:
03/10/08 22:10:45 (10 months ago)
Author:
rharkins
Message:

Dropped checkboxes and went to generic fields.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • checklistplugin/0.11/trac_checklist/db.py

    r3332 r3334  
    55from trac.core import Component, Interface, implements 
    66from trac.env import IEnvironmentSetupParticipant 
     7from datetime import datetime 
    78 
    89class IChecklistDBObserver(Interface): 
     
    1213    def checklist_getValues(context): 
    1314        "Returns a list of (value, when, who) tuples for the context passed." 
     15 
     16    def checklist_setValue(context, field, value, who): 
     17        "Adds or updates a value for the context field specified." 
    1418 
    1519class ChecklistDBComponent(Component): 
     
    4751 
    4852    def checklist_getValues(self, context): 
    49         return dict((name, (value, when, who)) 
     53        result = dict((name, (value, when, who)) 
    5054            for name, value, when, who in 
    5155            self.iterate(""" 
    52                 SELECT  field, int_value, updated_when, updater 
     56                SELECT  field, value, updated_when, updater 
    5357                FROM    checklist_value 
    5458                WHERE   context = %s 
    5559                """, context)) 
     60        self.log.debug('checklist_getValues(%r) = %r' % (context, result)) 
     61        return result 
    5662 
    5763    def checklist_setValue(self, context, field, value, who): 
    58         value = self.getValue(""" 
    59             SELECT  value 
     64        when = datetime.now().isoformat(':') 
     65        self.log.debug('checklist_setValue(%r, %r, %r, %r, %r)' % 
     66            (context, field, value, who, when)) 
     67        if self.getValue(""" 
     68            SELECT  COUNT(*) 
    6069            FROM    checklist_value 
    6170            WHERE   context = %s AND field = %s 
    62             """) 
    63         if value is None: 
     71            """, context, field): 
     72 
    6473            self.commit(""" 
    6574                UPDATE  checklist_value 
     
    105114                context         VARCHAR(255) NOT NULL, 
    106115                field           VARCHAR(255) NOT NULL, 
    107                 int_value       INTEGER NOT NULL, 
     116                value           text NOT NULL, 
    108117                updated_when    DATETIME NOT NULL, 
    109118                updater         VARCHAR(32) NOT NULL 
     
    160169 
    161170    def execute(self, sql, *params, **kw): 
    162         cursor = self.env.get_db_cnx().cursor() 
     171        self.log.debug('EXECUTING SQL:\n%s\n\t%r' % (sql, params)) 
     172        try: 
     173            cursor = self.db.cursor() 
     174        except: 
     175            self.db = self.env.get_db_cnx() 
     176            cursor = self.db.cursor() 
    163177        cursor.execute(sql, params) 
    164178        return cursor 
    165179 
    166180    def rollback(self): 
    167         self.db.cursor().rollback() 
     181        self.db.rollback() 
    168182 
    169183    def commit(self, sql=None, *params, **kw): 
    170184        if sql is not None: 
    171185            cursor = self.execute(sql, *params, **kw) 
    172         cursor.commit() 
     186        self.db.commit() 
    173187 
  • checklistplugin/0.11/trac_checklist/updater.py

    r3332 r3334  
    66 
    77import re, sys 
    8 from trac.core import * 
     8from trac.core import Component, ExtensionPoint, implements 
    99from trac.web import IRequestHandler 
    1010from genshi.builder import tag 
     11from db import IChecklistDBObserver 
    1112 
    1213class BadRequest(Exception): 
     
    2223 
    2324    __context__ : The context string to use for the fields provided. 
     25    __fields__ : The other fields to be processed. 
    2426 
    2527    All other query items are the checklist items that are turned "on".  These 
     
    4244    implements(IRequestHandler) 
    4345 
     46    clobservers = ExtensionPoint(IChecklistDBObserver) 
     47 
    4448    # IRequestHandler methods 
    4549    def match_request(self, req): 
     
    5256            if context is None: 
    5357                raise BadRequest('__context__ is required') 
     58            who = 'whoknows' 
     59            fields = args.pop('__fields__', ()) 
     60            for name in fields: 
     61                value = bool(args.get(name)) and 'on' or 'off' 
     62                self.updateField(context, name, value, who) 
    5463        except Exception, e: 
    5564            code = getattr(e, '__http_status__', 500) 
     
    6776            req.write('OK') 
    6877 
     78    def updateField(self, context, name, value, who): 
     79        # Broadcast the updates. 
     80        for observer in self.clobservers: 
     81            observer.checklist_setValue(context, name, value, who) 
     82