def rename(self): op_type = self.get_argument('type') old_id = self.get_argument('id') new_title = self.get_argument('new') new_name = new_title old_name = old_id[11:] # remove hw-sitemap_ if op_type == 'section': content_logic.rename_section(self, old_name, new_name, new_title) else: content_logic.rename_album(self, section_album[0], section_album[1], new_name, new_title)
def put(self): if not self.authenticate(author=True): return content_url = url_factory.load_basic_parameters(self) content = self.models.content.get(username=content_url["profile"], section=content_url["section"], name=content_url["name"])[0] if not content: raise tornado.web.HTTPError(404) if (not self.constants['single_user_site'] and content.username != self.current_user["username"]): raise tornado.web.HTTPError(400, "i call shenanigans") old_section = content.section old_album = content.album old_name = content.name old_hidden = content.hidden # remove old cached content if content.album: cache.remove( self, self.nav_url(username=content.username, section=content.section, name=content.album)) cache.remove( self, self.nav_url(username=content.username, section=content.section)) cache.remove(self, self.content_url(content)) section = (self.get_argument('section') if self.get_argument('section') else content_url["section"]) name = (self.get_argument('name') if self.get_argument('name', "") else content_url["name"]) hidden = int(self.get_argument('hidden', 0)) if content.section == 'main' and old_hidden != hidden: collection = self.models.content.get(username=content.username, section=old_name)[:] for item in collection: item.hidden = hidden item.save() if content.album == 'main' and old_hidden != hidden: collection = self.models.content.get(username=content.username, section=old_section, album=old_name)[:] for item in collection: item.hidden = hidden item.save() did_redirect = False if content.section == 'main' and old_name != name: did_redirect = True new_section = content_logic.rename_section(self, old_name, name, content.title) if content.album == 'main' and old_name != name: did_redirect = True new_album = content_logic.rename_album(self, content.section, old_name, name, content.title) try: self.save_content(content, content_url, new=False) except tornado.web.HTTPError as ex: if ex.status_code == 400: # dup return else: # re-raise raise ex # remove cached in possible new album and new sections if content.album: cache.remove( self, self.nav_url(username=content.username, section=content.section, name=content.album)) cache.remove( self, self.nav_url(username=content.username, section=content.section)) if content.album == 'main' and old_section != content.section: album_name = new_album if did_redirect else old_name album_items = self.models.content.get(username=content.username, album=album_name)[:] for item in album_items: item.section = (album_name if content.section == 'main' else content.section) if content.section == 'main': item.album = "" item.save() if content.name != old_name and not did_redirect: content_logic.create_redirect(self, content, old_section, old_name) if content.name != old_name or content.section != old_section: self.set_header('Location', self.content_url(content)) if not content.hidden: socialize.socialize(self, content) self.set_status(204)