示例#1
0
  def get(self):

    if view.render_if_cached(self) :
      return

    newData = []
    oldData = SeaiceData[:]
    host    = "http://127.0.0.10:8080/pics/?"
    host    = "http://omega.ice-pics.appspot.com/pics/?"
    host    = "http://ice-pics.appspot.com/pics/?"

    for gallery in oldData:
      if gallery["active"] :
        gal = copy.deepcopy(gallery)
        if not "anchor" in gal :
          for pic in gal["items"]:

            if "url" in pic :
              rot     = 0  if not pic.has_key("rot")       else int(pic["rot"])  ## 4 hours
              keep    = 14400  if not pic.has_key("keep")  else int(pic["keep"])  ## 4 hours
              width   = 140    if not pic.has_key("width") else pic["width"]
              params = "rot=%s&crop=%s&width=%s&keep=%s&" % (rot, pic['crop'], width, keep)
              pic["icon"] = host + params + urllib.urlencode({ 'url': pic["url"] })
              if type(pic['date']).__name__ == "function" :
                pic['date'] = pic['date']()

        newData.append(gal)
    
    templateData = {
      'gallerydata': newData, ##SeaiceData,
      'galleryjson': simplejson.dumps(newData),
      'title': config.APP['title'] + " - Daily Sea Ice Charts, Graphs and Forecasts"
      }
    view.ViewPage(cache_time=3600).render(self, templateData)
示例#2
0
文件: blog.py 项目: chunchu/bloog
 def get(self):
     if view.render_if_cached(self): return
     from google.appengine.api import datastore_errors
     search_term = self.request.get("s")
     query_string = 's=' + urllib.quote_plus(search_term) + '&'
     page = view.ViewPage()
     try:
         page.render_query(
             self, 'articles',
             models.blog.Article.all().search(
                 search_term,
                 properties=['title', 'body']).order('-published'), {
                     'search_term': cgi.escape(search_term),
                     'query_string': query_string
                 })
     except datastore_errors.NeedIndexError:
         page.render(
             self, {
                 'search_term':
                 cgi.escape(search_term),
                 'search_error_message':
                 """
                            Sorry, full-text searches are currently limited
                            to single words until a later AppEngine update.
                            """
             })
示例#3
0
文件: blog.py 项目: chunchu/bloog
    def get(self):
        if self.request.path == config.BLOG['legacy_atom_url']:
            self.redirect(config.BLOG['master_atom_url'], permanent=True)
            return

        logging.debug("ATOM feed")
        self.response.headers['Content-Type'] = 'application/atom+xml'
        if view.render_if_cached(self): return  # quick cache path

        articles = db.Query(models.blog.Article). \
                      filter('article_type =', 'blog entry'). \
                      order('-published').fetch(limit=10)
        updated = ''
        if articles: updated = articles[0].rfc3339_updated()

        try:
            full_content = self.request.params['full'] in ['1', 'true', 'True']
        except:
            full_content = False
        view.ViewPage().render(
            self, {
                "blog_updated_timestamp": updated,
                "articles": articles,
                "ext": "xml",
                'full_content': full_content
            })
示例#4
0
文件: blog.py 项目: chunchu/bloog
 def get(self):
     logging.debug("RootHandler#get")
     if view.render_if_cached(self): return  # quick cache path
     view.ViewPage().render_query(
         self, 'articles',
         db.Query(models.blog.Article). \
            filter('article_type =', 'blog entry').order('-published'))
示例#5
0
def render_article(handler, path, params = {}):
  """
    renders blods, drafts and articles
  """

  if view.render_if_cached(handler) :
    return

  article = db.Query(models.blog.Article).filter('permalink =', path).get()

  if not article:
    aio.debug("blog.render_article article not found: path: %s", path)
    handler.redirect('/404.html')
    # handler.error(404)
    # view.ViewPage(cache_time = 604800).render(handler, {
    #   'module_name':  'blog', 
    #   'handler_name': 'notfound',
    #   'sections':     ['Navigation', 'Home']
    # })
    return

  else :
    render_params = {
      "isBig":    article.is_big(),
      "article":  article,
      "title":    get_htmlTitle(article.title),
    }
    render_params.update(params)

    view.ViewPage().render(handler, render_params)
