Fix blog default category
This commit is contained in:
parent
a43db105b2
commit
8786b8d49c
|
@ -8,7 +8,6 @@ from flask import (Flask, g, request, session, render_template, send_file,
|
|||
from flask_sslify import SSLify
|
||||
import jinja2
|
||||
import os.path
|
||||
import time
|
||||
import sys
|
||||
|
||||
# Get the Flask app object ready right away so other modules can import it
|
||||
|
@ -29,7 +28,6 @@ from rophako.settings import Config
|
|||
Config.load_settings()
|
||||
Config.load_plugins()
|
||||
|
||||
from rophako import __version__
|
||||
from rophako.plugin import load_plugin
|
||||
from rophako.log import logger
|
||||
#import rophako.model.tracking as Tracking
|
||||
|
@ -64,6 +62,7 @@ app.jinja_loader = jinja2.ChoiceLoader([ jinja2.FileSystemLoader(x) for x in tem
|
|||
|
||||
app.jinja_env.globals["csrf_token"] = rophako.utils.generate_csrf_token
|
||||
app.jinja_env.globals["include_page"] = rophako.utils.include
|
||||
app.jinja_env.globals["settings"] = lambda: Config
|
||||
|
||||
# Preload the emoticon data.
|
||||
import rophako.model.emoticons as Emoticons
|
||||
|
@ -75,25 +74,7 @@ def before_request():
|
|||
"""Called before all requests. Initialize global template variables."""
|
||||
|
||||
# Default template vars.
|
||||
g.info = {
|
||||
"time": time.time(),
|
||||
"app": {
|
||||
"name": "Rophako",
|
||||
"version": __version__,
|
||||
"python_version": "{}.{}".format(sys.version_info.major, sys.version_info.minor),
|
||||
"author": "Noah Petherbridge",
|
||||
"photo_url": Config.photo.root_public,
|
||||
},
|
||||
"uri": request.path,
|
||||
"session": {
|
||||
"login": False, # Not logged in, until proven otherwise.
|
||||
"username": "guest",
|
||||
"uid": 0,
|
||||
"name": "Guest",
|
||||
"role": "user",
|
||||
},
|
||||
#"tracking": Tracking.track_visit(request, session),
|
||||
}
|
||||
g.info = rophako.utils.default_vars()
|
||||
|
||||
# Default session vars.
|
||||
if not "login" in session:
|
||||
|
|
|
@ -416,9 +416,11 @@ def partial_index(template_name="blog/index.inc.html"):
|
|||
pool = {} # The set of blog posts to show.
|
||||
|
||||
category = g.info.get("url_category", None)
|
||||
if category == Config.blog.default_category:
|
||||
category = ""
|
||||
|
||||
# Are we narrowing by category?
|
||||
if category:
|
||||
if category is not None:
|
||||
# Narrow down the index to just those that match the category.
|
||||
for post_id, data in index.items():
|
||||
if not category in data["categories"]:
|
||||
|
|
|
@ -39,7 +39,9 @@
|
|||
<div class="clear">
|
||||
<strong>Categories:</strong>
|
||||
{% if post["categories"]|length == 0 or (post["categories"]|length == 1 and post["categories"][0] == "") %}
|
||||
<a href="{{ url_for('blog.category', category=Uncategorized) }}">Uncategorized</a>{# TODO hardcoded name #}
|
||||
<a href="{{ url_for('blog.category', category=settings().blog.default_category) }}">
|
||||
{{ settings().blog.default_category }}
|
||||
</a>
|
||||
{% else %}
|
||||
<ul class="blog-categories">
|
||||
{% for tag in post["categories"] %}
|
||||
|
|
|
@ -14,6 +14,7 @@ import importlib
|
|||
import smtplib
|
||||
import markdown
|
||||
import json
|
||||
import sys
|
||||
try:
|
||||
import urlparse
|
||||
except ImportError:
|
||||
|
@ -22,6 +23,7 @@ import traceback
|
|||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
from rophako import __version__
|
||||
from rophako.log import logger
|
||||
from rophako.settings import Config
|
||||
|
||||
|
@ -65,6 +67,30 @@ def ajax_response(status, msg):
|
|||
))
|
||||
|
||||
|
||||
def default_vars():
|
||||
"""Default template variables."""
|
||||
return {
|
||||
"time": time.time(),
|
||||
"app": {
|
||||
"name": "Rophako",
|
||||
"version": __version__,
|
||||
"python_version": "{}.{}".format(sys.version_info.major, sys.version_info.minor),
|
||||
"author": "Noah Petherbridge",
|
||||
"photo_url": Config.photo.root_public,
|
||||
"config": Config,
|
||||
},
|
||||
"uri": request.path,
|
||||
"session": {
|
||||
"login": False, # Not logged in, until proven otherwise.
|
||||
"username": "guest",
|
||||
"uid": 0,
|
||||
"name": "Guest",
|
||||
"role": "user",
|
||||
},
|
||||
#"tracking": Tracking.track_visit(request, session),
|
||||
}
|
||||
|
||||
|
||||
def template(name, **kwargs):
|
||||
"""Render a template to the browser."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user