def modify_blog(cls, blog_id, title, tag, category, hide, content): blog = cls.get(cls.id == blog_id) blog.title = title if hide == 'False': blog.hide = False else: blog.hide = True blog.content_md = content blog.content_html = md2html(content) blog.save() check_tag = Tags.has_tag(tag) blogtags = BlogTags.get(BlogTags.blog_id == blog.id) if check_tag: blogtags.tags_id = check_tag.id else: tag = Tags.create(tag=tag) blogtags.tags_id = tag.id blogtags.save() check_category = Category.has_category(category) blogcategory = BlogCategory.get(BlogCategory.blog_id == blog.id) if check_category: blogcategory.category_id = check_category.id else: category = Category.create(category=category) blogcategory.category_id = category.id blogcategory.save()
def update_article(self): inputs = self.get_input() if web.ctx.method == "GET": article_id = inputs.get("article_id") category_list = Categories.select().where(Categories.status == 0) article = Articles.get_or_none(Articles.id == article_id) print(article.id) self.private_data["article"] = article self.private_data["category_list"] = category_list return self.display("admin/update_article") else: article_id = inputs.get("article_id") name = inputs.get('name') content = inputs.get('content') summary = inputs.get("summary") category_id = inputs.get("category_id") source_url = inputs.get("source_url", "") keywords = str(inputs.get("keywords", "")).strip() article = Articles.get_or_none(Articles.id == article_id) try: tags_list = keywords.split(",") if keywords else [] if tags_list: got_tags = Tags.select().where(Tags.name.in_(tags_list)) tmp_list = [] for tag in got_tags: tmp_list.append(tag.name) for tag_str in tags_list: tag_str.strip() if tag_str not in tmp_list: t = Tags(name=tag_str) t.save() db = TinyDB('settings/db.json') db.truncate() db.close() article.update(name=name, content=content, summary=summary, category_id=category_id, original_address=source_url, keywords=keywords, updateTime=time()).where( Articles.id == article_id).execute() self.private_data["update_success"] = True return web.seeother(self.make_url('articles')) except Exception as e: log.error('update article failed %s' % traceback.format_exc()) log.error('input params %s' % inputs) self.private_data["update_success"] = False return web.seeother(self.make_url('update_article'))
def dynamicMyBlogEdit(): t = Tags().query.all() tags = [] for i in t: tags.append((i.id, i.tag_name)) MyBlogEdit.tags = SelectField('Tag', choices=tags, coerce=int) return MyBlogEdit
def get_blog_detail(cls, blog_id): blog = cls.get(cls.id == blog_id) blogtags = BlogTags.get(BlogTags.blog_id == blog.id) tag = Tags.get(Tags.id == blogtags.tags_id).tag blogcategory = BlogCategory.get(BlogCategory.blog_id == blog_id) category = Category.get(Category.id == blogcategory.category_id).category return blog, tag, category
def get_all_entries(): with sqlite3.connect("./daily-journal.db") as conn: conn.row_factory = sqlite3.Row db_cursor = conn.cursor() db_cursor.execute(""" SELECT a.id, a.concept, a.entry, a.date, a.moodId, m.label label_mood FROM entries a JOIN moods m ON m.id = a.moodId """) entries = [] dataset = db_cursor.fetchall() for row in dataset: entry = Entries(row['id'], row['concept'], row['entry'], row['date'], row['moodId']) mood = Moods(row['id'], row['label_mood']) entry.mood = mood.__dict__ entries.append(entry.__dict__) db_cursor.execute( """ SELECT t.id, t.name, e.entry_id FROM entry_tag e JOIN tags t ON t.id = e.tag_id WHERE e.entry_id = ? """, (row['id'], )) tagset = db_cursor.fetchall() tags = [] for tag in tagset: each_tag = Tags(tag['id'], tag['name']) tags.append(each_tag.__dict__) entry.tags = tags return json.dumps(entries)
def create_new_blog(cls, title, tag, category, hide, content): blog = cls.create(title=title, content_md=content) if hide == 'False': blog.hide = False else: blog.hide = True blog.content_html = md2html(content) blog.save() check_tag = Tags.has_tag(tag) if check_tag: BlogTags.create(blog_id=blog.id, tags_id=check_tag.id) else: tag = Tags.create(tag=tag) BlogTags.create(blog_id=blog.id, tags_id=tag.id) check_category = Category.has_category(category) if check_category: BlogCategory.create(blog_id=blog.id, category_id=check_category.id) else: category = Category.create(category=category) BlogCategory.create(blog_id=blog.id, category_id=category.id)
def get_tags(self): db = TinyDB('settings/db.json') table = db.table('_default') res = table.get(where('name') == 'tags') if res: data = res.get("data") tags_dict_list = json.loads(data) else: tags_list = Tags.select().where(Tags.status == 0) tags_dict_list = [] for tag in tags_list: count = Articles.select().where( Articles.keywords.contains(str(tag.name))).count() tags_dict_list.append({tag.name: count}) db.truncate() table = db.table('_default') table.insert({"name": "tags", "data": json.dumps(tags_dict_list)}) db.close() return tags_dict_list
def get_all_tags(): with sqlite3.connect("./daily-journal.db") as conn: conn.row_factory = sqlite3.Row db_cursor = conn.cursor() db_cursor.execute(""" SELECT t.id, t.name FROM tags t """) tags = [] dataset = db_cursor.fetchall() for row in dataset: tag = Tags(row['id'], row['name']) tags.append(tag.__dict__) return json.dumps(tags)
def get_blog_by_tag(cls, tag): # tag_id = Tags.select(Tags.id).order_by(Tags.tag == tag, Tags.id.desc())[0].id - 1 tag_id = Tags.get(Tags.tag == tag).id blogs_ids = BlogTags.select(BlogTags.blog_id).where(BlogTags.tags_id == tag_id) return cls.select().filter(cls.id << blogs_ids)
def search_tags(cls, search): tags_ids = cls.select(cls.tags_id) return Tags.select(Tags.id, Tags.tag).filter((Tags.id << tags_ids)).where(Tags.tag.contains(search))
def get_all_tags(cls): tags_ids = cls.select(cls.tags_id) return Tags.select(Tags.id, Tags.tag).filter(Tags.id << tags_ids)
def get_tag(cls, blog_id): tag_id = cls.get(cls.blog_id == blog_id).tags_id return Tags.get(Tags.id == tag_id).tag
def tags(): tag = Tags() tagList = tag.query.all() return render_template('index/tags.html', tagList=tagList)
def topicList(): t = Tags() tagList = t.query.all() return render_template('admin/topicList.html', tagList=tagList)