Example #1
0
 def add(cls, user_name, label):
     exist = Tag.select().filter(Tag.user_name == user_name, Tag.label
                                 == label).first() is None
     if not exist:
         raise ServerException(f'{label} 已存在')
     tag = Tag(user_name=user_name, label=label)
     tag.insert()
     return Tag.select().filter(Tag.user_name == user_name,
                                Tag.label == label).one().id
Example #2
0
	def get_tags(self):
		from model.tagtoevent import TagToEvent
		from model.tag import Tag
		query = Tag.select(Tag.name)\
			.join(TagToEvent, on=(Tag.id == TagToEvent.tag_id))\
			.where(TagToEvent.event_id == self.id)
		return [tag.name for tag in query]
Example #3
0
 def publish_article(cls, user_name, id, title, tags, is_published):
     article = Article.select().get(id)
     article.title = title
     article.is_published = is_published
     tags = list(set(tags))
     tag_existed = Tag.select().filter(Tag.label.in_(tags)).all()
     for t in tag_existed:
         if t.user_name is None:
             t.user_name = user_name
             t.update()
     for t in list(
             set(tags).difference(set([tag.label for tag in tag_existed]))):
         Tag(user_name=user_name, label=t).insert()
     article.tags = json.dumps(tags)
     article.update()
     return True
 def _fill_cache_with_existing_tags(self):
     tag = Tag()
     tags = tag.select()
     for tg in tags:
         self._tags_cache[tg.name] = tg
Example #5
0
 def delete(cls, tag_id):
     tag = Tag.select().get(tag_id)
     if tag is None:
         raise ServerException('tag不存在')
     tag.delete()
     return True
Example #6
0
 def user_tag(cls, user_name):
     tags = Tag.select().filter(Tag.user_name == user_name).all()
     return [tag.get_json() for tag in tags]