Commit 2cf6e23c authored by Daniel STAN's avatar Daniel STAN

[voip] historique des appels

parent 8d07d9df
from django.contrib import admin
from models import Profile
from models import Profile, Call
admin.site.register(Profile)
admin.site.register(Call)
......@@ -116,3 +116,25 @@ mailbox=%(num)s@666
return self.num
else: # Both
return self.user.get_full_name() + u' <' + self.num + u'>'
class Call(models.Model):
""" Un appel archivé.
Automatiquement rempli par asterisk (et les scripts maisons de Nit)
"""
class Meta:
"""La table s'appelle history, on définit ici plutôt un nom pour un objet"""
db_table = 'voip_history'
verbose_name = u'Appel archivé'
verbose_name_plural = u'Appels archivés'
uniq_id = models.CharField(u"Identifiant de l'appel", max_length=80, primary_key=True)
src = models.CharField(u"Numéro appelant", max_length=80)
dst = models.CharField(u"Numéro appelant", max_length=80)
""" Une durée égale à NULL correspond à un appel en cours (sauf si plantage) """
duration = models.IntegerField(u"Durée de l'appel", null=True, blank=True)
date = models.DateField(u"Date d'initiation de l'appel")
def __unicode__(self):
return u"%s -> %s @ %s (%ds)" % (self.src, self.dst, self.date, self.duration)
......@@ -8,4 +8,8 @@ urlpatterns = patterns('',
url('^delete/$', views.delete, name="delete"),
url('^book/$', views.book, name="book"),
url('^book/download$', views.book, {'download': True}, name="book_download",),
url('^history/sent/$', views.history, {'received': False}, name='sent_calls'),
url('^history/sent/(?P<page>[0-9]+)$', views.history, {'received': False}),
url('^history/$', views.history, name="received_calls"),
url('^history/(?P<page>[0-9]+)$', views.history),
)
# -*- encoding: utf-8 -*-
import django.shortcuts
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from models import Profile
from models import Profile, Call
from forms import ProfileForm
from django.views.generic.edit import DeleteView
from django.shortcuts import get_object_or_404
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
import datetime
......@@ -54,3 +57,32 @@ def book(request, download=False):
date = datetime.datetime.now()
response['Content-Disposition'] = 'attachment; filename="CransBook_%d_%d_%d.vcf"' % (date.day, date.month, date.year)
return response
@login_required
def history(request, page=None, received=True):
""" Affiche un historique des appels, paginé """
num = get_object_or_404(Profile, user__exact=request.user).num
hist_list = Call.objects.all().filter(
**{'dst' if received else 'src' + '__exact': num}
).order_by('-date')
if received:
title = u'reçus'
else:
title = u'émis'
paginator = Paginator(hist_list, 25)
try:
hist = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
hist = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
hist = paginator.page(paginator.num_pages)
return django.shortcuts.render(request, 'voip/history.html', {
"history": hist,
'title': title,
})
{% extends "template.html" %}
{% block content %}
<h3>Historique des appels {{ title }}</h3>
<a href="{% url voip:index %}">Retour</a>
<table>
<tr>
<th>Source</th>
<th>Destination</th>
<th>Date</th>
<th>Durée (s)</th>
</tr>
{% for call in history %}
<tr>
<td>{{ call.src }}</td>
<td>{{ call.dst }}</td>
<td>{{ call.date }}</td>
<td>{{ call.duration }}</td>
</tr>
{% endfor %}
</table>
<div class="pagination">
<span class="step-links">
{% if history.has_previous %}
<a href="{{ history.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ history.number }} sur {{ history.paginator.num_pages }}.
</span>
{% if history.has_next %}
<a href="{{ history.next_page_number }}">next</a>
{% endif %}
</span>
</div>
{% endblock %}
......@@ -14,5 +14,8 @@
<a href="{% url voip:edit %}">Éditer</a>,
<a href="{% url voip:delete %}">Effacer</a> mon compte,
<a href="{% url voip:book %}">Consulter l'annuaire</a>
<br />
Historique des appels <a href="{% url voip:sent_calls %}">émis</a>
<a href="{% url voip:received_calls %}">reçus</a>
</p>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment