add timezone in user profile

This commit is contained in:
virusdefender 2017-01-24 13:21:49 +08:00
parent d9fad97e35
commit d1e505dc24
3 changed files with 10 additions and 1 deletions

View File

@ -1,6 +1,8 @@
import time
import pytz
from django.contrib import auth
from django.utils import timezone
from django.utils.translation import ugettext as _
from utils.api import JSONResponse
@ -26,3 +28,9 @@ class AdminRequiredMiddleware(object):
if path.startswith("/admin/") or path.startswith("/api/admin/"):
if not(request.user.is_authenticated() and request.user.is_admin()):
return JSONResponse.response({"error": "login-required", "data": _("Please login in first")})
class TimezoneMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
timezone.activate(pytz.timezone(request.user.userprofile.time_zone))

View File

@ -4,3 +4,4 @@ pillow
jsonfield
otpauth
flake8-quotes
pytz

View File

@ -32,7 +32,7 @@ class Command(BaseCommand):
rand_password = "rootroot"
user.set_password(rand_password)
user.save()
UserProfile.objects.create(user=user)
UserProfile.objects.create(user=user, time_zone="Asia/Shanghai")
self.stdout.write(self.style.SUCCESS("Successfully created super admin user.\n"
"Username: root\nPassword: %s\n"
"Remember to change password and turn on two factors auth "