Преглед на файлове

Add timezone offsetter and strftime template function

pull/2/head
Noah Petherbridge преди 4 години
родител
ревизия
0c71bc456b
променени са 7 файла, в които са добавени 16 реда и са изтрити 3 реда
  1. 2
    0
      .gitignore
  2. 2
    0
      Makefile
  3. 4
    0
      defaults.yml
  4. 1
    0
      requirements.txt
  5. 2
    0
      rophako/app.py
  6. 4
    2
      rophako/utils.py
  7. 1
    1
      rophako/www/layout.html

+ 2
- 0
.gitignore Целия файл

@@ -1,9 +1,11 @@
1 1
 # Don't check in site specific settings.
2 2
 settings.ini
3 3
 settings.yml
4
+/db
4 5
 
5 6
 # Compiled Python
6 7
 *.pyc
8
+__pycache__
7 9
 
8 10
 /site/www/static/photos/*.jpg
9 11
 /site/www/static/photos/*.png

+ 2
- 0
Makefile Целия файл

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

+ 4
- 0
defaults.yml Целия файл

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

+ 1
- 0
requirements.txt Целия файл

@@ -1,6 +1,7 @@
1 1
 flask
2 2
 flask-sslify
3 3
 redis
4
+pytz
4 5
 bcrypt
5 6
 pillow
6 7
 requests

+ 2
- 0
rophako/app.py Целия файл

@@ -8,6 +8,7 @@ from flask import (Flask, g, request, session, render_template, send_file,
8 8
 from flask_sslify import SSLify
9 9
 import jinja2
10 10
 import os.path
11
+import datetime
11 12
 import sys
12 13
 
13 14
 # 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
63 64
 app.jinja_env.globals["csrf_token"] = rophako.utils.generate_csrf_token
64 65
 app.jinja_env.globals["include_page"] = rophako.utils.include
65 66
 app.jinja_env.globals["settings"] = lambda: Config
67
+app.jinja_env.globals["strftime"] = lambda x: datetime.datetime.utcnow().strftime(x)
66 68
 
67 69
 # Preload the emoticon data.
68 70
 import rophako.model.emoticons as Emoticons

+ 4
- 2
rophako/utils.py Целия файл

@@ -9,6 +9,7 @@ import codecs
9 9
 import uuid
10 10
 import datetime
11 11
 import time
12
+import pytz
12 13
 import re
13 14
 import importlib
14 15
 import smtplib
@@ -329,8 +330,9 @@ def server_name():
329 330
 
330 331
 def pretty_time(time_format, unix):
331 332
     """Pretty-print a time stamp."""
332
-    date = datetime.datetime.fromtimestamp(unix)
333
-    return date.strftime(time_format)
333
+    tz   = pytz.timezone(Config.site.timezone)
334
+    date = datetime.datetime.fromtimestamp(unix, pytz.utc)
335
+    return date.astimezone(tz).strftime(time_format)
334 336
 
335 337
 
336 338
 def sanitize_name(name):

+ 1
- 1
rophako/www/layout.html Целия файл

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

Loading…
Отказ
Запис