From 0ff1519d97da6b117c3d0020fb6568704277337b Mon Sep 17 00:00:00 2001 From: Giorgos Verigakis Date: Tue, 18 Oct 2011 17:45:13 +0300 Subject: [PATCH] Allow editing of token expiration Uses HTML5 date picker. Refs #1470 --- pithos/admin/templates/users_info.html | 29 ++++++++++++++--- pithos/admin/templatetags/formatters.py | 52 +++++++++++++++++++++++++++++++ pithos/admin/views.py | 10 +++++- 3 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 pithos/admin/templatetags/__init__.py create mode 100644 pithos/admin/templatetags/formatters.py diff --git a/pithos/admin/templates/users_info.html b/pithos/admin/templates/users_info.html index 2148f03..fc74cf1 100644 --- a/pithos/admin/templates/users_info.html +++ b/pithos/admin/templates/users_info.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load formatters %} + {% block body %}
@@ -13,14 +15,14 @@
- +
- +
@@ -40,21 +42,38 @@
- +
- +
+ + GiB +
- + +
+
+ +
+ +
+ {{ user.auth_token_created }} +
+
+ +
+ +
+
diff --git a/pithos/admin/templatetags/__init__.py b/pithos/admin/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pithos/admin/templatetags/formatters.py b/pithos/admin/templatetags/formatters.py new file mode 100644 index 0000000..40cffea --- /dev/null +++ b/pithos/admin/templatetags/formatters.py @@ -0,0 +1,52 @@ +# Copyright 2011 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from django import template + +from pithos.api import util + + +register = template.Library() + + +@register.filter +def GiB(value): + try: + return int(value) / 1024 ** 3 + except ValueError: + return 0 + + +@register.filter +def isoformat(value): + return value.strftime('%Y-%m-%dT%H:%MZ') diff --git a/pithos/admin/views.py b/pithos/admin/views.py index 76366c9..fb27a18 100644 --- a/pithos/admin/views.py +++ b/pithos/admin/views.py @@ -31,6 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. +from datetime import datetime from functools import wraps from math import ceil @@ -41,6 +42,7 @@ from django.shortcuts import redirect from django.template.loader import render_to_string from pithos.aai.models import PithosUser +from pithos.api.util import isoformat def render_response(template, tab=None, status=200, **kwargs): @@ -131,8 +133,14 @@ def users_modify(request, user_id): user.realname = request.POST.get('realname') user.is_admin = True if request.POST.get('admin') else False user.affiliation = request.POST.get('affiliation') - user.quota = int(request.POST.get('quota') or 0) + user.quota = int(request.POST.get('quota') or 0) * 1024 ** 3 # In GiB user.auth_token = request.POST.get('auth_token') + try: + auth_token_expires = request.POST.get('auth_token_expires') + d = datetime.strptime(auth_token_expires, '%Y-%m-%dT%H:%MZ') + user.auth_token_expires = d + except ValueError: + pass user.save() return redirect(users_info, user.id) -- 1.7.10.4