Allow editing of token expiration
authorGiorgos Verigakis <verigak@gmail.com>
Tue, 18 Oct 2011 14:45:13 +0000 (17:45 +0300)
committerGiorgos Verigakis <verigak@gmail.com>
Wed, 19 Oct 2011 10:33:12 +0000 (13:33 +0300)
Uses HTML5 date picker.

Refs #1470

pithos/admin/templates/users_info.html
pithos/admin/templatetags/__init__.py [new file with mode: 0644]
pithos/admin/templatetags/formatters.py [new file with mode: 0644]
pithos/admin/views.py

index 2148f03..fc74cf1 100644 (file)
@@ -1,5 +1,7 @@
 {% extends "base.html" %}
 
+{% load formatters %}
+
 {% block body %}
 
 <form action="{% url admin.views.users_modify user.id %}" method="post">
   <div class="clearfix">
     <label for="user-uniq">Uniq</label>
     <div class="input">
-      <input class="medium" id="user-uniq" name="uniq" value="{{ user.uniq }}" type="text" />
+      <input class="span4" id="user-uniq" name="uniq" value="{{ user.uniq }}" type="text" />
     </div>
   </div>
 
   <div class="clearfix">
     <label for="user-realname">Real Name</label>
     <div class="input">
-      <input class="large" id="user-realname" name="realname" value="{{ user.realname }}" type="text" />
+      <input class="span4" id="user-realname" name="realname" value="{{ user.realname }}" type="text" />
     </div>
   </div>
 
   <div class="clearfix">
     <label for="user-affiliation">Affiliation</label>
     <div class="input">
-      <input class="large" id="user-affiliation" name="affiliation" value="{{ user.affiliation }}" type="text" />
+      <input class="span4" id="user-affiliation" name="affiliation" value="{{ user.affiliation }}" type="text" />
     </div>
   </div>
 
   <div class="clearfix">
     <label for="user-quota">Quota</label>
     <div class="input">
-      <input class="medium" id="user-affiliation" name="quota" value="{{ user.quota }}" type="text" />
+      <div class="input-append">
+        <input class="span2" id="user-quota" name="quota" value="{{ user.quota|GiB }}" type="text" />
+        <span class="add-on">GiB</span>
+      </div>
     </div>
   </div>
 
   <div class="clearfix">
     <label for="user-token">Token</label>
     <div class="input">
-      <input class="large" id="user-token" name="auth_token" value="{{ user.auth_token }}" type="text" />
+      <input class="span4" id="user-token" name="auth_token" value="{{ user.auth_token }}" type="text" />
+    </div>
+  </div>
+
+  <div class="clearfix">
+    <label for="token-created">Token Created</label>
+    <div class="input">
+      <span class="uneditable-input" id="token-created">{{ user.auth_token_created }}</span>
+    </div>
+  </div>
+
+  <div class="clearfix">
+    <label for="token-expires">Token Expires</label>
+    <div class="input">
+      <input type="datetime" class="span4" id="token-expires" name="auth_token_expires" value="{{ user.auth_token_expires|isoformat }}" />
     </div>
   </div>
 
diff --git a/pithos/admin/templatetags/__init__.py b/pithos/admin/templatetags/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pithos/admin/templatetags/formatters.py b/pithos/admin/templatetags/formatters.py
new file mode 100644 (file)
index 0000000..40cffea
--- /dev/null
@@ -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')
index 76366c9..fb27a18 100644 (file)
@@ -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)