def images_exists(self, hash): images = Image.gql("WHERE sha1_hash = :h", h = hash) for image in images: if image.sha1_hash == hash: return True return False
def post(self,subdomain=None): product_id=self.request.get("product_id") upload_files = self.get_uploads('file') # 'file' is file upload field in the form blob_info = upload_files[0] for i in range(0,5): count = Image.gql("WHERE __key__=KEY('Image','%s-%s') LIMIT 1" % (product_id,i)).count() if count == 0: image = Image(blob_key=str(blob_info.key()),key_name='%s-%s' %(product_id, i),user=subdomain) image.put() self.redirect('/serve/%s-%s' % (product_id,i)) break; self.response.out.write('Maximum number of images for this product id, please delete one before uploading.'),
def get(self, hash): res = self.request.get('res') r = res.split('x') if len(hash) <> 40: self.wrong_url() return # The default is the empty string. # Check for empty resolution string if res == '' or '' in r or len(r) < 2: self.wrong_url() return # check if dimensions are at least 100x100 if len(r[0]) < 3 or len(r[1]) < 3: self.wrong_url() return # check if dimensions are numbers at all try: int(r[0]) int(r[1]) except ValueError: self.wrong_url() return images = Image.gql("WHERE sha1_hash = :h ORDER BY filenumber", h = hash) # hash is only first 40 chars if images.count() == 0: self.wrong_url() return template_values = { 'images': images, 'hash' : hash, 'w' : r[0], 'h' : r[1] } path = os.path.join(os.path.dirname(__file__), 'templates/problem.html') self.response.out.write(template.render(path, template_values))