Exemplo n.º 1
0
def search(request, what):
    data = []
    data = data + [{'label': n.name, 'value': jslugify(n.slug), 'slug': n.slug, 'name': n.name, 'lat': n.lat, 'lng': n.lng, 'status': n.status }  for n in Node.objects.filter(name__icontains=what).exclude(status='u').only('name','slug','lat','lng','status')]
    data = data + [{'label': d.name, 'value': jslugify(d.node.slug), 'slug': d.node.slug, 'name': d.node.name, 'lat': d.node.lat, 'lng': d.node.lng, 'status': d.node.status }  for d in Device.objects.filter(name__icontains=what).only('name','node__name','node__slug','node__lat','node__lng','node__status')]
    data = data + [{'label': i.ipv4_address , 'value': jslugify(i.device.node.slug), 'slug': i.device.node.slug, 'name': i.device.node.name, 'lat': i.device.node.lat, 'lng': i.device.node.lng, 'status': i.device.node.status }  for i in Interface.objects.filter(ipv4_address__icontains=what).only('device__node__name','device__node__slug','device__node__lat','device__node__lng','status')]
    data = data + [{'label': i.ipv6_address , 'value': jslugify(i.device.node.slug), 'slug': i.device.node.slug, 'name': i.device.node.name, 'lat': i.device.node.lat, 'lng': i.device.node.lng, 'status': i.device.node.status }  for i in Interface.objects.filter(ipv6_address__icontains=what).only('device__node__name','device__node__slug','device__node__lat','device__node__lng','status')]
    data = data + [{'label': i.mac_address , 'value': jslugify(i.device.node.slug), 'slug': i.device.node.slug, 'name': i.device.node.name, 'lat': i.device.node.lat, 'lng': i.device.node.lng, 'status': i.device.node.status }  for i in Interface.objects.filter(mac_address__icontains=what).only('device__node__name','device__node__slug','device__node__lat','device__node__lng','status')]
    # I think this is useless cos all our devices have ssid: ninux.org
    #data = data + [{'label': d.ssid , 'value': jslugify(d.device.node.slug), 'slug': d.device.node.slug, 'name': d.device.node.name, 'lat': d.device.node.lat, 'lng': d.device.node.lng, 'status': d.device.node.status }  for d in Interface.objects.filter(ssid__icontains=what).only('device__node__name','device__node__slug','device__node__lat','device__node__lng','status')]
    if len(data) > 0:
        return HttpResponse(simplejson.dumps(data), mimetype='application/json')
    else:
        return HttpResponse('{}', mimetype='application/json')
Exemplo n.º 2
0
def nodes(request):
    """
    Returns a json list with all the nodes divided in active, potential and hostspot
    Populates javascript object nodeshot.nodes
    """
    # retrieve nodes in 3 different objects depending on the status
    active = Node.objects.filter(status = 'a').values('name', 'slug', 'id', 'lng', 'lat', 'status')
    # status ah (active & hotspot) will fall in the hotspot group, having the hotspot icon
    hotspot = Node.objects.filter(Q(status = 'h') | Q(status = 'ah')).values('name', 'slug', 'id', 'lng', 'lat', 'status')
    potential = Node.objects.filter(status = 'p').values('name', 'slug', 'id', 'lng', 'lat', 'status')

    # retrieve links, select_related() reduces the number of queries,
    # only() selects only the fields we need
    # double underscore __ indicates that we are following a foreign key
    link_queryset = Link.objects.all().exclude(hide=True).select_related().only(
        'from_interface__device__node__lat', 'from_interface__device__node__lng',
        'to_interface__device__node__lat', 'to_interface__device__node__lng',
        'to_interface__device__node__name', 'to_interface__device__node__name',
        'etx', 'dbm'
    )
    # evaluate queryset
    
    # prepare empty list
    links = []
    # loop over queryset (remember: evaluating queryset makes query to the db)
    for l in link_queryset:
        # determining link colour (depending on link quality)
        etx = l.get_quality('etx')
        dbm = l.get_quality('dbm')
        # prepare result
        entry = {
            'from_lng': l.from_interface.device.node.lng ,
            'from_lat': l.from_interface.device.node.lat,
            'to_lng': l.to_interface.device.node.lng,
            'to_lat': l.to_interface.device.node.lat,
            'etx': etx,
            'dbm': dbm
        }
        # append/push result into list
        links.append(entry)
    
    #prepare data for json serialization
    active_nodes, hotspot_nodes, potential_nodes = {}, {}, {}
    for node in active:
        node['jslug'] = jslugify(node['slug'])
        active_nodes[jslugify(node['slug'])] = node
    for node in hotspot:
        node['jslug'] = jslugify(node['slug'])
        hotspot_nodes[jslugify(node['slug'])] = node
    for node in potential:
        node['jslug'] = jslugify(node['slug'])
        potential_nodes[jslugify(node['slug'])] = node
    data = {
        'active': active_nodes,
        'hotspot': hotspot_nodes,        
        'potential': potential_nodes,
        'links': links
    }
    # return json
    return HttpResponse(simplejson.dumps(data), mimetype='application/json')
