Пример #1
0
def category(category_id):
    # permanent redirection to the new story URL
    # find story by category id
    story = model.Story.get_by('deprecated_category_id', category_id)
    redirect_url = None
    if story:
        redirect_url = flask.url_for('story', story_key=util.story_key(story))
    else:
        flask.abort(418)
    return flask.redirect(redirect_url, 301)  # add 301 for permanent redirection
Пример #2
0
def story(story_key):
    story_db = get_story_db(story_key)
    if story_db is None:
        flask.abort(404)
    resp_model = {}
    resp_model['html_class'] = 'story'
    resp_model['db_obj'] = story_db
    resp_model['canonical_path'] = flask.url_for(
        'story', story_key=util.story_key(story_db))
    decorate_page_response_model(resp_model)
    decorate_story_page_model(resp_model, story_db)
    mode = util.param('m', str)
    templatePath = 'public/story/story.html'
    if 'gallery' == mode:
        active = util.param('active', int)
        if story_db.story_items_expanded:
            if active > len(story_db.story_items_expanded):
                active = 1
            if active < 0:
                active = len(story_db.story_items_expanded)
        resp_model['active'] = active
        templatePath = 'public/story/story_gallery.html'
    return flask.render_template(templatePath, model=resp_model)
Пример #3
0
def expand_links(parentItem, extern=False):
    if isinstance(parentItem, list):
        for item in parentItem:
            expand_links(item, extern)
    else:
        modelType = util.get_if_exists(parentItem, "modelType", None)
        if "story" == modelType:
            story_key = None
            keyStr = util.get_if_exists(parentItem, "key", None)
            if not util.is_blank(keyStr):
                story_db = ndb.Key(urlsafe=keyStr).get()
                if story_db:
                    parentItem["visible"] = story_db.deleted
                    parentItem["url"] = flask.url_for("story", story_key=util.story_key(story_db), _external=extern)
                else:
                    parentItem["visible"] = False
        if "page" == modelType:
            keyStr = util.get_if_exists(parentItem, "url_component", "home")
            try:
                parentItem["url"] = flask.url_for(keyStr, _external=extern)
            except routing.BuildError:
                parentItem["url"] = flask.url_for("home", _external=extern)
        if "nodes" in parentItem:
            expand_links(parentItem["nodes"], extern)
Пример #4
0
def story_to_sitemap(story):
  sitemap = {}
  sitemap['url'] = flask.url_for('story', story_key=util.story_key(story), _external=True)
  sitemap['lastmod'] = story.modified.strftime('%Y-%m-%d')
  sitemap['priority'] = '0.7'
  return sitemap