# -*- coding: utf-8 -*- import libView; from libView import toHtml; import cgi # option to enable error-reports to remote browser import cgitb cgitb.enable() libView.doHeader("Encoding test") form = cgi.FieldStorage() text = form.getvalue("text", "sample text") print "<h2>Type some text to display</h2>" print "<form action='test_encoding.py' method='post'>" libView.printf("<input type=text name=text value=\"%s\">", (toHtml(text),)) print "<input type=submit value='OK'>" print "</form>" print "<p>You typed <span style='border:1px solid green; margin:2px; padding:2px;background-color:#CFC'>%s</span></p>" % (toHtml(text),) URL = "test_encoding.py?text=" + libView.toUrl(text) print "<p>URL would be %s <a href='%s'>Test</a></p>" % (URL, URL,) libView.doFooter();
if(len(bookmarks) == 0): print "<p>No bookmarks in this account yet</p>" else: count = 0 print "<ul>" for bookmark in bookmarks: tags = bookmark.get("tags", []) if(tag_filter == "" or tag_filter in tags): count += 1 tags_text = "" if(len(tags) != 0): for tag in tags: tags_text += " <a href=\"links.py?ac=%s&tag=%s\">%s</a>" %( toHtml(account_name), toHtml(tag), toHtml(tag),) tags_text = " [in" + tags_text + "]"; libView.printf("<li><a href=\"%s\">%s</a>%s</li>", ( toHtml(bookmark.get("url","")), toHtml(bookmark.get("name","untitled")), tags_text, )) if(count == 0): print "<li>No bookmarks matching filter</li>" print "</ul>" else: if(len(accounts.keys()) == 0): print "<p>No bookmark accounts have been setup</p>" else: for name, ac in accounts.items(): print "<p><a href=\"links.py?ac=%s\">%s</a></p>" % (name,name,) print "<p><a href=\"links.py?action=add\">Add a new bookmarks account</a></p>" libView.doFooter();
def showFolder(path, fullPath): libView.doHeader("Documents: " + path) folderHeader() if(not os.path.exists(fullPath)): print "<p>Invalid path</p>" else: files = os.listdir(fullPath) for f in files: ff = os.path.join(fullPath, f) if(os.path.isdir(ff)): libView.printf( "<p>Subdir: <a href=\"docs.py?path=%s%s/\">%s</a></p>", (toUrl(path), toUrl(f),toHtml(f),)) for f in files: if(f != "meta.json"): ff = os.path.join(fullPath, f) if(not os.path.isdir(ff)): libView.printf( "<p>File: <a href=\"docs.py?path=%s%s\">%s</a></p>", (toUrl(path), toUrl(f),toHtml(f),)) meta = getMeta(path) meta["count"] = meta.get("count",0) + 1 storeMeta(path, meta) libView.printf("<p>Folder has %d views</p>", meta["count"]) if(1): print "<h2>Upload</h2>" print "<form action=\"docs.py\" enctype=\"multipart/form-data\" method=\"post\">" libView.printf("<input type=\"file\" name=\"uploaded_file\" max_size=\"%s\">", (80 * 1024*1024,)) print "<input type=\"hidden\" name=\"action\" value=\"upload\">" libView.printf("<input type=\"hidden\" name=\"path\" value=\"%s\">", (toHtml(path),)) if(0): # option to require mime-type declaration on upload (otherwise just ask user-agent) filetypes = ("text/plain", "image/jpeg", "image/png", "application/pdf") print "<select>" for filetype in filetypes: libView.printf("<option name=\"%s\">%s</option>", (toHtml(filetype), toHtml(filetype),)) print "</select> " print "<input type=\"submit\" value=\"Upload\">" print "</form>" libView.doFooter();
# Displaying a folder #--------------------------------------------------------- if(form.has_key("uploaded_file")): #--------------------------------------------------------- # Upload #--------------------------------------------------------- fileitem = form["uploaded_file"] libView.doHeader("Uploaded file") #print str(fileitem) #print toHtml(str(dir(fileitem))) if fileitem.file: filename = fileitem.filename contentType = fileitem.headers.get("Content-Type", "") # according to wikipedia, is best to leave content-type unspecified if not known # rather than guessing "application/octet-stream", since then we allow the recipient to guess the type libView.printf("<p>Uploaded %s of type %s</p>", (toHtml(filename), toHtml(contentType),)) import hashlib h = hashlib.new("sha256") h.update(fileitem.filename) fileTitle = h.hexdigest() meta = libDocs.getMeta(path) file_list = meta.get("files", {}) fileVersion = 1 originalTitle = fileTitle while(fileTitle in file_list): fileVersion += 1 fileTitle = originalTitle + "_%03d" % fileVersion file_list[fileTitle] = {"name":filename, "type":contentType}