Add timezone offsetter and strftime template function

pull/2/head
Noah 2015-07-26 15:11:54 -07:00
parent bf18978195
commit 0c71bc456b
7 changed files with 16 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,9 +1,11 @@
# Don't check in site specific settings. # Don't check in site specific settings.
settings.ini settings.ini
settings.yml settings.yml
/db
# Compiled Python # Compiled Python
*.pyc *.pyc
__pycache__
/site/www/static/photos/*.jpg /site/www/static/photos/*.jpg
/site/www/static/photos/*.png /site/www/static/photos/*.png

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
clean:
find . | grep -E '(__pycache__|\.py[oc])' | xargs rm -rf

View File

@ -29,6 +29,10 @@ rophako:
# by other spots in this config file, for easy overriding). # by other spots in this config file, for easy overriding).
_date_format: &DATE_FORMAT '%A, %B %d %Y @ %I:%M:%S %p' _date_format: &DATE_FORMAT '%A, %B %d %Y @ %I:%M:%S %p'
# Preferred time zone to present datetimes in. See `pytz.all_timezones` for
# valid options here. Examples: "US/Eastern", "America/Los_Angeles" etc.
timezone: US/Pacific
# Where to save temp files for photo uploads etc. # Where to save temp files for photo uploads etc.
tempdir: /tmp tempdir: /tmp

View File

@ -1,6 +1,7 @@
flask flask
flask-sslify flask-sslify
redis redis
pytz
bcrypt bcrypt
pillow pillow
requests requests

View File

@ -8,6 +8,7 @@ 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 datetime
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
@ -63,6 +64,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 app.jinja_env.globals["settings"] = lambda: Config
app.jinja_env.globals["strftime"] = lambda x: datetime.datetime.utcnow().strftime(x)
# Preload the emoticon data. # Preload the emoticon data.
import rophako.model.emoticons as Emoticons import rophako.model.emoticons as Emoticons

View File

@ -9,6 +9,7 @@ import codecs
import uuid import uuid
import datetime import datetime
import time import time
import pytz
import re import re
import importlib import importlib
import smtplib import smtplib
@ -329,8 +330,9 @@ def server_name():
def pretty_time(time_format, unix): def pretty_time(time_format, unix):
"""Pretty-print a time stamp.""" """Pretty-print a time stamp."""
date = datetime.datetime.fromtimestamp(unix) tz = pytz.timezone(Config.site.timezone)
return date.strftime(time_format) date = datetime.datetime.fromtimestamp(unix, pytz.utc)
return date.astimezone(tz).strftime(time_format)
def sanitize_name(name): def sanitize_name(name):

View File

@ -56,7 +56,7 @@
<footer> <footer>
<div> <div>
&copy; 2014 Noah Petherbridge. Web design released along with the Rophako CMS &copy; {{ strftime("%Y") }} Noah Petherbridge. Web design released along with the Rophako CMS
under the GNU General Public License v2.0.<br> under the GNU General Public License v2.0.<br>
<a href="https://github.com/kirsle/rophako" target="_blank"> <a href="https://github.com/kirsle/rophako" target="_blank">
{{ app["name"] }} v{{ app["version"] }} on Python {{ app["python_version"] }} {{ app["name"] }} v{{ app["version"] }} on Python {{ app["python_version"] }}