Exemplo n.º 3
0
def index(request, slug=False):
    """
    Home of the map-server. Google Maps and all that stuff ;-)
    """
    # retrieve statistics
    try:
        stat = Statistic.objects.latest('date')
        # round km
        stat.km = int(stat.km)
    except ObjectDoesNotExist:
        stat = False

    # default case for next code block
    gmap_config = GMAP_CONFIG
    # if node is in querystring we want to center the map somewhere else
    if slug:
        try:
            node = Node.objects.only('lat', 'lng', 'slug',
                                     'status').get(slug=slug)
            gmap_config['is_default'] = 'false'
            gmap_config['node'] = '%s;%s' % (jslugify(node.slug), node.status)
            # convert to string otherwise django might format the decimal separator with a comma, which would break gmap
            gmap_config['lat'] = str(node.lat)
            gmap_config['lng'] = str(node.lng)
        except ObjectDoesNotExist:
            # if node requested doesn't exist return 404
            raise Http404

    # prepare context
    context = {
        'stat': stat,
        'gmap_config': gmap_config,
        'settings': {
            'HTML_TITLE_INDEX': HTML_TITLE_INDEX,
            'META_ROBOTS': META_ROBOTS,
            'SHOW_STATISTICS': SHOW_STATISTICS,
            'SHOW_KML_LINK': SHOW_KML_LINK,
            'HELP_URL': HELP_URL,
            'SHOW_ADMIN_LINK': SHOW_ADMIN_LINK,
            'TAB3': TAB3,
            'TAB4': TAB4,
            'WELCOME_TEXT': WELCOME_TEXT,
            'LINK_QUALITY': LINK_QUALITY
        },
        'DEBUG': DEBUG
    }

    return render_to_response('index.html',
                              context,
                              context_instance=RequestContext(request))
Exemplo n.º 4
0
def index(request, slug=False):
    """
    Home of the map-server. Google Maps and all that stuff ;-)
    """
    # retrieve statistics
    try:
        stat = Statistic.objects.latest('date')
        # round km
        stat.km = int(stat.km)
    except ObjectDoesNotExist:
        stat = False

    # default case for next code block
    gmap_center = GMAP_CENTER
    # if node is in querystring we want to center the map somewhere else
    if slug:
        try:
            node = Node.objects.only('lat', 'lng', 'slug','status').get(slug=slug)
            gmap_center = {
                'is_default': 'false',
                'node': '%s;%s' % (jslugify(node.slug), node.status),
                # convert to string otherwise django might format the decimal separator with a comma, which would break gmap
                'lat': str(node.lat),
                'lng': str(node.lng)
            }
        except ObjectDoesNotExist:
            # if node requested doesn't exist return 404
            raise Http404

    # prepare context
    context = {
        'stat': stat,
        'gmap_center': gmap_center,
        'settings': {
            'HTML_TITLE_INDEX': HTML_TITLE_INDEX,
            'META_ROBOTS': META_ROBOTS,
            'SHOW_STATISTICS': SHOW_STATISTICS,
            'SHOW_KML_LINK': SHOW_KML_LINK,
            'HELP_URL': HELP_URL,
            'SHOW_ADMIN_LINK': SHOW_ADMIN_LINK,
            'TAB3': TAB3,
            'TAB4': TAB4,
            'WELCOME_TEXT': WELCOME_TEXT,
            'LINK_QUALITY': LINK_QUALITY
        },
        'DEBUG': DEBUG
    }

    return render_to_response('index.html', context, context_instance=RequestContext(request))
