def post(self, id): import os, static, hashlib from models import StoryAuthor, Story, StoryDocument from django.template.defaultfilters import slugify from google.appengine.runtime.apiproxy_errors import RequestTooLargeError content = self.request.get('content') title = self.request.get('title') story = Story.get_by_id(int(id, 10)) story.content = content story.title = title story.put() try: request_document = self.request.get('document') document_file = self.request.POST['document'] if request_document: document_body = document_file.value document_digest = hashlib.sha1(document_body).hexdigest() split_name = os.path.splitext(os.path.basename(document_file.filename)) filename = slugify(split_name[0]) or document_digest document_name = filename + split_name[1] document_path = '/story/%d/document/%s/%s' % (story.key().id(), document_digest, document_name) logging.info(document_path) story_document = StoryDocument(story=story, path=document_path, name=document_name) story_document.put() document = static.set(document_path, document_body, document_file.type) self.get(id) except RequestTooLargeError, message: self.render_to_response("story_edit.html", story=Story.get_by_id(int(id, 10)), request_too_large_error=True)
def story(self, story_id, is_author=False): story = Story.get_by_id(int(story_id)) if not story: self.abort(404) if is_author and story.author != self.user: self.abort(401) return story
def decorate(self, entity_id=None): entity = None if entity_id: entity = Story.get_by_id(int(entity_id)) if not entity: self.error(404) return fun(self, entity)
def get(self, id): user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return logging.warn("Logged in as %s (%s)", user.nickname(), user.user_id()) self.render_to_response("story_edit.html", story=Story.get_by_id(int(id, 10)), request_too_large_error=False)