From 95717d1717b4b3e7b7b82a6de359e275b12c85d7 Mon Sep 17 00:00:00 2001
From: akun <6awkun@gmail.com>
Date: Thu, 3 Jul 2014 22:49:16 +0800
Subject: [PATCH] support customrize title and copyright, and split base.html
---
README.rst | 5 ++
src/pyhn/libs/context_processors.py | 11 ++++
src/pyhn/libs/templates/base.html | 52 ++-----------------
src/pyhn/libs/templates/footer.html | 11 ++++
src/pyhn/libs/templates/header.html | 43 +++++++++++++++
.../libs/tests/test_context_processors.py | 29 +++++++++++
src/pyhn/settings/common.py | 5 ++
src/pyhn/settings/local.example.py | 8 +++
8 files changed, 115 insertions(+), 49 deletions(-)
create mode 100644 src/pyhn/libs/context_processors.py
create mode 100644 src/pyhn/libs/templates/footer.html
create mode 100644 src/pyhn/libs/templates/header.html
create mode 100644 src/pyhn/libs/tests/test_context_processors.py
diff --git a/README.rst b/README.rst
index 974261c..14a3d92 100644
--- a/README.rst
+++ b/README.rst
@@ -64,6 +64,11 @@ Features
+ [o] user score
+ [o] calculate score in background
+* [o] Customrize
+
+ + [o] Title
+ + [o] Copyright
+
License
-------
diff --git a/src/pyhn/libs/context_processors.py b/src/pyhn/libs/context_processors.py
new file mode 100644
index 0000000..4ab2324
--- /dev/null
+++ b/src/pyhn/libs/context_processors.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+
+from django.conf import settings
+
+
+def pyhn_info(request):
+ return {
+ 'PYHN_TITLE': settings.PYHN_TITLE,
+ 'PYHN_COPYRIGHT': settings.PYHN_COPYRIGHT,
+ }
diff --git a/src/pyhn/libs/templates/base.html b/src/pyhn/libs/templates/base.html
index d2ec2bb..1c8cc16 100644
--- a/src/pyhn/libs/templates/base.html
+++ b/src/pyhn/libs/templates/base.html
@@ -1,6 +1,5 @@
{% load staticfiles %}
{% load i18n %}
-{% load pyhn_extras %}
@@ -12,7 +11,7 @@
-
Python Hacker News
+ {% if PYHN_TITLE %}{{ PYHN_TITLE }}{% else %}Python Hacker News{% endif %}
@@ -21,56 +20,11 @@
-
-
+ {% include 'header.html' %}
{% block container %}{% endblock %}
-
-
+ {% include 'footer.html' %}
diff --git a/src/pyhn/libs/templates/footer.html b/src/pyhn/libs/templates/footer.html
new file mode 100644
index 0000000..0d7ee95
--- /dev/null
+++ b/src/pyhn/libs/templates/footer.html
@@ -0,0 +1,11 @@
+
diff --git a/src/pyhn/libs/templates/header.html b/src/pyhn/libs/templates/header.html
new file mode 100644
index 0000000..7404129
--- /dev/null
+++ b/src/pyhn/libs/templates/header.html
@@ -0,0 +1,43 @@
+{% load i18n %}
+{% load pyhn_extras %}
+
+
diff --git a/src/pyhn/libs/tests/test_context_processors.py b/src/pyhn/libs/tests/test_context_processors.py
new file mode 100644
index 0000000..b2b2759
--- /dev/null
+++ b/src/pyhn/libs/tests/test_context_processors.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# coding=utf-8
+
+
+from django.test import TestCase
+
+from pyhn.libs import context_processors
+
+
+class ContextProcessorsTestCase(TestCase):
+
+ def test_pyhn_info_if_default(self):
+ context = context_processors.pyhn_info(self.client.request)
+ self.assertEqual('', context['PYHN_TITLE'])
+ self.assertEqual('', context['PYHN_COPYRIGHT'])
+
+ def test_pyhn_info_if_edit_settings(self):
+ from django.conf import settings
+ title = 'test_title'
+ copyright = 'test_copyright'
+ settings.PYHN_TITLE = title
+ settings.PYHN_COPYRIGHT = copyright
+
+ context = context_processors.pyhn_info(self.client.request)
+ self.assertEqual(title, context['PYHN_TITLE'])
+ self.assertEqual(copyright, context['PYHN_COPYRIGHT'])
+
+ settings.PYHN_TITLE = ''
+ settings.PYHN_COPYRIGHT = ''
diff --git a/src/pyhn/settings/common.py b/src/pyhn/settings/common.py
index 880839c..462468a 100644
--- a/src/pyhn/settings/common.py
+++ b/src/pyhn/settings/common.py
@@ -103,4 +103,9 @@
'django.core.context_processors.request',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
+ 'pyhn.libs.context_processors.pyhn_info',
)
+
+
+PYHN_TITLE = ''
+PYHN_COPYRIGHT = ''
diff --git a/src/pyhn/settings/local.example.py b/src/pyhn/settings/local.example.py
index 48b1889..2cdd5e2 100644
--- a/src/pyhn/settings/local.example.py
+++ b/src/pyhn/settings/local.example.py
@@ -36,3 +36,11 @@
# Sina Weibo
#SOCIAL_AUTH_WEIBO_KEY = ''
#SOCIAL_AUTH_WEIBO_SECRET = ''
+
+# Site Title
+# eg: PYHN_TITLE = "akun's News"
+#PYHN_TITLE = ''
+
+# Copyright
+# eg: PYHN_COPYRIGHT = '© 2014, akun'
+#PYHN_COPYRIGHT = ''