Exemplo n.º 5
0
def jstree(request):
    """
    Populates jquery.jstree plugin
    """
    # retrieve nodes in 3 different objects depending on the status
    active = Node.objects.filter(Q(status = 'a') | Q(status = 'ah')).values('name', 'slug', 'lng', 'lat', 'status').order_by('name') # status is necessary to link "active & hotspot" nodes correctly
    hotspot = Node.objects.filter(Q(status = 'h') | Q(status = 'ah')).values('name', 'slug', 'lng', 'lat').order_by('name')
    potential = Node.objects.filter(status = 'p').values('name', 'slug', 'lng', 'lat').order_by('name')
    # prepare empty lists
    data, active_list, hotspot_list, potential_list = [], [], [], []

    for a in active:
        # distinguish "active" from "active & hotspot"
        if a['status'] == 'a':
            status = 'active'
        elif a['status'] == 'ah':
            # treat "active & hotspot" like hotspots
            status = 'hotspot'
        
        active_list.append({
            'data': {
                'title': a['name'],
                'attr': {
                    'class': 'child',
                    'href': 'javascript:nodeshot.gmap.goToNode(nodeshot.nodes.%s.%s)' % (status, jslugify(a['slug']))
                }
            }
        })
    if len(active_list) > 0:
        data.append({
            'data': ugettext('Active Nodes'),
            'state': 'open',
            'attr': {
                'class': 'active_nodes',
            },
            'children': list(active_list)
        })

    for h in hotspot:
        hotspot_list.append({
            'data': {
                'title': h['name'],
                'attr': {
                    'class': 'child',
                    'href': 'javascript:nodeshot.gmap.goToNode(nodeshot.nodes.hotspot.%s)' % jslugify(h['slug'])
                }
            }
        })
    if len(hotspot_list) > 0:
        data.append({
            'data': ugettext('Hotspots'),
            'state': 'open',
            'attr': {
                'class': 'hotspot_nodes'
            },
            'children': list(hotspot_list)
        })

    for p in potential:
        potential_list.append({
            'data': {
                'title': p['name'],
                'attr': {
                    'class': 'child',
                    'href': 'javascript:nodeshot.gmap.goToNode(nodeshot.nodes.potential.%s)' % jslugify(p['slug'])
                }
            }
        })
    if len(potential_list) > 0:
        data.append({
            'data': ugettext('Potential Nodes'),
            'state': 'open',
            'attr': {
                'class': 'potential_nodes'
            },
            'children': list(potential_list)
        })
    # return json
    return HttpResponse(simplejson.dumps(data), mimetype='application/json')
Exemplo n.º 6
0
def jslugify_filter(value):
    """
    Template filter that executes jslugify()
    """
    return jslugify(value)
Exemplo n.º 7
0
def jslugify_filter(value):
    """
    Template filter that executes jslugify()
    """
    return jslugify(value)
