def add_entry(): form = EntryForm() if form.validate_on_submit(): post = EntryModel( title=form.title.data, text=markdown(form.text.data), slug=make_slug(form.title.data) ) try: post.put() except CapabilityDisabledError: flash(u'Read-only mode.') return redirect(url_for('projects'))
def blog(): entries = EntryModel.query().order(-EntryModel.timestamp) form = None if users.is_current_user_admin(): form = EntryForm() return { 'entries' : entries, 'form' : form }
def delete(self, entry_id): logging.info("test") entry = EntryModel.get_by_id(int(entry_id)) if entry is None: return {'status' : 404, 'message' : 'entry not found'}, 404 entry.delete() return '', 204
def show_post(post_slug): post = EntryModel.query(EntryModel.slug == post_slug).get() if not post: return render_template('404.html'), 404 form = None if users.is_current_user_admin(): form = EntryForm(obj=post) return { 'post' : post, 'form' : form }
def post(self): parser = reqparse.RequestParser() parser.add_argument('title') parser.add_argument('description') args = parser.parse_args() entry = EntryModel( title = args['title'], description = args['description'], added_by = users.get_current_user() ) try: entry.put() return Entry.format(entry), 201 except CapabilityDisabledError: return {'status' : 500, 'message' : 'can\'t access database'}, 500
def edit_entry(post_id): post = EntryModel.get_by_id(post_id) if not post: return render_template('404.html'), 404 form = EntryForm() if form.validate_on_submit(): post.title = form.title.data post.text = markdown(form.text.data) post.slug = make_slug(post.title) try: post.put() except CapabilityDisabledError: flash(u'Read-only mode.') return redirect(url_for('projects'))
def put(self, entry_id): parser = reqparse.RequestParser() parser.add_argument('title') parser.add_argument('description') args = parser.parse_args() entry = EntryModel.get_by_id(int(entry_id)) if entry is None: return {'status' : 404, 'message' : 'entry not found'}, 404 entry.title = args['title'] entry.description = args['description'] try: entry.put() return Entry.format(entry), 201 except CapabilityDisabledError: return {'status' : 500, 'message' : 'can\'t access database'}, 500
def get(self): parser = reqparse.RequestParser() parser.add_argument('cursor') args = parser.parse_args() curs = Cursor(urlsafe=args['cursor']) q = EntryModel.query() q_forward = q.order(-EntryModel.timestamp) q_reverse = q.order(EntryModel.timestamp) entries, next_curs, more = q_forward.fetch_page(10, start_cursor=curs) out = [] for entry in entries: out.append(Entry.format(entry)) nextCurs = "" if more: nextCurs = next_curs.urlsafe() prevCurs = "" if next_curs is not None: rev_cursor = next_curs.reversed() old_entries, prev_cursor, fewer = q_reverse.fetch_page(10, start_cursor=rev_cursor, offset=len(out)) if prev_cursor is not None: prevCurs = prev_cursor.urlsafe() return { 'meta': { 'prev_curs': prevCurs, 'curs': curs.urlsafe(), 'next_curs': nextCurs }, 'entries': out }
def del_entry(post_id): EntryModel.get_by_id(post_id).key.delete() return redirect(url_for('projects'))
def get(self, entry_id): entry = EntryModel.get_by_id(int(entry_id)) if entry is None: return {'status' : 404, 'message' : 'entry not found'}, 404 return Entry.format(entry), 200