示例#6
0
  def get(self, year, month):

    aio.debug("blog.MonthHandler: get for year %s, month %s", year, month)

    if view.render_if_cached(self):
      return

    yr = string.atoi(year)
    mth = string.atoi(month)
    start_date = datetime.datetime(yr, mth, 1)

    if mth == 12:
      end_date = datetime.datetime(string.atoi(year)+1, 1, 1)
    else :
      end_date = datetime.datetime(string.atoi(year), string.atoi(month) + 1, 1)

    page = view.ViewPage()

    page.render_query(
      self, 'articles',
      db.Query(models.blog.Article).order('-published'). \
        filter('published >=', start_date). \
        filter('published <', end_date).filter("article_type =", "blog entry"),
        {'title': config.APP['title'] + ' - Articles for ' + month + '/' + year + ' | ',
        'year': year, 'month': month}
    )
示例#7
0
文件: blog.py 项目: JamieS/bloog
 def get(self):
     logging.debug("RootHandler#get")
     if view.render_if_cached( self ): return  # quick cache path
     view.ViewPage().render_query(
         self, 'articles', 
         db.Query(models.blog.Article). \
            filter('article_type =', 'blog entry').order('-published'))
示例#8
0
文件: blog.py 项目: chunchu/bloog
def render_article(handler, path):
    # Handle precomputed legacy aliases
    # TODO: Use hash for case-insensitive lookup
    for alias in legacy_aliases.redirects:
        if path.lower() == alias.lower():
            self.redirect(legacy_aliases.redirects[alias])
            return

    # Test if client prefers JSON, so we can do fast-path cache if not.  Since the
    # cache key does not include content-type (maybe it should?) We have to check
    # this manually so that a cached HTML response isn't rendered when the client
    # actually wanted JSON.
    json_type = 'application/json'
    client_wants_json = (json_type == handler.request.accept.first_match(
        ['text/html', 'application/xhtml+xml', json_type]))
    if not client_wants_json and view.render_if_cached(handler): return

    article = db.Query(models.blog.Article).filter('permalink =', path).get()

    if not article:
        # This lets you map arbitrary URL patterns like /node/3
        #  to article properties, e.g. 3 -> legacy_id property
        article = legacy_id_mapping(path, config.BLOG["legacy_blog_software"])
        if article and config.BLOG["legacy_entry_redirect"]:
            handler.redirect('/' + article.permalink)
            return
        else:  # not found.
            handler.error(404)
            view.ViewPage(cache_time=36000).render(handler, {
                'module_name': 'blog',
                'handler_name': 'notfound'
            })
            return

    # Check if client is requesting javascript
    if client_wants_json:
        handler.response.headers['Content-Type'] = json_type
        handler.response.out.write(article.to_json())
        return
    else:
        two_columns = article.two_columns
        if two_columns is None:
            two_columns = article.is_big()
        allow_comments = article.allow_comments
        if allow_comments is None:
            age = (datetime.datetime.now() - article.published).days
            allow_comments = (age <= config.BLOG['days_can_comment'])
        title = "%s :: %s" % (article.title, config.BLOG['title'])
        view.ViewPage().render(
            handler, {
                "two_columns": two_columns,
                "allow_comments": allow_comments,
                "article": article,
                "title": title,
                "taglist": ', '.join(article.tags),
                "captcha": config.BLOG['recap_public_key'],
                "use_gravatars": config.BLOG['use_gravatars']
            })
示例#9
0
文件: blog.py 项目: JamieS/bloog
 def get(self):
     logging.debug("ArticlesHandler#get")
     if view.render_if_cached( self ) : return
     page = view.ViewPage()
     page.render_query(
         self, 'articles',
         db.Query(models.blog.Article). \
            filter('article_type =', 'article').order('title'),
         num_limit=20)