Exemplo n.º 8
0
def nodes(request):
    """
    Returns a json list with all the nodes divided in active, potential and hostspot
    Populates javascript object nodeshot.nodes
    """
    # retrieve nodes in 3 different objects depending on the status
    active = Node.objects.filter(status='a').values('name', 'slug', 'id',
                                                    'lng', 'lat', 'status')
    # status ah (active & hotspot) will fall in the hotspot group, having the hotspot icon
    hotspot = Node.objects.filter(Q(status='h') | Q(status='ah')).values(
        'name', 'slug', 'id', 'lng', 'lat', 'status')
    potential = Node.objects.filter(status='p').values('name', 'slug', 'id',
                                                       'lng', 'lat', 'status')

    # retrieve links, select_related() reduces the number of queries,
    # only() selects only the fields we need
    # double underscore __ indicates that we are following a foreign key
    link_queryset = Link.objects.all().exclude(
        hide=True).select_related().only('from_interface__device__node__lat',
                                         'from_interface__device__node__lng',
                                         'to_interface__device__node__lat',
                                         'to_interface__device__node__lng',
                                         'to_interface__device__node__name',
                                         'to_interface__device__node__name',
                                         'etx', 'dbm')
    # evaluate queryset

    # prepare empty list
    links = []
    # loop over queryset (remember: evaluating queryset makes query to the db)
    for l in link_queryset:
        # determining link colour (depending on link quality)
        etx = l.get_quality('etx')
        dbm = l.get_quality('dbm')
        # prepare result
        entry = {
            'from_lng': l.from_interface.device.node.lng,
            'from_lat': l.from_interface.device.node.lat,
            'to_lng': l.to_interface.device.node.lng,
            'to_lat': l.to_interface.device.node.lat,
            # raw values
            'retx': l.etx,
            'rdbm': l.dbm,
            # interpreted values (link quality, can be 1, 2 or 3)
            'etx': etx,
            'dbm': dbm
        }
        # append/push result into list
        links.append(entry)

    #prepare data for json serialization
    active_nodes, hotspot_nodes, potential_nodes = {}, {}, {}
    for node in active:
        node['jslug'] = jslugify(node['slug'])
        active_nodes[jslugify(node['slug'])] = node
    for node in hotspot:
        node['jslug'] = jslugify(node['slug'])
        hotspot_nodes[jslugify(node['slug'])] = node
    for node in potential:
        node['jslug'] = jslugify(node['slug'])
        potential_nodes[jslugify(node['slug'])] = node
    data = {
        'active': active_nodes,
        'hotspot': hotspot_nodes,
        'potential': potential_nodes,
        'links': links
    }
    # return json
    return HttpResponse(simplejson.dumps(data), mimetype='application/json')
Exemplo n.º 9
0
def search(request, what):
    data = []
    data = data + [{
        'label': n.name,
        'value': jslugify(n.slug),
        'slug': n.slug,
        'name': n.name,
        'lat': n.lat,
        'lng': n.lng,
        'status': n.status
    } for n in Node.objects.filter(name__icontains=what).exclude(
        status='u').only('name', 'slug', 'lat', 'lng', 'status')]
    data = data + [{
        'label': d.name,
        'value': jslugify(d.node.slug),
        'slug': d.node.slug,
        'name': d.node.name,
        'lat': d.node.lat,
        'lng': d.node.lng,
        'status': d.node.status
    } for d in Device.objects.filter(
        name__icontains=what).only('name', 'node__name', 'node__slug',
                                   'node__lat', 'node__lng', 'node__status')]
    data = data + [{
        'label': i.ipv4_address,
        'value': jslugify(i.device.node.slug),
        'slug': i.device.node.slug,
        'name': i.device.node.name,
        'lat': i.device.node.lat,
        'lng': i.device.node.lng,
        'status': i.device.node.status
    } for i in Interface.objects.filter(ipv4_address__icontains=what).only(
        'device__node__name', 'device__node__slug', 'device__node__lat',
        'device__node__lng', 'status')]
    data = data + [{
        'label': i.ipv6_address,
        'value': jslugify(i.device.node.slug),
        'slug': i.device.node.slug,
        'name': i.device.node.name,
        'lat': i.device.node.lat,
        'lng': i.device.node.lng,
        'status': i.device.node.status
    } for i in Interface.objects.filter(ipv6_address__icontains=what).only(
        'device__node__name', 'device__node__slug', 'device__node__lat',
        'device__node__lng', 'status')]
    data = data + [{
        'label': i.mac_address,
        'value': jslugify(i.device.node.slug),
        'slug': i.device.node.slug,
        'name': i.device.node.name,
        'lat': i.device.node.lat,
        'lng': i.device.node.lng,
        'status': i.device.node.status
    } for i in Interface.objects.filter(mac_address__icontains=what).only(
        'device__node__name', 'device__node__slug', 'device__node__lat',
        'device__node__lng', 'status')]
    # I think this is useless cos all our devices have ssid: ninux.org
    #data = data + [{'label': d.ssid , 'value': jslugify(d.device.node.slug), 'slug': d.device.node.slug, 'name': d.device.node.name, 'lat': d.device.node.lat, 'lng': d.device.node.lng, 'status': d.device.node.status }  for d in Interface.objects.filter(ssid__icontains=what).only('device__node__name','device__node__slug','device__node__lat','device__node__lng','status')]
    if len(data) > 0:
        return HttpResponse(simplejson.dumps(data),
                            mimetype='application/json')
    else:
        return HttpResponse('{}', mimetype='application/json')
