def add_type(self, predicate_uuid, type_uuid, string_uuid, label): """ adds the predicate """ tm = TypeManagement() tm.source_id = self.source_id tm.project_uuid = self.project_uuid tm.suggested_uuid = type_uuid tm.suggested_content_uuid = string_uuid type_obj = tm.get_make_type_within_pred_uuid(predicate_uuid, label) return type_obj
def create_type(self, post_data): """ creates a type item into a project """ ok = True required_params = ['source_id', 'item_type', 'predicate_uuid', 'label', 'note'] for r_param in required_params: if r_param not in post_data: # we're missing some required data # don't create the item ok = False message = 'Missing paramater: ' + r_param + '' self.errors.append(message) # now prep the type management ! tm = TypeManagement() tm.project_uuid = self.project_uuid uuid = False content_uuid = False if ok: # now check to see if this already exists label = post_data['label'].strip() type_note = post_data['note'].strip() tm.source_id = post_data['source_id'].strip() predicate_uuid = post_data['predicate_uuid'].strip() if self.check_non_blank_param(post_data, 'uuid')\ and self.check_non_blank_param(post_data, 'content_uuid'): uuid = post_data['uuid'].strip() if self.check_uuid_format(uuid): uuid_exists = self.check_uuid_exists(uuid) if uuid_exists: ok = False message = 'Cannot create a category called "' + label + '"' message += ', becuase the submitted UUID: ' + uuid message += ' already exists.' self.errors.append(message) note = '; '.join(self.errors) else: # ok! use this as the suggested UUID for making a new type tm.suggested_uuid = uuid content_uuid = self.validate_content_uuid(tm, post_data) if content_uuid is False: ok = False note = '; '.join(self.errors) else: # ok! the content uuid is also OK to use tm.suggested_content_uuid = content_uuid else: ok = False mesaage = 'Cannot create a category called "' + label + '"' mesaage += ', becuase the submitted UUID: ' + uuid mesaage += ' is badly formed.' self.errors.append(message) note = '; '.join(self.errors) elif self.check_non_blank_param(post_data, 'uuid') \ and not self.check_non_blank_param(post_data, 'content_uuid'): # we have a uuid for the type, but not the content. We can't # create the type however, since we're missing a content uuid uuid = post_data['uuid'].strip() ok = False mesaage = 'Cannot create a category called "' + label + '"' mesaage += ', becuase the submitted UUID: ' + str(uuid) mesaage += ' needs to have a valid Content UUID.' self.errors.append(message) note = '; '.join(self.errors) elif not self.check_non_blank_param(post_data, 'uuid') \ and self.check_non_blank_param(post_data, 'content_uuid'): # we have a uuid for the content only. a weird case, but possible content_uuid = self.validate_content_uuid(tm, post_data) if content_uuid is False: ok = False note = '; '.join(self.errors) else: # ok! the content uuid is also OK to use tm.suggested_content_uuid = content_uuid else: label = '[Item not created]' uuid = False if ok: type_uuid = tm.check_exists_pred_uuid_content(predicate_uuid, label, True) if type_uuid is not False: # we already have this type! ok = False uuid = str(type_uuid) message = 'Cannot create a category called "' + label + '"' message += ', becuase it already exists with UUID: ' + uuid self.errors.append(message) note = '; '.join(self.errors) if ok: tm.source_id = post_data['source_id'].strip() if content_uuid is False: newtype = tm.get_make_type_within_pred_uuid(predicate_uuid, label) content_uuid = str(newtype.content_uuid) uuid = str(newtype.uuid) else: tm.content = label newtype = tm.get_make_type_pred_uuid_content_uuid(predicate_uuid, content_uuid) content_uuid = newtype.content_uuid uuid = newtype.uuid # now add the note if not empty self.add_description_note(newtype.uuid, 'types', newtype.source_id, type_note) if ok: # now clear the cache a change was made self.created_uuid = uuid self.clear_caches() self.response = {'action': 'create-item-into', 'ok': ok, 'change': {'uuid': uuid, 'content_uuid': content_uuid, 'label': label, 'note': self.add_creation_note(ok)}} return self.response
def create_type(self, post_data): """ creates a type item into a project """ ok = True required_params = [ 'source_id', 'item_type', 'predicate_uuid', 'label', 'note' ] for r_param in required_params: if r_param not in post_data: # we're missing some required data # don't create the item ok = False message = 'Missing paramater: ' + r_param + '' if self.errors['params'] is False: self.errors['params'] = message else: self.errors['params'] += '; ' + message # now prep the type management ! tm = TypeManagement() tm.project_uuid = self.project_uuid uuid = False content_uuid = False if ok: # now check to see if this already exists label = post_data['label'].strip() type_note = post_data['note'].strip() tm.source_id = post_data['source_id'].strip() predicate_uuid = post_data['predicate_uuid'].strip() if self.check_non_blank_param(post_data, 'uuid')\ and self.check_non_blank_param(post_data, 'content_uuid'): uuid = post_data['uuid'].strip() if self.check_uuid_format(uuid): uuid_exists = self.check_uuid_exists(uuid) if uuid_exists: ok = False self.errors[ 'uuid'] = 'Cannot create a category called "' + label + '"' self.errors[ 'uuid'] += ', becuase the submitted UUID: ' + uuid self.errors['uuid'] += ' already exists.' note = self.errors['uuid'] else: # ok! use this as the suggested UUID for making a new type tm.suggested_uuid = uuid content_uuid = self.validate_content_uuid( tm, post_data) if content_uuid is False: ok = False note = self.errors['content_uuid'] else: # ok! the content uuid is also OK to use tm.suggested_content_uuid = content_uuid else: ok = False self.errors[ 'uuid'] = 'Cannot create a category called "' + label + '"' self.errors[ 'uuid'] += ', becuase the submitted UUID: ' + uuid self.errors['uuid'] += ' is badly formed.' note = self.errors['uuid'] elif self.check_non_blank_param(post_data, 'uuid') \ and not self.check_non_blank_param(post_data, 'content_uuid'): # we have a uuid for the type, but not the content. We can't # create the type however, since we're missing a content uuid uuid = post_data['uuid'].strip() ok = False self.errors[ 'uuid'] = 'Cannot create a category called "' + label + '"' self.errors['uuid'] += ', becuase the submitted UUID: ' + str( uuid) self.errors['uuid'] += ' needs to have a valid Content UUID.' note = self.errors['uuid'] elif not self.check_non_blank_param(post_data, 'uuid') \ and self.check_non_blank_param(post_data, 'content_uuid'): # we have a uuid for the content only. a weird case, but possible content_uuid = self.validate_content_uuid(tm, post_data) if content_uuid is False: ok = False note = self.errors['content_uuid'] else: # ok! the content uuid is also OK to use tm.suggested_content_uuid = content_uuid else: label = '[Item not created]' uuid = False if ok: type_uuid = tm.check_exists_pred_uuid_content( predicate_uuid, label, True) if type_uuid is not False: # we already have this type! ok = False uuid = type_uuid self.errors[ 'uuid'] = 'Cannot create a category called "' + label + '"' self.errors[ 'uuid'] += ', becuase it already exists with UUID: ' + uuid note = self.errors['uuid'] if ok: tm.source_id = post_data['source_id'].strip() if content_uuid is False: newtype = tm.get_make_type_within_pred_uuid( predicate_uuid, label) content_uuid = newtype.content_uuid uuid = newtype.uuid else: tm.content = label newtype = tm.get_make_type_pred_uuid_content_uuid( predicate_uuid, content_uuid) content_uuid = newtype.content_uuid uuid = newtype.uuid # now add the note if not empty self.add_description_note(newtype.uuid, 'types', newtype.source_id, type_note) self.response = { 'action': 'create-item-into', 'ok': ok, 'change': { 'uuid': uuid, 'content_uuid': content_uuid, 'label': label, 'note': self.add_creation_note(ok) } } return self.response