コード例 #1
0
ファイル: uimodules.py プロジェクト: Acidburn0zzz/helloworld
  def render(self):
    if self.handler.breadcrumbs["name"] == 'main':
      raise tornado.web.HTTPError(404)

    collection, common_options = content_logic.get_collection(self.handler)

    if collection and self.template_type == 'slideshow':
      collection.reverse()

    self.handler.display["collection"] = [ self.handler.ui["modules"].Content(
        content, template_type=self.template_type) for content in collection ]

    if not collection:
      del common_options['redirect']
      section_options = { 'username' : self.handler.breadcrumbs["profile"],
                          'section' : 'main',
                          'name' : self.handler.breadcrumbs["name"], }
      album_options = { 'username' : self.handler.breadcrumbs["profile"],
                          'section' : self.handler.breadcrumbs["section"],
                          'album' : 'main',
                          'name' : self.handler.breadcrumbs["name"], }
      section_options = dict(common_options.items() + section_options.items())
      album_options = dict(common_options.items() + album_options.items())
      main_section = self.handler.models.content.get(
          **section_options).order_by('date_created', 'DESC')[:]
      main_album = self.handler.models.content.get(
          **album_options).order_by('date_created', 'DESC')[:]
      if not main_album and not main_section:
        raise tornado.web.HTTPError(404)

      return self.handler.fill_template("simple.html")
    else:
      return self.handler.fill_template(self.template_type + ".html")
コード例 #2
0
ファイル: uimodules.py プロジェクト: randy-ran/helloworld
    def render(self):
        if self.handler.breadcrumbs["name"] == 'main':
            raise tornado.web.HTTPError(404)

        collection, common_options = content_logic.get_collection(self.handler)

        if collection and self.template_type == 'slideshow':
            collection.reverse()

        self.handler.display["collection"] = [
            self.handler.ui["modules"].Content(
                content, template_type=self.template_type)
            for content in collection
        ]

        if not collection:
            del common_options['redirect']
            section_options = {
                'username': self.handler.breadcrumbs["profile"],
                'section': 'main',
                'name': self.handler.breadcrumbs["name"],
            }
            album_options = {
                'username': self.handler.breadcrumbs["profile"],
                'section': self.handler.breadcrumbs["section"],
                'album': 'main',
                'name': self.handler.breadcrumbs["name"],
            }
            section_options = dict(common_options.items() +
                                   section_options.items())
            album_options = dict(common_options.items() +
                                 album_options.items())
            main_section = self.handler.models.content.get(
                **section_options).order_by('date_created', 'DESC')[:]
            main_album = self.handler.models.content.get(
                **album_options).order_by('date_created', 'DESC')[:]
            if not main_album and not main_section:
                raise tornado.web.HTTPError(404)

            return self.handler.fill_template("simple.html")
        else:
            return self.handler.fill_template(self.template_type + ".html")
コード例 #3
0
  def order(self):
    op_type = self.get_argument('type')
    dragged = self.get_argument('dragged')
    dropped = self.get_argument('dropped')
    section_album = self.get_argument('current_section_album')
    position = int(self.get_argument('position'))
    new_section = self.get_argument('new_section', '')

    profile = self.get_author_username()
    if dragged.find('hw-sitemap_') == 0:
      dragged = dragged[len('hw-sitemap_'):]
    else:
      dragged = dragged[len('hw-collection_'):]

    if op_type == 'content':
      name = dragged
      if dropped.find('hw-sitemap_') == 0:  # moving to another section/album
        section_album = dropped.split('_')
        content = self.models.content.get(username=profile, name=name)[0]
        content.section = section_album[1]
        if len(section_album) == 3:
          content.album = section_album[2]
        else:
          content.album = ''
        content.save()
        return
      else:
        section_album = section_album.split('_')
        collection, common_options = content_logic.get_collection(self,
            profile=profile, section=section_album[0],
            name=section_album[1])[:]
    elif op_type == 'section':
      name = dragged
      collection = content_logic.get_main_sections(self, profile=profile)
    else:
      section_album = dragged.split('_')
      name = section_album[1]

      if not new_section:
        collection = content_logic.get_albums(self, profile=profile,
            section=section_album[0])
      else:
        album_items = self.models.content.get(username=profile,
                                              album=name)[:]
        for item in album_items:
          item.section = new_section
          item.save()

        album_item = self.models.content.get(username=profile,
                                             name=name)[0]
        album_item.section = new_section
        album_item.save()

        collection = content_logic.get_albums(self, profile=profile,
            section=new_section)

    counter = 0
    inserted = False
    for item in collection:
      if counter == position:
        counter += 1
      item.order = counter
      if item.name == name:
        item.order = position
        inserted = True
        counter -= 1
      item.save()
      counter += 1
