mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 00:13:18 +00:00
add timezone in user profile
This commit is contained in:
parent
d9fad97e35
commit
d1e505dc24
@ -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))
|
||||
|
@ -4,3 +4,4 @@ pillow
|
||||
jsonfield
|
||||
otpauth
|
||||
flake8-quotes
|
||||
pytz
|
||||
|
@ -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 "
|
||||
|
Loading…
Reference in New Issue
Block a user