def populate_extensions(self, act_def): for k, v in act_def['extensions'].items(): if not uri.validate_uri(k): err_msg = "Extension ID %s is not a valid URI" % k log_message(self.log_dict, err_msg, __name__, self.populate_extensions.__name__, True) update_parent_log_status(self.log_dict, 400) raise exceptions.ParamError(err_msg) act_def_ext = models.extensions(key=k, value=v, content_object=self.activity.activity_definition) act_def_ext.save()
def saveResultToDB(self, result, resultExts): # Save the result with all of the args sc = result.pop('score', None) rslt = models.result(content_object=self.model_object, **result) rslt.save() if sc: sc.result = rslt sc.save() #If it has extensions, save them all if resultExts: for k, v in resultExts.items(): resExt = models.extensions(key=k, value=v, content_object=rslt) resExt.save() log_message(self.log_dict, "Result saved to database", __name__, self.saveResultToDB.__name__) return rslt
def saveContextToDB(self, context, contextExts): # Set context activities to context dict con_act_data = None if 'contextActivities' in context: con_act_data = context['contextActivities'] del context['contextActivities'] # Set context statement cs = None if 'cntx_statement' in context: cs = context['cntx_statement'] del context['cntx_statement'] # Save context cntx = models.context(content_object=self.model_object, **context) cntx.save() # Set context in context statement and save if cs: cs.context = cntx cs.save() # Save context activities if con_act_data: for con_act in con_act_data.items(): ca_id = con_act[1]['id'] if not uri.validate_uri(ca_id): raise exceptions.ParamError('Context Activity ID %s is not a valid URI' % ca_id) ca = models.ContextActivity(key=con_act[0], context_activity=ca_id, context=cntx) ca.save() cntx.save() # Save context extensions if contextExts: for k, v in contextExts.items(): if not uri.validate_uri(k): err_msg = "Extension ID %s is not a valid URI" % k log_message(self.log_dict, err_msg, __name__, self.saveContextToDB.__name__, True) update_parent_log_status(self.log_dict, 400) raise exceptions.ParamError(err_msg) conExt = models.extensions(key=k, value=v, content_object=cntx) conExt.save() log_message(self.log_dict, "Context saved to database", __name__, self.saveContextToDB.__name__) return cntx
def saveResultToDB(self, result, resultExts): # Save the result with all of the args sc = result.pop('score', None) rslt = models.result(content_object=self.model_object, **result) rslt.save() if sc: sc.result = rslt sc.save() #If it has extensions, save them all if resultExts: for k, v in resultExts.items(): if not uri.validate_uri(k): err_msg = "Extension ID %s is not a valid URI" % k log_message(self.log_dict, err_msg, __name__, self.saveResultToDB.__name__, True) update_parent_log_status(self.log_dict, 400) raise exceptions.ParamError(err_msg) resExt = models.extensions(key=k, value=v, content_object=rslt) resExt.save() log_message(self.log_dict, "Result saved to database", __name__, self.saveResultToDB.__name__) return rslt
def saveContextToDB(self, context, contextExts): # Set context activities to context dict con_act_data = None if 'contextActivities' in context: con_act_data = context['contextActivities'] del context['contextActivities'] # Set context statement cs = None if 'cntx_statement' in context: cs = context['cntx_statement'] del context['cntx_statement'] # Save context cntx = models.context(content_object=self.model_object, **context) cntx.save() # Set context in context statement and save if cs: cs.context = cntx cs.save() # Save context activities if con_act_data: for con_act in con_act_data.items(): ca = models.ContextActivity(key=con_act[0], context_activity=con_act[1]['id'], context=cntx) ca.save() cntx.save() # Save context extensions if contextExts: for k, v in contextExts.items(): conExt = models.extensions(key=k, value=v, content_object=cntx) conExt.save() log_message(self.log_dict, "Context saved to database", __name__, self.saveContextToDB.__name__) return cntx
def populate_extensions(self, act_def): for k, v in act_def['extensions'].items(): act_def_ext = models.extensions(key=k, value=v, content_object=self.activity.activity_definition) act_def_ext.save()