...
 
Commits (8)
import models
from django.contrib import admin
admin.site.register(models.VirtAP)
from django.db import models
# Create your models here.
class VirtAP(models.Model):
u"""Une borne virtuelle"""
class Meta:
verbose_name = "Borne WiFi virtuelle"
verbose_name_plural = "Bornes WiFi virtuelles"
#ordering = ['batiment', 'etage']
host = models.CharField(max_length=255)
location = models.CharField(max_length=255)
lat = models.FloatField()
lon = models.FloatField()
def xmlRepr(self, doc):
borne = doc.createElement('borne')
borne.setAttribute('virtual', 'virtual')
def addTextNode(label, value):
node = doc.createElement(label)
node.appendChild(doc.createTextNode(unicode(value)))
borne.appendChild(node)
addTextNode('hostname', self.host)
addTextNode('lon', self.lon)
addTextNode('lat', self.lat)
addTextNode('location', self.location)
addTextNode('client_count', '0')
return borne
......@@ -24,6 +24,8 @@ import django.shortcuts
from django.template import RequestContext
from django.http import HttpResponse
from models import VirtAP
#from django.contrib.auth.decorators import login_required, permission_required
......@@ -31,6 +33,8 @@ def get_xml(request):
import parse_xml
public = not request.user.groups.filter(name='crans_nounou')
doc = parse_xml.global_status(public)
for ap in VirtAP.objects.all():
doc.documentElement.appendChild(ap.xmlRepr(doc))
return HttpResponse(doc.toxml('utf-8'),content_type='text/xml; coding=utf-8')
def index(request):
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# DATABASE.PY -- Gestion des bases de données multiples dans l'intranet
#
# Copyright (C) 2010 Nicolas Dandrimont
# Authors: Nicolas Dandrimont <olasd@crans.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import settings
class Router(object):
"""Effectue le routage entre les différentes bases de données"""
def db_for_read(self, model, **hints):
"""Base de données à utiliser pour la lecture"""
if model._meta.app_label == "prises":
return "switchs"
return "default"
def db_for_write(self, model, **hints):
"""Base de données à utiliser pour l'écriture"""
if model._meta.app_label == "prises":
return "switchs"
return "default"
def allow_syncdb(self, db, model):
"""Autoriser l'écriture du modèle donné dans la base de données ?"""
if db == "switchs":
if model._meta.app_label == "prises":
return True
return False
else:
if model._meta.app_label == "prises":
return False
return True
......@@ -45,7 +45,7 @@ class LDAPUserBackend(ModelBackend):
return None
try:
conn = lc_ldap(user = username, cred = password)
conn = lc_ldap(user = username, cred = password, test=settings.LDAP_TEST)
ldap_user = conn.search(dn = conn.dn, scope = ldap.SCOPE_BASE)[0]
except IndexError:
return None
......
......@@ -11,6 +11,8 @@ TEMPLATE_DEBUG = DEBUG
EMAIL_SUBJECT_PREFIX = "[Intranet2 Cr@ns] "
# Utiliser la base ldap de test ?
LDAP_TEST = True
ADMINS = (
'Intranet', 'root@crans.org',
......
......@@ -99,13 +99,22 @@
font-size: 75%;
}
.borne .pan_to {
.borne .pan_to , .borne .edit {
float: right;
margin-top: 10px;
font-size: 0.65em;
font-weight: normal;
}
.borne .coords.modified {
color: red;
}
.borne .edit {
margin-left: 3px;
}
/* sorting */
.order {
......
......@@ -15,7 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var debug = document.location.hostname != 'intranet2.crans.org';
//var debug = document.location.hostname != 'intranet2.crans.org';
var debug = false;
var WifiMap;
......@@ -24,9 +25,11 @@ window.addEventListener('load',function () { WifiMap.init(); });
//Wifi map !
WifiMap = {
modeSwitcher: null,
'init': function() {
var that = this;
this.map = new OpenLayers.Map({'div': 'map','controls':[]});
this.moved = null;
// Note: Min lon: 2.325175
// : Min lat: 48.786424
// : Min lon: 2.33118
......@@ -61,7 +64,7 @@ WifiMap = {
//Layer de base (OSM actuellement)
this.map.addLayers([this.layer]);
//Controles divers (ceux ci-dessous sont visibles)
this.map.addControl(new WifiMap.ModeSwitcher({'wifiMap': this}));
this.map.addControl(this.modeSwitcher = new WifiMap.ModeSwitcher({'wifiMap': this}));
this.map.addControl(new OpenLayers.Control.Navigation());
this.map.addControl(new OpenLayers.Control.PanZoom());
......@@ -91,10 +94,17 @@ WifiMap = {
}
});
WifiMap.map.events.register("click",map,function (e) {
var pos = WifiMap.map.getLonLatFromViewPortPx(WifiMap.map.events.getMousePosition(e));
console.debug(pos.lon, pos.lat);
});
this.map.events.register("click",this,function (e) {
var pos = this.map.getLonLatFromViewPortPx(this.map.events.getMousePosition(e));
var gps = pos.clone().transform(this.projections.map,this.projections.gps);
$('x').value = gps.lon;
$('y').value = gps.lat;
if( this.moved) {
this.moved.moveTo(gps);
this.moved = false;
}
});
//Event select: tout déselectionner
this.map.events.register('click', undefined, this.highlight.bind(this,undefined));
......@@ -136,15 +146,19 @@ WifiMap = {
borne.wifiMap = this;
//Noms des fichiers images suivant le mode de la borne
var files = {'on': 'marker-green', 'ens': 'marker-blue', 'off': 'marker'};
var files = {'on': 'marker-green', 'ens': 'marker-blue', 'off': 'marker',
'autres': 'marker-gold'};
borne.update_info = function(xml) {
//Clean up last marker
var old = this.marker;
this.xml = xml;
var highlighted = this.highlighted;
var type = "on";
if( xml.hasAttribute('offline'))
type = "off";
if( xml.hasAttribute('virtual'))
type = "autres";
this.layer = that.bornesLayers[type]; //On définit layer même
//S'il n'est pas sûr qu'on placera la borne sur la carte
if(old) {
......@@ -153,20 +167,22 @@ WifiMap = {
old.destroy(); this.marker = null;
}
//New coords !
try {
var x = parseFloat(xml.getElementsByTagName('lon')[0].firstChild.nodeValue);
var y = parseFloat(xml.getElementsByTagName('lat')[0].firstChild.nodeValue);
}
catch(e) {
this.mapPosition = undefined;
//Mettre à jour les infos tabulaires de la borne avant de quitter
this.update_borne_infos(xml);
return;
}
//New coords ?
if( !this.mapPosition || !this.mapPosition.modified) {
try {
var x = parseFloat(xml.getElementsByTagName('lon')[0].firstChild.nodeValue);
var y = parseFloat(xml.getElementsByTagName('lat')[0].firstChild.nodeValue);
}
catch(e) {
this.mapPosition = undefined;
//Mettre à jour les infos tabulaires de la borne avant de quitter
this.update_borne_infos(xml);
return;
}
//mapPosition sera stockée dans les coordonnées de la map
this.mapPosition = new OpenLayers.LonLat(x,y);
//mapPosition sera stockée dans les coordonnées de la map
this.mapPosition = new OpenLayers.LonLat(x,y);
}
this.mapPosition.transform(that.projections.gps,that.projections.map);
......@@ -184,7 +200,7 @@ WifiMap = {
var url = '/static/OpenLayers/img/' + (files[type]) + '.png';
var icon = new OpenLayers.Icon(url,size,offset);
this.marker = new OpenLayers.Marker(this.mapPosition,icon);
this.marker = new OpenLayers.Marker(this.mapPosition, icon);
this.layer.addMarker(this.marker);
this.update_marker_size();
......@@ -222,6 +238,12 @@ WifiMap = {
this.update_marker_size();
};
borne.moveTo = function (gps) {
this.mapPosition = gps;
this.mapPosition.modified = true;
this.update_info(this.xml);
};
//Met à jour la taille du markeur (notamment après un zoom)
borne.update_marker_size = function() {
if( ! this.marker ) return; //Nothing to do
......@@ -282,6 +304,13 @@ WifiMap = {
else if( child.tagName == 'uptime')
templates.fillSpanClass(html,'uptime',
format_uptime(parseInt(getInnerText(child))));
else if( child.tagName == 'editable') {
var edit = templates.getInstance(html, 'edit');
edit.addEventListener('click', function (event) {
alert('Not implemented yet');
event.preventDefault();
});
}
else if( child.tagName == 'client_count') {
this.count = parseInt(getInnerText(child));
var c = parseInt(getInnerText(child));
......@@ -310,7 +339,7 @@ WifiMap = {
//Si position sur la carte, on active le bouton pour zoomer dessus
if(this.mapPosition) {
panTo = getElementsByClassName(html,'pan_to')[0]
panTo = getElementsByClassName(html,'pan_to')[0];
panTo.addEventListener('click',
(function (event) {
if(this.mapPosition) {
......@@ -322,6 +351,22 @@ WifiMap = {
panTo.className = panTo.className.replace(/ *template ?/,'');
}
setCoord = getElementsByClassName(html,'setCoord')[0];
setCoord.addEventListener('click',
(function (event) {
this.wifiMap.moved = this;
event.preventDefault();
}).bind(this));
coords = getElementsByClassName(html, 'coords')[0];
if( this.mapPosition) {
var gps = this.mapPosition.clone();
gps.transform(that.projections.map, that.projections.gps);
setInnerText(coords, gps.lon + ' ' + gps.lat)
this.mapPosition.modified && coords.setAttribute('class', 'coords modified');
}
else
setInnerText(coords, 'N/A');
//On fixe la nouvelle bar d'info
if(this.html_list)
this.html_list.parentNode.replaceChild(html,this.html_list);
......@@ -408,6 +453,7 @@ WifiMap = {
this.listeBornes[hostname].update_info(xml);
}
this.sort();
this.modeSwitcher.updateMap();
},
//Met à jour la date de dernière màj
......
......@@ -16,6 +16,8 @@ Dernière mise à jour il y a <label id="last_update"> </label>
<div id="toolbar">
<div id="borne_template" class="borne template">
<h3>
<a href="#" class="edit template"><img src="/static/img/edit.png"/>
</a>
<a href="#" class="pan_to template"><img src="/static/img/point.png"/>
<span class="location template content"></span>
</a>
......@@ -26,6 +28,8 @@ Dernière mise à jour il y a <label id="last_update"> </label>
<span class="uptime template">Uptime: <span class="content"></span></span>
<ul>
<li class="comment template">Liste commentaire</li>
<li class="coord">Lon/Lat <span class="coords">N/A</span>
<a href="#" class="setCoord">Placer</a></li>
<li class="prise template">Prise: <span class="content"></span></li>
</ul>
<div class="network template">
......@@ -42,4 +46,6 @@ Dernière mise à jour il y a <label id="last_update"> </label>
</div>
<div id="map">
</div>
<input type="text" id="x">
<input type="text" id="y">
{% endblock %}