Parcourir la source

Implement a crude user interface for DSL lines

Baptiste Jonglez il y a 10 ans
Parent
commit
6c2ff3b451
4 fichiers modifiés avec 71 ajouts et 2 suppressions
  1. 32 0
      coin/dsl_ldap/templates/dsl_ldap/dsl.html
  2. 15 0
      coin/dsl_ldap/urls.py
  3. 23 2
      coin/dsl_ldap/views.py
  4. 1 0
      coin/urls.py

+ 32 - 0
coin/dsl_ldap/templates/dsl_ldap/dsl.html

@@ -0,0 +1,32 @@
+{% extends "base.html" %}
+
+{% load subnets %}
+
+{% block content %}
+<div class="row">
+  <form action="" method="post">{% csrf_token %}
+    {% for message in messages %}
+    <div class="message{% if message.tags %} {{ message.tags }}{% endif %}">
+        {{ message }}
+    </div>
+    {% endfor %}
+  {{ form.non_field_errors }}
+  <div>Numéro de téléphone : {{ object.phone_number }}</div>
+  <div>Identifiant ADSL : {{ object.full_login }}</div>
+  <div>
+    {{ form.password.errors }}
+    {{ form.password.label_tag }}
+    {{ form.password }}
+    Mettre un mot de passe vide pour en générer un nouveau automatiquement
+  </div>
+  <div>État : {{ object.activated|yesno:"activé,désactivé" }}</div>
+  <div>Blocs IP :
+    <ul>
+      {% for subnet in object.ip_subnet.all %}
+      <li>{{ subnet|prettify }}</li>
+      {% endfor %}
+    </ul></div>
+  <input type="submit" value="Mettre à jour" />
+</form>
+</div>
+{% endblock %}

+ 15 - 0
coin/dsl_ldap/urls.py

@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.conf.urls import patterns, url
+
+from .views import DSLView
+
+
+urlpatterns = patterns(
+    '',
+    # This is part of the generic configuration interface (the "name" is
+    # the same as the "backend_name" of the model).
+    url(r'^(?P<pk>\d+)$', DSLView.as_view(template_name="dsl_ldap/dsl.html"),
+        name="details")
+)

+ 23 - 2
coin/dsl_ldap/views.py

@@ -1,6 +1,27 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
-from django.shortcuts import render
+from django.shortcuts import get_object_or_404
+from django.views.generic.edit import UpdateView
+from django.contrib.auth.decorators import login_required
+from django.contrib.messages.views import SuccessMessageMixin
+from django.utils.decorators import method_decorator
 
-# Create your views here.
+from .models import DSLConfiguration
+
+
+class DSLView(SuccessMessageMixin, UpdateView):
+    model = DSLConfiguration
+    fields = ['password']
+    success_message = "Configuration enregistrée avec succès !"
+
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(DSLView, self).dispatch(*args, **kwargs)
+
+    def get_object(self):
+        if self.request.user.is_superuser:
+            return get_object_or_404(DSLConfiguration, pk=self.kwargs.get("pk"))
+        # For normal users, ensure the VPN belongs to them.
+        return get_object_or_404(DSLConfiguration, pk=self.kwargs.get("pk"),
+                                 offersubscription__member=self.request.user)

+ 1 - 0
coin/urls.py

@@ -26,6 +26,7 @@ urlpatterns = patterns(
     url(r'^billing/', include('coin.billing.urls', namespace='billing')),
     url(r'^subscription/', include('coin.offers.urls', namespace='subscription')),
     url(r'^vpn/', include('coin.vpn.urls', namespace='vpn')),
+    url(r'^dsl/', include('coin.dsl_ldap.urls', namespace='dsl_ldap')),
 
     url(r'^admin/', include(admin.site.urls)),