Fix blog default category

This commit is contained in:
Noah 2015-07-20 14:09:14 -07:00
parent a43db105b2
commit 8786b8d49c
7 changed files with 37 additions and 26 deletions

View File

@ -8,7 +8,6 @@ from flask import (Flask, g, request, session, render_template, send_file,
from flask_sslify import SSLify from flask_sslify import SSLify
import jinja2 import jinja2
import os.path import os.path
import time
import sys import sys
# Get the Flask app object ready right away so other modules can import it # 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_settings()
Config.load_plugins() Config.load_plugins()
from rophako import __version__
from rophako.plugin import load_plugin from rophako.plugin import load_plugin
from rophako.log import logger from rophako.log import logger
#import rophako.model.tracking as Tracking #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["csrf_token"] = rophako.utils.generate_csrf_token
app.jinja_env.globals["include_page"] = rophako.utils.include app.jinja_env.globals["include_page"] = rophako.utils.include
app.jinja_env.globals["settings"] = lambda: Config
# Preload the emoticon data. # Preload the emoticon data.
import rophako.model.emoticons as Emoticons import rophako.model.emoticons as Emoticons
@ -75,25 +74,7 @@ def before_request():
"""Called before all requests. Initialize global template variables.""" """Called before all requests. Initialize global template variables."""
# Default template vars. # Default template vars.
g.info = { g.info = rophako.utils.default_vars()
"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),
}
# Default session vars. # Default session vars.
if not "login" in session: if not "login" in session:

View File

@ -416,9 +416,11 @@ def partial_index(template_name="blog/index.inc.html"):
pool = {} # The set of blog posts to show. pool = {} # The set of blog posts to show.
category = g.info.get("url_category", None) category = g.info.get("url_category", None)
if category == Config.blog.default_category:
category = ""
# Are we narrowing by category? # Are we narrowing by category?
if category: if category is not None:
# Narrow down the index to just those that match the category. # Narrow down the index to just those that match the category.
for post_id, data in index.items(): for post_id, data in index.items():
if not category in data["categories"]: if not category in data["categories"]:

View File

@ -39,7 +39,9 @@
<div class="clear"> <div class="clear">
<strong>Categories:</strong> <strong>Categories:</strong>
{% if post["categories"]|length == 0 or (post["categories"]|length == 1 and post["categories"][0] == "") %} {% 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 %} {% else %}
<ul class="blog-categories"> <ul class="blog-categories">
{% for tag in post["categories"] %} {% for tag in post["categories"] %}

View File

@ -14,6 +14,7 @@ import importlib
import smtplib import smtplib
import markdown import markdown
import json import json
import sys
try: try:
import urlparse import urlparse
except ImportError: except ImportError:
@ -22,6 +23,7 @@ import traceback
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from rophako import __version__
from rophako.log import logger from rophako.log import logger
from rophako.settings import Config 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): def template(name, **kwargs):
"""Render a template to the browser.""" """Render a template to the browser."""