示例#10
0
文件: blog.py 项目: chunchu/bloog
 def get(self):
     logging.debug("ArticlesHandler#get")
     if view.render_if_cached(self): return
     page = view.ViewPage()
     page.render_query(
         self, 'articles',
         db.Query(models.blog.Article). \
            filter('article_type =', 'article').order('title'),
         num_limit=20)
示例#11
0
文件: blog.py 项目: JamieS/bloog
 def get(self, encoded_tag):
     if view.render_if_cached( self ) : return
     tag =  re.sub('(%25|%)(\d\d)', 
                   lambda cmatch: chr(string.atoi(cmatch.group(2), 16)),                 
                   encoded_tag)   # No urllib.unquote in AppEngine?
     view.ViewPage().render_query(
         self, 'articles', 
         db.Query(models.blog.Article).filter(
           'tags =', tag ).order('-published'), 
         {'tag': tag, 'title': "Articles tagged with'" + tag + "'"} )
示例#12
0
文件: blog.py 项目: JamieS/bloog
 def get(self):
   logging.debug("Sending Sitemap")
   self.response.headers['Content-Type'] = 'text/xml'
   if view.render_if_cached( self ): return  # quick cache path
   articles = db.Query(models.blog.Article).order('-published').fetch(1000)
   if articles:
     view.ViewPage().render(self, {
         "articles": articles,
         "ext": "xml",
         "root_url": config.BLOG['root_url']
     })
示例#13
0
文件: blog.py 项目: JamieS/bloog
def render_article(handler, path):
    # Handle precomputed legacy aliases
    # TODO: Use hash for case-insensitive lookup
    for alias in legacy_aliases.redirects:
        if path.lower() == alias.lower():
            self.redirect(legacy_aliases.redirects[alias])
            return

    # Test if client prefers JSON, so we can do fast-path cache if not.  Since the 
    # cache key does not include content-type (maybe it should?) We have to check 
    # this manually so that a cached HTML response isn't rendered when the client 
    # actually wanted JSON.
    json_type = 'application/json'
    client_wants_json = ( json_type == handler.request.accept.first_match(
      ['text/html', 'application/xhtml+xml', json_type] ) )
    if not client_wants_json and view.render_if_cached( handler ) : return

    article = db.Query(models.blog.Article).filter('permalink =', path).get()

    if not article:
        # This lets you map arbitrary URL patterns like /node/3
        #  to article properties, e.g. 3 -> legacy_id property
        article = legacy_id_mapping(path, config.BLOG["legacy_blog_software"])
        if article and config.BLOG["legacy_entry_redirect"]:
            handler.redirect('/' + article.permalink)
            return
        else: # not found.
            handler.error(404)
            view.ViewPage(cache_time=36000).render(handler, 
                {'module_name': 'blog', 'handler_name': 'notfound'})
            return

    # Check if client is requesting javascript
    if client_wants_json:
        handler.response.headers['Content-Type'] = json_type
        handler.response.out.write(article.to_json())
        return
    else:
        two_columns = article.two_columns
        if two_columns is None:
            two_columns = article.is_big()
        allow_comments = article.allow_comments
        if allow_comments is None:
            age = (datetime.datetime.now() - article.published).days
            allow_comments = (age <= config.BLOG['days_can_comment'])
        title = "%s :: %s" %  ( article.title, config.BLOG['title'] )
        view.ViewPage().render(handler, { "two_columns": two_columns,
                               "allow_comments": allow_comments,
                               "article": article,
                               "title": title,
                               "taglist": ', '.join(article.tags),
                               "captcha": config.BLOG['recap_public_key'],
                               "use_gravatars": config.BLOG['use_gravatars']
        })
示例#14
0
 def get(self, year):
   logging.debug("YearHandler#get for year %s", year)
   if view.render_if_cached(self):
     return
   start_date = datetime.datetime(string.atoi(year), 1, 1)
   end_date = datetime.datetime(string.atoi(year), 12, 31, 23, 59, 59)
   page = view.ViewPage()
   page.render_query(
     self, 'articles',
     db.Query(models.blog.Article).order('-published'). \
        filter('published >=', start_date). \
        filter('published <=', end_date).filter("article_type =", "blog entry"),
     {'title': config.APP['title'] + ' - Articles for ' + year + ' | ', 'year': year})
