Fixed empty password check bug
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 1 Aug 2010 14:30:57 +0000 (14:30 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sun, 1 Aug 2010 14:30:57 +0000 (14:30 +0000)
Sources stats improved

bin/djais/views.py
html_templates/sources_index.html [new file with mode: 0644]
html_templates/user_change_password.html
html_templates/user_edit.html

index 6a6f7c25d9f3e10fedf76974a5629b38998a04a5..003e10206901ac2d896f70ce1afcd1468e0e8767 100644 (file)
@@ -32,6 +32,7 @@ def auth(username, raw_password):
         return None
     if not user.check_password(raw_password):
         return None
+    # TODO: update access_datetime
     return user
 
 
@@ -552,8 +553,10 @@ class UserEditForm(forms.Form):
     def clean_login(self):
         new_login = self.cleaned_data['login']
         if new_login != self.old_login:
-            if  User.objects.filter(login=new_login).count():
+            if User.objects.filter(login=new_login).count():
                 raise forms.ValidationError("Sorry that login is already in use. Try another one.")
+            if new_login == u'add':
+                raise forms.ValidationError("Sorry that login is reserved. Try another one.")
         return new_login
 
 @http_authenticate(auth, 'ais')
@@ -584,6 +587,7 @@ def user_edit(request, login):
             user.email = form.cleaned_data['email']
             user.phone = form.cleaned_data['phone']
             user.save()
+            #TODO grant access to sandbox fleet
             return HttpResponseRedirect('/user/')
     else: # GET
         form = UserEditForm(initial=initial)
@@ -594,6 +598,7 @@ def user_edit(request, login):
 class ChangePasswordForm(forms.Form):
     new_password = forms.CharField(max_length=16, widget=forms.PasswordInput())
     new_password_check = forms.CharField(max_length=16, widget=forms.PasswordInput())
+
     def clean_generic_password(self, field_name):
         password = self.cleaned_data[field_name]
         try:
@@ -604,15 +609,17 @@ class ChangePasswordForm(forms.Form):
 
     def clean_new_password(self):
         return self.clean_generic_password('new_password')
+
     def clean_new_password_check(self):
         return self.clean_generic_password('new_password_check')
+
     def clean(self):
         cleaned_data = self.cleaned_data
         pass1 = cleaned_data.get('new_password')
         pass2 = cleaned_data.get('new_password_check')
-        if pass1 != pass2:
-            self._errors['new_password_check'] = forms.util.ErrorList(['Passwords check must match'])
-            del cleaned_data['new_password_check']
+        if pass1 != pass2 and pass2:
+            self._errors['new_password_check'] = forms.util.ErrorList(['Passwords must match'])
+            del cleaned_data['new_password_check'] # FIXME
         return cleaned_data
 
 
@@ -672,6 +679,21 @@ periods = ({
     'seconds': 90*24*60*60
     })
         
+@http_authenticate(auth, 'ais')
+def sources_index(request):
+    peers_config = peers_get_config()
+    peers_display = []
+    for id4, peer in peers_config.iteritems():
+        peer['id4'] = id4
+        peer['id2'] = id4[2:]
+        peer['active'] = is_id4_active(id4)
+        peers_display.append(peer)
+        
+    peers_display = sorted(peers_display, key=lambda k: k['id4'])
+
+    return render_to_response('sources_index.html', {'sources':peers_display, 'periods': periods}, RequestContext(request))
+
+
 @http_authenticate(auth, 'ais')
 def sources_stats(request):
     filter_peers = request.REQUEST.get('peers', None)
@@ -742,16 +764,3 @@ def sources_stats(request):
     return render_to_response('sources.html', {'sources':peers_display, 'show_bytes': 'bytes' in filter_types,  'show_counts': 'counts' in filter_types, 'periods': display_periods}, RequestContext(request))
 
 
-@http_authenticate(auth, 'ais')
-def sources_index(request):
-    peers_config = peers_get_config()
-    peers_display = []
-    for id4, peer in peers_config.iteritems():
-        peer['id4'] = id4
-        peer['id2'] = id4[2:]
-        peer['active'] = is_id4_active(id4)
-        peers_display.append(peer)
-        
-    peers_display = sorted(peers_display, key=lambda k: k['id4'])
-
-    return render_to_response('sources_index.html', {'sources':peers_display, 'periods': periods}, RequestContext(request))
diff --git a/html_templates/sources_index.html b/html_templates/sources_index.html
new file mode 100644 (file)
index 0000000..6cfd5f2
--- /dev/null
@@ -0,0 +1,64 @@
+{% extends "base.html" %}
+
+{% block style_extra %}
+<style type="text/css">
+span.off {
+    color: red;
+}
+span.on {
+    color: green;
+}
+span.id2 {
+}
+</style>
+{% endblock %}
+
+{% block breadcrumbs %}
+{{ block.super }}
+&gt; <a href="/source/">sources</a>
+{% endblock %}
+
+{% block content %}
+<h3>Monitored sources</h3>
+<ul style='padding-left: 1ex;'>
+{% for source in sources %}
+<li style="list-style: none;">
+<span class={% if source.active %}on{% else %}off{% endif %}>
+{% if source.active %} ✔{% else %} ✖{% endif %}
+<span class=id2>{{source.id2}}</span>
+</span>
+{{source.name}}
+<br>
+{% endfor %}
+</ul>
+<h3>Statistical graphs</h3>
+<p>
+
+<form action='stats' method='get'>
+Sources:
+<select name=peers>
+<option value="">All</option>
+{% for source in sources %}
+<option value={{source.id4}}>{{source.name}}</option>
+{% endfor %}
+</select>
+
+Types:
+<select name=types>
+<option value="">All</option>
+<option value=bytes>Bandwidth</option>
+<option value=counts selected>Packet'izer</option>
+</select>
+
+Periods:
+<select name=periods>
+{% for period in periods %}
+<option value={{period.name_tiny}} {% if period.default %}selected{%endif%}>{{period.name_long}}</option>
+{% endfor %}
+<option value="">All</option>
+
+</select>
+
+<input type=submit value="View stats">
+</form>
+{% endblock %}
index 258ebee1d9270f28a0ce32fb6fe45847bdd7f680..f19485d870bdb2d4b7f96eadba21682d7c926e11 100644 (file)
@@ -13,9 +13,7 @@ Password change - AIS
 <h3>Change password of {{ auser.name }}</h3>
 
 <form method="post">
-<table>
-{{ form.as_table }}
-</table>
+{% include "fragment_formerror.html" %}
 <input type=submit>
 </form>
 {% endblock %}
index d099de31f7827d41e3a9ff9b227d20edb7a6b1ce..d6f07fa63c49db1a75a265baea74af0a85152802 100644 (file)
@@ -1,19 +1,17 @@
 {% extends "user_detail.html" %}
 
 {% block breadcrumbs %}
-{% if auser.id %}
 {{ block.super }}
-&gt; <a href="/user/{{auser.login}}/edit">edit</a>
+{% if auser.id %}
+    &gt; <a href="/user/{{auser.login}}/edit">edit</a>
 {% endif %}
 {% endblock %}
 
 {% block content %}
 <h3>AIS user edition</h3>
 
-<form method="post">
-<table>
-{{ form.as_table }}
-</table>
-<input type=submit>
+<form method=post>
+{% include "fragment_formerror.html" %}
+<input type=submit value=Save>
 </form>
 {% endblock %}