Browse Source

vues ServiceType & IPResource

Élie Bouttier 8 years ago
parent
commit
837442efac

+ 2 - 7
adhesions/templates/adhesions/user_detail.html

@@ -1,14 +1,9 @@
 {% extends 'base.html' %}
 
 {% block content %}
-
-<a class="btn btn-primary" href="{% url 'user-list' %}"><span class="glyphicon glyphicon-arrow-left"></span>&nbsp;Retour à la liste des utilisateurs</a>
-
-<br /><br />
-
 <div class="panel panel-primary">
     <div class="panel-heading">
-        {{ user.profile }}
+        <h4>{{ user.profile }}</h4>
     </div>
     <table class="table table-bordered">
         <tr>
@@ -50,7 +45,7 @@
 
 <div class="panel panel-primary">
     <div class="panel-heading">
-        Associations
+        <h4>Associations</h4>
     </div>
     <table class="table table-bordered">
         {% for corp in user.corporations.all %}

+ 0 - 5
adhesions/templates/adhesions/user_list.html

@@ -1,11 +1,6 @@
 {% extends 'base.html' %}
 
 {% block content %}
-{% comment %}
-
-<br /><br />
-{% endcomment %}
-
 <div class="panel panel-primary">
     <div class="panel-heading">
         <a class="btn btn-success pull-right" href="{% url 'user-add' %}"><span class="glyphicon glyphicon-user"></span>&nbsp;Ajouter un utilisateur</a>

+ 2 - 0
djadhere/templates/base.html

@@ -57,6 +57,8 @@
                     <li><a href="{% url 'corporation-list' %}"><span class="glyphicon glyphicon-globe">&nbsp;Associations</a></li>
                     <li><a href="{% url 'adhesion-list' %}"><span class="glyphicon glyphicon-heart-empty">&nbsp;Adhérents</a></li>
                     <li><a href="{% url 'service-list' %}"><span class="glyphicon glyphicon-tasks">&nbsp;Services</a></li>
+                    <li><a href="{% url 'servicetype-list' %}"><span class="glyphicon glyphicon-king">&nbsp;Catégories</a></li>
+                    <li><a href="{% url 'ip-list' %}"><span class="glyphicon glyphicon-asterisk">&nbsp;IP</a></li>
                 </ul>
             </li>
             {% endif %}

+ 1 - 1
djadhere/urls.py

@@ -19,7 +19,7 @@ from django.contrib import admin
 
 urlpatterns = [
     url(r'^accounts/', include('accounts.urls')),
-    url(r'^services/', include('services.urls')),
+    url(r'^', include('services.urls')),
     url(r'^', include('adhesions.urls')),
     url(r'^admin/', admin.site.urls),
 ]

+ 9 - 0
services/models.py

@@ -24,6 +24,14 @@ class IPResource(models.Model):
         else:
             return False
 
+    @property
+    def services(self):
+        allocations = self.allocations.filter(get_active_filter()).all()
+        if allocations:
+            return ', '.join(allocations)
+        else:
+            return '–'
+
     class Meta:
         verbose_name = 'ressource IP'
         verbose_name_plural = 'ressources IP'
@@ -116,6 +124,7 @@ class ResourceAllocation(models.Model):
     class Meta:
         verbose_name = 'allocation'
         verbose_name_plural = 'allocations'
+        ordering = ['-start']
 
     def __str__(self):
         return str(self.resource)

+ 34 - 0
services/templates/services/ipresource_detail.html

