Commit 85571f30 authored by Daniel STAN's avatar Daniel STAN

[voip] Ajout de l'application

parent f30b1cb5
from django.contrib import admin
from models import Profile
admin.site.register(Profile)
from django.forms import ModelForm
from models import Profile
class ProfileForm(ModelForm):
class Meta:
model = Profile
exclude = ('user',)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
""" Profil d'utilisateur Voip """
class Meta:
verbose_name = u'Profil SIP'
verbose_name_plural = u'Profils SIP'
CALLER_IDS = [
('full_name', u'Nom complet'),
('number', u'Numéro de Téléphone'),
('both', u'Nom et numéro de téléphone'),
]
user = models.OneToOneField(User, primary_key=True)
password = models.CharField(u"Mot de passe", max_length=32, null=False, blank=False)
published = models.BooleanField(u"Publication dans l'annuaire")
caller_id = models.CharField(u"Affichage de l'appelant", max_length=9, choices=CALLER_IDS)
def __unicode__(self):
return self.user.username
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
from django.conf.urls.defaults import patterns, url
import views
urlpatterns = patterns('',
url('^$', views.index, name="index"),
url('^edit/$', views.edit, name="edit"),
)
import django.shortcuts
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from models import Profile
from forms import ProfileForm
from django.utils.importlib import import_module
conn_pool = import_module('conn_pool', 'intranet')
@login_required
def index(request):
try:
profile = Profile.objects.filter(user__exact=request.user)[0]
except IndexError:
return django.shortcuts.render(request, "voip/noaccount.html")
try:
dn = conn_pool.CONNS[request.user.username].dn.split(',')
except KeyError:
dn = ''
if dn.startswith('aid='):
sip_ext = '1%04d' % int(dn[4:])
else:
sip_ext = '????'
return django.shortcuts.render(request, "voip/view.html",
{
'profile': profile,
'sip_ext': sip_ext,
})
@login_required
def edit(request):
try:
profile = Profile.objects.filter(user__exact=request.user)[0]
except IndexError:
profile = None
if request.method == 'POST':
form = ProfileForm(request.POST, instance=profile)
if form.is_valid():
profile = form.save(commit=False)
profile.user = request.user
profile.save()
return django.shortcuts.redirect('voip:index')
else:
form = ProfileForm(instance=profile)
return django.shortcuts.render(request, "voip/edit.html", {'form': form})
......@@ -195,6 +195,11 @@ INTRANET_APPS = (
'category': 'Services',
'test': (lambda u: True)
},
{
'name':'voip',
'category': 'Services',
'test': (lambda u: True)
},
)
INTRANET_APPS = tuple([ i for i in INTRANET_APPS if i['name'] not in
......
{% extends "template.html" %}
{% block content %}
<form method="POST" action="">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="OK" />
</form>
{% endblock %}
{% extends "template.html" %}
{% block content %}
Vous n'avez pas encore activé votre compte SIP.
<a href="{% url voip:edit %}">Créer votre compte</a>
{% endblock %}
{% extends "template.html" %}
{% block content %}
<h3>Vos paramètres de connexion</h3>
<p>
<dl>
<dt>Serveur</dt><dd>sip.crans.org</dd>
<dt>Nom d'utilisateur</dt><dd>{{ sip_ext }}</dd>
<dt>Mot de passe</dt><dd>{{ profile.password }}</dd>
<dt>Publication dans l'annuaire</dt>
<dd>{{ profile.published|yesno:"Activée,Désactivée" }}</dd>
<dt>Présentation de l'appelant</dt><dd>{{ profile.get_caller_id_display }}</dd>
</dl>
<a href="{% url voip:edit %}">Éditer</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