def loginLink(): if current_user.is_authenticated(): return dict(loggedIn=True, loginLink='<a href="/logout">Logout %s</a>' % current_user.cwruid) else: return dict(loginLink='<a href="/login">Login</a>')
def display_blog(): """ View to display existing blog posts """ new_post = None if current_user.is_authenticated(): query = UserRoleModel.all() query.filter('user ='******'webmaster': new_post = forms.NewPostForm() break query = models.PostModel.all() query.order('-timestamp') posts = query.fetch(10) for post in posts: post.url_timestamp = urllib.quote_plus(str(post.timestamp)) post.url_title = urllib.quote_plus(post.title) post_form = forms.NewPostForm() if request.method == 'POST' and post_form.validate(): post = models.PostModel(title=post_form.title.data, timestamp=dt.datetime.now(), text=post_form.text.data, author=current_user.key()) post.put() post.url_timestamp = urllib.quote_plus(str(post.timestamp)) post.url_title = urllib.quote_plus(post.title) posts.insert(0, post) if len(posts) > 10: del posts[-1] post_form = forms.NewPostForm(None) post_form = forms.NewPostForm(None) return render_template('blogs/display_posts.html', new_post=new_post, posts=posts)
def profileLink(): if current_user.is_authenticated(): return dict(profileLink='<a href="/members/view/%s" >My Profile</a>' % current_user.cwruid) else: return dict(profileLink='')
def loginLink(): if current_user.is_authenticated(): return dict(loggedIn = True, loginLink='<a href="/logout">Logout %s</a>' % current_user.cwruid) else: return dict(loginLink='<a href="/login">Login</a>')
def view_blog_post(timestamp, title): """ View to display blog post and associated comments """ edit_post = None # determine if the user has the proper role to edit if current_user.is_authenticated(): query = UserRoleModel.all() query.filter('user ='******'webmaster': edit_post = True break # get the blog posts query = models.PostModel.all() str_timestamp = urllib.unquote_plus(timestamp) timestamp = dt.datetime.strptime(str_timestamp, '%Y-%m-%d %H:%M:%S.%f') query.filter('timestamp =', timestamp) query.filter('title =', urllib.unquote_plus(title)) try: post = query.fetch(1)[0] except IndexError: return render_template('404.html'), 404 # add the urlencoded version of timestamp and post.url_timestamp = urllib.quote_plus(str(post.timestamp)) post.url_title = urllib.quote_plus(post.title) # get the comments query = models.CommentModel.all() query.filter('post =', post.key()) query.order('timestamp') comments = query.fetch(query.count()) # go through and add forms with delete button to each comment if the user # has edit privileges if edit_post is not None: for comment in comments: comment.delete = forms.DeleteCommentForm(None) comment.delete.key.data = comment.key() comment.url_timestamp = urllib.quote_plus(str(comment.timestamp)) form = forms.NewComment(request.form) if request.method == "POST" and form.validate(): comment = models.CommentModel(post=post.key(), timestamp=dt.datetime.now(), text=form.text.data, author=current_user.key()) comment.put() comment.delete = forms.DeleteCommentForm(None) comment.delete.key.data = comment.key() comment.url_timestamp = urllib.quote_plus(str(comment.timestamp)) comments.append(comment) return render_template('blogs/display_post.html', edit_post=edit_post, current_user=current_user, post=post, comments=comments, new_comment=forms.NewComment(None))
def view_blog_post(timestamp, title): """ View to display blog post and associated comments """ edit_post = None # determine if the user has the proper role to edit if current_user.is_authenticated(): query = UserRoleModel.all() query.filter('user ='******'webmaster': edit_post = True break # get the blog posts query = models.PostModel.all() str_timestamp = urllib.unquote_plus(timestamp) timestamp = dt.datetime.strptime(str_timestamp, '%Y-%m-%d %H:%M:%S.%f') query.filter('timestamp =', timestamp) query.filter('title =', urllib.unquote_plus(title)) try: post = query.fetch(1)[0] except IndexError: return render_template('404.html'), 404 # add the urlencoded version of timestamp and post.url_timestamp = urllib.quote_plus(str(post.timestamp)) post.url_title = urllib.quote_plus(post.title) # get the comments query = models.CommentModel.all() query.filter('post =', post.key()) query.order('timestamp') comments = query.fetch(query.count()) # go through and add forms with delete button to each comment if the user # has edit privileges if edit_post is not None: for comment in comments: comment.delete = forms.DeleteCommentForm(None) comment.delete.key.data = comment.key() comment.url_timestamp = urllib.quote_plus(str(comment.timestamp)) form = forms.NewComment(request.form) if request.method=="POST" and form.validate(): comment = models.CommentModel(post=post.key(), timestamp=dt.datetime.now(), text=form.text.data, author=current_user.key()) comment.put() comment.delete = forms.DeleteCommentForm(None) comment.delete.key.data = comment.key() comment.url_timestamp = urllib.quote_plus(str(comment.timestamp)) comments.append(comment) return render_template('blogs/display_post.html', edit_post=edit_post, current_user=current_user, post=post, comments=comments, new_comment=forms.NewComment(None))