def post(self): ''' Handles blog entry creation ''' self.response.headers['Content-Type'] = 'text/html' isValid = True values = {} subject = self.request.get('subject') if not subject: values['subject_error'] = 'Blog subject is required' isValid = False else: logging.info("Creating blog entry with subject: %s" % str(subject)) content = self.request.get('content') if not content: values['content_error'] = 'Blog content is required' isValid = False else: logging.info("Creating blog entry with content: %s" % str(content)) path = None if not isValid: values['subject'] = subject values['content'] = content path = os.path.join(os.path.dirname(__file__), 'create_blog_entry.html') self.response.out.write(template.render(path, values)) else: blog = BlogData(subject=subject, content=content) service = BlogService(BlogDataStoreFactory()) service.save(blog) blog_id = blog.key().id() str_blog_id = str(blog_id) logging.info("Successfully posted blog entry. Redirectinr to '/unit5/%s" % str_blog_id ) self.redirect('/unit5/%s' % str_blog_id)
def get(self): ''' Handles displaying a json for all blog entries ''' self.response.headers['Content-Type'] = 'application/json' service = BlogService(BlogDataStoreFactory()) blog_json = service.create_all_json() self.response.out.write(blog_json)
def get(self): ''' Handles initial get request ''' self.response.headers['Content-Type'] = 'text/html' service = BlogService(BlogDataStoreFactory()) blog_entries = service.fetchAll() values = {'blog_entries': blog_entries} path = os.path.join(os.path.dirname(__file__), 'blog.html') self.response.out.write(template.render(path, values))
def setUp(self): # First, create an instance of the Testbed class. self.testbed = testbed.Testbed() # Then activate the testbed, which prepares the service stubs for use. self.testbed.activate() # Next, declare which service stubs you want to use. self.testbed.init_datastore_v3_stub() self.factory = BlogDataStoreFactory() self.storage = self.factory.get_storage() self.service = BlogService(self.factory)
def get(self, entry_id): ''' Handles displaying a blog entry ''' self.response.headers['Content-Type'] = 'text/html' # entry_id = self.request.get('entry_id') service = BlogService(BlogDataStoreFactory()) data = service.fetch(int(entry_id)) values = {'subject': data.subject, 'content':data.content} path = os.path.join(os.path.dirname(__file__), 'show_blog_entry.html') self.response.out.write(template.render(path, values))