def _saveContextToDB(self, context, contextExts): # pdb.set_trace() con_act_data = None if 'contextActivities' in context: con_act_data = context['contextActivities'] del context['contextActivities'] # if 'instructor' in context: # del context['instructor'] # if 'team' in context: # del context['team'] # if 'cntx_statement' in context: # del context['cntx_statement'] # pdb.set_trace() cntx = models.context(**context) cntx.save() 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']) ca.save() cntx.contextActivities.add(ca) cntx.save() if contextExts: for k, v in contextExts.items(): conExt = models.context_extensions(key=k, value=v, context=cntx) conExt.save() return cntx
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 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