示例#15
0
文件: blog.py 项目: chunchu/bloog
 def get(self, encoded_tag):
     if view.render_if_cached(self): return
     tag = re.sub('(%25|%)(\d\d)',
                  lambda cmatch: chr(string.atoi(cmatch.group(2), 16)),
                  encoded_tag)  # No urllib.unquote in AppEngine?
     view.ViewPage().render_query(
         self, 'articles',
         db.Query(models.blog.Article).filter('tags =',
                                              tag).order('-published'),
         {
             'tag': tag,
             'title': "Articles tagged with'" + tag + "'"
         })
示例#16
0
文件: blog.py 项目: chunchu/bloog
 def get(self):
     logging.debug("Sending Sitemap")
     self.response.headers['Content-Type'] = 'text/xml'
     if view.render_if_cached(self): return  # quick cache path
     articles = db.Query(
         models.blog.Article).order('-published').fetch(1000)
     if articles:
         view.ViewPage().render(
             self, {
                 "articles": articles,
                 "ext": "xml",
                 "root_url": config.BLOG['root_url']
             })
示例#17
0
  def get(self):

    aio.debug("ArticlesHandler#get")

    if view.render_if_cached(self) :
      return

    page = view.ViewPage()
    page.render_query(
      self, "articles", 
      db.Query(models.blog.Article).filter("article_type =", "article").order("title"),
      params = {
        "title": "Articles | " + config.APP["title"]
      }
    )
示例#18
0
  def get(self, what, year=None):
    """
      what = all, blogs, drafts, articles
    """

    aio.debug("CollHandler#get: %s for year: '%s'", what, year)

    start_date = None; end_date = None; 

    if view.render_if_cached(self) : return

    page = view.ViewPage()

    if what in ["all", "blogs", "articles", "drafts"] :

      if year :
        start_date = datetime.datetime(string.atoi(year), 1, 1)
        end_date   = datetime.datetime(string.atoi(year), 12, 31, 23, 59, 59)

      if what == "all" :
        query = db.Query(models.blog.Article)
      elif what == "drafts"   : 
        query = db.Query(models.blog.Article).filter('article_type =', 'draft')
      elif what == "blogs"    : 
        query = db.Query(models.blog.Article).filter('article_type =', 'blog entry')
      elif what == "articles" : 
        query = db.Query(models.blog.Article).filter('article_type =', 'article')

      if start_date and end_date :
        query = query.filter('updated >=', start_date).filter('updated <=', end_date)

      if year and what == "all" :
          title = "%s - Entries for year %s" % (config.APP['title'], year)
      else : 
          title = "%s - %s" % (config.APP['title'], what.title())

      page.render_query(self, 'articles', query, {
        'title': title,
        year:    year
      })

    else :
      self.error(404)
      view.ViewPage(cache_time = 604800).render(self, {
        'module_name': 'blog', 
        'handler_name': 'notfound',
        'sections': ['Navigation', 'Home']
      })
示例#19
0
 def get(self, encoded_tag):
   logging.debug("Sending atom feed for tag %s", encoded_tag)
   self.response.headers['Content-Type'] = 'application/atom+xml'
   if view.render_if_cached(self):
     return
   tag = unicode(urllib.unquote(encoded_tag),
       config.APP['charset'])
   articles = db.Query(models.blog.Article).filter('tags =',
       tag).order('-published')
   updated = ''
   if articles:
     updated = articles[0].rfc3339_updated()
   page = view.ViewPage()
   page.render(self, {"blog_updated_timestamp": updated,
     "articles": articles, "ext": "xml", "handler_name": "tag",
     "tag_name": tag})
示例#20
0
文件: blog.py 项目: JamieS/bloog
 def get(self):
     if view.render_if_cached( self ) : return
     from google.appengine.api import datastore_errors
     search_term = self.request.get("s")
     query_string = 's=' + urllib.quote_plus(search_term) + '&'
     page = view.ViewPage()
     try:
         page.render_query( self, 'articles', 
             models.blog.Article.all().search( search_term,
                 properties=['title','body'] ).order('-published'), 
             {'search_term': cgi.escape(search_term),
                 'query_string': query_string} )
     except datastore_errors.NeedIndexError:
         page.render(self, {'search_term': cgi.escape(search_term),
                            'search_error_message': """
                            Sorry, full-text searches are currently limited
                            to single words until a later AppEngine update.
                            """})
