def __populate_definition(self, act, definition, the_object): #Initialize object's activity definition self.activity_definition = {} #Name, description, type, and interactionType are all required - extensions optional try: self.activity_definition['name'] = definition['name'] except KeyError: raise Exception("No activity definition name provided, must provide name") try: self.activity_definition['description'] = definition['description'] except KeyError: raise Exception("No activity definition description provided, must provide description") try: self.activity_definition['type'] = definition['type'] except KeyError: raise Exception("No activity definition type provided, must provide type") try: self.activity_definition['interactionType'] = definition['interactionType'] except KeyError: raise Exception("No activity definition interactionType provided, must provide interactionType") try: self.activity_definition['extensions'] = definition['extensions'] except KeyError: self.activity_definition['extensions'] = None #Save activity definition to DB the_act_def = models.activity_definition(name=self.activity_definition['name'], description=self.activity_definition['description'], activity_definition_type=self.activity_definition['type'], interactionType=self.activity_definition['interactionType'], activity=act) the_act_def.save() ''' adn = models.activity_definition.objects.get(activity=act).name print 'act_def_name ' + str(adn) add = models.activity_definition.objects.get(activity=act).description print 'act_def_desc ' + str(add) adt = models.activity_definition.objects.get(activity=act).activity_definition_type print 'act_def_type ' + str(adt) adi = models.activity_definition.objects.get(activity=act).interactionType print 'act_def_intType ' + str(adi) adid = models.activity_definition.objects.get(activity=act).activity print 'act_def_act_id ' + str(adid) ''' # If there are extensions, save each one to the DB if self.activity_definition['extensions']: for k, v in self.activity_definition['extensions'].items(): the_act_def_ext = models.activity_extentions(key=k, value=v, activity_definition=the_act_def) the_act_def_ext.save() '''
def save_activity_definition_to_db(self,act_def_type, intType): created = True try: self.activity.activity_definition created = False except: actdef = models.activity_definition(activity_definition_type=act_def_type, interactionType=intType, activity=self.activity) actdef.save() if created: log_message(self.log_dict, "Activity definition saved to database", __name__, self.save_activity_definition_to_db.__name__) else: log_message(self.log_dict, "Activity definition retrieved from database", __name__,self.save_activity_definition_to_db.__name__) return created
def _save_activity_definition_to_db(self,act_def_type, intType): act_def = models.activity_definition(activity_definition_type=act_def_type, interactionType=intType) act_def.save() return act_def