def html(self, req): if self.error > 0: return req.getTAL(theme.getTemplate("searchresult.html"), { "query": self.query, "r": self, "collections": self.collections, "language": lang(req) }, macro="error") if self.active < 0: if len(self.resultlist) == 0: return req.getTAL(theme.getTemplate("searchresult.html"), { "query": self.query, "r": self, "collections": self.collections, "language": lang(req) }, macro="noresult") else: if len(self.resultlist) == 1: self.resultlist[self.active].feedback(req) return self.resultlist[self.active].html(req) else: return req.getTAL(theme.getTemplate("searchresult.html"), { "query": self.query, "collections": self.collections, "reslist": self.resultlist, "r": self, "language": lang(req) }, macro="listcollections") else: self.resultlist[self.active].feedback(req) return self.resultlist[self.active].html(req)
def write(self, req, contentHTML, show_navbar=1): self.params["show_navbar"] = show_navbar self.params["content"] = contentHTML self.params["act_node"] = req.params.get("id", req.params.get("dir", "")) self.params["acl"] = AccessData(req) rootnode = tree.getRoot("collections") self.params["header_items"] = rootnode.getCustomItems("header") self.params["footer_left_items"] = rootnode.getCustomItems("footer_left") self.params["footer_right_items"] = rootnode.getCustomItems("footer_right") self.params["t"] = time.strftime("%d.%m.%Y %H:%M:%S") self.params["head_meta"] = req.params.get('head_meta', '') # header self.params["header"] = req.getTAL(theme.getTemplate("frame.html"), self.params, macro="frame_header") # footer self.params["footer"] = req.getTAL(theme.getTemplate("frame.html"), self.params, macro="frame_footer") self.params["tree"] = "" self.params["search"] = "" if show_navbar == 1: # search mask self.params["search"] = req.getTAL( theme.getTemplate("frame.html"), { "search": self.params["navigation"]["search"], "act_node": self.params["act_node"]}, macro="frame_search") # tree self.params["tree"] = req.getTAL( theme.getTemplate("frame.html"), { "collections": self.collection_portlet.getCollections(), "acl": self.params["acl"]}, macro="frame_tree") req.writeTAL(theme.getTemplate("frame.html"), self.params, macro="frame")
def getHelp(req): global menustructure, items, paths, all_paths, index v = {'user': getUserFromRequest(req)} if "language_change" in req.params: # change language req.session["language"] = req.params.get('language_change') language = translation.lang(req) if "edit.x" in req.params: # edit content print "edit page" if "refresh.x" in req.params: # refresh content menustructure = [] index = {} items = {} paths = {} all_paths = {} initHelp() if req.path[-1] == "/": req.path = req.path[:-1] if re.sub('^\.', '', req.path.replace("/", ".")) in all_paths: pathlangs = all_paths[re.sub('^\.', '', req.path.replace("/", "."))] if language not in pathlangs: content = getHelpFileContent(req.path, pathlangs[0]) else: content = getHelpFileContent(req.path, language) else: # page not found 404 req.setStatus(httpstatus.HTTP_NOT_FOUND) content = req.getTAL(theme.getTemplate("help.html"), {}, macro='notfound') if "export" in req.params: if req.params.get('export') == "pdf": print "deliver pdf" req.reply_headers['Content-Type'] = "application/pdf; charset=utf-8" content = content.replace('"/help/', '"http://' + config.get('host.name') + '/help/') req.write(buildHelpPDF(req.params.get('url'), language)) return if language not in menustructure: menustructure.append(language) for path in all_paths: addExtItem(language, path, items[language]) v['content'] = content v['languages'] = config.get('i18n.languages').split(',') v['curlang'] = translation.lang(req) v['items'] = items[translation.lang(req)] v['path'] = req.path.split("/")[1:] v['url'] = req.path v['indexvalues'] = index[language] indexchars = sorted(set([i[0].upper() for i in index[language].keys()])) v['indexchars'] = indexchars req.writeTAL(theme.getTemplate("help.html"), v, macro='help')
def show_help(req): if req.params.get("maskid", "") != "": field = getNode(req.params.get("maskid", "")) else: field = getNode(req.params.get("id", "")) req.writeTAL(theme.getTemplate("popups.html"), {"field": field}, macro="show_help")
def html(self, req): paths = "" stylebig = self.getContentStyles() liststyle = req.session.get("style-" + self.node.getContentType(), "") if not self.node.isContainer(): plist = getPaths(self.node, AccessData(req)) paths = tal.getTAL(theme.getTemplate("content_nav.html"), {"paths": plist}, macro="paths", language=lang(req)) # render style of node for nodebig if len(stylebig) > 1: # more than on style found for item in stylebig: if liststyle: if item.getName() == liststyle.getName(): return getFormatedString( self.node.show_node_big( req, template=item.getTemplate())) + paths else: if item.isDefaultStyle(): return getFormatedString( self.node.show_node_big( req, template=item.getTemplate())) + paths elif len(stylebig) == 1: return getFormatedString( self.node.show_node_big( req, template=stylebig[0].getTemplate())) + paths return getFormatedString(self.node.show_node_big(req)) + paths
def pwdchange(req, error=0): if len(req.params) > 2 and "password_old" not in req.params: # user changed to browsing return buildURL(req) user = users.getUserFromRequest(req) if not user.canChangePWD() and not user.isAdmin(): error = 4 # no rights elif "ChangeSubmit" in req.params: if user.getName() == config.get("user.guestuser"): req.request["Location"] = req.makeLink("node", {"id": tree.getRoot("collections").id}) return httpstatus.HTTP_MOVED_TEMPORARILY else: if not users.checkLogin(user.getName(), req.params.get("password_old")): error = 1 # old pwd does not match elif req.params.get("password_new1") != req.params.get("password_new2"): error = 2 # new pwds do not match else: user.setPassword(req.params.get("password_new2")) req.request["Location"] = req.makeLink("node", {"id": tree.getRoot("collections").id}) return httpstatus.HTTP_MOVED_TEMPORARILY navframe = frame.getNavigationFrame(req) navframe.feedback(req) contentHTML = req.getTAL(theme.getTemplate("login.html"), {"error": error, "user": user}, macro="change_pwd") navframe.write(req, contentHTML) return httpstatus.HTTP_OK
def getAttachmentBrowser(node, req): f, s = filebrowser(node, req) req.writeTAL(theme.getTemplate("popups.html"), { "files": f, "sum_size": s, "id": req.params.get("id", ""), "path": req.params.get("path", "") }, macro="attachmentbrowser")
def html(self, req): styles = [] nodeprint = "1" # show print icon styles = self.content.getContentStyles() if "raw" in req.params: path = "" else: items = req.params.get("itemsperpage") try: id = self.content.node.id node = self.content.node if not node.getContentType() in ['collection', 'directory']: nodeprint = 0 else: if node.get("system.print") != "": nodeprint = node.get("system.print") except: id = 0 printlink = '/print/' + str(id) if nodeprint == "1" and "sortfield0" in req.params.keys(): printlink += '?sortfield0=' + str( req.params.get("sortfield0")) + '&sortfield1=' + str( req.params.get("sortfield1")) if req.params.get("show_navbar") == 0 or req.session.get( "area") == "publish": breadscrubs = [] else: try: breadscrubs = self.getPath(lang(req), access=AccessData(req)) except AttributeError: log.exception("") return req.error(404, "Object cannot be shown") path = req.getTAL(theme.getTemplate("content_nav.html"), { "params": self.params, "path": breadscrubs, "styles": styles, "logo": self.collectionlogo, "searchmode": req.params.get("searchmode", ""), "items": items, "id": id, "nodeprint": nodeprint, "printlink": printlink, "area": req.session.get("area", "") }, macro="path") return path + '\n<!-- CONTENT START -->\n' + self.content.html( req) + '\n<!-- CONTENT END -->\n'
def html(self, req): if self.error > 0: return req.getTAL(theme.getTemplate("searchresult.html"), { "query": self.query, "r": self, "collections": self.collections, "language": lang(req)}, macro="error") if self.active < 0: if len(self.resultlist) == 0: return req.getTAL(theme.getTemplate("searchresult.html"), { "query": self.query, "r": self, "collections": self.collections, "language": lang(req)}, macro="noresult") else: if len(self.resultlist) == 1: self.resultlist[self.active].feedback(req) return self.resultlist[self.active].html(req) else: return req.getTAL(theme.getTemplate("searchresult.html"), {"query": self.query, "collections": self.collections, "reslist": self.resultlist, "r": self, "language": lang(req)}, macro="listcollections") else: self.resultlist[self.active].feedback(req) return self.resultlist[self.active].html(req)
def html(self, req): styles = [] nodeprint = "1" # show print icon styles = self.content.getContentStyles() if "raw" in req.params: path = "" else: items = req.params.get("itemsperpage") try: id = self.content.node.id node = self.content.node if not node.getContentType() in ['collection', 'directory']: nodeprint = 0 else: if node.get("system.print") != "": nodeprint = node.get("system.print") except: id = 0 printlink = '/print/' + str(id) if nodeprint == "1" and "sortfield0" in req.params.keys(): printlink += '?sortfield0=' + str(req.params.get("sortfield0")) + '&sortfield1=' + str(req.params.get("sortfield1")) if req.params.get("show_navbar") == 0 or req.session.get("area") == "publish": breadscrubs = [] else: try: breadscrubs = self.getPath(lang(req), access=AccessData(req)) except AttributeError: log.exception("") return req.error(404, "Object cannot be shown") path = req.getTAL( theme.getTemplate("content_nav.html"), { "params": self.params, "path": breadscrubs, "styles": styles, "logo": self.collectionlogo, "searchmode": req.params.get( "searchmode", ""), "items": items, "id": id, "nodeprint": nodeprint, "printlink": printlink, "area": req.session.get( "area", "")}, macro="path") return path + '\n<!-- CONTENT START -->\n' + self.content.html(req) + '\n<!-- CONTENT END -->\n'
def pwdchange(req, error=0): if len( req.params ) > 2 and "password_old" not in req.params: # user changed to browsing return buildURL(req) user = users.getUserFromRequest(req) if not user.canChangePWD() and not user.isAdmin(): error = 4 # no rights elif "ChangeSubmit" in req.params: if user.getName() == config.get("user.guestuser"): req.request["Location"] = req.makeLink( "node", {"id": tree.getRoot("collections").id}) return httpstatus.HTTP_MOVED_TEMPORARILY else: if not users.checkLogin(user.getName(), req.params.get("password_old")): error = 1 # old pwd does not match elif req.params.get("password_new1") != req.params.get( "password_new2"): error = 2 # new pwds do not match else: user.setPassword(req.params.get("password_new2")) req.request["Location"] = req.makeLink( "node", {"id": tree.getRoot("collections").id}) return httpstatus.HTTP_MOVED_TEMPORARILY navframe = frame.getNavigationFrame(req) navframe.feedback(req) contentHTML = req.getTAL(theme.getTemplate("login.html"), { "error": error, "user": user }, macro="change_pwd") navframe.write(req, contentHTML) return httpstatus.HTTP_OK
def html(self, req): paths = "" stylebig = self.getContentStyles() liststyle = req.session.get("style-" + self.node.getContentType(), "") if not self.node.isContainer(): plist = getPaths(self.node, AccessData(req)) paths = tal.getTAL(theme.getTemplate("content_nav.html"), {"paths": plist}, macro="paths", language=lang(req)) # render style of node for nodebig if len(stylebig) > 1: # more than on style found for item in stylebig: if liststyle: if item.getName() == liststyle.getName(): return getFormatedString(self.node.show_node_big(req, template=item.getTemplate())) + paths else: if item.isDefaultStyle(): return getFormatedString(self.node.show_node_big(req, template=item.getTemplate())) + paths elif len(stylebig) == 1: return getFormatedString(self.node.show_node_big(req, template=stylebig[0].getTemplate())) + paths return getFormatedString(self.node.show_node_big(req)) + paths
def pwdforgotten(req): if len(req.params) > 3: # user changed to browsing return buildURL(req) navframe = frame.getNavigationFrame(req) navframe.feedback(req) if req.params.get("action", "") == "activate": # do activation of new password id, key = req.params.get("key").replace("/", "").split('-') targetuser = users.getUser(id) if targetuser.get("newpassword.activation_key") == key: newpassword = targetuser.get("newpassword.password") if newpassword: targetuser.set("password", newpassword) print "password reset for user '%s' (id=%s) reset" % ( targetuser.getName(), targetuser.id) targetuser.removeAttribute("newpassword.password") targetuser.set("newpassword.time_activated", date.format_date()) logging.getLogger('usertracing').info( "new password activated for user: %s - was requested: %s by %s" % (targetuser.getName(), targetuser.get("newpassword.time_requested"), targetuser.get("newpassword.request_ip"))) navframe.write( req, req.getTAL(theme.getTemplate("login.html"), {"username": targetuser.getName()}, macro="pwdforgotten_password_activated")) return httpstatus.HTTP_OK else: print "invalid key: wrong key or already used key" navframe.write( req, req.getTAL( theme.getTemplate("login.html"), {"message": "pwdforgotten_password_invalid_key"}, macro="pwdforgotten_message")) return httpstatus.HTTP_OK elif "user" in req.params: # create email with activation information username = req.params.get("user", "") if username == '': req.params['error'] = "pwdforgotten_noentry" else: targetuser = users.getUser(username) if not targetuser or not targetuser.canChangePWD(): logging.getLogger('usertracing').info( "new password requested for non-existing user: "******"pwdforgotten_nosuchuser" else: password = users.makeRandomPassword() randomkey = mkKey() targetuser.set("newpassword.password", hashlib.md5(password).hexdigest()) targetuser.set("newpassword.time_requested", date.format_date()) targetuser.set("newpassword.activation_key", randomkey) targetuser.set("newpassword.request_ip", req.ip) v = {} v["name"] = targetuser.getName() v["host"] = config.get("host.name") v["login"] = targetuser.getName() v["language"] = lang(req) v["activationlink"] = v[ "host"] + "/pwdforgotten?action=activate&key=%s-%s" % ( targetuser.id, randomkey) v["email"] = targetuser.getEmail() v["userid"] = targetuser.getName() # going to send the mail try: mailtext = req.getTAL(theme.getTemplate("login.html"), v, macro="emailtext") mailtext = mailtext.strip().replace( "[$newpassword]", password).replace("[wird eingesetzt]", password) mail.sendmail(config.get("email.admin"), targetuser.getEmail(), t(lang(req), "pwdforgotten_email_subject"), mailtext) logging.getLogger('usertracing').info( "new password requested for user: %s - activation email sent" % username) navframe.write( req, req.getTAL(theme.getTemplate("login.html"), {"message": "pwdforgotten_butmailnowsent"}, macro="pwdforgotten_message")) return httpstatus.HTTP_OK except mail.SocketError: print "Socket error while sending mail" logging.getLogger('usertracing').info( "new password requested for user: %s - failed to send activation email" % username) return req.getTAL( theme.getTemplate("login.html"), {"message": "pwdforgotten_emailsenderror"}, macro="pwdforgotten_message") # standard operation navframe.write( req, req.getTAL(theme.getTemplate("login.html"), { "error": req.params.get("error"), "user": users.getUserFromRequest(req) }, macro="pwdforgotten")) return httpstatus.HTTP_OK
def html(self, req): return tal.getTAL(theme.getTemplate("content_error.html"), {"error": self.error}, language=lang(req))
def pwdforgotten(req): if len(req.params) > 3: # user changed to browsing return buildURL(req) navframe = frame.getNavigationFrame(req) navframe.feedback(req) if req.params.get("action", "") == "activate": # do activation of new password id, key = req.params.get("key").replace("/", "").split('-') targetuser = users.getUser(id) if targetuser.get("newpassword.activation_key") == key: newpassword = targetuser.get("newpassword.password") if newpassword: targetuser.set("password", newpassword) print "password reset for user '%s' (id=%s) reset" % (targetuser.getName(), targetuser.id) targetuser.removeAttribute("newpassword.password") targetuser.set("newpassword.time_activated", date.format_date()) logging.getLogger('usertracing').info( "new password activated for user: %s - was requested: %s by %s" % (targetuser.getName(), targetuser.get("newpassword.time_requested"), targetuser.get("newpassword.request_ip"))) navframe.write( req, req.getTAL( theme.getTemplate("login.html"), { "username": targetuser.getName()}, macro="pwdforgotten_password_activated")) return httpstatus.HTTP_OK else: print "invalid key: wrong key or already used key" navframe.write( req, req.getTAL( theme.getTemplate("login.html"), { "message": "pwdforgotten_password_invalid_key"}, macro="pwdforgotten_message")) return httpstatus.HTTP_OK elif "user" in req.params: # create email with activation information username = req.params.get("user", "") if username == '': req.params['error'] = "pwdforgotten_noentry" else: targetuser = users.getUser(username) if not targetuser or not targetuser.canChangePWD(): logging.getLogger('usertracing').info("new password requested for non-existing user: "******"pwdforgotten_nosuchuser" else: password = users.makeRandomPassword() randomkey = mkKey() targetuser.set("newpassword.password", hashlib.md5(password).hexdigest()) targetuser.set("newpassword.time_requested", date.format_date()) targetuser.set("newpassword.activation_key", randomkey) targetuser.set("newpassword.request_ip", req.ip) v = {} v["name"] = targetuser.getName() v["host"] = config.get("host.name") v["login"] = targetuser.getName() v["language"] = lang(req) v["activationlink"] = v["host"] + "/pwdforgotten?action=activate&key=%s-%s" % (targetuser.id, randomkey) v["email"] = targetuser.getEmail() v["userid"] = targetuser.getName() # going to send the mail try: mailtext = req.getTAL(theme.getTemplate("login.html"), v, macro="emailtext") mailtext = mailtext.strip().replace("[$newpassword]", password).replace("[wird eingesetzt]", password) mail.sendmail(config.get("email.admin"), targetuser.getEmail(), t(lang(req), "pwdforgotten_email_subject"), mailtext) logging.getLogger('usertracing').info("new password requested for user: %s - activation email sent" % username) navframe.write( req, req.getTAL( theme.getTemplate("login.html"), { "message": "pwdforgotten_butmailnowsent"}, macro="pwdforgotten_message")) return httpstatus.HTTP_OK except mail.SocketError: print "Socket error while sending mail" logging.getLogger('usertracing').info( "new password requested for user: %s - failed to send activation email" % username) return req.getTAL( theme.getTemplate("login.html"), {"message": "pwdforgotten_emailsenderror"}, macro="pwdforgotten_message") # standard operation navframe.write(req, req.getTAL(theme.getTemplate("login.html"), { "error": req.params.get("error"), "user": users.getUserFromRequest(req)}, macro="pwdforgotten")) return httpstatus.HTTP_OK
def html(self, req): language = lang(req) if not language: language = None if self.content: headline = tal.getTAL(theme.getTemplate("content_nav.html"), {"nav": self}, macro="navheadline", language=lang(req)) return headline + self.content.html(req) nav_list = list() nav_page = list() if "itemsperpage" not in req.params: files_per_page = 9 else: if req.params.get("itemsperpage") == "-1": files_per_page = len(self.files) else: files_per_page = int(req.params.get("itemsperpage")) min = 0 max = (len(self.files) + files_per_page - 1) / files_per_page - 1 left = self.page - 6 right = self.page + 6 if left < 0: left = 0 if right > max or right >= max - 2: right = max if left <= min + 2: left = min if left > min: nav_list.append("/node?page=" + str(min)) nav_list.append('...') nav_page.append(min) nav_page.append(-1) for a in range(left, right + 1): nav_list.append("/node?page=" + str(a)) nav_page.append(a) if right < max: nav_list.append('...') nav_list.append("/node?page=" + str(max)) nav_page.append(-1) nav_page.append(max) tal_files = [] tal_ids = [] i = 0 for i in range(self.page * files_per_page, (self.page + 1) * files_per_page): if i < self.num: file = self.files[i] self.id2pos[self.files[i].id] = i tal_files += [SingleFile(file, i, self.num, language=language)] tal_ids += [ SingleFile(file, i, self.num, language=language).node.id ] i += 1 liststyle = req.session.get( "liststyle-" + self.collection.id, "") # .split(";")[0]# user/session setting for liststyle? if not liststyle: # no liststsyle, use collection default liststyle = self.liststyle filesHTML = req.getTAL(theme.getTemplate("content_nav.html"), { "nav_list": nav_list, "nav_page": nav_page, "act_page": self.page, "sortfields": self.sortfields, "sortfieldslist": self.getSortFieldsList(), "files": tal_files, "ids": ",".join(tal_ids), "maxresult": len(self.files), "op": "", "query": req.params.get("query", "") }, macro="files") # use template of style and build html content contentList = liststyle.renderTemplate( req, { "nav_list": nav_list, "nav_page": nav_page, "act_page": self.page, "files": tal_files, "maxresult": len(self.files), "op": "", "language": lang(req) }) sidebar = "" # check for sidebar if self.collection.get("system.sidebar") != "": for sb in [ s for s in self.collection.get("system.sidebar").split(";") if s != "" ]: l, fn = sb.split(":") if l == lang(req): for f in [ f for f in self.collection.getFiles() if fn.endswith(f.getName()) ]: sidebar = replaceModules( self, req, includetemplate(self, f.retrieveFile(), {})).strip() if sidebar != "": return '<div id="portal-column-one">{0}<div id="nodes">{1}</div>{0}</div><div id="portal-column-two">{2}</div>'.format( filesHTML, contentList, sidebar) else: return '{0}<div id="nodes">{1}</div>{0}'.format( filesHTML, contentList)
def html(self, req): language = lang(req) if not language: language = None if self.content: headline = tal.getTAL(theme.getTemplate("content_nav.html"), {"nav": self}, macro="navheadline", language=lang(req)) return headline + self.content.html(req) nav_list = list() nav_page = list() if "itemsperpage" not in req.params: files_per_page = 9 else: if req.params.get("itemsperpage") == "-1": files_per_page = len(self.files) else: files_per_page = int(req.params.get("itemsperpage")) min = 0 max = (len(self.files) + files_per_page - 1) / files_per_page - 1 left = self.page - 6 right = self.page + 6 if left < 0: left = 0 if right > max or right >= max - 2: right = max if left <= min + 2: left = min if left > min: nav_list.append("/node?page=" + str(min)) nav_list.append('...') nav_page.append(min) nav_page.append(-1) for a in range(left, right + 1): nav_list.append("/node?page=" + str(a)) nav_page.append(a) if right < max: nav_list.append('...') nav_list.append("/node?page=" + str(max)) nav_page.append(-1) nav_page.append(max) tal_files = [] tal_ids = [] i = 0 for i in range(self.page * files_per_page, (self.page + 1) * files_per_page): if i < self.num: file = self.files[i] self.id2pos[self.files[i].id] = i tal_files += [SingleFile(file, i, self.num, language=language)] tal_ids += [ SingleFile(file, i, self.num, language=language).node.id ] i = i + 1 liststyle = req.session.get( "liststyle-" + self.collection.id, "") # .split(";")[0]# user/session setting for liststyle? if not liststyle: # no liststsyle, use collection default liststyle = self.liststyle filesHTML = req.getTAL(theme.getTemplate("content_nav.html"), { "nav_list": nav_list, "nav_page": nav_page, "act_page": self.page, "sortfields": self.sortfields, "sortfieldslist": self.getSortFieldsList(), "files": tal_files, "ids": ",".join(tal_ids), "maxresult": len(self.files), "op": "", "query": req.params.get("query", "") }, macro="files") # use template of style and build html content contentList = liststyle.renderTemplate( req, { "nav_list": nav_list, "nav_page": nav_page, "act_page": self.page, "files": tal_files, "maxresult": len(self.files), "op": "", "language": lang(req) }) return filesHTML + '<div id="nodes">' + contentList + '</div>' + filesHTML
def show_shoppingbag(req, msg=""): """open shoppingbag and show content""" img = False doc = False media = False (width, height) = calculate_dimensions(req) v = {"width": width, "height": height} f = [] # deliver image dimensions of original def calc_dim(file): ret = "" try: w = int(file.get("width")) h = int(file.get("height")) except: return "padding:0px 0px;width:90px;height:90px;" if w > h: factor = 90.0 / w h = h * 90.0 / w w = 90 ret += 'padding:%spx 0px;' % str(int((90 - h) / 2)) else: w = w * 90.0 / h h = 90 ret += 'padding:0px %spx;' % str(int((90 - w) / 2)) return ret + 'width:%spx;height:%spx;' % (str(int(w)), str(int(h))) # deliver document file size def calc_size(file): for f in file.getFiles(): if f.getType() == "document": return format_filesize(f.getSize()) return "" def calc_length(file): try: return file.getDuration() except: return "" access = AccessData(req) sb = req.session.get("shoppingbag", []) sb = [nid for nid in sb if nid.strip()] for node in access.filter(tree.NodeList(sb)): if node.getCategoryName() == "image": img = True if node.getCategoryName() == "document": doc = True if node.getCategoryName() in ["audio", "video"]: media = True f.append(node) if len(f) != len(req.session.get("shoppingbag", [])) and msg == "": msg = "popup_shoppingbag_items_filtered" v["files"] = f v["image"] = img v["document"] = doc v["media"] = media v["img_perc_range"] = range(1, 11) v["img_pix_sizes"] = ["1600x1200", "1280x960", "1024x768", "800x600"] v["calc_dim"] = calc_dim v["calc_size"] = calc_size v["calc_length"] = calc_length user = users.getUserFromRequest(req) v["shoppingbags"] = user.getShoppingBag() v["user"] = user v["msg"] = msg req.writeTAL(theme.getTemplate("shoppingbag.html"), v, macro="shoppingbag") return httpstatus.HTTP_OK
def login(req): if len(req.params) > 2 and "user" not in req.params: # user changed to browsing return buildURL(req) error = 0 username = req.params.get("user", config.get("user.guestuser")) password = req.params.get("password", "") if username == "" and "user" in req.params: # empty username error = 1 elif "LoginSubmit" in req.params: # try given values user = users.checkLogin(username, password, req=req) if user: if "contentarea" in req.session: del req.session["contentarea"] req.session["user"] = user logging.getLogger('usertracing').info(user.name + " logged in") if user.getUserType() == "users": if user.stdPassword(): return pwdchange(req, 3) else: x = users.getExternalAuthentificator(user.getUserType()) if x and x.stdPassword(user): return pwdchange(req, 3) if req.session.get('return_after_login'): req.request['Location'] = req.session['return_after_login'] elif config.get("config.ssh", "") == "yes": req.request["Location"] = ''.join(["https://", config.get("host.name"), "/node?id=", tree.getRoot("collections").id]) else: req.request["Location"] = ''.join(["/node?id=", tree.getRoot("collections").id]) return httpstatus.HTTP_MOVED_TEMPORARILY else: error = 1 referer = next((h.split(":", 1)[1].strip() for h in req.header if h.startswith("Referer:")), None) if referer is None or any(uri in referer for uri in ('/login', '/logout', '/pwdforgotten', '/pwdchange', '/pnode')): req.session['return_after_login'] = False else: if '/edit' in referer: # returns the user to /edit/ instead of /edit/edit_content?id=604993, which has no sidebar req.session['return_after_login'] = '******'.join(referer .split('/')[:-1]) else: req.session['return_after_login'] = referer # standard login form user = users.getUserFromRequest(req) navframe = frame.getNavigationFrame(req) navframe.feedback(req) navframe.write(req, req.getTAL(theme.getTemplate("login.html"), {"error": error, "user": user}, macro="login")) return httpstatus.HTTP_OK
def html(self, req): language = lang(req) if not language: language = None if self.content: headline = tal.getTAL(theme.getTemplate("content_nav.html"), {"nav": self}, macro="navheadline", language=lang(req)) return headline + self.content.html(req) nav_list = list() nav_page = list() if "itemsperpage" not in req.params: files_per_page = 9 else: if req.params.get("itemsperpage") == "-1": files_per_page = len(self.files) else: files_per_page = int(req.params.get("itemsperpage")) min = 0 max = (len(self.files) + files_per_page - 1) / files_per_page - 1 left = self.page - 6 right = self.page + 6 if left < 0: left = 0 if right > max or right >= max - 2: right = max if left <= min + 2: left = min if left > min: nav_list.append("/node?page=" + str(min)) nav_list.append('...') nav_page.append(min) nav_page.append(-1) for a in range(left, right + 1): nav_list.append("/node?page=" + str(a)) nav_page.append(a) if right < max: nav_list.append('...') nav_list.append("/node?page=" + str(max)) nav_page.append(-1) nav_page.append(max) tal_files = [] tal_ids = [] i = 0 for i in range(self.page * files_per_page, (self.page + 1) * files_per_page): if i < self.num: file = self.files[i] self.id2pos[self.files[i].id] = i tal_files += [SingleFile(file, i, self.num, language=language)] tal_ids += [SingleFile(file, i, self.num, language=language).node.id] i += 1 liststyle = req.session.get("liststyle-" + self.collection.id, "") # .split(";")[0]# user/session setting for liststyle? if not liststyle: # no liststsyle, use collection default liststyle = self.liststyle filesHTML = req.getTAL(theme.getTemplate("content_nav.html"), { "nav_list": nav_list, "nav_page": nav_page, "act_page": self.page, "sortfields": self.sortfields, "sortfieldslist": self.getSortFieldsList(), "files": tal_files, "ids": ",".join(tal_ids), "maxresult": len(self.files), "op": "", "query": req.params.get("query", "")}, macro="files") # use template of style and build html content contentList = liststyle.renderTemplate(req, {"nav_list": nav_list, "nav_page": nav_page, "act_page": self.page, "files": tal_files, "maxresult": len(self.files), "op": "", "language": lang(req)}) sidebar = "" # check for sidebar if self.collection.get("system.sidebar") != "": for sb in [s for s in self.collection.get("system.sidebar").split(";") if s != ""]: l, fn = sb.split(":") if l == lang(req): for f in [f for f in self.collection.getFiles() if fn.endswith(f.getName())]: sidebar = replaceModules(self, req, includetemplate(self, f.retrieveFile(), {})).strip() if sidebar != "": return '<div id="portal-column-one">{0}<div id="nodes">{1}</div>{0}</div><div id="portal-column-two">{2}</div>'.format(filesHTML, contentList, sidebar) else: return '{0}<div id="nodes">{1}</div>{0}'.format(filesHTML, contentList)
def login(req): if len(req.params ) > 2 and "user" not in req.params: # user changed to browsing return buildURL(req) error = 0 username = req.params.get("user", config.get("user.guestuser")) password = req.params.get("password", "") if username == "" and "user" in req.params: # empty username error = 1 elif "LoginSubmit" in req.params: # try given values user = users.checkLogin(username, password, req=req) if user: if "contentarea" in req.session: del req.session["contentarea"] req.session["user"] = user logging.getLogger('usertracing').info(user.name + " logged in") if user.getUserType() == "users": if user.stdPassword(): return pwdchange(req, 3) else: x = users.getExternalAuthentificator(user.getUserType()) if x and x.stdPassword(user): return pwdchange(req, 3) if req.session.get('return_after_login'): req.request['Location'] = req.session['return_after_login'] elif config.get("config.ssh", "") == "yes": req.request["Location"] = ''.join([ "https://", config.get("host.name"), "/node?id=", tree.getRoot("collections").id ]) else: req.request["Location"] = ''.join( ["/node?id=", tree.getRoot("collections").id]) return httpstatus.HTTP_MOVED_TEMPORARILY else: error = 1 referer = next((h.split(":", 1)[1].strip() for h in req.header if h.startswith("Referer:")), None) if referer is None or any(uri in referer for uri in ('/login', '/logout', '/pwdforgotten', '/pwdchange', '/pnode')): req.session['return_after_login'] = False else: if '/edit' in referer: # returns the user to /edit/ instead of /edit/edit_content?id=604993, which has no sidebar req.session['return_after_login'] = '******'.join( referer.split('/')[:-1]) else: req.session['return_after_login'] = referer # standard login form user = users.getUserFromRequest(req) navframe = frame.getNavigationFrame(req) navframe.feedback(req) navframe.write( req, req.getTAL(theme.getTemplate("login.html"), { "error": error, "user": user }, macro="login")) return httpstatus.HTTP_OK
def getAttachmentBrowser(node, req): f, s = filebrowser(node, req) req.writeTAL(theme.getTemplate("popups.html"), {"files": f, "sum_size": s, "id": req.params.get( "id", ""), "path": req.params.get("path", "")}, macro="attachmentbrowser")
def html(self, req): language = lang(req) if not language: language = None if self.content: headline = tal.getTAL(theme.getTemplate("content_nav.html"), {"nav": self}, macro="navheadline", language=lang(req)) return headline + self.content.html(req) nav_list = list() nav_page = list() if "itemsperpage" not in req.params: files_per_page = 9 else: if req.params.get("itemsperpage") == "-1": files_per_page = len(self.files) else: files_per_page = int(req.params.get("itemsperpage")) min = 0 max = (len(self.files) + files_per_page - 1) / files_per_page - 1 left = self.page - 6 right = self.page + 6 if left < 0: left = 0 if right > max or right >= max - 2: right = max if left <= min + 2: left = min if left > min: nav_list.append("/node?page=" + str(min)) nav_list.append('...') nav_page.append(min) nav_page.append(-1) for a in range(left, right + 1): nav_list.append("/node?page=" + str(a)) nav_page.append(a) if right < max: nav_list.append('...') nav_list.append("/node?page=" + str(max)) nav_page.append(-1) nav_page.append(max) tal_files = [] tal_ids = [] i = 0 for i in range(self.page * files_per_page, (self.page + 1) * files_per_page): if i < self.num: file = self.files[i] self.id2pos[self.files[i].id] = i tal_files += [SingleFile(file, i, self.num, language=language)] tal_ids += [SingleFile(file, i, self.num, language=language).node.id] i = i + 1 liststyle = req.session.get("liststyle-" + self.collection.id, "") # .split(";")[0]# user/session setting for liststyle? if not liststyle: # no liststsyle, use collection default liststyle = self.liststyle filesHTML = req.getTAL(theme.getTemplate("content_nav.html"), { "nav_list": nav_list, "nav_page": nav_page, "act_page": self.page, "sortfields": self.sortfields, "sortfieldslist": self.getSortFieldsList(), "files": tal_files, "ids": ",".join(tal_ids), "maxresult": len(self.files), "op": "", "query": req.params.get("query", "")}, macro="files") # use template of style and build html content contentList = liststyle.renderTemplate(req, {"nav_list": nav_list, "nav_page": nav_page, "act_page": self.page, "files": tal_files, "maxresult": len(self.files), "op": "", "language": lang(req)}) return filesHTML + '<div id="nodes">' + contentList + '</div>' + filesHTML