Esempio n. 1
0
 def get(self):
     msg = self.request.get('msg')
     if msg:
         template_values = {
             'msg': msg
         }
         template = JINJA_ENVIRONMENT.get_template('info.html')
         self.response.write(template.render(template_values))
     else:
         blog_name = self.request.get('blog_name')
         curs = Cursor(urlsafe=self.request.get('cursor'))
         tags = []
         
         if blog_name == '':
             blogposts_query = BlogPost.query().order(-BlogPost.create_time) 
             templist = []
             for post in blogposts_query.fetch():
                 templist = templist + post.taglist
             tags = list(set(templist))
             selectedblog=''
         else:
             blogposts_query = BlogPost.query(ancestor=blog_key(blog_name)).order(-BlogPost.create_time) 
             blog_query = Blog.query().filter(Blog.blog_name == blog_name)
             selectedblog = blog_query.fetch()[0]
             
         blogposts, next_curs, more = blogposts_query.fetch_page(MAX_POST_PER_PAGE, start_cursor=curs)
         cur_url = ''
         if more and next_curs:
             cur_url = next_curs.urlsafe()
         
         user = users.get_current_user()
         if user:
             blogs_query = Blog.query(ancestor=user_key(user.email())).order(-Blog.create_time)
             blogs = blogs_query.fetch()
             url = users.create_logout_url(self.request.uri)
             url_linktext = 'Logout'   
         else:
             blogs = ''
             url = users.create_login_url(self.request.uri)
             url_linktext = 'Login'
 
         template_values = {
             'user': user,
             'blogs': blogs,
             'selectedblog': selectedblog,
             'blogposts':  blogposts,
             'url': url,
             'url_linktext': url_linktext,
             'cur_url': cur_url,
             'tags': tags,
         }    
          
         template = JINJA_ENVIRONMENT.get_template('index.html')
         self.response.write(template.render(template_values))
Esempio n. 2
0
 def get(self, postId, param):
     if param == '.json':
         return self.serveJson(postId)
     blog = Blog.getById(str(postId))
     if not blog:
         self.error(404)
         return
     self.render('permalink.html', blog=blog, user=self.user)
Esempio n. 3
0
def submit():
    
    if request.method == 'POST':
         title = request.form['title']
         body = request.form['body']
         
         if title and body:
             data = Blog(title, body, "null")
             db.session.add(data)
             db.session.commit()
             flash("Submission Successful")
         else:
             flash("Enter the required fields")
             
         return render_template('submit.html')
     
    return render_template('submit.html')
Esempio n. 4
0
 def post(self):
     user = users.get_current_user()
     blog_name = self.request.get('blog_name')
     
     blogs_query = Blog.query().order(-Blog.create_time)
     blogs_query = blogs_query.filter(Blog.blog_name == blog_name)
     blogs = blogs_query.fetch()
           
     if blogs: 
         query_params = {'msg': EXISTING_BLOG_MSG}
         self.redirect('/?'+ urllib.urlencode(query_params))
     else:      
         blog = Blog(parent=main.user_key(user.email()))
         blog.author = user
         blog.blog_name = blog_name
         blog.create_time = datetime.now()
         blog.put()
         self.redirect('/?blog_name='+blog.blog_name)
Esempio n. 5
0
 def post(self, param_username):
     # retrieve submission fields
     subject = self.request.get('subject')
     content = self.request.get('content')
     username = self.user.username
     profile_name = self.user.profile_name
     # check that all required fields are filled in
     if subject and content:
         newBlog = Blog.createBlog(subject=subject,
                                   content=content,
                                   username=username,
                                   profile_name=profile_name)
         newBlog.content = newBlog.content.replace('\\n', '<br>')
         # flush the cache on db write
         Cache.flush()
         key = newBlog.put()
         self.redirect("/entry/%s" % str(key.id()))
     else:
         error = 'Please submit both subject and content'
         self.render_newpost(subject=subject, content=content, error=error)
Esempio n. 6
0
 def get(self):
 
     blog_name = self.request.get('blog_name')
     blogs_query = Blog.query().order(-Blog.create_time)
     blogs_query = blogs_query.filter(Blog.blog_name == blog_name)
     blogs = blogs_query.fetch()
     blog = blogs[0]
     
     posts_query = BlogPost.query(ancestor=main.blog_key(blog_name)).order(-BlogPost.create_time)
     posts = posts_query.fetch()
     
     template_values = {
         'blog': blog,
         'posts': posts,
         'back_url': self.request.uri
     }
     
     template = main.JINJA_ENVIRONMENT.get_template('rss.html')
     self.response.headers['Content-Type'] = 'text/plain'
     self.response.write(template.render(template_values))
     
Esempio n. 7
0
 def serveJson(self, postId):
     blog = Blog.getById(str(postId))
     json_file = {'subject': blog.subject, 'content': blog.content}
     json_out = json.dumps(json_file)
     return self.write(json_out)