Changeset 123

Show
Ignore:
Timestamp:
04/10/07 19:40:10 (2 years ago)
Author:
johnbywater
Message:

Added pending state, approval methods. Completed separation of domainmodel from kforge: added soleInstance, added database initialisation; fixed-up dm.db.util, fixed-up plugins; fixed-up tests (now running cleanly, except logger test error printing to STDOUT).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/bin/domainmodel-admin

    r29 r123  
    11#!/usr/bin/env python 
    22 
     3import os 
     4os.environ['DJANGO_SETTINGS_MODULE'] = 'dm.django.settings.main' 
     5 
    36import dm.cli.admin 
    4  
    57dm.cli.admin.UtilityRunner() 
    68 
  • trunk/src/dm/cli/admin.py

    r108 r123  
    104104        
    105105    def takeDatabaseAction(self, actionName): 
    106         raise Exception, "Method not implemented." 
     106        dbUtilClass = self.getDatabaseUtilityClass() 
     107        dbUtil = dbUtilClass() 
     108        actionMethod = getattr(dbUtil, actionName) 
     109        actionMethod() 
     110 
     111    def getDatabaseUtilityClass(self): 
     112        from dm.util.db import Database 
     113        return Database 
    107114        
    108115    def help_db(self, line=None): 
     
    246253    # lower-cased with underscore to match definition in system dictionary  
    247254    system_name = 'domainmodel' 
     255    utilityClass = AdministrationUtility 
    248256 
    249257    def __init__(self, *args, **kwds): 
  • trunk/src/dm/command/__init__.py

    r106 r123  
    33""" 
    44 
    5 from dm.ioc import * 
    6 from dm.exceptions import * 
     5from dm.command.base import * 
     6from dm.command.initialise import * 
    77 
    8 debug = RequiredFeature('Debug') 
    9  
    10 # todo: Move base class to base.pm module (create it first). 
    11 class Command(object): 
    12     """ 
    13     Command layer supertype. 
    14     'Service Layer', [Fowler, 2003] 'Command (233)' [GoF, 1995]. 
    15     """ 
    16  
    17     registry   = RequiredFeature('DomainRegistry') 
    18     dictionary = RequiredFeature('SystemDictionary') 
    19     logger     = RequiredFeature('Logger') 
    20     exceptionClass = KforgeCommandError 
    21  
    22     def __init__(self, isTransaction=False, **kwds): 
    23         self.isTransaction = isTransaction 
    24         if self.isTransaction: 
    25             self.transaction = self.registry.database.beginTransaction() 
    26         self.kwds = kwds 
    27         self.logger = RequiredFeature('Logger') 
    28  
    29     def execute(self): 
    30         if debug: 
    31             #message = "Command: "+ self.getCommandName() +" "+ str(self.kwds) 
    32             message = "Executed command: "+ self.getCommandName() 
    33             self.logger.debug(message) 
    34  
    35     def getCommandName(self): 
    36         return self.__class__.__name__ 
    37  
    38     def commitSuccess(self): 
    39         "Commit any transaction." 
    40         if self.isTransaction: 
    41             self.transaction.commit() 
    42  
    43     def raiseError(self, message): 
    44         "Raise command error exception." 
    45         if self.isTransaction: 
    46             self.transaction.rollback() 
    47         if debug: 
    48             self.logger.debug("Command error: " + message) 
    49         exceptionClass = self.exceptionClass 
    50         raise exceptionClass(message) 
    51  
    52  
    53 class MacroCommand(Command): 
    54     "Execute a sequence of commands." 
    55  
    56     def execute(self): 
    57         "Make them so." 
    58         commands = self.getCommands() 
    59         for command in commands: 
    60             command.execute() 
    61  
    62     def getCommands(self): 
    63         "List of commands." 
    64         return [] 
    65  
    66  
    67 class DomainObjectCommand(Command): 
    68  
    69     # todo: rename: objectId -> domainObjectKey 
    70  
    71     def __init__(self, typeName=None, objectId=None, objectKwds={}, **kwds): 
    72         super(DomainObjectCommand, self).__init__(**kwds) 
    73         if not typeName:  
    74             raise KforgeCommandError("No typeName parameter for %s" % str(self)) 
    75         self.typeName = typeName 
    76         self.objectId = objectId 
    77         self.objectKwds = objectKwds 
    78  
    79     def assertDomainClassRegistered(self): 
    80         if not self.registry.isDomainClassRegistered(self.typeName): 
    81             message = "Domain class not registered: %s" % self.typeName 
    82             self.raiseError(message) 
    83  
    84     def getDomainClass(self): 
    85         return self.registry.getDomainClass(self.typeName) 
    86          
    87     def createRegister(self): 
    88         self.assertDomainClassRegistered() 
    89         objectClass = self.getDomainClass() 
    90         return objectClass.createRegister() 
    91  
    92 # todo: rename following <Action>DomainObject (e.g. "Create [a] domain object!") 
    93  
    94 class DomainObjectList(DomainObjectCommand): 
    95  
    96     def __init__(self, userQuery='', startsWith='', startsWithAttributeName='', **kwds): 
    97         super(DomainObjectList, self).__init__(**kwds) 
    98         self.userQuery= userQuery 
    99         self.startsWith = startsWith 
    100         self.startsWithAttributeName = startsWithAttributeName 
    101  
    102     def execute(self): 
    103         super(DomainObjectList, self).execute() 
    104         domainObjectRegister = self.createRegister() 
    105         if self.startsWith: 
    106             if not self.startsWithAttributeName: 
    107                 self.startsWithAttributeName = domainObjectRegister.keyName 
    108             selectedDomainObjects = domainObjectRegister.startsWith( 
    109                 value=self.startsWith, 
    110                 attributeName=self.startsWithAttributeName 
    111             ) 
    112             self.results = [p for p in selectedDomainObjects] 
    113         elif self.userQuery: 
    114             selectedDomainObjects = domainObjectRegister.search( 
    115                 userQuery=self.userQuery 
    116             ) 
    117             self.results = [p for p in selectedDomainObjects] 
    118         else: 
    119             self.results = [p for p in domainObjectRegister] 
    120  
    121  
    122 class DomainObjectCreate(DomainObjectCommand): 
    123  
    124     def execute(self): 
    125         register = self.createRegister() 
    126         objectKwds = self.objectKwds 
    127         try: 
    128             if self.objectId: 
    129                 self.object = register.create(self.objectId, **objectKwds) 
    130             else: 
    131                 self.object = register.create(**objectKwds) 
    132         except KforgeDomError, inst: 
    133             message = "Can't create domain object: %s " % str(inst) 
    134             self.raiseError(message) 
    135  
    136  
    137 class DomainObjectRead(DomainObjectCommand): 
    138  
    139     def execute(self): 
    140         register = self.createRegister() 
    141         objectKwds = self.objectKwds 
    142         try: 
    143             if self.objectId: 
    144                 self.object = register.read(self.objectId, **objectKwds) 
    145             else: 
    146                 self.object = register.read(**objectKwds) 
    147         except KforgeError, inst: 
    148             self.raiseError(str(inst)) 
    149   
    150   
    151 # todo: 
    152 class DomainObjectUpdate(DomainObjectCommand): 
    153     pass 
    154  
    155  
    156 # todo: 
    157 class DomainObjectDelete(DomainObjectCommand): 
    158     pass 
    159  
  • trunk/src/dm/command/accesscontrol.py

    r108 r123  
    1 from dm.command import Command 
     1from dm.command.base import Command 
    22from dm.exceptions import * 
    33from dm.strategy import FindProtectionObject 
  • trunk/src/dm/command/captcha.py

    r2 r123  
    1 from dm.command import DomainObjectCreate 
    2 from dm.command import DomainObjectRead 
     1from dm.command.base import DomainObjectCreate 
     2from dm.command.base import DomainObjectRead 
    33 
    44class CaptchaCreate(DomainObjectCreate): 
  • trunk/src/dm/command/person.py

    r108 r123  
    1 from dm.command import * 
     1from dm.command.base import * 
    22import dm.re 
    33import re 
  • trunk/src/dm/command/plugin.py

    r2 r123  
    1 from dm.command import *  
     1from dm.command.base import *  
    22import dm.re 
    33import re 
  • trunk/src/dm/command/role.py

    r2 r123  
    11# todo: delete? 
    22 
    3 from dm.command import Command 
     3from dm.command.base import Command 
    44 
    55class RoleCommand(Command): 
  • trunk/src/dm/command/state.py

    r2 r123  
    1 from dm.command import Command 
     1from dm.command.base import Command 
    22 
    33class StateCommand(Command): 
  • trunk/src/dm/db.py

    r120 r123  
    4848debug = RequiredFeature('Debug') 
    4949logger = RequiredFeature('Logger') 
     50 
     51dbdebug = False 
    5052 
    5153class ConnectionFacade(object): 
     
    117119                else: 
    118120                    record = records 
    119             if debug: 
     121            if dbdebug and debug: 
    120122                logger.debug('Found %s record from database.' % (className)) 
    121123            return record 
     
    134136                return True 
    135137            if '__endsBefore__' in kwds: 
     138                return True 
     139            if '__dateCreatedAfter__' in kwds: 
     140                return True 
     141            if '__dateCreatedBefore__' in kwds: 
     142                return True 
     143            if '__lastModifiedAfter__' in kwds: 
     144                return True 
     145            if '__lastModifiedBefore__' in kwds: 
    136146                return True 
    137147            return False 
     
    172182            else: 
    173183                records = self.getRecordClass(className).select() 
    174             if debug: 
     184            if dbdebug and debug: 
    175185                logger.debug('Listed %s records from database.' % (className)) 
    176186            return records 
     
    605615            self.domainObject = obj  
    606616            self.domainObject.record = self 
    607             if debug: 
     617            if dbdebug and debug: 
    608618                message = "Record returned newly instantiated %s." % self.getClassName() 
    609619                logger.debug(message) 
     
    612622            if not self.isCached(): 
    613623                if not self.domainObject in loadedList: 
    614                     if debug: 
     624                    if dbdebug and debug: 
    615625                        message = "Record loads existing %s instance with values." % self.getClassName() 
    616626                        logger.debug(message) 
    617627                    self.loadDomainObject(loadedList) 
    618628                else: 
    619                     if debug: 
     629                    if dbdebug and debug: 
    620630                        message = "Loaded %s record avoids loading loop." % self.getClassName() 
    621631                        logger.debug(message) 
    622632            else:  
    623                 if debug: 
     633                if dbdebug and debug: 
    624634                    message = "Record returned %s with existing values." % self.getClassName() 
    625635                    logger.debug(message) 
     
    629639        "Creates recorded domain object." 
    630640        domainClass = self.getDomainClass() 
    631         if debug: 
     641        if dbdebug and debug: 
    632642            message = "Instantiating domain object from: %s" % domainClass 
    633643            logger.debug(message) 
     
    647657        "Maps values from record to domain object." 
    648658        if sync: 
    649             if debug: 
     659            if dbdebug and debug: 
    650660                message = "Synchronising mapper values with RDBMS." 
    651661                logger.debug(message) 
    652662            self.sync() 
    653663        elif sync: 
    654             if debug: 
     664            if dbdebug and debug: 
    655665                message = "Not synchronising mapper values with RDBMS." 
    656666                logger.debug(message) 
    657         if debug: 
     667        if dbdebug and debug: 
    658668            message = "Loading domain object values from mapper." 
    659669            logger.debug(message) 
     
    709719                    isChanged = True 
    710720        if isChanged: 
    711             if debug: 
     721            if dbdebug and debug: 
    712722                message = "Updating RDBMS with %s mapper value." % ( 
    713723                    self.meta.domName 
     
    863873                ) 
    864874                sqlEqualsList.append(sqlEquals) 
     875            elif name == '__dateCreatedBefore__': 
     876                sqlSafeName = self.makeSqlName('date_created') 
     877                sqlEquals = "%s < %s" % ( 
     878                    sqlSafeName, sqlSafeValue 
     879                ) 
     880                sqlEqualsList.append(sqlEquals) 
     881            elif name == '__dateCreatedAfter__': 
     882                sqlSafeName = self.makeSqlName('date_created') 
     883                sqlEquals = "%s > %s" % ( 
     884                    sqlSafeName, sqlSafeValue 
     885                ) 
     886                sqlEqualsList.append(sqlEquals) 
     887            elif name == '__lastModifiedBefore__': 
     888                sqlSafeName = self.makeSqlName('last_modified') 
     889                sqlEquals = "%s < %s" % ( 
     890                    sqlSafeName, sqlSafeValue 
     891                ) 
     892                sqlEqualsList.append(sqlEquals) 
     893            elif name == '__lastModifiedAfter__': 
     894                sqlSafeName = self.makeSqlName('last_modified') 
     895                sqlEquals = "%s > %s" % ( 
     896                    sqlSafeName, sqlSafeValue 
     897                ) 
     898                sqlEqualsList.append(sqlEquals) 
    865899            else: 
    866900                sqlSafeName = self.makeSqlName(name) 
  • trunk/src/dm/dictionary.py

    r113 r123  
    5151        self[TIMEZONE]            = '' 
    5252        self[SKIP_EMAIL_SENDING]  = '' 
     53        self[WWW_PORT]            = '80' 
    5354 
    5455    def makeConfigFilePath(self): 
  • trunk/src/dm/dictionarywords.py

    r120 r123  
    2323LOG_PATH   = 'logging.log_file' 
    2424LOG_LEVEL  = 'logging.level' 
     25DOMAIN_NAME = 'domain_name' 
    2526AUTH_COOKIE_NAME = 'auth_cookie_name' 
    2627NO_AUTH_COOKIE_NAME = 'no_auth_cookie_name' 
     
    2930TIMEZONE = 'environ.tz' 
    3031SKIP_EMAIL_SENDING = 'skip_email_sending' 
     32WWW_PORT = 'www.port' 
    3133 
  • trunk/src/dm/dom/base.py

    r116 r123  
    55 
    66debug = RequiredFeature('Debug') 
     7domdebug = False 
    78 
    89class DomainBase(object): 
     
    7172        if self.isCached: 
    7273            if key in self.cache: 
    73                 if debug: 
     74                if domdebug and debug: 
    7475                    message = "Cache hit for key: '%s'" % key 
    7576                    self.log.debug(message) 
    7677                return self.readCache(key) 
    7778            else: 
    78                 if debug: 
     79                if domdebug and debug: 
    7980                    message = "Cache miss for key: '%s'" % key 
    8081                    self.log.debug(message) 
    81         if debug: 
     82        if domdebug and debug: 
    8283            message = "Retrieving from %s record for key: '%s'" % (self, key) 
    8384            if message == 'WeekEarmarkTemplate': 
     
    615616        self.log.info(message) 
    616617 
     618    def raiseApprove(self): 
     619        "Raises onApprove event." 
     620        self.onApprove() 
     621        message = "Approved %s: '%s'" % ( 
     622            self.__class__.__name__, 
     623            self.getRegisterKeyValue() 
     624        ) 
     625        self.log.info(message) 
     626 
    617627    def raiseUndelete(self): 
    618628        "Raises onUndelete event." 
     
    625635 
    626636    def raisePurge(self): 
    627         "Raises onDelete event." 
     637        "Raises onPurge event." 
    628638        self.onPurge() 
    629639 
     
    639649        "Abstract handler for Delete object event." 
    640650        self.notifyPlugins(self.__class__.__name__ + 'Delete', self) 
     651     
     652    def onApprove(self): 
     653        "Abstract handler for Approve object event." 
     654        self.notifyPlugins(self.__class__.__name__ + 'Approve', self) 
    641655     
    642656    def onUndelete(self): 
     
    668682        if not('startsWithAttributeName' in kwds and kwds['startsWithAttributeName']): 
    669683            kwds['startsWithAttributeName'] = self.startsWithAttributeName 
    670         if debug: 
     684        if domdebug and debug: 
    671685            className = self.registerClass.__name__ 
    672686            message = "Creating '%s' register with kwds: %s" % (className, kwds) 
  • trunk/src/dm/dom/meta.py

    r114 r123  
    442442        choices = [] 
    443443        associateRegister = self.getAssociatedObjectRegister(domainObject) 
    444         for associateObject in associateRegister.getSortedList(): 
     444        objectList = [] 
     445        if associateRegister != []: 
     446            objectList = associateRegister.getSortedList() 
     447        for associateObject in objectList: 
    445448            key = associateRegister.getRegisterKey(associateObject) 
    446449            if self.isKeyDomainObject(): 
  • trunk/src/dm/dom/plugin.py

    r45 r123  
    99    "Registered plugin." 
    1010 
     11    # todo: move down to KForge's definition of a plugin 
    1112    services = HasManyPages('Service', 'name', 'project', pageKeys=getProjects)  
    1213     
  • trunk/src/dm/dom/state.py

    r106 r123  
    1616        self.getBehaviour().deleteObject(object) 
    1717 
     18    def approveObject(self, object): 
     19        self.getBehaviour().approveObject(object) 
     20 
    1821    def undeleteObject(self, object): 
    1922        self.getBehaviour().undeleteObject(object) 
     
    2730     
    2831        def deleteObject(self, object): 
     32            pass 
     33             
     34        def approveObject(self, object): 
    2935            pass 
    3036             
     
    6369            object.destroySelf() 
    6470 
    65  
    66  
     71    class PendingBehaviour(AbstractStateBehaviour): 
     72     
     73        def approveObject(self, object): 
     74            object.decacheItem() 
     75            object.state = self.states['active'] 
     76            object.save() 
     77            object.raiseApprove() 
     78     
     79        def deleteObject(self, object): 
     80            object.deleteAggregates() 
     81            object.raiseDelete() 
     82            object.decacheItem() 
     83            object.state = self.states['deleted'] 
     84            object.save() 
     85             
     86        def purgeObject(self, object): 
     87            message = 'A pending object cannot be purged: %s' % str(object) 
     88            raise dm.exceptions.KforgeDomError(message)  
     89     
    6790    def getBehaviour(self): 
    6891        if not self.behaviour: 
  • trunk/src/dm/dom/stateful.py

    r106 r123  
    5252        if isCompoundingRegister: 
    5353            registerClass = self.__class__ 
    54             self.deleted = registerClass(typeName, isCompoundingRegister=False, **kwds) 
     54            self.pending = registerClass( 
     55                typeName, isCompoundingRegister=False, **kwds) 
     56            self.pending.requiredStateName = 'pending' 
     57            self.deleted = registerClass( 
     58                typeName, isCompoundingRegister=False, **kwds) 
    5559            self.deleted.requiredStateName = 'deleted' 
    56             self.all = registerClass(typeName, isCompoundingRegister=False, **kwds) 
     60            self.all = registerClass( 
     61                typeName, isCompoundingRegister=False, **kwds) 
    5762            self.all.requiredStateName = '' 
    5863 
     
    7176        else: 
    7277            super(StatefulObject, self).delete() 
     78 
     79    def approve(self): 
     80        if self.state: 
     81            self.state.approveObject(self) 
    7382 
    7483    def undelete(self): 
  • trunk/src/dm/strategy.py

    r111 r123  
    11from dm.ioc import RequiredFeature 
     2 
     3moddebug = False 
    24 
    35class BaseStrategy(object): 
    46 
    57    registry = RequiredFeature('DomainRegistry') 
     8    debug = RequiredFeature('Debug') 
     9    logger = RequiredFeature('Logger') 
    610     
    711    def __init__(self): 
    812        pass 
     13 
     14 
     15class MakeProtectedNames(BaseStrategy): 
     16 
     17    def __init__(self, protectedObject): 
     18        super(MakeProtectedNames, self).__init__() 
     19        self.protectedObject = protectedObject 
     20 
     21    def make(self): 
     22        protectedNames = [] 
     23        if self.protectedObject.__class__ == type: 
     24            if moddebug and self.debug: 
     25                self.logger.debug('Making protected name for class: %s' % self.protectedObject) 
     26            className = self.protectedObject.__name__ 
     27            protectedNames.append(className) 
     28        else: 
     29            if moddebug and self.debug: 
     30                self.logger.debug('Making protected names for instance: %s' % self.protectedObject) 
     31            keyValue = self.protectedObject.id 
     32            className = self.protectedObject.__class__.__name__ 
     33            instanceName = className + "." + str(keyValue) 
     34            protectedNames.append(instanceName) 
     35            protectedNames.append(className) 
     36        if not protectedNames: 
     37            msg = "No protected names derived from protection object: %s" % ( 
     38                self.protectedObject 
     39            ) 
     40            raise Exception, msg 
     41        elif moddebug and self.debug: 
     42            self.logger.debug('Made protected names: %s' % protectedNames) 
     43        return protectedNames 
    944 
    1045 
     
    2156         
    2257 
    23 class MakeProtectedNames(BaseStrategy): 
     58class FindProtectionObjects(BaseStrategy): 
    2459 
    2560    def __init__(self, protectedObject): 
    26         super(MakeProtectedNames, self).__init__() 
     61        super(FindProtectionObjects, self).__init__() 
    2762        self.protectedObject = protectedObject 
    2863 
    29     def make(self): 
    30         protectedNames = [] 
    31         if self.protectedObject.__class__ == type: 
    32             className = self.protectedObject.__name__ 
    33             protectedNames.append(className) 
    34         else: 
    35             keyValue = self.protectedObject.id 
    36             className = self.protectedObject.__class__.__name__ 
    37             instanceName = className + "." + str(keyValue) 
    38             protectedNames.append(instanceName) 
    39             protectedNames.append(className) 
    40         if not protectedNames: 
    41             msg = "No protected names derived from protection object: %s" % ( 
    42                 self.protectedObject 
     64    def find(self): 
     65        if moddebug and self.debug: 
     66            self.logger.debug('Finding protection objects for: %s' % self.protectedObject) 
     67        makeNames = MakeProtectedNames(self.protectedObject) 
     68        protectedNames = makeNames.make() 
     69        protectionObjects = [] 
     70        for name in protectedNames: 
     71            if name in self.registry.protectionObjects: 
     72                protection = self.registry.protectionObjects[name] 
     73                protectionObjects.append(protection) 
     74        if not protectionObjects: 
     75            raise Exception, "No protection for %s (protected names: %s)" % ( 
     76                self.protectedObject, protectedNames 
    4377            ) 
    44             raise Exception, msg 
    45         return protectedNames 
     78        return protectionObjects 
    4679 
    4780 
     
    6396 
    6497 
    65 class FindProtectionObjects(BaseStrategy): 
    66  
    67     def __init__(self, protectedObject): 
    68         super(FindProtectionObjects, self).__init__() 
    69         self.protectedObject = protectedObject 
    70  
    71     def find(self): 
    72         makeNames = MakeProtectedNames(self.protectedObject) 
    73         protectedNames = makeNames.make() 
    74         protectionObjects = [] 
    75         for name in protectedNames: 
    76             if name in self.registry.protectionObjects: 
    77                 protection = self.registry.protectionObjects[name] 
    78                 protectionObjects.append(protection) 
    79         if not protectionObjects: 
    80             raise Exception, "No protection for %s (protected names: %s)" % ( 
    81                 self.protectedObject, protectedNames 
    82             ) 
    83         return protectionObjects 
    84  
    85  
    8698class CreateProtectionObject(BaseStrategy): 
    8799 
  • trunk/src/dm/strategytest.py

    r111 r123  
    2727     
    2828        self.protectedObject = self.registry.plugins['accesscontrol'] 
     29        self.failUnlessEqual(self.protectedObject.id, 1) 
     30        self.failUnlessEqual(self.protectedObject.name, 'accesscontrol') 
    2931        makeName = MakeProtectedName(self.protectedObject) 
    3032        protectedName = makeName.make() 
     
    7173        findObject = FindProtectionObject(protectedObject) 
    7274        protectionObject = findObject.find() 
    73         self.failUnlessEqual(protectionObject.name, 'Plugin.1') 
     75        self.failUnlessEqual(protectionObject.name, 'Plugin') 
    7476     
    7577    def testProtectedDomainObjectClass(self): 
     
    9294        findObjects = FindProtectionObjects(protectedObject) 
    9395        protectionObjects = findObjects.find() 
    94         self.failUnlessEqual(len(protectionObjects), 2) 
    95         self.failUnlessEqual(protectionObjects[0].name, 'Plugin.1') 
    96         self.failUnlessEqual(protectionObjects[1].name, 'Plugin') 
     96        self.failUnlessEqual(len(protectionObjects), 1) 
     97        self.failUnlessEqual(protectionObjects[0].name, 'Plugin') 
    9798     
    9899    def testProtectedDomainObjectClass(self): 
  • trunk/src/dm/util/db.py

    r113 r123  
    8080        Initialises service database by creating initial domain object records. 
    8181        """ 
    82         pass 
     82        initModelCommandClass = self.getInitModelCommandClass() 
     83        initModelCommand = initModelCommandClass() 
     84        initModelCommand.execute() 
    8385 
     86    def getInitModelCommandClass(self): 
     87        commandSet = self.getApplicationCommandSet() 
     88        return commandSet['InitialiseDomainModel'] 
     89 
     90    def getApplicationCommandSet(self): 
     91        import dm.soleInstance 
     92        commandSet = dm.soleInstance.application.commands 
     93        return commandSet 
     94 
  • trunk/src/dm/view/base.py

    r113 r123  
    4343        self._canUpdateSystem = None 
    4444        self._canCreatePerson = None 
     45        self._canApprovePerson = None 
    4546        self._canReadPerson = None 
    4647        self._canUpdatePerson = None 
     
    138139        return self.authoriseActionObject('Create', protectedObject) 
    139140 
     141    def canApprove(self, protectedObject): 
     142        return self.authoriseActionObject('Approve', protectedObject) 
     143 
    140144    def canRead(self, protectedObject): 
    141145        return self.authoriseActionObject('Read', protectedObject) 
     
    173177            self._canCreatePerson = self.canCreate(protectedObject) 
    174178        return self._canCreatePerson 
     179 
     180    def canApprovePerson(self): 
     181        if self._canApprovePerson == None: 
     182            if self.person: 
     183                protectedObject = self.person 
     184            else: 
     185                protectedObject = self.getDomainClass('Person') 
     186            self._canApprovePerson = self.canApprove(protectedObject) 
     187        return self._canApprovePerson 
    175188 
    176189    def canReadPerson(self): 
     
    835848 
    836849 
     850class AbstractPendingView(AbstractListView): 
     851 
     852    def getManipulatedObjectRegister(self): 
     853        r = super(AbstractPendingView, self).getManipulatedObjectRegister() 
     854        return r.pending 
     855         
     856 
    837857class AbstractSearchView(AbstractClassView): 
    838858 
     
    10121032        domainObject = self.getManipulatedDomainObject() 
    10131033        domainObject.delete() 
     1034 
     1035 
     1036class AbstractApproveView(AbstractFormView): 
     1037 
     1038    def __init__(self, **kwds): 
     1039        super(AbstractApproveView, self).__init__(**kwds) 
     1040        self.formErrors = {} 
     1041 
     1042    def getInitialParams(self): 
     1043        initialParams = MultiValueDict() 
     1044        domainObject = self.getManipulatedDomainObject() 
     1045        domainObjectValueDict = domainObject.asDictValues() 
     1046        initialParams.update(domainObjectValueDict) 
     1047        return initialParams 
     1048 
     1049    def manipulateDomainObject(self): 
     1050        super(AbstractApproveView, self).manipulateDomainObject() 
     1051        domainObject = self.getManipulatedDomainObject() 
     1052        domainObject.approve() 
    10141053 
    10151054 
  • trunk/src/dm/view/manipulator.py

    r112 r123  
    6060        self.fields = [] 
    6161        self.buildFields() 
     62        if not fieldNames: 
     63            for field in self.fields: 
     64                self.fieldNames.append(field.field_name) 
    6265 
    6366    def buildFields(self): 
     
    217220        return None 
    218221 
     222    def update(self, data): 
     223        self.data = data 
     224        self.setNonAssociateListAttributes() 
     225        self.setAssociateListAttributes() 
     226 
     227    def setNonAssociateListAttributes(self): 
     228        for metaAttr in self.metaObject.attributes: 
     229            if not metaAttr.isAssociateList: 
     230                if metaAttr.name in self.fieldNames: 
     231                    #if self.data.has_key(metaAttr.name): 
     232                    #    metaAttr.setAttributeFromMultiValueDict( 
     233                    #        self.domainObject, self.data 
     234                    #    ) 
     235                    metaAttr.setAttributeFromMultiValueDict( 
     236                        self.domainObject, self.data 
     237                    ) 
     238        self.domainObject.save() 
     239         
    219240    def setAssociateListAttributes(self): 
    220241        for metaAttr in self.metaObject.attributes: 
     
    223244            
    224245    def setAssociateListAttribute(self, metaAttr): 
    225         if self.data.has_key(metaAttr.name): 
    226             metaAttr.setAttributeFromMultiValueDict( 
    227                 self.domainObject, self.data 
    228             ) 
    229  
    230     def update(self, data): 
    231         self.data = data 
    232         self.setNonAssociateListAttributes() 
    233         self.setAssociateListAttributes() 
    234  
    235     def setNonAssociateListAttributes(self): 
    236         for metaAttr in self.metaObject.attributes: 
    237             if not metaAttr.isAssociateList: 
    238                 if self.data.has_key(metaAttr.name): 
    239                     metaAttr.setAttributeFromMultiValueDict( 
    240                         self.domainObject, self.data 
    241                     ) 
    242         self.domainObject.save() 
    243          
     246        if metaAttr.name in self.fieldNames: 
     247            if self.data.has_key(metaAttr.name): 
     248                metaAttr.setAttributeFromMultiValueDict( 
     249                    self.domainObject, self.data 
     250                ) 
     251 
    244252    def getAttributeField(self, attrName): 
    245253        for field in self.fields: