コード例 #1
0
ファイル: handlers.py プロジェクト: seithenin/jwa
 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})
コード例 #2
0
ファイル: test_all.py プロジェクト: seithenin/jwa
 def testPicturePrice(self):
     gallery = Gallery(title='g1')
     gallery.put()
     test_price = 1.99
     # price is actualy save in _price_by_cent as int
     # befor saving it convert to 199, then when retrieve it convert back
     picture = Picture(
         gallery=gallery, title='p1', price=test_price
     )
     picture.put()
     # test price is still orignal value
     self.assertEqual(picture.price, test_price)
コード例 #3
0
ファイル: forms.py プロジェクト: xiaohanzhang/jwa
    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
コード例 #4
0
ファイル: handlers.py プロジェクト: xiaohanzhang/jwa
    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,
        })
コード例 #5
0
ファイル: forms.py プロジェクト: seithenin/jwa
    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