rapport modif + widget
authorOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 28 Jun 2012 17:04:13 +0000 (13:04 -0400)
committerOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 28 Jun 2012 17:04:13 +0000 (13:04 -0400)
project/dashboard.py
project/menu.py
project/rh/historique.py [new file with mode: 0644]
project/rh/templates/rh/rapports/historique_des_modifications.html [new file with mode: 0644]
project/rh/urls.py
project/rh/views.py

index 39b516b..082f85a 100644 (file)
@@ -14,12 +14,16 @@ And to activate the app index dashboard::
 
 from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
 from django.utils.translation import ugettext_lazy as _
+from reversion.models import Revision
+from project.decorators import in_drh_or_admin
+from project.rh.historique import format_revisions
 
 class CustomIndexDashboard(Dashboard):
     """
     Custom index dashboard for SIGMA.
     """
     def init_with_context(self, context):
+        request = context['request']
 
         # append an app list module for "Applications"
         self.children.append(modules.AppList(
@@ -36,6 +40,23 @@ class CustomIndexDashboard(Dashboard):
             ),
         ))
 
+        if in_drh_or_admin(request.user):
+            revisions = format_revisions(Revision.objects.order_by('-date_created')[:10])
+            children = []
+            for rev in revisions:
+                children.append({
+                    'title': u"%s: %s %s (%s)" % (rev['date_created'],
+                        rev['type'], rev['objet'], rev['comment']),
+                    'url': rev['url'],
+                    'external': False,
+                    })
+            self.children.append(modules.LinkList(
+                title='10 dernières modifications',
+                children=children,)
+            )
+
+
+
         # append an app list module for "Configuration"
         self.children.append(modules.AppList(
             _('Configuration'),
index 2b83d25..f763ba7 100644 (file)
@@ -71,6 +71,8 @@ class CustomMenu(Menu):
                         #     reverse('rhr_postes_hierarchie')),
                         items.MenuItem('Rapport de masse salariale',
                             reverse('rhr_masse_salariale')),
+                        items.MenuItem('Rapport des modifications',
+                            reverse('rhr_historique_des_modifications')),
                         ]),
 
                 items.MenuItem('Organigrammes',
diff --git a/project/rh/historique.py b/project/rh/historique.py
new file mode 100644 (file)
index 0000000..65c1149
--- /dev/null
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+
+from django.core.urlresolvers import reverse
+
+def format_revisions(qs):
+
+    results = []
+    for rev in qs:
+        for v in rev.version_set.all():
+            try:
+                url = reverse('%s_apercu' % v.content_type.model,
+                        args=(v.object.id, ))
+                type = v.content_type
+                objet = v.object
+                break
+            except:
+                url = None
+                type = None
+                objet = None
+
+        results.append({
+            'date_created': rev.date_created,
+            'user': rev.user,
+            'comment': rev.comment,
+            'url': url,
+            'type': type,
+            'objet': objet,
+
+            })
+    return results
diff --git a/project/rh/templates/rh/rapports/historique_des_modifications.html b/project/rh/templates/rh/rapports/historique_des_modifications.html
new file mode 100644 (file)
index 0000000..4fc4971
--- /dev/null
@@ -0,0 +1,61 @@
+{% extends "admin/base_site.html" %}
+
+{% load adminmedia i18n change_list %}
+
+{% block extrahead %}
+  <script type="text/javascript" src="/admin/jsi18n"></script>
+  <script type="text/javascript" src="{{ STATIC_URL }}/admin/js/core.js"></script>
+  <script type="text/javascript" src="{{ STATIC_URL }}admin/js/admin/RelatedObjectLookups.js"></script>
+  {{ block.super }}
+{% endblock %}
+
+{% block title %}
+    Historique des modifications
+{% endblock %}
+
+{% block content %}
+
+<h1>Historique des modifications</h1>
+
+<br />
+
+<table id="result_list" class="results">
+  <thead>
+      <tr>
+          {% for h in headers %}
+            <th>{{ h }}</th>
+          {% endfor %}
+      </tr>
+  </thead>
+  {% for revision in revisions %}
+  <tr class="{% cycle 'row1' 'row2' %}">
+      <td>{{ revision.date_created }}</td>
+      <td>{{ revision.user }}</td>
+      <td>{% if revision.type %}{{ revision.type }}{% endif %}</td>
+      <td>{% if revision.url %}<a href="{{ revision.url }}"
+             onclick="return showAddAnotherPopup(this);">
+             {{ revision.objet }}<a>{% endif %}</td>
+      <td>{{ revision.comment }}</td>
+  </tr>
+  {% endfor %}
+</table>
+
+<br />
+
+<div class="pagination">
+    <span class="step-links">
+        {% if page.has_previous %}
+            <a href="?page={{ page.previous_page_number }}">Précédente</a>
+        {% endif %}
+
+        <span class="current">
+            Page {{ page.number }} / {{ page.paginator.num_pages }}.
+        </span>
+
+        {% if page.has_next %}
+            <a href="?page={{ page.next_page_number }}">Suivante</a>
+        {% endif %}
+    </span>
+</div>
+
+{% endblock %}
index d4bfdf5..876e592 100644 (file)
@@ -37,4 +37,9 @@ urlpatterns = patterns('project.rh.views',
         'organigrammes_implantation', name='rho_implantation'),
     url(r'^admin/rh/organigrammes/bureau/(\d+)$', 'organigrammes_region',
         name='rho_region'),
+
+    #historique
+    url(r'^admin/rh/rapports/modifications$',
+        'historique_des_modifications',
+        name='rhr_historique_des_modifications'),
 )
index c89042d..774f1ce 100644 (file)
@@ -14,6 +14,8 @@ from django.db.models import Q
 from django.http import HttpResponse
 from django.shortcuts import render, get_object_or_404
 
+from reversion.models import Revision
+
 from project.decorators import drh_or_admin_required
 from project.decorators import region_protected
 from project.groups import \
@@ -25,6 +27,7 @@ from project.rh.change_list import RechercheTemporelle
 from project.rh.forms import MasseSalarialeForm
 from project.rh.lib import get_lookup_params
 from project.rh.templatetags.rapports import SortHeaders
+from project.rh.historique import format_revisions
 
 TWOPLACES = Decimal('0.01')
 
@@ -778,3 +781,28 @@ def organigrammes_region(request, id):
     return render(request, 'rh/organigrammes/vide.html', {
         'svg': svg
     }, content_type="image/svg+xml")
+
+
+@login_required
+@drh_or_admin_required
+def historique_des_modifications(request,):
+
+    from django.core.paginator import Paginator
+
+    revisions = Revision.objects.all().order_by('-date_created')
+    paginator = Paginator(revisions, 20)
+    page = request.GET.get('page')
+    try:
+        page_revisions = paginator.page(page)
+    except:
+        page_revisions = paginator.page(1)
+
+    results = format_revisions(page_revisions.object_list)
+
+    c = {
+            'headers': ('Date', 'Auteur', 'Type', 'Objet', 'Commentaire', ),
+            'revisions': results,
+            'page': page_revisions,
+    }
+
+    return render(request, 'rh/rapports/historique_des_modifications.html', c)