def add_article_lib(self, title, content, desc, category_id, thumbnail, tags, article_id): '''发布新闻''' if category_id == '' or tags == '': return {'status': False, 'msg': '请选择分类或者标签!'} if title == '' or content == '' or desc == '': return {'status': False, 'msg': '请输入标题、内容、简介!'} # 判断文章是否存在,存在则是编辑,不存在则是新增 if article_id != '': article = Article.by_id(article_id) article.tags = [] # 如果文章已存在,则避免标签重复,这里直接将标签置空 else: article = Article() article.content = content article.title = title article.desc = desc article.category_id = category_id article.thumbnail = thumbnail for tags_id in tags: tag = Tag.by_id(tags_id) article.tags.append(tag) article.user_id = self.current_user.id self.db.add(article) self.db.commit() if article_id != '': return {'status': True, 'msg': '文档修改成功!'} return {'status': True, 'msg': '文档提交成功!'}
def add_article_lib(self, title, content, desc, category_id, thumbnail, tags, article_id): ''' 上传文章 及修改文章 ''' if category_id == '' or tags == '': return {'status': False, 'msg': '请选择分类或者标签'} if title == '' or content == '' or desc == '': return {'status': False, 'msg': '请输入标题,内容, 简介'} if article_id != '': print '2-' * 19 article = Article.by_id(article_id) article.tags = [] else: print '-1-' * 10 article = Article() article.content = content article.title = title article.desc = desc article.category_id = category_id article.thumbnail = thumbnail for tags_id in tags: tag = Tag.by_id(tags_id) article.tags.append(tag) article.user_id = self.current_user.id self.db.add(article) self.db.commit() if article_id != '': return {'status': True, 'msg': '文档修改成功'} return {'status': True, 'msg': '文档提交成功'}
def add_article_lib(self, title, content, desc, category_id, thumbnail, tags, article_id): if category_id == '' or tags == []: return {'status': False, 'msg': '请选择分类或标签'} if title == '' or content == '' or desc == '': return {'status': False, 'msg': '请输入标题、内容、摘要'} if article_id != '': article = Article.by_id(article_id) article.tags = [] else: article = Article() article.title = title article.content = content article.desc = desc article.category_id = category_id article.thumbnail = thumbnail for tags_id in tags: tag = Tag.by_id(tags_id) article.tags.append(tag) article.user_id = self.current_user.id self.db.add(article) self.db.commit() if article_id != '': return {'status': True, 'msg': '文档修改成功!'} return {'status': True, 'msg': '文档提交成功!'}