def is_valid(self): is_valid = super(PictureForm, self).is_valid() self.cleaned_data = self.fields.copy() gallery_id = self.cleaned_data.get('gallery_id') gallery = Gallery.get_by_id(int(gallery_id)) if gallery: self.cleaned_data['gallery'] = gallery else: self.errors['gallery'] = 'Can not find the porfolio' del self.cleaned_data['gallery_id'] if self.cleaned_data.has_key('price'): price = self.cleaned_data['price'] if price == '': self.cleaned_data['_price_by_cent'] = None del self.cleaned_data['price'] else: try: self.cleaned_data['price'] = float(price) except ValueError: self.errors['price'] = 'Price is not valid' self.cleaned_data['original_available'] = bool( self.cleaned_data['original_available'] ) image = self.cleaned_data.get('image') if image == None or len(image) == 0: if hasattr(self, 'instance'): image = self.instance.image if len(image) == 0: self.errors['image'] = 'Please upload an image' else: self.cleaned_data['image'] = db.Blob(watermark(image)) return len(self.errors) == 0
def get(self): id = self.request.get("_id") gallery = None if id: gallery = Gallery.get_by_id(int(id)) if not gallery: gallery = Gallery.all().get() self.render_to_template("porfolio.html", {"gallery_list": Gallery.all(), "gallery": gallery})
def get(self): id = self.request.get('_id') picture_id = self.request.get('picture_id') picture = Picture.get_by_id(int(picture_id)) if picture_id else None gallery_list = Gallery.all().order('-create_date') if id: gallery = Gallery.get_by_id(int(id)) else: if picture is None: gallery = gallery_list.get() else: gallery = picture.gallery if gallery and (picture is None or picture.gallery.id != gallery.id): picture = gallery.pictures.get() self.render_to_template('porfolio.html', { 'gallery_list': gallery_list, 'gallery': gallery, 'cur_picture': picture, })
def is_valid(self): is_valid = super(PictureForm, self).is_valid() self.cleaned_data = self.fields.copy() gallery_id = self.cleaned_data.get('gallery_id') gallery = Gallery.get_by_id(int(gallery_id)) if gallery: self.cleaned_data['gallery'] = gallery else: self.errors['gallery'] = 'Can not find the porfolio' del self.cleaned_data['gallery_id'] title = self.cleaned_data.get('title') if not title: self.errors['title'] = 'This field is required' price = self.cleaned_data.get('price') if price: try: self.cleaned_data['price'] = float(price) except ValueError: self.errors['price'] = 'Price is not valid' else: del self.cleaned_data['price'] self.cleaned_data['original_available'] = bool( self.cleaned_data['original_available'] ) image = self.cleaned_data.get('image') if image == None or len(image) == 0: if hasattr(self, 'instance'): image = self.instance.image if len(image) == 0: self.errors['image'] = 'Please upload an image' else: self.cleaned_data['image'] = db.Blob(str(image)) return len(self.errors) == 0