def get(self, key): edit = self.request.get('edit') template_dict = {'key': key, 'show_form' : True,'members': Member.all(), 'edit':edit,'thing' : self.thing_descriptors.get(edit),'images':Image.all().filter('name != ', "no-name") } if key == 'new': template_dict['form_data'] = { 'author': Member.get_current_member().handle, 'date': unicode(datetime.date.today())} else: try: if(edit=='news'): thing = NewsArticleNew.get(Key(key)) form_data={'title':thing.title,'author':thing.author,'date':unicode(thing.date),'body':thing.body,'picture':thing.picture} elif(edit=='talk'): thing = TalkNew.get(Key(key)) form_data={'title':thing.title,'author':thing.author,'date':unicode(thing.date),'body':thing.body,'video':thing.video} elif(edit=='hack'): thing = Hack.get(Key(key)) form_data={'title':thing.title,'date':unicode(thing.date),'body':thing.body,'picture':thing.picture} template_dict['form_data']=form_data except BadKeyError: template_dict['message'] = \ 'Could not find %s with key %r.' % (self.thing_descriptors.get(edit), key) template_dict['show_form'] = False self.render_template('edit', template_dict)
def get(self): if 'tabselect' in self.request.GET: tabselect = self.request.get('tabselect') else: tabselect='general' self.render_template('admin', {'news_list' : NewsArticleNew.all().order('-date'), 'talk_list' : TalkNew.all().order('-date'), 'hack_list' : Hack.all().order('-date'), 'image_list' : Image.all(), 'image_height' : self.image_height, 'image_width' : self.image_width, 'members': Member.all(), 'message' : self.admin_message, 'tabselect':tabselect})
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)
def post(self): post = self.request.POST kind=post['kind'] if kind== 'taglineform': properties = GeneralSiteProperties.all().get() if properties == None: properties = GeneralSiteProperties(tag_line=post['tagline']) properties.put() else: properties.tag_line = post['tagline'] properties.put() elif kind=="image_upload": if(self.request.get("picture")): try: if('resize' in post): pictureImage = Image(picture=images.resize(self.request.get("picture"),int(post['height']), int(post['width'])), name="no-name",title=" ",alt=" ") else: pictureImage = Image(picture=self.request.get("picture"),name="no-name",title=" ",alt=" ") if(post['alias']!=""): replace=True name=post['alias'] for other_image in Image.all(): if other_image.name == name : replace=False self.admin_message="You cannot use %s as an alias as it is used for another image" % name if replace : pictureImage.name=name if(post['title']!=""): pictureImage.name=post['title'] if(post['alt']!=""): pictureImage.name=post['alt'] pictureImage.put() self.admin_message = 'Image uploaded' except RequestTooLargeError: self.admin_message = 'Image not uploaded - too large' except TypeError: self.admin_message = 'Width and Height have to be integers' else: self.admin_message = 'You need to actually select a picture!' kind='image' else : things_deleted = 0 for entry_key in self.request.POST.getall('delete_entry'): try: entry_key = Key(entry_key) except BadKeyError: # Wrong syntax for a key, move on to next key. continue if(kind=='news'): thing = NewsArticleNew.get(entry_key) elif(kind=='talk'): thing = TalkNew.get(entry_key) elif(kind=='hack'): thing = Hack.get(entry_key) if thing: thing.delete() things_deleted += 1 # Else, not article has this key. self.admin_message = '%d %s(s) deleted.' % (things_deleted,self.thing_descriptors.get(kind)) self.render_template('admin', {'news_list' : NewsArticleNew.all().order('-date'), 'talk_list' : TalkNew.all().order('-date'), 'hack_list' : Hack.all().order('-date'), 'image_list' : Image.all(), 'image_height' : self.image_height, 'image_width' : self.image_width, 'members': Member.all(), 'message' : self.admin_message, 'tabselect':kind})