def _modify_(self, **kwargs): username = tools.getSSOUsername() linkid = kwargs.get("linkid", "") title = tools.escapeascii(kwargs.get("title", "")) lists = kwargs.get("lists", []) url = kwargs.get("url", "") otherlists = kwargs.get("otherlists", "") returnto = kwargs.get("returnto", "") # remove any whitespace/newlines in url url = "".join(url.split()) if type(lists) not in [tuple, list]: lists = [lists] lists.extend(otherlists.split()) if linkid: link = MYGLOBALS.g_db.getLink(linkid) if link._url != url: MYGLOBALS.g_db._changeLinkUrl(link, url) link.title = title newlistset = [] for listname in lists: if "{*}" in url: if listname[-1] != "/": listname += "/" try: newlistset.append(MYGLOBALS.g_db.getList(listname, create=True)) except: return self.redirectToEditLink(error="invalid keyword '%s'" % listname, **kwargs) for LL in newlistset: if LL not in link.lists: LL.addLink(link) for LL in [x for x in link.lists]: if LL not in newlistset: LL.removeLink(link) if not LL.links: MYGLOBALS.g_db.deleteList(LL) link.lists = newlistset link.editedBy(username) MYGLOBALS.g_db.save() return self.redirect("/." + returnto) if not lists: return self.redirectToEditLink(error="delete links that have no lists", **kwargs) if not url: return self.redirectToEditLink(error="URL required", **kwargs) # if url already exists, redirect to that link's edit page if url in MYGLOBALS.g_db.linksByUrl: link = MYGLOBALS.g_db.linksByUrl[url] # only modify lists; other fields will only be set if there # is no original combinedlists = set([x.name for x in link.lists]) | set(lists) fields = {'title': link.title or title, 'lists': " ".join(combinedlists), 'linkid': str(link.linkid) } return self.redirectToEditLink(error="found identical existing URL; confirm changes and re-submit", **fields) link = MYGLOBALS.g_db.addLink(lists, url, title, username) MYGLOBALS.g_db.save() return self.redirect("/." + returnto)
def _login_(self, redirect=""): tools.getSSOUsername(redirect) if redirect: return self.redirect(redirect) return self.undirect()