Skip to content

Commit

Permalink
support customrize title and copyright, and split base.html
Browse files Browse the repository at this point in the history
  • Loading branch information
akun committed Jul 3, 2014
1 parent 4338230 commit 95717d1
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 49 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ Features
+ [o] user score
+ [o] calculate score in background

* [o] Customrize

+ [o] Title
+ [o] Copyright

License
-------

Expand Down
11 changes: 11 additions & 0 deletions src/pyhn/libs/context_processors.py
Original file line number Diff line number Diff line change
@@ -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,
}
52 changes: 3 additions & 49 deletions src/pyhn/libs/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% load staticfiles %}
{% load i18n %}
{% load pyhn_extras %}

<!DOCTYPE html>
<html lang="en">
Expand All @@ -12,7 +11,7 @@
<meta name="author" content="">
<link rel="shortcut icon" href="{% static 'favicon.ico' %}">

<title>Python Hacker News</title>
<title>{% if PYHN_TITLE %}{{ PYHN_TITLE }}{% else %}Python Hacker News{% endif %}</title>

<link rel="stylesheet" type="text/css" href="{% static 'libs/bootstrap-3.1.1-dist/css/bootstrap.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'libs/sco.js/css/sco.message.css' %}" />
Expand All @@ -21,56 +20,11 @@

<body>

<div class="navbar navbar-default navbar-fix-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'index' %}">Python Hacker News</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{% url 'news:newest' %}">{% trans 'New' %}</a></li>
{% if perms.can_submit %}
<li><a href="{% url 'news:submit' %}">{% trans 'Submit' %}</a></li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if request.user.is_authenticated %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="{{ request.user.email|gravatar_url }}" /> {{ request.user.username }} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{% url 'account:index' %}">Account</a></li>
<li><a href="{% url 'account:logout' %}">Sign Out</a></li>
</ul>
</li>
{% else %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="{{ request.user.email|gravatar_url }}" /> {{ request.user.username }} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{% url 'social:begin' 'github' %}">{% trans 'Sign in with GitHub' %}</a></li>
<li><a href="{% url 'social:begin' 'weibo' %}">{% trans 'Sign in with Sina Weibo' %}</a></li>
</ul>
</li>
{% endif %}
</ul>
</div>
</div>
</div>

{% include 'header.html' %}
<div class="container">
{% block container %}{% endblock %}
</div>

<div id="footer">
<div class="container">
<p class="text-muted">&copy; 2014 Python Hacker News, akun</p>
</div>
</div>
{% include 'footer.html' %}

<script src="{% static 'libs/jquery-1.11.0.min.js' %}"></script>
<script src="{% static 'libs/jquery.cookie.js' %}"></script>
Expand Down
11 changes: 11 additions & 0 deletions src/pyhn/libs/templates/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div id="footer">
<div class="container">
<p class="text-muted">
{% if PYHN_COPYRIGHT %}
{{ PYHN_COPYRIGHT|safe }}
{% else %}
&copy; 2014 <a href="https://github.com/akun">akun</a>. Powered by <a href="https://github.com/akun/PyHackerNews">Python Hacker News</a>. Report <a href="https://github.com/akun/PyHackerNews/issues/new">issue</a>
{% endif %}
</p>
</div>
</div>
43 changes: 43 additions & 0 deletions src/pyhn/libs/templates/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% load i18n %}
{% load pyhn_extras %}

<div class="navbar navbar-default navbar-fix-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'index' %}">{% if PYHN_TITLE %}{{ PYHN_TITLE }}{% else %}Python Hacker News{% endif %}</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{% url 'news:newest' %}">{% trans 'New' %}</a></li>
{% if perms.can_submit %}
<li><a href="{% url 'news:submit' %}">{% trans 'Submit' %}</a></li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if request.user.is_authenticated %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="{{ request.user.email|gravatar_url }}" /> {{ request.user.username }} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{% url 'account:index' %}">Account</a></li>
<li><a href="{% url 'account:logout' %}">Sign Out</a></li>
</ul>
</li>
{% else %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="{{ request.user.email|gravatar_url }}" /> {{ request.user.username }} <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{% url 'social:begin' 'github' %}">{% trans 'Sign in with GitHub' %}</a></li>
<li><a href="{% url 'social:begin' 'weibo' %}">{% trans 'Sign in with Sina Weibo' %}</a></li>
</ul>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
29 changes: 29 additions & 0 deletions src/pyhn/libs/tests/test_context_processors.py
Original file line number Diff line number Diff line change
@@ -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 = ''
5 changes: 5 additions & 0 deletions src/pyhn/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
8 changes: 8 additions & 0 deletions src/pyhn/settings/local.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '&copy; 2014, <a href="https://github.com/akun">akun</a>'
#PYHN_COPYRIGHT = ''

0 comments on commit 95717d1

Please sign in to comment.