Browse Source

Merge branch 'master' of git.illyse.org:coin

Fabs 10 years ago
parent
commit
2ac93aadd1
6 changed files with 78 additions and 34 deletions
  1. 4 1
      coin/members/models.py
  2. 3 0
      coin/settings.py
  3. 41 19
      coin/static/css/illyse.css
  4. 13 3
      coin/vpn/models.py
  5. 13 10
      coin/vpn/templates/vpn/vpn.html
  6. 4 1
      coin/vpn/views.py

+ 4 - 1
coin/members/models.py

@@ -14,6 +14,7 @@ from coin.mixins import CoinLdapSyncMixin
 from coin import utils
 from django.contrib.auth.signals import user_logged_in
 from django.conf import settings
+from django.core.validators import RegexValidator
 
 
 class Member(CoinLdapSyncMixin, models.Model):
@@ -53,7 +54,9 @@ class Member(CoinLdapSyncMixin, models.Model):
     # TODO: use a django module that provides an address model? (would
     # support more countries and address types)
     address = models.TextField(verbose_name=u'Adresse')
-    postal_code = models.CharField(max_length=15,
+    postal_code = models.CharField(max_length=5,
+                                   validators=[RegexValidator(regex=r'^\d{5}$', 
+                                               message=u'Code postal non valide.')],
                                    verbose_name=u'Code postal')
     city = models.CharField(max_length=200,
                             verbose_name=u'Commune')

+ 3 - 0
coin/settings.py

@@ -251,6 +251,9 @@ AUTH_LDAP_USER_FLAGS_BY_GROUP = {
 
 GRAPHITE_SERVER = "http://graphite-dev.illyse.org"
 
+# Reset session if cookie older than 2h.
+SESSION_COOKIE_AGE = 7200
+
 # Surcharge les paramètres en utilisant le fichier settings-local.py
 try:
     from settings_local import *

+ 41 - 19
coin/static/css/illyse.css

@@ -197,6 +197,46 @@ span.italic {
     content: "⚠ ";
     font-weight: bold;
 }
+
+h3.graphtitle select {
+	display: inline;
+	background-color: transparent;
+	border: 0 none transparent;
+	font-family: inherit;
+	box-shadow: none;
+	font-size: 0.9em;
+	width: auto;
+	margin: 0;
+	padding: 0;
+}
+h3.graphtitle select option {
+	font-size: 0.6em;
+}
+
+a.cfglink:before {
+	content: "⎘ ";
+}
+
+/* Champs éditables */
+
+.flatform:before {
+   content: "Les champs marqués d'un ✎ sont éditables.";
+}
+.flatform .legend {
+	clear: both;
+}
+
+.flatfield label {
+	background-color: #0086A9;
+	color: #F0F0F0;
+	font-size: 0.9em;
+	padding: 0.2em 0.5em;
+}
+.flatfield td+td:before {
+	content: "✎";
+	float: left;
+}
+
 .flatfield input {
 	margin-bottom: 0;
 	border: 0 none transparent;
@@ -205,6 +245,7 @@ span.italic {
 	box-shadow: none;
 	font-size: 1.1em;
 	color: #222222;
+	width: 90%;
 }
 .flatfield input::-moz-placeholder {
 	font-style: italic;
@@ -219,22 +260,3 @@ span.italic {
 	background-color: #FFFFFF;
 	border: 1px solid #C0C0C0;
 }
-
-h3.graphtitle select {
-	display: inline;
-	background-color: transparent;
-	border: 0 none transparent;
-	font-family: inherit;
-	box-shadow: none;
-	font-size: 0.9em;
-	width: auto;
-	margin: 0;
-	padding: 0;
-}
-h3.graphtitle select option {
-	font-size: 0.6em;
-}
-
-a.cfglink:before {
-	content: "⎘ ";
-}

+ 13 - 3
coin/vpn/models.py

@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 from django.db import models
 from django.core.exceptions import ValidationError
+from django.core.urlresolvers import reverse
 from netfields import InetAddressField, NetManager
 import ldapdb.models
 from ldapdb.models.fields import CharField, ListField
@@ -21,16 +22,25 @@ class VPNSubscription(CoinLdapSyncMixin, models.Model):
         validators=[ValidateBackendType(backend_name)])
     activated = models.BooleanField(default=False)
     login = models.CharField(max_length=50, unique=True, blank=True,
+                             verbose_name="identifiant",
                              help_text="leave empty for automatic generation")
     password = models.CharField(max_length=256, blank=True, null=True)
     ipv4_endpoint = InetAddressField(validators=[validation.validate_v4],
-                                     blank=True, null=True)
+                                     verbose_name="IPv4", blank=True, null=True,
+                                     help_text="Addresse IPv4 utilisée par "
+                                     "défaut sur le VPN")
     ipv6_endpoint = InetAddressField(validators=[validation.validate_v6],
-                                     blank=True, null=True)
-    comment = models.CharField(blank=True, max_length=512)
+                                     verbose_name="IPv6", blank=True, null=True,
+                                     help_text="Addresse IPv6 utilisée par "
+                                     "défaut sur le VPN")
+    comment = models.CharField(blank=True, max_length=512,
+                               verbose_name="commentaire")
 
     objects = NetManager()
 
+    def get_absolute_url(self):
+        return reverse('vpn:openvpn_ldap', args=[str(self.pk)])
+
     # These two methods are part of the general configuration interface.
     def save_subnet(self, subnet, creation):
         self.check_endpoints(delete=True)

+ 13 - 10
coin/vpn/templates/vpn/vpn.html

@@ -3,6 +3,8 @@
 {% block content %}
 <div class="row">
     <h2>Configuration du VPN</h2>
+    <form class="flatform" action="{{ object.get_absolute_url }}" method="post">{% csrf_token %}
+    <p class="legend">Quand vous aurez terminé vos modifications, cliquez sur <input class="button" type="submit" value="Valider" /></p>
     
     <div class="large-6 columns">
         <div class="panel">
@@ -18,13 +20,13 @@
                     </td>
                 </tr>
                 {% endblock %}<tr class="flatfield">
-                    <td class="center"><span class="label">Commentaire</span></td>
-                    <td><input type="text" value="{{object.comment}}" /></td>
+                    <td class="center">{{ form.comment.label_tag }}</td>
+                    <td>{{ form.comment }}</td>
                 </tr>
                 <tr>
                     <td class="center boolviewer" colspan="2">
                         <input type="checkbox" disabled="disabled"{% if object.activated %} checked="checked"{% endif %} />
-                        <span>Ce VPN est {% if object.activated %}activé{% else %}désactivé{% endif %}</span>
+                        <span>Ce VPN est {{ object.activated|yesno:"activé,désactivé" }}</span>
                     </td>
                 </tr>
             </table>
@@ -35,25 +37,26 @@
         <div class="panel">
             <h3>Adresses IP</h3>
             <table class="full-width">
+              {{ form.non_field_errors }}
                 <tr class="flatfield">
-                    <td class="center"><span class="label">IPv4</span></td>
-                    <td><input type="text" name="endpoint4" {% if object.ipv4_endpoint %}value="{{ object.ipv4_endpoint }}" {% endif %} placeholder="Aucune adresse"/></td>
+                    <td class="center">{{ form.ipv4_endpoint.label_tag }}</td>
+                    <td>{{ form.ipv4_endpoint }} {{ form.ipv4_endpoint.errors }}</td>
                 </tr>
                 <tr class="flatfield">
-                    <td class="center"><span class="label">IPv6</span></td>
-                    <td><input type="text" name="endpoint6" {% if object.ipv6_endpoint %}value="{{ object.ipv6_endpoint }}" {% endif %} placeholder="Aucune adresse"/></td>
+                    <td class="center">{{ form.ipv6_endpoint.label_tag }}</td>
+                    <td>{{ form.ipv6_endpoint }} {{ form.ipv6_endpoint.errors }}</td>
                 </tr>
                 <tr>
                     <td class="center"><span class="label">Sous-réseaux</span></td>
                     <td>
-                        {% if object.ipv4_endpoint or object.ipv6_endpoint %}<ul>
-                            {% for subnet in object.administrative_subscription.ip_subnet.all %}<li>{{ subnet }}</li>{% endfor %}
-                        </ul>{% else %}<span class="italic">Aucune adresse</span>{% endif %}
+                        {% for subnet in object.administrative_subscription.ip_subnet.all %}{{ subnet }}<br/>{% endfor %}
                     </td>
                 </tr>
             </table>
         </div>
     </div>
+    <p class="legend">Quand vous aurez terminé vos modifications, cliquez sur <input class="button" type="submit" value="Valider" /></p>
+    </form>
 </div>
 
 <div class="row">

+ 4 - 1
coin/vpn/views.py

@@ -5,12 +5,15 @@ from django.contrib.auth.models import User
 from django.http import StreamingHttpResponse
 from django.shortcuts import render_to_response, get_object_or_404
 from django.views.generic.detail import DetailView
+from django.views.generic.edit import UpdateView
 from django.conf import settings
 
 from coin.vpn.models import VPNSubscription
 
 
-class VPNView(DetailView):
+class VPNView(UpdateView):
+    model = VPNSubscription
+    fields = ['ipv4_endpoint', 'ipv6_endpoint', 'comment']
 
     def get_object(self):
         return get_object_or_404(VPNSubscription, pk=self.args[0],