def post(self): self.admin_or_login() # get new post DB properties title = self.request.get('post-title') body = self.request.get('post-body') if not title or not body: # forgot something - make user go back return self.render('new-blog-post.html', post_title=title, post_body=body) title_path = get_title_path(title, character_limit=30) today = datetime.date.today() offset = len(Mail.get_posts_by_date(today)) # TODO: use gql.count() instead of len(posts) # put post in DB mail_key = Mail(title=title, title_path=title_path, body=body, bday_offset=offset).put() # get blog post document search properties fields = [search.TextField(name='title', value=title), search.TextField(name='body', value=body)] doc = search.Document(doc_id=mail_key.urlsafe(), fields=fields) # put blog post in document search try: search.Index(name=SEARCH_INDEX_NAME).put(doc) except search.Error: logging.error('Document search PUT failed') # TODO: small bug - have to refresh after redirect self.redirect('/blog')
def get(self, year, month, day, offset=None, limit=MAX_POSTS_PER_PAGE): if offset is not None: offset = int(offset) limit = 1 year, month, day = map(int, (year, month, day)) date = datetime.datetime(year, month, day) posts = Mail.get_posts_by_date(date, limit=limit, offset=offset) self.view_posts(posts)