@@ -0,0 +1,34 @@
+{% extends 'base.html' %}
+
+{% load bootstrap3 %}
+
+{% block content %}
+<div class="panel panel-primary">
+    <div class="panel-heading">
+        <h3>{{ ipresource }}</h3>
+        <h4>Historique des allocations</h4>
+    </div>
+    {% for allocation in ipresource.allocations.all %}
+    {% if forloop.first %}
+    <table class="table">
+        <tr>
+            <th>Service</th>
+            <th>Début</th>
+            <th>Fin</th>
+        </tr>
+    {% endif %}
+        <tr>
+            <td>{{ allocation.service }}</td>
+            <td>{{ allocation.start }}</td>
+            <td>{{ allocation.end|default:'–' }}</td>
+        </tr>
+    {% if forloop.last %}
+    </table>
+    {% endif %}
+    {% empty %}
+    <div class="panel-body">
+        <em>Auncune allocation.</em>
+    </div>
+    {% endfor %}
+</div>
+{% endblock %}

+ 9 - 0
services/templates/services/ipresource_form.html

@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+
+{% block content %}
+
+<h1>{% if ipresource %}Modifier{% else %}Ajouter{% endif %} une ressource IP</h1>
+
+{% include '_form.html' %}
+
+{% endblock %}

+ 28 - 0
services/templates/services/ipresource_list.html

@@ -0,0 +1,28 @@
+{% extends 'base.html' %}
+
+{% load bootstrap3 %}
+
+{% block content %}
+<div class="panel panel-primary">
+    <div class="panel-heading">
+        {% comment %}<a class="btn btn-success pull-right" href="{% url 'ip-add' %}">Ajouter une ressource IP</a>{% endcomment %}
+        <h1>Ressources IP</h1>
+    </div>
+    {% for ip in object_list %}
+    {% if forloop.first %}
+    <table class="table">
+        <tr>
+            <th>Adresse</th>
+            <th>Affectations actives</th>
+        </tr>
+    {% endif %}
+        <tr>
+            <td><a href="{% url 'ip-detail' ip.pk %}">{{ ip }}</a></td>
+            <td>{{ ip.services }}</td>
+        </tr>
+    {% if forloop.last %}
+    </table>
+    {% endif %}
+    {% endfor %}
+</div>
+{% endblock %}

+ 40 - 0
services/templates/services/servicetype_detail.html

@@ -0,0 +1,40 @@
+{% extends 'base.html' %}
+
+{% load bootstrap3 %}
+
+{% block usertab %}{% if service.adhesion == request.user.profile.adhesion %} class="active"{% endif %}{% endblock %}
+{% block corptab %}{% if service.adhesion != request.user.profile.adhesion %} active{% endif %}{% endblock %}
+
+{% block content %}
+<div class="panel panel-primary">
+    <div class="panel-heading">
+        <h3>{{ servicetype }}</h3>
+    </div>
+    {% for service in servicetype.services.all %}
+    {% if forloop.first %}
+    <table class="table">
+        <tr>
+            <th>#</th>
+            <th>Label</th>
+            <th>Adhérent</th>
+            <th></th>
+        </tr>
+    {% endif %}
+        <tr>
+            <td><a href="{% url 'service-detail' service.pk %}">#{{ service.pk }}</a></td>
+            <td>{{ service.label }}</td>
+            <td>
+                <a href="{% url 'adhesion-detail' service.adhesion.id %}">ADT{{ service.adhesion.pk }}</a>
+                –
+                <a href="{{ service.adhesion.get_adherent_detail_url }}">{{ service.adhesion }}</a>
+            </td>
+            <td class="text-right">
+                <a href="{% url 'service-edit' service.pk %}"><span class="glyphicon glyphicon-pencil"></span>&nbsp;Modifier</a>
+            </td>
+        </tr>
+    {% if forloop.last %}
+    </table>
+    {% endif %}
+    {% endfor %}
+</div>
+{% endblock %}

+ 30 - 0
services/templates/services/servicetype_list.html

