def lastdate(self, **params): user = get_user() if cherrypy.request.method == "GET": return user.get_info('lastdate', '') elif cherrypy.request.method == "POST": lastdate = cherrypy.request.params.get('lastdate') if lastdate: user.set_info('lastdate', lastdate) return '' raise cherrypy.HTTPError(404)
def render(template_name, context={}): """Render the template named in `template`. - `context` may be used to provide variables to the template. """ template = myenv.get_template(template_name) context['user'] = get_user() context['path'] = cherrypy.request.path_info context['params'] = cherrypy.request.params return template.render(context)
def mediainfo(self, path="", mimepattern=None, hidden=0, exactpath=0): """Return information on the media at a given path. `path` is treated as a path prefix: information on all files in the specified directory which begin with the specified prefix is returned. Returned information is: - `path`: The value of path supplied (useful to tie the response to a request in an async environment). - `sep`: The path separator to use. - `dirpath`: The path of the directory holding `path`, with a separator at the end. - `parent`: The path of the parent directory of this path. - `dirs`: A list of the directories in dirpath with the appropriate prefix. Entries in this are dicts containing: - `name`: The filename. - `mtime`: The modification time of the file - `hidden`: True iff the file is hidden. - `files`: A list of the files in dirpath with the appropriate prefix. Entries in this are dicts containing: - `name`: The filename. - `type`: The type of the file. - `mtime`: The modification time of the file - `hidden`: True iff the file is hidden. If the path which would be contained in `dirpath` is not a directory, this will instead return a 404 error. """ if exactpath: hidden = False if mimepattern: mimepattern = mimepattern.split("/", 1) if len(mimepattern) == 1 or mimepattern[1] == "*": mimepattern = [mimepattern[0], None] tmp = path.rsplit("/", 1) if len(tmp) == 1: tmp = (tmp[0], "") dirpath, fileprefix = tmp parentpath = dirpath.rsplit("/", 1) if len(parentpath) == 1: parentpath = "" else: parentpath = parentpath[0] if not parentpath.endswith("/"): parentpath += "/" if not dirpath.endswith("/"): dirpath += "/" files = [] dirs = [] if mapper.isdir(dirpath): user = get_user() user.set_info("media_lastdir", dirpath) user.objects.flush() for name in mapper.listdir(dirpath): if exactpath: if name != fileprefix: continue else: if not name.startswith(fileprefix): continue subpath = "/".join((dirpath.rstrip("/"), name)) if not hidden and mapper.is_hidden(subpath): continue if mapper.isdir(subpath): dirs.append(mapper.get_dir_info(subpath)) elif mapper.isfile(subpath): info = mapper.get_file_info(subpath) if mimepattern is not None: infomime = info["mimetype"] if infomime is None: continue infomime = infomime.split("/", 1) if len(infomime) == 1: infomime = [infomime[0], None] if infomime[0] != mimepattern[0]: continue if mimepattern[1] is not None and infomime[1] != mimepattern[1]: continue files.append(info) dirs.sort(key=lambda x: x.get("name")) files.sort(key=lambda x: x.get("name")) response = dict(path=path, sep="/", dirpath=dirpath, parent=parentpath, dirs=dirs, files=files) return jsonresp(response)