Пример #1
0
 def createClass(self, classId, msg):
     logInfo('{0} could not find class with id: {1} in database.  Creating new class'.format(self.serviceName, classId), 3)
     classUUID = str(uuid4())
     clazz = DBClass(id=classUUID, ids=[classId], name='', roles={}, students=[], kcs=[])
     clazz.save()
     self.classCache[classId] = clazz
     newClassAlias = DBClasssAlias(trueId=classUUID, alias=classId)
     newClassAlias.save()
     return clazz    
Пример #2
0
 def retrieveClassFromCacheOrDB(self, classId, msg, useCache=True):
     logInfo("Entering retrieveClassFromCacheOrDB with arguments {0}".format(classId), 5)
     if classId is None or classId == '':
         return None
     clazz = self.studentCache.get(classId)
     if clazz is not None and useCache:
         logInfo('{0} found classroom object with id:{1}'.format(self.serviceName, clazz), 4)
         return clazz
     else:
         logInfo('{0} could not find cached classroom object with id: {1}.  Falling back to database.'.format(self.serviceName, classId), 3)
         classAliasList = DBClasssAlias.find_by_index("AliasIndex", classId)
         if len(classAliasList) > 0:
             #there should only be one object returned, should put it a log statement if that isn't correct.
             for classAlias in classAliasList:
                 clazz = classAlias.getStudent()
                 
         if clazz is None:
             clazz = self.createClass(classId, msg)
         #Cache the result so we don't need to worry about looking it up again.
         self.classCache[classId] = clazz
         return clazz