Formatting fix

This commit is contained in:
nikolark committed 2011-12-06 19:59:21 +01:00
1 parent 44ba1cab45
commit 4ddec04b79
2 files changed
+11 -4

No files matched your search

+9
View File
@@ -1,4 +1,5 @@
# coding: utf-8
import datetime
import re
from subprocess import Popen, PIPE
@@ -59,3 +60,11 @@ def set_radius_password(username, raw_password):
radius_user.value = passwd.radius_create(raw_password)
radius_user.save()
return True
def format_krb5_date(date):
try:
formatted_date = datetime.datetime.strptime(date, '%a %b %d %H:%M:%S %Z %Y')
formatted_date = formatted_date.strftime('%Y-%m-%d %H:%M:%S')
except ValueError:
formatted_date = 'never'
return formatted_date
+2 -4
View File
@@ -1,5 +1,4 @@
# coding: utf-8
import datetime
import simplejson as json
from django.http import HttpResponse, HttpResponseRedirect
@@ -51,10 +50,9 @@ def profile(request):
def client_status(request):
krb5_principal = utils.get_kerberos_principal(request.user)
if krb5_principal:
last_succ_auth = datetime.datetime.strptime(krb5_principal['Last successful authentication'],
'%a %b %d %H:%M:%S %Z %Y')
last_succ_auth = utils.format_krb5_date(krb5_principal['last successful authentication'])
status = { 'active' : True,
'last_successful_auth' : last_succ_auth.strftime('%Y-%m-%d %H:%M:%S'),
'last_successful_auth' : last_succ_auth,
'last_modified' : krb5_principal['Last modified'] }
else:
status = { 'active' : False }