示例#21
0
  def get(self):

    aio.debug("RootHandler#get")

    if view.render_if_cached(self) :
      return

    page = view.ViewPage()

    page.render_query(
      self, 'articles',
      db.Query(models.blog.Article).filter('article_type =', 'blog entry').order('-published'),
      params = {
        "module_name": None, 
        "handler_name": "base", 
        "title": get_htmlTitle()
      }
    )
示例#22
0
  def get(self):
    logging.debug("Sending Atom feed")
    self.response.headers['Content-Type'] = 'application/atom+xml'
    if view.render_if_cached(self):
      return
    articles = db.Query(models.blog.Article). \
            filter('article_type =', 'blog entry'). \
            order('-published').fetch(limit = 10)
    updated = ''
    if articles:
      updated = articles[0].rfc3339_updated()

    page = view.ViewPage()
    page.render(self, {
      "blog_updated_timestamp": updated,
      "articles": articles, 
      "ext": "xml",
      "use_summary": config.BLOG['feed_use_summary']
    })
示例#23
0
  def get(self, layers="8", datum=None, position="4-N89-E0", toponym=""):

    if view.render_if_cached(self):
      return

    title = config.APP['title'] + " - Daily Satellite Images + Observations"
    if toponym  : title += ": " + urllib.unquote(toponym)
    if position : title += ", " + position
    title = title.replace("\"", "'")

    template_data  = {
      'yir': Clock().year,
      'ipu': self.request.remote_addr,
      'deb': config.DEBUG,
      'title': title,
      'description': "Interactive Satelite Maps of Earth and Arctic",
    }

    view.ViewPage(cache_time=3600).render(self, template_data)
示例#24
0
文件: blog.py 项目: JamieS/bloog
    def get(self):
        if self.request.path == config.BLOG['legacy_atom_url']:
            self.redirect(config.BLOG['master_atom_url'],permanent=True)
            return
        
        logging.debug("ATOM feed")
        self.response.headers['Content-Type'] = 'application/atom+xml'
        if view.render_if_cached( self ): return  # quick cache path

        articles = db.Query(models.blog.Article). \
                      filter('article_type =', 'blog entry'). \
                      order('-published').fetch(limit=10)
        updated = ''
        if articles: updated = articles[0].rfc3339_updated()
        
        try: full_content= self.request.params['full'] in ['1','true','True']
        except: full_content= False
        view.ViewPage().render(self, {"blog_updated_timestamp": updated, 
                           "articles": articles, "ext": "xml",
                           'full_content': full_content })
示例#25
0
  def get(self, encoded_tag=""):

    if view.render_if_cached(self):
      return
    
    tag = unicode(urllib.unquote(encoded_tag), config.APP['charset'])
    page = view.ViewPage()

    template_data = {
      'tag': tag,
      "title": config.APP["title"] + " - Articles tagged with &quot;" + tag + "&quot;"
    }

    if tag :
      page.render_query(
        self, 'articles',
        db.Query(models.blog.Article).filter('tags =', tag).order('-published'), template_data)
    else :
      ##TODO: render nice tag Cloud here
      page.render_query(
        self, 'articles',
        db.Query(models.blog.Article).order('-published'), template_data)
示例#26
0
  def get(self, params=""):

    if view.render_if_cached(self):
      return

    aio.debug("plug.ZoomHandler params: %s", params)

    if len(params) == 0 :
      self.redirect("/maps/circumpolar")
      return

    else :
      params = params.split("/")
      dzi = params[0]
      if len(params) > 1 : pos = urllib.unquote(params[1])



    template_data  = {
      'title':          config.APP['title'] + ' - Zoom: ' + params[0].title(),
      'dzi':            params[0],
    }

    view.ViewPage(cache_time=3600).render(self, template_data)