def get_actions(request, album, photos): if not has_permission(request, 'edit', album): return [] actions = [] visibilities = set() for photo in photos: visibilities.add(photo['visibility']) if len(visibilities) == 1: visibility = iter(visibilities).next() if visibility != 'public': actions.append(dict(name='publish_all', title='publish all photos')) if visibility != 'private': actions.append(dict(name='hide_all', title='hide all photos')) else: actions.append(dict(name='publish_all', title='publish all photos')) actions.append(dict(name='hide_all', title='hide all photos')) if 'new' in visibilities: actions.append(dict(name='publish_new', title='publish new photos')) actions.append(dict(name='hide_new', title='hide new photos')) if 'public' in visibilities: actions.append(dict(name='hide_public', title='hide public photos')) if 'private' in visibilities: actions.append(dict(name='publish_hidden', title='publish hidden photos')) actions.append(dict(name='delete_all', title='delete all photos', href=model_url(request, album, 'delete_photos'))) if 'new' in visibilities: actions.append(dict(name='delete_new', title='delete new photos', href=model_url(request, album, 'delete_photos', 'new'))) if 'private' in visibilities: actions.append(dict(name='delete_hidden', title='delete hidden photos', href=model_url(request, album, 'delete_photos', 'private'))) return actions
def get_actions(photo, request): if not has_permission(request, 'edit', photo): return [] actions = [] if photo.visibility != 'public': actions.append(dict(name='publish', title='publish photo')) if photo.visibility != 'private': actions.append(dict(name='hide', title='hide photo')) actions.append(dict(name='left', title='rotate left')) actions.append(dict(name='right', title='rotate right')) actions.append(dict(name='delete', title='delete photo', href=model_url(request, photo, 'delete'))) return actions
def __call__(self, request, fname): catalog = request.app_context.catalog id, dims, ext = fname.split('.') photo = catalog.photo(id).get() if not has_permission(request, 'view', photo): if request.remote_user: return HTTPForbidden() return HTTPUnauthorized() cache_file = os.path.join(self.cache_dir, fname) if not os.path.exists(cache_file): req_size = tuple(map(int, dims.split('x'))) target_size = _target_size(req_size, photo.size) image = photo.image image.thumbnail(target_size, Image.ANTIALIAS) image.save(cache_file, quality=90) os.utime(cache_file, (-1, os.path.getmtime(photo.fspath))) return FileResponse(cache_file)
def may(self, permission): return has_permission(self._request, permission)