Changeset 9593


Ignore:
Timestamp:
Aug 28, 2011, 1:34:06 PM (13 years ago)
Author:
rick
Message:

Fix the organization imports

Location:
src/django_gheat/gheat
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/admin.py

    r9592 r9593  
    2020
    2121class OrganizationAdmin(admin.ModelAdmin):
    22   list_display = ['name']
     22  list_display = ['name', 'fullname']
    2323  ordering = ['name']
    2424admin.site.register(Organization, OrganizationAdmin)
  • src/django_gheat/gheat/management/commands/import_nodes.py

    r9590 r9593  
    33#
    44# 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 -
    58#
    69# Rick van der Zwet <info@rickvanderzwet.nl>
     
    2528  args = '[<filename>]'
    2629  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  )
    2733
    2834  def handle(self, *args, **options):
     35    if options['debug']:
     36      logger.setLevel(logging.DEBUG)
    2937    if len(args) == 0:
    3038      self.print_help(sys.argv[0],sys.argv[1])
     
    4654    hosts = yaml.load(fh)
    4755    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)
    5066      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))
    5373
  • src/django_gheat/gheat/models.py

    r9592 r9593  
    6767  def get_name_by_ssid(ssid):
    6868    """ Try to determine the organization via the SSID """
     69    ssid = ssid.lower()
    6970    name = None
    7071    if ssid.startswith('ap') and ssid.endswith('wleiden.net'):
    7172      name = 'WirelessLeiden'
    72     elif ssid.startswith('ap') and 'WirelessLeiden' in ssid:
     73    elif ssid.startswith('il-') and ssid.endswith('wleiden.net'):
    7374      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'
    7483    return name
    7584
     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
    7694class Node(models.Model):
    77   name = models.CharField(max_length=50)
     95  name = models.CharField(max_length=50, unique=True)
    7896  latitude = models.FloatField(null=True,blank=True)
    7997  longitude = models.FloatField(null=True,blank=True)
    8098  organization = models.ForeignKey(Organization,null=True, blank=True)
    81   class Meta:
    82     unique_together = ('name', 'organization')
    8399
    84100  def __unicode__(self):
  • src/django_gheat/gheat/sql/organization.sql

    r9592 r9593  
    1 INSERT INTO `gheat_organization` VALUES (1,'Stichting Wireless Leiden','WirelessLeiden');
     1INSERT 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.