def topic(self): username = self.get_argument('username') section = self.get_argument('section') album = self.get_argument('album', '') topic = self.get_argument('topic') section_item = self.models.content.get(username=username, section='main', name=section)[0] template = section_item.template if not template and album: album_item = self.models.content.get(username=username, section=section, album='main', name=album)[0] template = album_item.template if template != 'forum': raise tornado.web.HTTPError(400, "i call shenanigans") content = self.models.content() content.username = username content.section = section content.album = album content.title = topic content.name = content_logic.get_unique_name(self, content, "_", topic) content.forum = True current_datetime = datetime.datetime.utcnow() content.date_created = current_datetime content.date_updated = current_datetime content.save() self.set_header('Location', self.content_url(content))
def save_content(self, content, content_url, new): # things not to be changed by the user content.username = self.get_author_username() # must be filled in content.style = self.get_argument('style', "") content.code = self.get_argument('code', "") content.view = self.get_argument('view', "") section_template = self.get_argument('section_template', "") # linkify soup = BeautifulSoup(content.view) for text in soup.findAll(text=True): if text.parent.name not in ('a', 'script', 'style'): text.replaceWith( url_factory.linkify_tags( self, content.username, tornado.escape.linkify( tornado.escape.xhtml_unescape(text)))) content.view = soup.renderContents() template = self.get_argument('template', "") if template: parent_template = template elif new or content.section == 'main': parent_template = "feed" else: parent_template = self.models.content.get( username=content.username, section='main', name=content.section)[0].template section = (self.get_argument('section') if self.get_argument('section') else content_url["section"]) content.section = (content_logic.create_section( self, content.username, section, parent_template)) # secondary things to be changed by user, filled in by default current_datetime = datetime.datetime.utcnow() if self.request.method == "POST": content.date_created = current_datetime content.date_updated = current_datetime if content.section != 'main': album = self.get_argument('album', "") album_template = template if not new and content.album: original_album = self.models.content.get( username=content.username, album='main', name=content.album)[0] if original_album: album_template = original_album.template content.album = content_logic.create_album(self, content.username, content.section, album, album_template) title = self.get_argument('title', "") thumb = self.get_argument('thumb', "") name = (self.get_argument('name') if self.get_argument('name', "") else content_url["name"]) content.name = content_logic.get_unique_name(self, content, name, title) content.title = title content.thumb = thumb if (content.section == 'main' or content.album == 'main' or template not in ('album', 'events', 'feed', 'forum', 'slideshow', 'store')): content.template = template else: content.template = '' content.sort_type = self.get_argument('sort_type', "") content.price = float(self.get_argument('price', 0)) content.thread = self.get_argument('thread', '') date_start = self.get_argument('date_start', None) date_end = self.get_argument('date_end', None) content.date_start = (datetime.datetime.fromtimestamp(int(date_start)) if date_start is not None and date_start != 'NaN' and date_start != '' else None) content.date_end = (datetime.datetime.fromtimestamp(int(date_end)) if date_end is not None and date_end != 'NaN' and date_end != '' else None) date_repeats = self.get_argument('date_repeats', 0) content.date_repeats = int(date_repeats) if date_repeats != '' else 0 hidden = self.get_argument('hidden', 0) content.hidden = int(hidden) if hidden != '' else 0 content.save()