Skip to content
Browse files

Frontend improvement and missing math_captcha settings file

  • Loading branch information...
1 parent d937ad0 commit 530eca3fcd031016376ab5e5d46c88b1a785cc69 nemesisdesign committed
Showing with 101 additions and 34 deletions.
  1. +0 −1 math_captcha/settings.py
  2. +1 −0 nodeshot/forms.py
  3. +7 −1 nodeshot/models.py
  4. +93 −32 nodeshot/views.py
View
1 math_captcha/settings.py
@@ -1,6 +1,5 @@
from django.conf import settings
-
NUMBERS = getattr(settings, 'MATH_CAPTCHA_NUMBERS', range(1,6))
OPERATORS = getattr(settings, 'MATH_CAPTCHA_OPERATORS', '-+')
QUESTION = getattr(settings, 'MATH_CAPTCHA_QUESTION', 'Are you human?')
View
1 nodeshot/forms.py
@@ -109,6 +109,7 @@ def add_node(request):
# set node as unconfirmed, malicious users could edit the hidden input field easily with instruments like firebug.
node.status = 'u'
# generate slug
+ # TODO: remove this because is being done at model level
node.slug = slugify(node.name)
# save new node in the database (password encryption, activation_key and email notification is done in models.py)
node.save()
View
8 nodeshot/models.py
@@ -6,6 +6,7 @@
from django.core.mail import send_mail
from django.core.exceptions import ImproperlyConfigured
from django.template.loader import render_to_string
+from django.template.defaultfilters import slugify
from nodeshot.utils import notify_admins
# for UserProfile
@@ -298,6 +299,9 @@ def confirm(self):
def save(self):
''' Override the save method in order to generate the activation key for new nodes. '''
+ # generate slug if needed
+ if self.slug == '':
+ self.slug = slugify(self.name)
# if saving a new object
if self.pk is None and not IMPORTING:
self.set_activation_key()
@@ -413,7 +417,7 @@ class UserProfile(models.Model):
def notify_on_delete(sender, instance, using, **kwargs):
''' Notify admins when nodes are deleted. Only for production use '''
# if in testing mode don't send emails
- if DEBUG:
+ if DEBUG or IMPORTING:
return False
# if purging old unconfirmed nodes don't send emails
if instance.status == 'u' and instance.added + timedelta(days=ACTIVATION_DAYS) < datetime.now():
@@ -433,6 +437,8 @@ def notify_on_delete(sender, instance, using, **kwargs):
def update_statistics(sender, instance, using, **kwargs):
''' Adds a new record in the statistic table if needed. Called by signals '''
+ if IMPORTING:
+ return False
# retrieve links, select_related() reduces the number of queries, only() selects only the fields we need
links = Link.objects.all().select_related().only(
'from_interface__device__node__lat', 'from_interface__device__node__lng',
View
125 nodeshot/views.py
@@ -15,6 +15,7 @@
from django.core.exceptions import ObjectDoesNotExist
from forms import ContactForm, PasswordResetForm
from datetime import datetime, timedelta
+from django.db.models import Q
# retrieve map center or set default if not specified
try:
@@ -167,7 +168,6 @@ def generate_rrd(request):
return HttpResponse('Error')
def info(request):
- import logging
devices = Device.objects.all().order_by('node__name', 'added').select_related().only('name', 'type', 'node__name', 'node__status', 'node__slug');
new_devices = []
# loop over queryset
@@ -177,48 +177,109 @@ def info(request):
entry['status'] = 'on'
else:
entry['status'] = 'off'
+
+ interfaces = device.interface_set.all()
+
entry['device_type'] = device.type
entry['node'] = device.node
entry['name'] = device.name
- entry['ips'] = [ip['ipv4_address'] for ip in device.interface_set.values('ipv4_address')] if device.interface_set.count() > 0 else ""
- #entry['macs'] = [mac['mac_address'] if mac['mac_address'] != None else '' for mac in device.interface_set.values('mac_address')] if device.interface_set.count() > 0 else ""
+ ip_list = []
macs_list = []
- for interface in device.interface_set.all():
+ for interface in interfaces:
+ ip_list.append(interface.ipv4_address)
if interface.mac_address != None and interface.mac_address != '':
macs_list.append(interface.mac_address)
+ entry['ips'] = ip_list
entry['macs'] = macs_list
+
+ #entry['ips'] = [ip['ipv4_address'] for ip in device.interface_set.values('ipv4_address')] if device.interface_set.count() > 0 else ""
+ #entry['macs'] = [mac['mac_address'] if mac['mac_address'] != None else '' for mac in device.interface_set.values('mac_address')] if device.interface_set.count() > 0 else ""
+
+ links = Link.objects.filter(
+ Q(from_interface__device = device) | Q(to_interface__device = device)
+ ).select_related().only(
+ 'dbm',
+ 'from_interface__mac_address',
+ 'from_interface__device__node__name',
+ 'from_interface__device__node__slug',
+ 'to_interface__mac_address',
+ 'to_interface__device__node__name',
+ 'to_interface__device__node__slug'
+ )
+ import logging
+ #links_to = Link.objects.filter(to_interface__device = device).select_related().only('dbm', 'from_interface__mac_address', 'from_interface__device__node__name', 'from_interface__device__node__slug')
+ # evaluate QuerySet
+ links = list(links)
+ for link in links:
+ #logging.log(1, link.to_interface.device.node.name == device.node.name)
+ #logging.log(1, link.from_interface.device.node.name == device.node.name)
+ # if link is between same node skip
+ if(link.to_interface.device.node.id == device.node.id and link.from_interface.device.node.id == device.node.id):
+ if DEBUG:
+ #logging.log(1, 'duplicate for node %s' % device.node.name)
+ logging.log(1, 'removing link %s' % link)
+ links.remove(link)
+ #continue
+ if(link.from_interface.device.id == device.id):
+ if link.to_interface.mac_address not in entry['macs']:
+ link.signal_bar = signal_to_bar(link.dbm)
+ link.destination = {
+ 'name': link.to_interface.device.node.name,
+ 'slug': link.to_interface.device.node.slug
+ }
+
+ else:
+ links.remove(link)
+ elif(link.to_interface.device.id == device.id):
+ if link.from_interface.mac_address not in entry['macs']:
+ link.signal_bar = signal_to_bar(link.dbm)
+ link.destination = {
+ 'name': link.from_interface.device.node.name,
+ 'slug': link.from_interface.device.node.slug
+ }
+ else:
+ links.remove(link)
+ logging.log(1, 'adding link %s' % link)
+ #links_to = list(links_to)
+ #for link in links_to:
+ # if link.from_interface.mac_address not in entry['macs']:
+ # link.signal_bar = signal_to_bar(link.dbm)
+ # link.destination = {
+ # 'name': link.from_interface.device.node.name,
+ # 'slug': link.from_interface.device.node.slug
+ # }
+ # else:
+ # links_to.remove(link)
# heuristic count for good representation of the signal bar (from 0 to 100)
- links_from = Link.objects.filter(from_interface__device = device).select_related().only('dbm', 'to_interface__mac_address', 'to_interface__device__node__name', 'to_interface__device__node__slug')
- links_to = Link.objects.filter(to_interface__device = device).select_related().only('dbm', 'from_interface__mac_address', 'from_interface__device__node__name', 'from_interface__device__node__slug')
- # convert QuerySet in list
- links_from = list(links_from)
- for link in links_from:
- if link.to_interface.mac_address not in entry['macs']:
- link.signal_bar = signal_to_bar(link.dbm)
- link.destination = {
- 'name': link.to_interface.device.node.name,
- 'slug': link.to_interface.device.node.slug
- }
- #link.destination['name'] = link.to_interface.device.name
- #link.destination['slug'] = link.to_interface.device.slug
- else:
- links_from.remove(link)
- links_to = list(links_to)
- for link in links_to:
- if link.from_interface.mac_address not in entry['macs']:
- link.signal_bar = signal_to_bar(link.dbm)
- link.destination = {
- 'name': link.from_interface.device.node.name,
- 'slug': link.from_interface.device.node.slug
- }
- #link.destination['name'] = link.from_interface.device.name
- #link.destination['slug'] = link.from_interface.device.slug
- else:
- links_to.remove(link)
+ #links_from = Link.objects.filter(from_interface__device = device).select_related().only('dbm', 'to_interface__mac_address', 'to_interface__device__node__name', 'to_interface__device__node__slug')
+ #links_to = Link.objects.filter(to_interface__device = device).select_related().only('dbm', 'from_interface__mac_address', 'from_interface__device__node__name', 'from_interface__device__node__slug')
+ ## convert QuerySet in list
+ #links_from = list(links_from)
+ #for link in links_from:
+ # if link.to_interface.mac_address not in entry['macs']:
+ # link.signal_bar = signal_to_bar(link.dbm)
+ # link.destination = {
+ # 'name': link.to_interface.device.node.name,
+ # 'slug': link.to_interface.device.node.slug
+ # }
+ # else:
+ # links_from.remove(link)
+ #links_to = list(links_to)
+ #for link in links_to:
+ # if link.from_interface.mac_address not in entry['macs']:
+ # link.signal_bar = signal_to_bar(link.dbm)
+ # link.destination = {
+ # 'name': link.from_interface.device.node.name,
+ # 'slug': link.from_interface.device.node.slug
+ # }
+ # else:
+ # links_to.remove(link)
- entry['links'] = links_from + links_to
+ #entry['links'] = links_from + links_to
+
+ entry['links'] = links
#entry['ssids'] = [ssid['ssid'] for ssid in device.interface_set.values('ssid')] if device.interface_set.count() > 0 else ""
new_devices.append(entry)

0 comments on commit 530eca3

Please sign in to comment.
Something went wrong with that request. Please try again.