コード例 #4
0
    def get(self):
        self.display["section_style"] = ""
        self.display["section_code"] = ""
        self.display["album_style"] = ""
        self.display["album_code"] = ""

        self.display["edit"] = self.get_argument('edit', False)

        is_special = False
        template = None
        # /profile/section/name
        content = self.models.content.get(username=self.breadcrumbs["profile"],
                                          section=self.breadcrumbs["section"],
                                          name=self.breadcrumbs["name"])[0]
        self.display["content"] = content
        # hmm, not sure this should go here, TODO fix ise now, clean up later

        if not content:
            # not found: see if the url maybe exists, and wasn't properly redirected
            alternate = self.models.content.get(
                username=self.breadcrumbs["profile"],
                name=self.breadcrumbs["name"])[0]
            if alternate:
                self.redirect(self.content_url(
                    alternate, referrer=self.breadcrumbs['uri']),
                              permanent=True)
                return
            raise tornado.web.HTTPError(404)
        elif content.template:
            template = content.template
            is_special = True
        elif content.album == 'main':
            # /profile/section/album
            parent_content = self.models.content.get(
                username=self.breadcrumbs["profile"],
                section="main",
                name=self.breadcrumbs["section"])[0]

            if not parent_content or parent_content.template == "":
                raise tornado.web.HTTPError(404)
            else:
                template = parent_content.template
                is_special = True

        content_owner = self.models.users.get(username=content.username)[0]
        is_owner_viewing = self.is_owner_viewing(content.username)
        self.display['content_owner'] = content_owner
        self.display['is_owner_viewing'] = is_owner_viewing

        if (content_owner.adult_content
                and self.get_cookie("adult_content") != "1"
                and not is_owner_viewing):
            self.fill_template("adult_content.html")
            return

        if content.redirect:
            if self.display["edit"]:
                self.display["refers_to"] = self.content_url(
                    self.models.content.get(content.redirect))
            else:
                redirect = self.models.content.get(content.redirect)
                self.redirect(self.content_url(
                    redirect, referrer=self.breadcrumbs['uri']),
                              permanent=True)
                return

        if content.style and not re.search(r"<link|<style", content.style,
                                           re.I | re.M):
            content.style = '<style>\n' + content.style + '\n</style>'
        if content.code and not re.search(r"<script", content.code,
                                          re.I | re.M):
            content.code = '<script>\n' + content.code + '\n</script>'

        self.display["content_thumb"] = content_logic.get_thumbnail(
            self, content)
        self.display["is_store"] = template == 'store'
        self.display["is_events"] = template == 'events'

        # grab parent's styling, code
        self.display["section_template"] = None
        self.display["section_sort_type"] = None
        content_section = self.models.content.get(username=content.username,
                                                  section='main',
                                                  name=content.section)[0]
        if content.section != 'main':
            if content_section:
                if content_section.style and not re.search(
                        r"<link|<style", content_section.style, re.I | re.M):
                    content_section.style = ('<style>\n' +
                                             content_section.style +
                                             '\n</style>')
                if content_section.code and not re.search(
                        r"<script", content_section.code, re.I | re.M):
                    content_section.code = ('<script>\n' +
                                            content_section.code +
                                            '\n</script>')
                self.display["section_style"] = content_section.style
                self.display["section_code"] = content_section.code
                self.display["section_template"] = content_section.template
                self.display["section_sort_type"] = content_section.sort_type
                self.display["is_store"] = (self.display["is_store"]
                                            or content_section.template
                                            == 'store')
                self.display["is_events"] = (self.display["is_events"]
                                             or content_section.template
                                             == 'events')
        else:
            self.display["section_template"] = content.template
            self.display["section_sort_type"] = content.sort_type

        self.display["main_section_title"] = (content_section.title
                                              if content.section != 'main' else
                                              content.title)
        self.display["main_section_name"] = (
            content.section if content.section != 'main' else content.name)

        content_album = self.models.content.get(username=content.username,
                                                section=content.section,
                                                album='main',
                                                name=content.album)[0]
        if content.album:
            self.display["main_album_title"] = (content_album.title
                                                if content.album != 'main' else
                                                content.title)
            self.display["main_album_name"] = (
                content.album if content.album != 'main' else content.name)
        else:
            self.display["main_album_title"] = None

        if content.album and content.album != 'main':
            if content_album:
                if content_album.style and not re.search(
                        r"<link|<style", content_album.style, re.I | re.M):
                    content_album.style = ('<style>\n' + content_album.style +
                                           '\n</style>')
                if content_album.code and not re.search(
                        r"<script", content_album.code, re.I | re.M):
                    content_album.code = ('<script>\n' + content_album.code +
                                          '\n</script>')
                self.display["album_style"] = content_album.style
                self.display["album_code"] = content_album.code
                if content_album.template:
                    self.display["section_template"] = content_album.template
                if content_album.sort_type:
                    self.display["section_sort_type"] = content_album.sort_type
                self.display["is_store"] = (self.display["is_store"] or
                                            content_album.template == 'store')
                self.display["is_events"] = (self.display["is_events"]
                                             or content_album.template
                                             == 'events')

        # figure out breadcrumbs, grab neighbors
        if is_special:
            if self.breadcrumbs["section"] == 'main':
                content_options = {
                    'username': content.username,
                    'section': content.name,
                    'name': None,
                }
            else:
                content_options = {
                    'username': content.username,
                    'section': content.name,
                    'name': self.breadcrumbs["name"],
                }
        elif content.album:
            content_options = {
                'username': content.username,
                'section': content.section,
                'name': content.album,
            }
        else:
            content_options = {
                'username': content.username,
                'section': content.section,
                'name': None,
            }

        if not content.hidden:
            collection, common_options = content_logic.get_collection(
                self,
                profile=content_options['username'],
                section=content_options['section'],
                name=content_options['name'])

            index = -1
            for i, p in enumerate(collection):
                if p.id == content.id:
                    index = i
                    break

        if not content.hidden and len(collection):
            if self.display["section_sort_type"] == "":
                self.display["start"] = collection[len(collection) - 1]
                self.display["previous"] = (collection[index + 1] if index +
                                            1 < len(collection) else None)
                self.display["next"] = (collection[index - 1]
                                        if index - 1 >= 0 else None)
                self.display["last"] = collection[0]
            else:
                self.display["start"] = collection[0]
                self.display["previous"] = (collection[index - 1]
                                            if index - 1 >= 0 else None)
                self.display["next"] = (collection[index + 1] if
                                        index + 1 < len(collection) else None)
                self.display["last"] = collection[len(collection) - 1]
        else:
            self.display["start"] = None

        if is_special:
            if self.breadcrumbs["section"] == 'main':
                self.display["top_url"] = self.nav_url(
                    username=content.username, section=content.name)
            else:
                self.display["top_url"] = self.nav_url(
                    username=content.username,
                    section=content.name,
                    name=self.breadcrumbs["name"])
        else:
            if self.display["section_template"] in ('first', 'latest'):
                self.display["top_url"] = self.nav_url(
                    username=content.username,
                    section=content.section,
                    name=content.album,
                    mode='archive')
            else:
                self.display["top_url"] = self.nav_url(
                    username=content.username,
                    section=content.section,
                    name=content.album)

        self.display['has_code'] = (content.code != "" or re.search(
            r"<script", content.view, re.I | re.M)
                                    or self.display["section_code"]
                                    or self.display["album_code"])
        if self.display["edit"] and self.display['has_code']:
            content.original_code = content.code
            content.code = self.code_workaround(content.code)
            content.view = self.code_workaround(content.view)
            if content_section:
                content_section.code = self.code_workaround(
                    content_section.code)
            if content_album:
                content_album.code = self.code_workaround(content_album.code)

        # increase view count (if it's not the owner looking at it)
        #if not is_owner_viewing:
        #  content.count = content.count + 1
        #  content.save()

        is_robot = content_logic.is_viewed_by_robot(self)
        if is_robot:  # human views are handled by the stats image
            content.count_robot = content.count_robot + 1
            content.save()

        if is_owner_viewing:
            # otherwise, when restarting browser, it shows old data and
            # freaks you out!
            self.prevent_caching()

        if is_special:
            self.display["individual_content"] = False
            self.display["content"] = content
            self.display["template"] = template
            rendered_content = self.ui["modules"][template.capitalize()]()
        else:
            try:
                content = self.ui["modules"].Content(
                    content,
                    simple=False,
                    template_type=self.display["section_template"])
            except tornado.web.HTTPError as ex:
                if ex.status_code == 401:
                    # we're logging in
                    return
                else:
                    # re-raise
                    raise ex

            self.display['content'] = content

            if self.request.headers.get(
                    "X-Requested-With") == "XMLHttpRequest":
                self.prevent_caching()
                self.write(self.ui["modules"].ContentView(content))
                return
            else:
                rendered_content = self.fill_template("view.html")

        if not self.current_user:
            cache.add(self, content, rendered_content)