def tag_create(data): logging.error(data) num = data.get('num') namespace = data.get('namespace') value = data.get('value') tag1 = models.Tag.get_key_by_namespace_and_value(namespace, value) if tag1: logging.info('tag1 namespace and value exists') return common.error_response(None, 400) parent = None if data.get('parentNum'): parentNum = data.get('parentNum') if not isinstance(parent, int): logging.error('parentNum must be int type') return common.error_response(None, 400) parent = models.get_by_num('Tag', parentNum) if not parent: logging.error('parent_num(%d) not found' % parentNum) return common.error_response(None, 400) if num: num = int(num) tag2 = models.get_by_num('Tag', num) if tag2: logging.info('tag2 namespace and value exists') return common.error_response(None, 400) tag = models.Tag(num=num, namespace=namespace, value=value, parent_tag = parent) else: tag = models.Tag(namespace=namespace, value=value, parent_tag = parent) tag.put() tag.num = tag.key().id() tag.put() return common.json_response(tag.format())
def tag_create(data): logging.error(data) num = data.get('num') namespace = data.get('namespace') value = data.get('value') tag1 = models.Tag.get_key_by_namespace_and_value(namespace, value) if tag1: logging.info('tag1 namespace and value exists') return common.error_response(None, 400) parent = None if data.get('parentNum'): parentNum = data.get('parentNum') if not isinstance(parent, int): logging.error('parentNum must be int type') return common.error_response(None, 400) parent = models.get_by_num('Tag', parentNum) if not parent: logging.error('parent_num(%d) not found' % parentNum) return common.error_response(None, 400) if num: num = int(num) tag2 = models.get_by_num('Tag', num) if tag2: logging.info('tag2 namespace and value exists') return common.error_response(None, 400) tag = models.Tag(num=num, namespace=namespace, value=value, parent_tag=parent) else: tag = models.Tag(namespace=namespace, value=value, parent_tag=parent) tag.put() tag.num = tag.key().id() tag.put() return common.json_response(tag.format())
def tag_detail_by_num(tag_num): tag = models.get_by_num('Tag', tag_num, key_only=False) if not tag: return common.error_response(None, 404) return common.json_response(tag.format())