Skip to content

Commit

Permalink
Ensure that a shortName is assigned to a every MapSet before save.
Browse files Browse the repository at this point in the history
  • Loading branch information
deleted committed Jul 25, 2012
1 parent 1440d36 commit 9d1f213
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions geocamMapSet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse

from django.db.models.signals import pre_save
from django.dispatch import receiver

from geocamUtil import anyjson as json
from geocamMapSet import settings
storage_backend = getattr(settings, 'STORAGE_BACKEND', None)
Expand Down Expand Up @@ -166,6 +169,15 @@ def fromJSON(cls, userName, shortName, obj):
class Meta:
ordering = ['-mtime']

@receiver(pre_save, sender=MapSet)
def mapset_pre_save(sender, instance, raw, *args, **kwargs):
'''
Pre-save signal handler.
Ensure that a shortName is assigned before save.
'''
if not raw:
if not instance.shortName:
instance.shortName = sender.shortNameFromName(instance.name)

class MapSetLayer(models.Model):
name = models.CharField(primary_key=True, max_length=255)
Expand Down

0 comments on commit 9d1f213

Please sign in to comment.