def page(context, request): #get mongoDB posts blog_data = BlogData(request, 'page') page = blog_data.get_post_by_url(context.__name__) if page is None: raise HTTPNotFound('notfound').exception return {'cur_page': page[u'shortname'], 'page_title': page[u'title'], 'url': page[u'url'], 'body': page[u'body'] }
def page(context, request): #get mongoDB posts blog_data = BlogData(request, 'page') page = blog_data.get_post_by_url(context.__name__) if page is None: raise HTTPNotFound('notfound').exception return { 'cur_page': page[u'shortname'], 'page_title': page[u'title'], 'url': page[u'url'], 'body': page[u'body'] }
def post(context, request): #get mongoDB posts blog_data = BlogData(request) post = blog_data.get_post_by_url(context.__name__) if post is None: raise HTTPNotFound('notfound').exception postDate = post[u'postDate'].strftime("%B %d %Y") return {'cur_page': '', 'page_title': post[u'title'], 'title': post[u'title'], 'category': post[u'category'], 'author': post[u'author'], 'url': post[u'url'], 'date': postDate, 'blog_body': post[u'postText'], 'tags': post[u'tags']}
def post(context, request): #get mongoDB posts blog_data = BlogData(request) post = blog_data.get_post_by_url(context.__name__) if post is None: raise HTTPNotFound('notfound').exception postDate = post[u'postDate'].strftime("%B %d %Y") return { 'cur_page': '', 'page_title': post[u'title'], 'title': post[u'title'], 'category': post[u'category'], 'author': post[u'author'], 'url': post[u'url'], 'date': postDate, 'blog_body': post[u'postText'], 'tags': post[u'tags'] }
def new_post(context, request): post_data = dict() blog_data = BlogData(request) #This handles the New entry post if 'postBlog' in request.params: if request.params['action_type'] == 'add': for key, value in request.params.items(): if key == 'tags': value = value.split(', ') if key != 'postBlog' or key != 'action_type': post_data[key] = value post_data['author'] = 'Brett Dangerfield' post_data['postDate'] = datetime.datetime.utcnow() #check to see if the post is active if 'active' in post_data.keys(): post_data['active'] = True else: post_data['active'] = False #insert the post into mongo collection = request.db['blogPosts'] try: collection.insert(post_data, safe=True) return {'success': True, 'message': 'Post Saved'} except pymongo.errors.DuplicateKeyError: return {'success': False, 'message': 'Duplicate URL'} #we are editing an existing post elif request.params['action_type'] == 'edit': for key, value in request.params.items(): if key == 'tags': value = value.split(', ') if key != 'postBlog' or key != 'action_type': post_data[key] = value post_data['author'] = 'Brett Dangerfield' post_data['postDate'] = datetime.datetime.utcnow() #check to see if the post is active if 'active' in post_data.keys(): post_data['active'] = True else: post_data['active'] = False #insert the post into mongo collection = request.db['blogPosts'] try: collection.update({'url': post_data['url']}, post_data) return {'success': True, 'message': 'Post Saved'} except pymongo.errors.DuplicateKeyError: return {'success': False, 'message': 'Duplicate URL'} #now let's handle the list of entries elif 'listPosts' in request.params: posts = blog_data.get_all_posts(50, 1) entries = [] for post in posts: postDate = post[u'postDate'].strftime("%B %d %Y") tags = post[u'tags'] if u'tags' in post else '' entry = {'title': post[u'title'], 'url': post[u'url'], 'date': postDate, 'category': post[u'category'], 'tags': tags, 'active': post[u'active']} entries.append(entry) return {'entries': entries} #get a single post for editing elif 'editPost' in request.params: post = blog_data.get_post_by_url(request.params['id']) return {'title': post[u'title'], 'category': post[u'category'], 'author': post[u'author'], 'url': post[u'url'], 'author': post[u'author'], 'blog_body': post[u'postText'], 'active': post[u'active'], 'tags': post[u'tags']}
def new_post(context, request): post_data = dict() blog_data = BlogData(request) #This handles the New entry post if 'postBlog' in request.params: if request.params['action_type'] == 'add': for key, value in request.params.items(): if key == 'tags': value = value.split(', ') if key != 'postBlog' or key != 'action_type': post_data[key] = value post_data['author'] = 'Brett Dangerfield' post_data['postDate'] = datetime.datetime.utcnow() #check to see if the post is active if 'active' in post_data.keys(): post_data['active'] = True else: post_data['active'] = False #insert the post into mongo collection = request.db['blogPosts'] try: collection.insert(post_data, safe=True) return {'success': True, 'message': 'Post Saved'} except pymongo.errors.DuplicateKeyError: return {'success': False, 'message': 'Duplicate URL'} #we are editing an existing post elif request.params['action_type'] == 'edit': for key, value in request.params.items(): if key == 'tags': value = value.split(', ') if key != 'postBlog' or key != 'action_type': post_data[key] = value post_data['author'] = 'Brett Dangerfield' post_data['postDate'] = datetime.datetime.utcnow() #check to see if the post is active if 'active' in post_data.keys(): post_data['active'] = True else: post_data['active'] = False #insert the post into mongo collection = request.db['blogPosts'] try: collection.update({'url': post_data['url']}, post_data) return {'success': True, 'message': 'Post Saved'} except pymongo.errors.DuplicateKeyError: return {'success': False, 'message': 'Duplicate URL'} #now let's handle the list of entries elif 'listPosts' in request.params: posts = blog_data.get_all_posts(50, 1) entries = [] for post in posts: postDate = post[u'postDate'].strftime("%B %d %Y") tags = post[u'tags'] if u'tags' in post else '' entry = { 'title': post[u'title'], 'url': post[u'url'], 'date': postDate, 'category': post[u'category'], 'tags': tags, 'active': post[u'active'] } entries.append(entry) return {'entries': entries} #get a single post for editing elif 'editPost' in request.params: post = blog_data.get_post_by_url(request.params['id']) return { 'title': post[u'title'], 'category': post[u'category'], 'author': post[u'author'], 'url': post[u'url'], 'author': post[u'author'], 'blog_body': post[u'postText'], 'active': post[u'active'], 'tags': post[u'tags'] }