Changeset 9592


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

Organization needs to be a special Model to make fudgings around with it more easy.

Location:
src/django_gheat
Files:
2 added
7 edited

Legend:

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

    r9590 r9592  
    55  list_display = ['ssid','mac', 'organization']
    66  search_fields = ['ssid', 'mac', 'organization']
     7  ordering = ['ssid']
    78admin.site.register(Accespoint, AccespointAdmin)
    89
     
    1819admin.site.register(Node, NodeAdmin)
    1920
     21class OrganizationAdmin(admin.ModelAdmin):
     22  list_display = ['name']
     23  ordering = ['name']
     24admin.site.register(Organization, OrganizationAdmin)
     25
    2026admin.site.register(Apparatuur)
    2127admin.site.register(Gebruiker)
  • src/django_gheat/gheat/management/commands/import_droidstumbler.py

    r9579 r9592  
    4343  return count
    4444
     45organizations = dict(Organization.objects.all().values_list('name','id'))
     46def get_organization_id_by_ssid(ssid):
     47  name = Organization.get_name_by_ssid(ssid)
     48  if not name:
     49    return 'NULL'
     50  else:
     51    return int(organizations[name])
    4552
    4653def import_droidstumbler(filename, meetrondje):
     
    96103      ssid, encryption = ap_pool[bssid]
    97104      # Special trick in SSID ts avoid escaping in later stage
    98       item = str((bssid.upper(),ssid.replace('%','%%'),encryption,Accespoint.get_organization(ssid)))
     105      item = str((bssid.upper(),ssid.replace('%','%%'),encryption,get_organization_id_by_ssid(ssid)))
    99106      sql_values.append(item)
    100     counters['ap_added'] = bulk_sql('gheat_accespoint (`mac`, `ssid`, `encryptie`, `organization`)',sql_values)
     107    counters['ap_added'] = bulk_sql('gheat_accespoint (`mac`, `ssid`, `encryptie`, `organization_id`)',sql_values)
    101108
    102109  # Build mapping for meting import
  • src/django_gheat/gheat/management/commands/import_kismet.py

    r9579 r9592  
    1919from collections import defaultdict
    2020
    21 from import_droidstumbler import bulk_sql
     21from import_droidstumbler import bulk_sql,get_organization_id_by_ssid
    2222
    2323logger = logging.getLogger(__name__)
     
    7676      ssid, encryption = ap_pool[bssid]
    7777      # Special trick in SSID ts avoid escaping in later stage
    78       item = str((bssid.upper(),ssid.replace('%','%%'),encryption,Accespoint.get_organization(ssid)))
     78      item = str((bssid.upper(),ssid.replace('%','%%'),encryption,get_organization_id_by_ssid(ssid)))
    7979      sql_values.append(item)
    80     counters['ap_added'] = bulk_sql('gheat_accespoint (`mac`, `ssid`, `encryptie`, `organization`)',sql_values)
     80    counters['ap_added'] = bulk_sql('gheat_accespoint (`mac`, `ssid`, `encryptie`, `organization_id`)',sql_values)
    8181
    8282  # Determine which Wireless Clients to add
  • src/django_gheat/gheat/models.py

    r9590 r9592  
    5858
    5959
    60 ORGANIZATION_CHOICES = (
    61   ('WirelessLeiden', 'Wireless Leiden'),
    62 )
     60class Organization(models.Model):
     61  fullname = models.CharField(max_length=100,unique=True)
     62  name = models.CharField(max_length=100,unique=True)
     63  def __unicode__(self):
     64    return self.fullname
     65
     66  @staticmethod
     67  def get_name_by_ssid(ssid):
     68    """ Try to determine the organization via the SSID """
     69    name = None
     70    if ssid.startswith('ap') and ssid.endswith('wleiden.net'):
     71      name = 'WirelessLeiden'
     72    elif ssid.startswith('ap') and 'WirelessLeiden' in ssid:
     73      name = 'WirelessLeiden'
     74    return name
    6375
    6476class Node(models.Model):
     
    6678  latitude = models.FloatField(null=True,blank=True)
    6779  longitude = models.FloatField(null=True,blank=True)
    68   organization = models.CharField(max_length="50",choices=ORGANIZATION_CHOICES,null=True,blank=True)
     80  organization = models.ForeignKey(Organization,null=True, blank=True)
     81  class Meta:
     82    unique_together = ('name', 'organization')
     83
     84  def __unicode__(self):
     85    return "%s - %s" % (self.name, self.organization)
    6986
    7087class Accespoint(models.Model):
    7188  mac = models.CharField(max_length=17)
    7289  ssid = models.CharField(max_length=64)
    73   organization = models.CharField(max_length="50",choices=ORGANIZATION_CHOICES,null=True,blank=True)
     90  organization = models.ForeignKey(Organization,null=True, blank=True)
    7491  encryptie = models.BooleanField()
    7592  class Meta:
     
    7895    return "%s - %s" % (self.mac, self.ssid)
    7996
    80   @staticmethod
    81   def get_organization(ssid):
    82     """ Try to determine the organization via the SSID """
    83     organization = ''
    84     if ssid.startswith('ap') and ssid.endswith('wleiden.net'):
    85       organization = 'WirelessLeiden'
    86     elif ssid.startswith('ap') and 'WirelessLeiden' in ssid:
    87       organization = 'WirelessLeiden'
    88     return organization
    8997
    9098  def save(self, *args, **kwargs):
  • src/django_gheat/wlheatmap/filters.py

    r9579 r9592  
    2020      # Get list if accespoints found in the specific 'Meting', and make this is list.
    2121      wirelessleiden_ssid = Meting.objects.filter(meetrondje=mr,
    22         accespoint__organization='WirelessLeiden').\
     22        accespoint__organization__name='WirelessLeiden').\
    2323        values_list('accespoint__ssid',flat=True).\
    2424        order_by('accespoint__ssid').distinct()
  • src/django_gheat/wlheatmap/nodelist.py

    r9579 r9592  
    4040  filter = {}
    4141  filter.update({
    42     'organization' : 'WirelessLeiden',
     42    'organization__name' : 'WirelessLeiden',
    4343    'meting__latitude__lt' : maxlat,
    4444    'meting__longitude__lt' : maxlon,
  • src/django_gheat/wlheatmap/templates/js/LayerBase.js

    r9579 r9592  
    184184    initialize: function(name, options) {
    185185        var url = get_balanced_urls('http://', {{ settings.DJANGO_CDN_DOMAINS|safe }},
    186           '{{ settings.DJANGO_PREFIX }}/wlheatmap/tile/${z}/${x},${y}.png?colour=255,0,0&accespoint__organization=WirelessLeiden');
     186          '{{ settings.DJANGO_PREFIX }}/wlheatmap/tile/${z}/${x},${y}.png?colour=255,0,0&accespoint__organization__name=WirelessLeiden');
    187187        options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
    188188        var newArguments = [name, url, options];
Note: See TracChangeset for help on using the changeset viewer.