Exemplo n.º 10
0
def jstree(request):
    """
    Populates jquery.jstree plugin
    """
    # retrieve nodes in 3 different objects depending on the status
    active = Node.objects.filter(Q(status='a') | Q(status='ah')).values(
        'name', 'slug', 'lng', 'lat', 'status').order_by(
            'name'
        )  # status is necessary to link "active & hotspot" nodes correctly
    hotspot = Node.objects.filter(Q(status='h') | Q(status='ah')).values(
        'name', 'slug', 'lng', 'lat').order_by('name')
    potential = Node.objects.filter(status='p').values('name', 'slug', 'lng',
                                                       'lat').order_by('name')
    # prepare empty lists
    data, active_list, hotspot_list, potential_list = [], [], [], []

    for a in active:
        # distinguish "active" from "active & hotspot"
        if a['status'] == 'a':
            status = 'active'
        elif a['status'] == 'ah':
            # treat "active & hotspot" like hotspots
            status = 'hotspot'

        active_list.append({
            'data': {
                'title': a['name'],
                'attr': {
                    'class':
                    'child',
                    'href':
                    'javascript:nodeshot.gmap.goToNode(nodeshot.nodes.%s.%s)' %
                    (status, jslugify(a['slug']))
                }
            }
        })
    if len(active_list) > 0:
        data.append({
            'data': ugettext('Active Nodes'),
            'state': 'open',
            'attr': {
                'class': 'active_nodes',
            },
            'children': list(active_list)
        })

    for h in hotspot:
        hotspot_list.append({
            'data': {
                'title': h['name'],
                'attr': {
                    'class':
                    'child',
                    'href':
                    'javascript:nodeshot.gmap.goToNode(nodeshot.nodes.hotspot.%s)'
                    % jslugify(h['slug'])
                }
            }
        })
    if len(hotspot_list) > 0:
        data.append({
            'data': ugettext('Hotspots'),
            'state': 'open',
            'attr': {
                'class': 'hotspot_nodes'
            },
            'children': list(hotspot_list)
        })

    for p in potential:
        potential_list.append({
            'data': {
                'title': p['name'],
                'attr': {
                    'class':
                    'child',
                    'href':
                    'javascript:nodeshot.gmap.goToNode(nodeshot.nodes.potential.%s)'
                    % jslugify(p['slug'])
                }
            }
        })
    if len(potential_list) > 0:
        data.append({
            'data': ugettext('Potential Nodes'),
            'state': 'open',
            'attr': {
                'class': 'potential_nodes'
            },
            'children': list(potential_list)
        })
    # return json
    return HttpResponse(simplejson.dumps(data), mimetype='application/json')