diff --git a/brutaldon/forms.py b/brutaldon/forms.py
index 873c9f2..8f96ab4 100644
--- a/brutaldon/forms.py
+++ b/brutaldon/forms.py
@@ -1,11 +1,14 @@
from django import forms
from django.conf import settings
+from pytz import common_timezones
PRIVACY_CHOICES = (('public', 'Public'),
('unlisted', 'Unlisted'),
('private', 'Private'),
('direct', 'Direct'))
+timezones = [ (tz, tz) for tz in common_timezones]
+
MAX_LENGTH = settings.TOOT_MAX_LENGTH
class LoginForm(forms.Form):
@@ -35,6 +38,11 @@ class SettingsForm(forms.Form):
help_text=
"""Should replies be filtered out of your home timeline, giving you only pure,
Original Content?""")
+ timezone = forms.ChoiceField(label="Your local timezone",
+ choices=timezones,
+ required=False,
+ help_text=
+ """What time zone do you prefer to have times displayed in? The default choice is UTC.""")
class PostForm(forms.Form):
diff --git a/brutaldon/middleware/timezone.py b/brutaldon/middleware/timezone.py
new file mode 100644
index 0000000..0cba5b6
--- /dev/null
+++ b/brutaldon/middleware/timezone.py
@@ -0,0 +1,12 @@
+import pytz
+
+from django.utils import timezone
+from django.utils.deprecation import MiddlewareMixin
+
+class TimezoneMiddleware(MiddlewareMixin):
+ def process_request(self, request):
+ tzname = request.session.get('timezone', "UTC")
+ if tzname:
+ timezone.activate(pytz.timezone(tzname))
+ else:
+ timezone.deactivate()
diff --git a/brutaldon/settings.py b/brutaldon/settings.py
index edf081e..607155a 100644
--- a/brutaldon/settings.py
+++ b/brutaldon/settings.py
@@ -51,6 +51,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
+ 'brutaldon.middleware.timezone.TimezoneMiddleware',
]
ROOT_URLCONF = 'brutaldon.urls'
diff --git a/brutaldon/templates/setup/settings.html b/brutaldon/templates/setup/settings.html
index 336caf5..9205bad 100644
--- a/brutaldon/templates/setup/settings.html
+++ b/brutaldon/templates/setup/settings.html
@@ -18,11 +18,21 @@
-
+
+
{{ form.timezone.label }}
+
+
+ {% render_field form.timezone class+="select" %}
+
+
+
+
+
diff --git a/brutaldon/templatetags/humanetime.py b/brutaldon/templatetags/humanetime.py
index 0d2be68..4c4113a 100644
--- a/brutaldon/templatetags/humanetime.py
+++ b/brutaldon/templatetags/humanetime.py
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
-from django.utils.timezone import get_default_timezone, get_current_timezone, make_naive
+from django.utils.timezone import get_default_timezone, get_current_timezone, localtime
+from django.utils.timezone import now as django_now
from django import template
register = template.Library()
@@ -24,16 +25,20 @@ def humane_time(arg):
It is not safe to use on future times.
'''
- now = datetime.now()
- arg = make_naive(arg, timezone=get_current_timezone())
+ now = django_now()
+ arg = localtime(arg)
diff = now - arg
+ if arg.tzinfo == now.tzinfo:
+ utc = " (UTC)"
+ else:
+ utc = ""
if diff < timedelta(hours=6):
- return arg.strftime("%a, %b %d, %Y at %I:%M %p")
+ return arg.strftime("%a, %b %d, %Y at %I:%M %p") + utc
elif diff < timedelta(hours=12):
- return arg.strftime("%a, %b %d, %Y around %I %p")
- elif diff < timedelta(days=2):
- return arg.strftime("%a, %b %d, %Y in the ") + time_of_day(arg.hour)
+ return arg.strftime("%a, %b %d, %Y around %I %p") + utc
+ elif diff < timedelta(hours=36):
+ return arg.strftime("%a, %b %d, %Y in the ") + time_of_day(arg.hour) + utc
elif diff < timedelta(days=6*28):
return arg.strftime("%b %d, %Y")
elif diff < timedelta(days=10*365):
diff --git a/brutaldon/views.py b/brutaldon/views.py
index 4c4930c..b6efaad 100644
--- a/brutaldon/views.py
+++ b/brutaldon/views.py
@@ -321,6 +321,7 @@ def settings(request):
request.session['fullbrutalism'] = form.cleaned_data['fullbrutalism']
request.session['filter_replies'] = form.cleaned_data['filter_replies']
request.session['filter_boosts'] = form.cleaned_data['filter_boosts']
+ request.session['timezone'] = form.cleaned_data['timezone']
return redirect(home)
else:
return render(request, 'setup/settings.html',
@@ -328,7 +329,12 @@ def settings(request):
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)})
else:
- form = SettingsForm(request.session)
+ form = SettingsForm(initial={
+ "fullbrutalism": fullbrutalism_p(request),
+ "filter_replies": request.session.get('filter_replies', False),
+ "filter_boosts": request.session.get('filter_boosts', False),
+ "timezone": request.session.get('timezone', 'UTC')
+ })
return render(request, 'setup/settings.html',
{ 'form': form,
'own_acct': request.session['user'],