Changeset 9593 for src/django_gheat
- Timestamp:
- Aug 28, 2011, 1:34:06 PM (13 years ago)
- Location:
- src/django_gheat/gheat
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/gheat/admin.py
r9592 r9593 20 20 21 21 class OrganizationAdmin(admin.ModelAdmin): 22 list_display = ['name' ]22 list_display = ['name', 'fullname'] 23 23 ordering = ['name'] 24 24 admin.site.register(Organization, OrganizationAdmin) -
src/django_gheat/gheat/management/commands/import_nodes.py
r9590 r9593 3 3 # 4 4 # Script for importing nodes from yaml information generated by gformat.py 5 # 6 # Example: $ ~/wleiden/node-config/genesis/tools/gformat.py full-export | 7 # ./manage.py import_nodes - 5 8 # 6 9 # Rick van der Zwet <info@rickvanderzwet.nl> … … 25 28 args = '[<filename>]' 26 29 help = 'Specify - to read from stdin' 30 option_list = BaseCommand.option_list + ( 31 make_option('-g', '--debug', dest='debug', default='False', help="Debug", action="store_true"), 32 ) 27 33 28 34 def handle(self, *args, **options): 35 if options['debug']: 36 logger.setLevel(logging.DEBUG) 29 37 if len(args) == 0: 30 38 self.print_help(sys.argv[0],sys.argv[1]) … … 46 54 hosts = yaml.load(fh) 47 55 for host,items in hosts.iteritems(): 48 node, created = Node.objects.get_or_create(name=host, 49 latitude=items['latitude'],longitude=items['longitude']) 56 for iface_key in [x for x in items.keys() if x.startswith('iface_')]: 57 if items[iface_key].has_key('ssid'): 58 org = Organization.get_by_ssid(items[iface_key]['ssid']) 59 if org: break 60 logger.error("NO Organization for SSID '%s'", items[iface_key]['ssid']) 61 62 if not org: 63 logger.warning("NO Organization for Node '%s'", host) 64 65 node, created = Node.objects.get_or_create(name=host) 50 66 if created: 51 logger.info("Created Node '%s'" % node)) 52 logger.info("Processed %s items" % len(hosts)) 67 logger.info("Created Node '%s'", node) 68 node.latitude = items['latitude'] 69 node.longitude = items['longitude'] 70 node.organization = org 71 node.save() 72 logger.info("Processed %s items", len(hosts)) 53 73 -
src/django_gheat/gheat/models.py
r9592 r9593 67 67 def get_name_by_ssid(ssid): 68 68 """ Try to determine the organization via the SSID """ 69 ssid = ssid.lower() 69 70 name = None 70 71 if ssid.startswith('ap') and ssid.endswith('wleiden.net'): 71 72 name = 'WirelessLeiden' 72 elif ssid.startswith(' ap') and 'WirelessLeiden' in ssid:73 elif ssid.startswith('il-') and ssid.endswith('wleiden.net'): 73 74 name = 'WirelessLeiden' 75 elif ssid.startswith('ap') and 'wirelessleiden' in ssid: 76 name = 'WirelessLeiden' 77 elif ssid.startswith('ap-') and 'westeinder' in ssid: 78 name = 'WirelessPlassen' 79 elif ssid.endswith('walphen.net'): 80 name = 'WirelessAlphen' 81 elif 'wirelessarnhem' in ssid: 82 name = 'WirelessArnhem' 74 83 return name 75 84 85 @staticmethod 86 def get_by_ssid(ssid): 87 name = Organization.get_name_by_ssid(ssid) 88 if not name: 89 return None 90 else: 91 return Organization.objects.get(name=name) 92 93 76 94 class Node(models.Model): 77 name = models.CharField(max_length=50 )95 name = models.CharField(max_length=50, unique=True) 78 96 latitude = models.FloatField(null=True,blank=True) 79 97 longitude = models.FloatField(null=True,blank=True) 80 98 organization = models.ForeignKey(Organization,null=True, blank=True) 81 class Meta:82 unique_together = ('name', 'organization')83 99 84 100 def __unicode__(self): -
src/django_gheat/gheat/sql/organization.sql
r9592 r9593 1 INSERT INTO `gheat_organization` VALUES (1,'Stichting Wireless Leiden','WirelessLeiden') ;1 INSERT INTO `gheat_organization` VALUES (1,'Stichting Wireless Leiden','WirelessLeiden'),(2,'Stichting Wireless Arnhem','WirelessArnhem'),(3,'Stichting Wireless Kaag & Braassem','WirelessPlassen'),(4,'Stichting Wireless Alphen','WirelessAlphen');
Note:
See TracChangeset
for help on using the changeset viewer.