Commit 9392e35a authored by Daniel STAN's avatar Daniel STAN

[voip] Affichage/Download de l'annuaire

parent 37e768f5
......@@ -104,6 +104,9 @@ mailbox=%(num)s@666
'uid': self.user.username,
}
def get_category(self):
""" Renvoie la catégorie du profil, dans l'annuaire """
return "Cr@ns"
def get_caller_id(self):
""" Calcule le texte descriptif de l'appelant """
......
......@@ -6,4 +6,6 @@ urlpatterns = patterns('',
url('^$', views.index, name="index"),
url('^edit/$', views.edit, name="edit"),
url('^delete/$', views.delete, name="delete"),
url('^book/$', views.book, name="book"),
url('^book/download$', views.book, {'download': True}, name="book_download",),
)
......@@ -8,6 +8,7 @@ from forms import ProfileForm
from django.views.generic.edit import DeleteView
from django.shortcuts import get_object_or_404
import datetime
@login_required
def index(request):
......@@ -41,3 +42,15 @@ def delete(request):
obj.delete()
return django.shortcuts.redirect('apps.accueil.views.view')
return django.shortcuts.render(request, "voip/delete.html")
@login_required
def book(request, download=False):
data = {'profiles': Profile.objects.filter(published__exact=True).order_by('num')}
if not download:
return django.shortcuts.render(request, "voip/book.html", data)
response = django.shortcuts.render(request, "voip/book.vcf", data,
content_type='text/x-vcard')
date = datetime.datetime.now()
response['Content-Disposition'] = 'attachment; filename="CransBook_%d_%d_%d.vcf"' % (date.day, date.month, date.year)
return response
{% extends "template.html" %}
{% block content %}
<h3>Annuaire</h3>
<a href="{% url voip:book_download %}">Télécharger (vcf)</a>,
<a href="{% url voip:index %}">Retour</a>
<table>
<tr>
<th>Nom</th>
<th>Prénom</th>
<th>Numéro</th>
</tr>
{% for profile in profiles %}
<tr>
<td>{{ profile.user.last_name }}</td>
<td>{{ profile.user.first_name }}</td>
<td>{{ profile.num }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
{% for profile in profiles %}
BEGIN:VCARD
VERSION:3.0
TEL;TYPE=VOIP:{{ profile.num }}
N:{{ profile.user.first_name }};{{ profile.user.last_name }};;;
FN:{{ profile.user.get_full_name }}
CATEGORIES:{{ profile.get_category }}
END:VCARD
{% endfor %}
......@@ -12,6 +12,7 @@
({{ profile.get_caller_id }})</dd>
</dl>
<a href="{% url voip:edit %}">Éditer</a>,
<a href="{% url voip:delete %}">Effacer</a> mon compte
<a href="{% url voip:delete %}">Effacer</a> mon compte,
<a href="{% url voip:book %}">Consulter l'annuaire</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