def get(self, hash, extension=None): q = Album.all().filter('hash =', hash) album = q.get() if album: if extension: return self.error(404) q = Image.all().filter('album =', album) return self.response.out.write(render_template('album.html', { 'name': album.name, 'images': q, })) q = Image.all().filter('hash =', hash) image = q.get() if image: if not extension: return self.response.out.write(render_template('image.html', { 'image': image })) elif image.extension == extension: return write_image(self, image.image_data, extension) else: return self.error(404) return self.error(404)
def delete(self, album_id, image_id, extension=None): """DELETE handler for gallery images. URL pattern: /albums/${album_id}/images/${image_id} If image exists, returns 200 OK. If image doesn't exist, returns 404 NOT FOUND. Returns 401 UNAUTHORIZED to all calls if authorization fails. """ q = Album.all().filter('album_id =', album_id) album = q.get() if not album: return self.error(404) q = Image.all().filter('album =', album).filter('image_id =', image_id) image = q.get() if not image: return self.error(404) if extension and extension != image.extension: return self.error(404) if not config.DEMO_MODE: image.delete()
def get(self, album_id, image_id, extension=None): """GET handler for GGB image metadata and files. URL pattern: /albums/${album_id}/images/${image_id}(${extension}) If called without a file extension: If image exists, returns 200 OK with JSON image data structure. Returns Content-type: application/json. If image doesn't exist, returns 404 NOT FOUND. If called with a file extension: If image exists and has the matching extension, returns the image. Returned Content-type matches the image format. Otherwise returns 404 NOT FOUND. Returns 401 UNAUTHORIZED to all calls if authorization fails. """ q = Album.all().filter('album_id =', album_id) album = q.get() if not album: return self.error(404) q = Image.all().filter('album =', album).filter('image_id =', image_id) image = q.get() if not image: return self.error(404) if not extension: data = image.to_dict() return write_json(self, image.to_dict()) if extension != image.extension: return self.error(404) write_image(self, image.image_data, image.extension)
def get(self): ''' List all album ''' self.template_value['albums'] = [(album.name, album.slug, album.count, album.cover_url) for album in Album.all()] return self.render()
def get(self): u = self.request.get("u") if u: self.template_value['albums'] = Album.all() self.template_value['u'] = u self.template_value['name'] = u.split( "/")[-1] or "aaaa" + mime.split("/")[-1] return self.render("upload-web2.html") self.render("upload-web.html")
def get(self): """GET handler for gallery albums. URL pattern: /albums Returns 200 OK with JSON data structure containing list of albums. Returns Content-type: application/json. Returns 401 UNAUTHORIZED to all calls if authorization fails. """ write_json(self, [album.to_dict() for album in Album.all()])
def post(self, album_id): """POST handler for a gallery image. URL pattern: /albums/${album_id}/images POST data must be of type multipart/form and contain image as 'file'. POST data must also contain image metadata: 'name'. Image filename must include an extension. Returns 201 CREATED with JSON data structure describing new image. Returns Content-type: application/json. Also returns Location header pointing to API URL for image details. Include 'wrapjson' parameter in POST to wrap returns JSON in a <textarea>. This also changes the returned Content-type to text/html. If album doesn't exist, returns 404 NOT FOUND. If request is poorly formatted returns 400 BAD REQUEST. Returns 401 UNAUTHORIZED to all calls if authorization fails. """ q = Album.all().filter('album_id =', album_id) album = q.get() if not album: return self.error(404) try: data = dict(((str(k), v) for k, v in self.request.POST.items())) if 'file' in data: data['extension'] = data['file'].filename.split('.')[-1].lower() if data['extension'] == data['file'].filename: data['extension'] = '' else: data['extension'] = '.' + data['extension'] data['image_data'] = data['file'].file.read() image = Image(image_id=config.IMAGE_ID_GENERATOR(), album=album, **data) except: data = {} self.error(400) else: if not config.DEMO_MODE: image.put() data = image.to_dict() self.response.headers['Location'] = data['url'] self.response.set_status(201) write_json(self, data, wrapjson='wrapjson' in self.request.POST)
def get(self, album_id): """GET handler for a particular gallery album. URL pattern: /albums/${album_id} If album exists, returns 200 OK with JSON album data structure. Returns Content-type: application/json. If album doesn't exist, returns 404 NOT FOUND. Returns 401 UNAUTHORIZED to all calls if authorization fails. """ q = Album.all().filter('album_id =', album_id) album = q.get() if not album: return self.error(404) write_json(self, album.to_dict())
def delete(self, album_id): """DELETE handler for gallery album. URL pattern: /albums/${album_id} If album exists, returns 200 OK. If album doesn't exist, returns 404 NOT FOUND. Also deletes all images associated with this album. Returns 401 UNAUTHORIZED to all calls if authorization fails. """ q = Album.all().filter('album_id =', album_id) album = q.get() if not album: return self.error(404) if not config.DEMO_MODE: q = Image.all().filter('album =', album) for image in q: image.delete() album.delete()
def update_photos(): logging.info('-> updateing pages') from importing import get_docs_data, get_albums_data albums = get_albums_data(Var.get_value('admin'),Var.get_value('password')) docs_by_keys = dict((album['res_id'],album) for album in albums) updated_or_deleted = set() updated_cnt = deleted_cnt = created_cnt = 0 pupdated_cnt = pdeleted_cnt = pcreated_cnt = 0 # updateing for album in Album.all(): # delete if not album.res_id in docs_by_keys: for photo in album.photos: photo.delete() logging.info('photo %s deleted (in album=%s)', photo.res_id, album.res_id) pdeleted_cnt+=1 album.delete() deleted_cnt+=1 logging.info('album %s deleted'%album.res_id) updated_or_deleted.add( album.res_id ) else: # update existing album doc = docs_by_keys[album.res_id] album.title = doc['title'] album.put() logging.info('album %s updated'%doc['res_id']) updated_or_deleted.add( album.res_id ) ###################### # update/delete his photos pupdated_or_deleted=set() pdocs_by_keys = dict( (pdoc['res_id'],pdoc) for pdoc in doc['photos']) #add/remove/update for photo in album.photos: if not photo.res_id in pdocs_by_keys: photo.delete() pdeleted_cnt+=1 logging.info('photo %s deleted (in album=%s)', photo.res_id, album.res_id) else: pdoc = pdocs_by_keys[photo.res_id] photo.title = pdoc['title'] photo.src = pdoc['src'] photo.mimetype = pdoc['mimetype'] photo.height = pdoc['height'] photo.width = pdoc['width'] photo.order = doc['photos'].index(pdoc) photo.put() pupdated_cnt+=1 logging.info('photo %s updated (in album=%s)', photo.res_id, album.res_id) pupdated_or_deleted.add(photo.res_id) ###################### ## create new photos new_photos_ids = set(pdocs_by_keys) - pupdated_or_deleted for new_photo_id in new_photos_ids: pdoc = pdocs_by_keys[new_photo_id] Photo( album=album, key_name=pdoc['res_id'], src=pdoc['src'], title=pdoc['title'], mimetype=pdoc['mimetype'], height=pdoc['height'], width=pdoc['width'], order=doc['photos'].index(pdoc) ).put() logging.info('photo %s created (in album=%s)', photo.res_id, album.res_id) pcreated_cnt+=1 updated_cnt+=1 # new pages new_albums_ids = set(docs_by_keys) - updated_or_deleted for new_album_id in new_albums_ids: doc = docs_by_keys[new_album_id] # create new album album = Album(key_name=doc['res_id'], title = doc['title']) album.put() for pdoc in doc['photos']: # create new photo Photo( album=album, key_name=pdoc['res_id'], src=pdoc['src'], title=pdoc['title'], mimetype=pdoc['mimetype'], height=pdoc['height'], width=pdoc['width'], order=doc['photos'].index(pdoc) ).put() pcreated_cnt+=1 logging.info('photo %s created (in album=%s)', pdoc['res_id'], album.res_id ) logging.info('album %s created'%doc['res_id']) created_cnt+=1 logging.info('<- updateing album/photos updated=%s created=%s deleted=%s pupdated=%s pcreated=%s pdeleted=%s', updated_cnt, created_cnt, deleted_cnt, pupdated_cnt, pcreated_cnt, pdeleted_cnt)
def get(self): self.template_value['albums']=Album.all() self.render('index.html')
def get(self): self.template_value['albums'] = Album.all() self.template_value['album_select'] = self.request.get("album", "") self.render('upload-html5.html')
def get(self): self.template_value['albums'] = Album.all() self.render("upload_common.html")
def photos(self): """ zwroc strone ze zdjeciami """ albums = Album.all() return self.render('admin/photos2.html', albums=albums)