Changeset 3334
- Timestamp:
- 03/10/08 22:10:45 (10 months ago)
- Files:
-
- checklistplugin/0.11/trac_checklist/db.py (modified) (5 diffs)
- checklistplugin/0.11/trac_checklist/updater.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
checklistplugin/0.11/trac_checklist/db.py
r3332 r3334 5 5 from trac.core import Component, Interface, implements 6 6 from trac.env import IEnvironmentSetupParticipant 7 from datetime import datetime 7 8 8 9 class IChecklistDBObserver(Interface): … … 12 13 def checklist_getValues(context): 13 14 "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." 14 18 15 19 class ChecklistDBComponent(Component): … … 47 51 48 52 def checklist_getValues(self, context): 49 re turndict((name, (value, when, who))53 result = dict((name, (value, when, who)) 50 54 for name, value, when, who in 51 55 self.iterate(""" 52 SELECT field, int_value, updated_when, updater56 SELECT field, value, updated_when, updater 53 57 FROM checklist_value 54 58 WHERE context = %s 55 59 """, context)) 60 self.log.debug('checklist_getValues(%r) = %r' % (context, result)) 61 return result 56 62 57 63 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(*) 60 69 FROM checklist_value 61 70 WHERE context = %s AND field = %s 62 """ )63 if value is None: 71 """, context, field): 72 64 73 self.commit(""" 65 74 UPDATE checklist_value … … 105 114 context VARCHAR(255) NOT NULL, 106 115 field VARCHAR(255) NOT NULL, 107 int_value INTEGERNOT NULL,116 value text NOT NULL, 108 117 updated_when DATETIME NOT NULL, 109 118 updater VARCHAR(32) NOT NULL … … 160 169 161 170 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() 163 177 cursor.execute(sql, params) 164 178 return cursor 165 179 166 180 def rollback(self): 167 self.db. cursor().rollback()181 self.db.rollback() 168 182 169 183 def commit(self, sql=None, *params, **kw): 170 184 if sql is not None: 171 185 cursor = self.execute(sql, *params, **kw) 172 cursor.commit()186 self.db.commit() 173 187 checklistplugin/0.11/trac_checklist/updater.py
r3332 r3334 6 6 7 7 import re, sys 8 from trac.core import *8 from trac.core import Component, ExtensionPoint, implements 9 9 from trac.web import IRequestHandler 10 10 from genshi.builder import tag 11 from db import IChecklistDBObserver 11 12 12 13 class BadRequest(Exception): … … 22 23 23 24 __context__ : The context string to use for the fields provided. 25 __fields__ : The other fields to be processed. 24 26 25 27 All other query items are the checklist items that are turned "on". These … … 42 44 implements(IRequestHandler) 43 45 46 clobservers = ExtensionPoint(IChecklistDBObserver) 47 44 48 # IRequestHandler methods 45 49 def match_request(self, req): … … 52 56 if context is None: 53 57 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) 54 63 except Exception, e: 55 64 code = getattr(e, '__http_status__', 500) … … 67 76 req.write('OK') 68 77 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
