def get(self, id): id = urllib.unquote(urllib.unquote(id)) greetings = FotosDB2.get_by_id(int(id)) if greetings.user == users.get_current_user().nickname(): blob = blobstore.BlobInfo.get(greetings.foto) blob.delete() greetings.delete() else: pass return self.redirect('/fotos/%s' % users.get_current_user().nickname())
def post(self): if users.get_current_user() and self.get_uploads('foto'): self.pc = 100 self.big = 500 self.mob = 50 self.max_size = 2097152 upload_files = self.get_uploads('foto') blob_info = upload_files[0] key = blob_info.key() if key: user = users.get_current_user() usert = FotosDB() blob = blobstore.BlobInfo(key) image = blob.open() prop = blob.content_type import re m = re.search("image/jpeg|image/png|image/gif", prop) if m is None: blobstore.BlobInfo(key).delete() return self.redirect('/fotos/%s?msg=%s' % (users.get_current_user(), u'Type is not support')) image = image.read() img = images.Image(image) if len(image) >= self.max_size: blobstore.BlobInfo(key).delete() return self.redirect('/fotos/%s?msg=%s' % (users.get_current_user(), u'Max size 2MB')) if img.width >= self.pc or img.height >= self.pc: foto_pc = images.resize(image, self.pc, self.pc) else: foto_pc = image if img.width >= self.mob or img.height >= self.mob: foto_mob = images.resize(image, self.mob, self.mob) else: foto_mob = image if img.width >= self.big or img.height >= self.big: foto_big = images.resize(image, self.big, self.big) else: foto_big = image usert.foto = str(key) usert.foto_mob = db.Blob(foto_mob) usert.foto_big = db.Blob(foto_big) usert.foto_pc = db.Blob(foto_pc) usert.user = user.nickname() usert.put() return self.redirect('/fotos/%s' % (users.get_current_user()))
def get(self, mode, ruser): self.valid_chars = frozenset("0123456789") self.response.headers['Content-Type'] = "image/png" no_valid = False if ruser is int: ruser = ruser for n in ruser: if n in self.valid_chars: pass else: no_valid = True if no_valid: fname = 'img_m.txt' img_f = open(fname, 'r') image = img_f.read() return self.response.out.write(image) else: ruser = urllib.unquote(urllib.unquote(ruser)) mode = urllib.unquote(urllib.unquote(mode)) foto_get = FotosDB.get_by_id(int(ruser)) if mode == 'big': foto = foto_get.foto_big elif mode == 'pc': foto = foto_get.foto_pc if mode == 'big': foto = foto_get.foto_big elif mode == 'mob': foto = foto_get.foto_mob if mode == 'big': foto = foto_get.foto_big elif mode == 'org': foto = blobstore.BlobInfo.get(foto_get.foto) return self.send_blob(foto) if foto: return self.response.out.write(foto) else: fname = 'img_m.txt' img_f = open(fname, 'r') image = img_f.read() return self.response.out.write(image)