def detail(blog_id): u = current_user() b = Blog.find(blog_id) Blog.get(blog_id) v = b.user() token = new_csrf_token() return render_template('routes_blog/blog_detail.html', blog=b, u=u, v=v, token=token)
def update(blog_id): blog = Blog.get(Blog.blog_id == blog_id) if not blog: abort(400) form = BlogForm(name=blog.name, url=blog.url, description=blog.description) if request.method == 'GET': return render_template('update.html', blog=blog, form=form) else: if form.validate_on_submit(): try: blog.name = form.name.data blog.url = form.url.data blog.description = form.description.data blog.update_time = datetime.now() blog.save() flash(u'更新 {name} 成功'.format(name=form.name.data)) return redirect('/manage') except IntegrityError: flash(u'更新 {name} 失败,该条目已存在'.format(name=form.name.data), 'error') return render_template('update.html', blog=blog, form=form) else: flash(u'更新失败,参数错误', 'error') return render_template('update.html', blog=blog, form=form)
def update_entry(identifier): item = Blog.get(int(identifier)) if not item: return mismatch() ownership = (item.author == g.user) if access(request.path, g.role.id, ownership) != 1: return forbidden() return update_form(FormBlog(obj=item), item, "Updated blog entry.", "/blog/%s" % (identifier))
def footer_info(self): try: blog_obj = Blog.get(Blog.id == 1) footer_text = blog_obj.copyright return footer_text except Exception as e: Logger().log(e, True) return server_error
def delete_entry(identifier): item = Blog.get(int(identifier)) if not item: return mismatch() ownership = (item.author == g.user) if access(request.path, g.role.id, ownership) != 1: return forbidden() headline = "%s löschen?" % (item.title) text = "Menü %s wirklich löschen?" % (item.title) return delete_form(item, headline, text, "Deleted blog entry.", "/blog", "/blog/%s" % (identifier))
def create(cls, blog_id, content, creator_id): sql = 'insert into {} (blog_id,content,creator_id) values(%s, %s, %s)'.format(cls.__table__) params = (blog_id, content, creator_id) id = store.execute(sql,params) store.commit() if id: blog = Blog.get(blog_id) blog.add_comment_count(1) return id
def create(cls, blog_id, content, creator_id): sql = 'insert into {} (blog_id,content,creator_id) values(%s, %s, %s)'.format( cls.__table__) params = (blog_id, content, creator_id) id = store.execute(sql, params) store.commit() if id: blog = Blog.get(blog_id) blog.add_comment_count(1) return id
def blog_show(blog_id): blog = Blog.get(blog_id) user = get_user() if not user: is_join = False else: is_join = blog.get_is_join(user.id) comment_list = Comment.get_comments(blog_id) return header_render('blog_show.html', blog=blog, comment_list = comment_list, is_join = is_join)
def get(self): blog_info = {} try: blog_obj = Blog.get(Blog.id == 1) blog_info['title'] = blog_obj.title blog_info['site'] = blog_obj.site blog_info['about'] = blog_obj.about blog_info['copy_right'] = blog_obj.copyright self.render('admin/blog.html', blog_info=blog_info) except Exception as e: Logger().log(e, True) self.render('index/500.html')
def blog(identifier): actions = menubar("blog", g.role.id) i = int(identifier) if i == 0: item = Blog.query.order_by( Blog.changedOn.desc()).first() # @UndefinedVariable else: item = Blog.get(i) if not item: return render("modules/blog-empty.html", actions=actions) ownership = (item.author == g.user) item.actions = contextmenu("blog", g.role.id, ownership) return render("modules/blog.html", item=item, actions=actions)
def status(blog_id): blog = Blog.get(Blog.blog_id == blog_id) if not blog: abort(400) if blog.status: blog.status = 0 flash(u'{name}下线成功'.format(name=blog.name)) else: blog.status = 1 flash(u'{name}上线成功'.format(name=blog.name)) blog.update_time = datetime.now() blog.save() return redirect('/manage')
def get_title_data(self, info): try: blog_obj = Blog.get(Blog.id == 1) if info == 'title': title_data = blog_obj.title elif info == 'site': title_data = blog_obj.site else: return server_error return title_data except Exception as e: Logger().log(e, True) return server_error
def get(self): try: blog_obj = Blog.get(Blog.id == 1) user_obj = UserInfo.get(UserInfo.username == 'yang') about_data = { 'username': user_obj.username, 'email': user_obj.email, 'about': blog_obj.about } except Exception as e: Logger().log(e, True) return self.render('index/500.html') self.render('index/about.html', about_data=about_data)
def post(self, *args, **kwargs): ret = {'status': 'false', 'message': '', 'data': ''} title = self.get_argument('title', None) site = self.get_argument('site', None) about = self.get_argument('about', None) copy_right = self.get_argument('copy_right', None) if title and site and about and copy_right: try: blog_obj = Blog.get(Blog.id == 1) blog_obj.title = title blog_obj.site = site blog_obj.about = about blog_obj.copyright = copy_right blog_obj.update_date = datetime.datetime.now() blog_obj.save() ret['status'] = 'true' ret['message'] = '网站信息修改成功' except Exception as e: Logger().log(e, True) ret['message'] = '网站信息修改失败' else: ret['message'] = '参数非法' Logger().log(ret, True) self.write(json.dumps(ret))
class Menu(object): def __init__(self, user): self.user = user self._account = self._user_has_account() self.blog_map = {} self.blog_posts = None if self._account is not None: self._blog = self._account print("Welcome back {}.".format(self.user)) else: self._prompt_user_for_account() def _user_has_account(self): return Database.find_one(collection=constants.BLOG_COLLECTION, query={'author': self.user}) def _prompt_user_for_account(self): print( "\nSeems you do not have an associated account, please create a new blog...." + "\n") title = input("Enter a title for your Blog: ") description = input("Enter description for your Blog: ") self._blog = Blog(author=self.user, description=description, title=title) self._blog.save_to_mongo() self._blog = self._blog.json() print("[+] Successfully created!!") def list_all_blogs(self): table = PrettyTable(['S.No', 'Blog Title', 'Description', 'Author']) for i, b in enumerate([ d for d in Database.find(collection=constants.BLOG_COLLECTION, query={}) ]): table.add_row( [i + 1, b.get('title'), b.get('description'), b.get('author')]) self.blog_map.setdefault(i + 1, b) print(table) return self.blog_map def get_all_posts_for_blog(self, selected_blog): self.blog_posts = Post.from_blog(selected_blog.get('id')) post_table = PrettyTable( ['id', 'title', 'content', 'author', 'created_at']) for i, post in enumerate(self.blog_posts): post_table.add_row([ post.get('id'), post.get('title'), post.get('content'), post.get('author'), post.get('created_at'), ]) print("\nPrinting all POSTS for BLOG <{}>".format( selected_blog.get('title')), end="\n") print(post_table) def run_menu(self): row = input("Do you wish to read (R) or write (W) the blogs? (R/W) :") if row.upper() == 'R': print('Choose a blog:') blog_map = self.list_all_blogs() user_selection = input('Enter your selection(S.No.): ') try: user_selection = int(user_selection) if user_selection > len(blog_map): int('a') selected_blog = blog_map.get(user_selection) self.get_all_posts_for_blog(selected_blog) except ValueError: print("Invalid value detected, aborting...") elif row.upper() == 'W': print("[+]-------" * 5 + "[+]") new_post = Blog.from_mongo(self._blog.get('id')).new_post() print( f"\nPOST <{new_post.get('title')}> created for blog <{self._blog.get('title')}>.\n" ) else: print("Thank you for blogging with us!")
def delete_post(self, request): obj = Blog.get(id=request.params[0]) if request.user == obj.author: obj.delete() return self.render('blog/list')
def view(self, request): blog = Blog.get(slug=request.data['slug']) objects = Article.filter(blog=blog).last('date_create') return self.render('blog/view', {'objects': objects})
def delete(self): sql = 'delete from {} where id=%s'.format(self.__table__) store.execute(sql, self.id) store.commit() blog = Blog.get(self.blog_id) blog.add_comment_count(-1)
def get_blog(): if request.get_json()['uid'] is None: return {'success': False, 'err': 'Invalid request body'} retrieve_blog = Blog.get(request.get_json()['uid']) return {'blog': retrieve_blog.to_dict()}