Merge lp:~ricardokirkner/django-openid-auth/compatible-sqlite-migration into lp:~django-openid-auth/django-openid-auth/trunk

Proposed by Ricardo Kirkner
Status: Merged
Approved by: Ricardo Kirkner
Approved revision: 113
Merged at revision: 112
Proposed branch: lp:~ricardokirkner/django-openid-auth/compatible-sqlite-migration
Merge into: lp:~django-openid-auth/django-openid-auth/trunk
Diff against target: 31 lines (+9/-7)
1 file modified
django_openid_auth/migrations/0002_add_perm_account_verified.py (+9/-7)
To merge this branch: bzr merge lp:~ricardokirkner/django-openid-auth/compatible-sqlite-migration
Reviewer Review Type Date Requested Status
Fabián Ezequiel Gallina (community) Approve
django-openid-auth developers Pending
Review via email: mp+232796@code.launchpad.net

Commit message

make migration more generic and compatible with sqlite

Description of the change

Ensures that all Permission objects for models are up to date.

Given this is Django a version updgrade, and there's a South
bug[0] that won't let it track the permissions Meta for
models, we need to ensure all of them get synced correctly for
all installed apps.

[0] http://south.aeracode.org/ticket/211

To post a comment you must log in.
113. By Ricardo Kirkner

fix extra whitespace

Revision history for this message
Fabián Ezequiel Gallina (fgallina) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'django_openid_auth/migrations/0002_add_perm_account_verified.py'
2--- django_openid_auth/migrations/0002_add_perm_account_verified.py 2014-08-29 16:50:41 +0000
3+++ django_openid_auth/migrations/0002_add_perm_account_verified.py 2014-09-01 11:42:01 +0000
4@@ -2,18 +2,20 @@
5 from south.utils import datetime_utils as datetime
6 from south.db import db
7 from south.v2 import DataMigration
8-from django.db import models
9+from django.contrib.auth.management import create_permissions
10+from django.db import transaction
11+from django.db.models import get_app, get_models
12
13 class Migration(DataMigration):
14
15 def forwards(self, orm):
16 "Write your forwards methods here."
17- ct, created = orm['contenttypes.ContentType'].objects.get_or_create(
18- model='useropenid', app_label='django_openid_auth',
19- defaults=dict(name='user open id'))
20- perm, created = orm['auth.permission'].objects.get_or_create(
21- content_type=ct, codename='account_verified',
22- defaults=dict(name=u'The OpenID account has been verified'))
23+ models = get_models()
24+ apps = [get_app(model._meta.app_label) for model in models]
25+ for app in apps:
26+ # Safeguard for sqlite. See http://bit.ly/1rRHC9Y
27+ with transaction.autocommit():
28+ create_permissions(app, models, verbosity=0)
29
30 def backwards(self, orm):
31 "Write your backwards methods here."

Subscribers

People subscribed via source and target branches