Changeset 17c118f


Ignore:
Timestamp:
Jun 5, 2013, 6:42:54 AM (12 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, stable, stage
Children:
d983e4f, 53e624e
Parents:
ecf87c8
git-author:
Alex Dehnert <adehnert@…> (06/05/13 06:33:23)
git-committer:
Alex Dehnert <adehnert@…> (06/05/13 06:42:54)
Message:

Create rooms if missing while setting lock_type

Apparently 50-020 is in some, but not all, instances of the DB. This makes sure
that it will get created, rather than failing the migration. (We could just
leave it missing and ignore the error, but it seems nice to include all access
type info we can get.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/space/migrations/0006_lock_types_setup.py

    r30256e2 r17c118f  
    8888        spaces.filter(number__startswith='50-').update(lock_type=lock_types.get(slug='unknown'))
    8989        spaces.filter(number__startswith='N52-').update(lock_type=lock_types.get(slug='semo'))
     90        created_rooms = []
    9091        for room, lock_type in room_lock_types:
    9192            print "Setting room=%s's lock_type to %s" % (room, lock_type, )
    92             room_obj = spaces.get(number=room)
    93             room_obj.lock_type = lock_types.get(slug=lock_type)
     93            lt_obj = lock_types.get(slug=lock_type)
     94            room_obj, created = spaces.get_or_create(number=room, defaults=dict(lock_type=lt_obj))
     95            if created: created_rooms.append(room_obj)
     96            room_obj.lock_type = lt_obj
    9497            room_obj.save()
     98
     99        for room_obj in created_rooms:
     100            print "Created %s while setting lock_type" % (room_obj.number, )
    95101
    96102
Note: See TracChangeset for help on using the changeset viewer.