def new_blog(self, title, description): # __init__(self, author, title, description, author_id, _id=None): blog = Blog(author=self.email, title=title, description=description, author_id=self._id) blog.save_to_mongo()
def new_blog(self, title, description): # author, title, description, author_id blog = Blog(author=self.email, title =title, desciption=description, author_id = self._id) blog.save_to_mongo()
def new_blog(self, title, description): # author, title, description, author_id, blog = Blog(author=self.email, title=title, description=description, author_id=self._id) blog.save_to_mongo()
def new_blog(self, title, description): #author, title, description, author_id; the author details can be obtained from session blog = Blog(author=self.email, title=title, description=description, author_id=self._id) blog.save_to_mongo()
def new_blog(self, title, description): """Create a new blog and save to mongo""" blog = Blog(author=self.email, title=title, description=description, author_id=self._id) blog.save_to_mongo()
def _prompt_user_for_account(self): title = input("Enter blog title: ") description = input("Enter blog description: ") blog = Blog(author=self.user, title=title, description=description) blog.save_to_mongo() self.user_blog = blog
def new_blog(self, title, description): #author, title, description, author_id #becaue they are logged in, we know the author and author_id blog = Blog(author=self.email, title=title, description=description, author_id=self._id) #current authors id blog.save_to_mongo()
def _prompt_user_for_account(self): title = input("Enter blog name: ") description = input("Enter blog description") blog = Blog(author=self.user, title=title, description=description) blog.save_to_mongo() self.user_blog = blog
def new_blog(self, title, description): # create new blog and save to database blog = Blog(author=self.email, title=title, description=description, author_id=self._id) blog.save_to_mongo()
def user_blogs(): l_email = session['email'] Blog.get_author_id("857dc58fdf8a4d8fba74d3e39c08e130") blogs = Blog return render_template("user_blogs.html", blog=blogs, email=l_email)
def create_new_blog(): if request.method=='GET': return render_template('new_blog.html') else: title=request.form['title'] description=request.form['description'] user=User.get_by_email(session['email']) blog=Blog(user.email,title,description,user._id) blog.save_to_mongo() return make_response(user_blogs(user._id))
def create_new_blog(): if request.method == 'GET': return render_template('new_blog.html') else: title = request.form['title'] description = request.form['description'] user = User.get_by_email(session['email']) new_blog = Blog(user.email, title, description, user._id) new_blog.save_to_mongo() return make_response(user_blogs(user._id))
def new_blog(): if request.method == 'GET': return render_template("new_blog.html") else: title = request.form['title'] description = request.form['description'] new_blog = Blog(title, description) new_blog.save_to_mongo() return redirect('/')
def new_blogs(): if request.method == "GET": return render_template("new_blog.html") else: user = User.get_by_email(session['email']) blog = Blog(author=user.email, title=request.form['title'], author_id=user._id, description=request.form['description']) blog.save_to_mongo() return make_response(get_blog(user._id))
def new_blog(self, title, description): """ The data will come from the website the user has to enter the title, description from a form the author_id and author will come from there sessions """ blog = Blog(author=self.email, title=title, description=description, author_id=self._id) blog.save_to_mongo()
def new_blog(self, description, title): # 写新 blog 发生在 login 之后,所以我们就已经有了用户的各种信息 # What do Blog class have: # author, title, description, author_id blog = Blog(author=self.email, author_id=self._id, description=description, title=title ) # author 和 author_id 都是从 User 对象里来的,所以直接用 self 就可以 # title 和 description 是要用户后来添加的 blog.save_to_mongo()
def create_new_blog(): if request.method == "GET": return render_template("new_blog.html") else: title = request.form["title"] description = request.form["description"] user = User.get_by_email(session["email"]) new_blog = Blog(user.email, title, description, user._id) new_blog.save_to_mongo() return make_response(user_blogs(user._id))
def new_blog(self, title, description): # Blog(self, author, title, description, author_id, _id=None): # Here using email as the author of the blog blog = Blog(author=self.email, title=title, description=description, author_id=self._id) # note - we should do checking for duplicates / unsafe HTML # save blog after init blog.save_to_mongo()
def create_new_blog(): if request.method == 'GET': # the user just arrive at the end point return render_template('new_blog.html') else: # user press the submit button title = request.form['title'] description = request.form['description'] user = User.get_by_email(session['email']) new_blog = Blog(user.email, title, description, user._id) new_blog.save_to_mongo() return make_response(user_blogs( user._id)) # we want to redirect user to his blog
def create_new_blog(): #user came in directly from a url; so show them the create new from if request.method == 'GET': return render_template('new_blog.html') else: title= request.form['title'] description= request.form['description'] user = User.get_by_email(session['email']) new_blog=Blog(user.email, title, description, user._id) new_blog.save_to_mongo() #the below returns or calls user_blogs return make_response(user_blogs(user._id))
def create_new_blog(): if request.method == "GET": return render_template("new_blog.html") elif request.method == "POST": title = request.form["title"] description = request.form["description"] email = session["email"] current_user = User.get_by_email(email) new_blog = Blog(author=email, title=title, description=description, author_id=current_user.user_id) new_blog.save_to_mongo() return make_response(user_blogs_list())
def new_blog(): if request.method == 'GET': if session['email']: return render_template('new_blog.html') else: return render_template('index.html') else: title = request.form['title'] description = request.form['description'] blog = Blog(session['email'], title, description) blog.save_to_mongo() return make_response(blogs())
def create_newblog(): if request.method == 'GET': return render_template("newblog.html") else: user = User.getByEmail(session['email']) title = request.form['title'] description = request.form['description'] blog = Blog(author=user.email, title=title, description=description, author_id=user.id, _id=0) blog.save_database() return make_response(user_blogs(user.id))
def create_new_blog(): if request.method == 'GET': if session['email'] is None: return render_template( "login.html", message="Login or Register to create a blog! .") else: return render_template('new_blog.html', parameter=True) else: title = request.form['title'] description = request.form['description'] usr = User.get_by_email(session['email']) new_blog = Blog(usr.email, title, description, usr._id) new_blog.save_to_mongo() return make_response(user_blogs(usr._id))
def create_new_blog(): if request.method == 'GET': return render_template('new_blog.html') else: # post: received post data from 'new_blog.html' title = request.form['title'] description = request.form['description'] user = User.get_by_email(session['email']) new_blog = Blog(user.email, title, description, user._id) new_blog.save_to_mongo() # make_response is to turn to function user_blog with the value user._id blogs = Blog.find_by_author_id(user._id) return render_template("profile.html", email=session['email'], blogs=blogs)
def update_blog(blog_id): if request.method == 'GET': return render_template('update_blog.html', blog_id=blog_id) else: title = request.form['title'] description = request.form['description'] existing_blog = Blog.from_mongo(blog_id) if str.strip(title) == "": title = existing_blog.title if str.strip(description) == "": description = existing_blog.description updated_blog = Blog(existing_blog.author, existing_blog.author_id, title, description, existing_blog._id) updated_blog.update_blog(blog_id) return make_response(user_blogs())
async def update_article( article: Blog, current_user: User = Depends(get_current_active_user)): data = article.dict() b = BlogManager() article_data = Blog(**data) #article_data = article_data.dict() #print(article_data) status = b.update_article(document=article_data.slug, model=article_data) if status: return b.get_article(document=article_data.slug) else: return {"message": "failed"}
def _user_has_account(self): blog = Database.find_one('blogs', {'author': self.user}) if blog is not None: self.user_blog = Blog.from_mongo(blog['id']) return True else: return False
def create_new_blog(): if request.method == 'GET': return render_template( 'new_blog.html') #if users accesses page directly else: title = request.form['title'] description = request.form['description'] user = User.get_by_email(session['email']) new_blog = Blog(user.email, title, description, user._id) new_blog.save_to_mongo() # return render_template('user_blogs') return make_response( user_blogs(user._id) ) #can be useful to write blog for someone else ie as co-author
def new_post(blog_id, title, content, date=datetime.datetime.utcnow()): # title, content, date = datetime.datetime.utcnow() blog = Blog.from_mongo( blog_id ) # We need to consider the blog the user is writing to, blog_id sent # by website blog.new_post(title=title, content=content, date=date)
def _user_has_account(self): blog = Database.find_one(collection='blogs', query={'author': self.user}) if blog is not None: self.user_blog = Blog.from_mongo(blog['_id']) return True return False
def blog_posts(blog_id): print("blog_id {}".format(blog_id)) blog = Blog.from_mongo(blog_id) posts = blog.get_posts() return render_template('posts.html', posts=posts, blog_title=blog.title, blog_id=blog._id)
def blog_posts(blog_id): """Load posts from the selected blog""" blog = Blog.from_mongo(blog_id) posts = blog.get_posts() return render_template('posts.html', posts=posts, blog_title=blog.title, blog_id=blog._id)
def list_post(blog_id): blog = Blog.from_mongo(blog_id) posts = blog.get_all_posts() return render_template('user_posts.html', posts=posts, name_of_blog=blog.title, blog_id=blog._id)
def posts(blog_id): blog = Blog.from_mongo(blog_id) posts = blog.get_posts() return render_template('posts.html', posts=posts, blog_id=blog._id, blog_title=blog.title)
def new_post(self, blog_id, title, comment, date=datetime.datetime.utcnow()): blog = Blog.from_mongo(blog_id) blog.new_post(title=title, comment=comment, date=date)
def _user_has_account(self): blog = Database.find_one('blogs', {'author': self.user}) if blog is not None: #self.user_blog = blog #This would work however returning the object is better for this case self.user_blog = Blog.from_mongo(blog['id']) return True else: return False
def new_post(self,blog_id,title,content,date=datetime.datetime.utcnow()): blog=Blog.from_mongo(blog_id) blog.new_post(title=title, content=content, date=date )
def get_blogs(self): # Verify the structure of documents in DB for ease of retrieval. # Retrieval is best using an author ID because author name can be duplicated. unless is username. So Blog model is updated now to suit the change. prior only author name existed. return Blog.find_by_author_id(self._id)
def new_post(blog_id, title, content, date=datetime.datetime.utcnow()): #blog_id to know which blog to save to. This is automated no need to input from user. # title, content, date=datetime.utcnow() blog = Blog.from_mongo(blog_id) blog.new_post(title=title, content=content, date=date) #This has save to mongodb so we do not need to add save here.
def blog_posts(blog_id): blog = Blog.from_mongo(blog_id) posts = blog.get_posts() return render_template('posts.html', posts=posts, blog_title=blog.title, blog_id=blog._id)
def _view_blog(self): blog_to_see = input("Enter the ID of the blog you'd like to read: ") blog= Blog.from_mongo(blog_to_see) posts = blog.get_posts() for post in posts: print("Date: {}, title:{}\n\n{}".format(post['created_date'], post['title'], post['content']))
def new_blog(self,title,description): blog=Blog(self.email,title,description,self._id) blog.save_to_mongo()
def get_blogs(self): return Blog.find_by_author_id(self._id)