@@ -0,0 +1,30 @@
+{% extends 'base.html' %}
+
+{% load bootstrap3 %}
+
+{% block content %}
+<div class="panel panel-primary">
+    <div class="panel-heading">
+        <a class="btn btn-success pull-right" href="{% url 'servicetype-add' %}">Ajouter un type de service</a>
+        <h1>Types de services</h1>
+    </div>
+    {% for type in object_list %}
+    {% if forloop.first %}
+    <table class="table">
+        <tr>
+            <th>Nom</th>
+            <th></th>
+        </tr>
+    {% endif %}
+        <tr>
+            <td><a href="{% url 'servicetype-detail' type.pk %}">{{ type.name }}</a></td>
+            <td class="text-right">
+                <a href="{% url 'servicetype-edit' type.pk %}"><span class="glyphicon glyphicon-pencil"></span>&nbsp;Modifier</a>
+            </td>
+        </tr>
+    {% if forloop.last %}
+    </table>
+    {% endif %}
+    {% endfor %}
+</div>
+{% endblock %}

+ 10 - 3
services/urls.py

@@ -4,7 +4,14 @@ from . import views
 
 
 urlpatterns = [
-    url(r'^$', views.ServiceList.as_view(), name='service-list'),
-    url(r'^(?P<pk>[0-9]+)/$', views.ServiceDetail.as_view(), name='service-detail'),
-    url(r'^(?P<pk>[0-9]+)/edit/$', views.ServiceUpdate.as_view(), name='service-edit'),
+    url(r'^services/$', views.ServiceList.as_view(), name='service-list'),
+    url(r'^services/(?P<pk>[0-9]+)/$', views.ServiceDetail.as_view(), name='service-detail'),
+    url(r'^services/(?P<pk>[0-9]+)/edit/$', views.ServiceUpdate.as_view(), name='service-edit'),
+    url(r'^servicetypes/$', views.ServiceTypeList.as_view(), name='servicetype-list'),
+    url(r'^servicetypes/add/$', views.ServiceTypeCreate.as_view(), name='servicetype-add'),
+    url(r'^servicetypes/(?P<pk>[0-9]+)/$', views.ServiceTypeDetail.as_view(), name='servicetype-detail'),
+    url(r'^servicetypes/(?P<pk>[0-9]+)/edit/$', views.ServiceTypeUpdate.as_view(), name='servicetype-edit'),
+    url(r'^ip/$', views.IPResourceList.as_view(), name='ip-list'),
+    #url(r'^ip/add/$', views.IPResourceCreate.as_view(), name='ip-add'),
+    url(r'^ip/(?P<pk>[0-9]+)/$', views.IPResourceDetail.as_view(), name='ip-detail'),
 ]

+ 36 - 2
services/views.py

@@ -1,9 +1,9 @@
 from django.shortcuts import render
-from django.views.generic import ListView, DetailView, UpdateView
+from django.views.generic import ListView, CreateView, DetailView, UpdateView
 from django.contrib.auth.mixins import LoginRequiredMixin
 from django.contrib.auth.mixins import PermissionRequiredMixin
 
-from .models import Service
+from .models import Service, ServiceType, IPResource
 
 
 class ServiceMixin(PermissionRequiredMixin):
@@ -26,3 +26,37 @@ class ServiceDetail(LoginRequiredMixin, DetailView):
 
 class ServiceUpdate(ServiceMixin, UpdateView):
     fields = ['label', 'notes', 'active']
+
+
+class ServiceTypeMixin(PermissionRequiredMixin):
+    model = ServiceType
+    permission_required = 'services.change_servicetype'
+
+
+class ServiceTypeList(ServiceTypeMixin, ListView):
+    pass
+
+
+class ServiceTypeCreate(ServiceTypeMixin, CreateView):
+    pass
+
+
+class ServiceTypeDetail(ServiceTypeMixin, DetailView):
+    pass
+
+
+class ServiceTypeUpdate(ServiceTypeMixin, UpdateView):
+    pass
+
+
+class IPResourceMixin(PermissionRequiredMixin):
+    model = IPResource
+    permission_required = 'services.change_ipresource'
+
+
+class IPResourceList(IPResourceMixin, ListView):
+    pass
+
+
+class IPResourceDetail(IPResourceMixin, DetailView):
+    pass