def post(self, key): post = self.request.POST edit = self.request.get('kind') form_data = dict((k, post.get(k, '')) for k in ('title', 'author', 'date', 'body', 'picture','video')) template_dict = {'form_data': form_data, 'key': key, 'show_form' : True,'members': Member.all(), 'edit':edit,'thing' : self.thing_descriptors.get(edit),'images':Image.all().filter('name != ', "no-name")} try: this_date = utils.parse_date(form_data['date']) except ValueError: template_dict['message'] = \ 'Date is not in the correct format (YYYY-MM-DD).' else: if key == 'new': try: if(edit=="news"): thing = NewsArticleNew( title=post['title'], author=Member.get_by_id(int(post['author'])), date=this_date, body=post['body'] ) elif(edit=="talk"): thing = TalkNew( title=post['title'], author=Member.get_by_id(int(post['author'])), date=this_date, body=post['body'] ) if('video' in post): talk.video = post['video'] elif(edit=="hack"): thing = Hack( title=post['title'], date=this_date, body=post['body'] ) if(edit=="news" or edit=="hack"): if(self.request.get("picture")): pictureImage = Image( picture=images.resize(self.request.get("picture"), self.image_height, self.image_width), name="no-name",title=" ",alt=" ") if post['picture_title'] : pictureImage.title=post['picture_title'] if post['picture_alt'] : pictureImage.alt=post['picture_alt'] pictureImage.put() thing.picture=pictureImage elif(post['picture_alias']!="none"): thing.picture=Image.get_by_id(int(post['picture_alias'])) thing.put() template_dict['key']=thing.key except datastore_errors.Error: template_dict['message'] = \ 'Could not create new %s.' % self.thing_descriptors.get(edit) else: template_dict['message'] = '%s created.' % self.thing_descriptors.get(edit) template_dict['show_form'] = False else: try: if(edit=="news"): thing = NewsArticleNew.get(Key(key)) thing.title = form_data['title'] thing.author = Member.get_by_id(int(post['author'])) thing.date = this_date thing.body = form_data['body'] elif(edit=="talk"): thing = TalkNew.get(Key(key)) thing.title = form_data['title'] thing.date = this_date thing.body = form_data['body'] elif(edit=="hack"): thing = Hack.get(Key(key)) thing.title = form_data['title'] thing.date = this_date thing.body = form_data['body'] if(self.request.get("picture")): pictureImage = Image(picture=images.resize(self.request.get("picture"), self.image_height, self.image_width), name="no-name",title=" ",alt=" ") if post['picture_title'] : pictureImage.title=post['picture_title'] if post['picture_alt'] : pictureImage.alt=post['picture_alt'] pictureImage.put() thing.picture = pictureImage elif(post['picture_alias']!="none"): thing.picture=Image.get_by_id(int(post['picture_alias'])) if 'delete_picture' in post: thing.picture=None except BadKeyError: template_dict['message'] = \ 'Could not find %s with key %r.' % (self.thing_descriptors.get(edit),key) else: try: thing.put() except datastore_errors.Error: template_dict['message'] = \ 'Could not save changes to %s.' % self.thing_descriptors.get(edit) else: template_dict['form_data'] = thing template_dict['message'] = 'Changes saved.' self.render_template('edit', template_dict)