commit 16cf0f730f4a95dab2407cae208bd1d98781a287
Author: Sofia Papagiannaki <papagian@gmail.com>
Date:   Tue Dec 4 14:22:28 2012 +0200

    Fix migrations

diff --git a/snf-astakos-app/astakos/im/migrations/0015_auto__add_groupkind__add_astakosgroup__add_resourcemetadata__add_astak.py b/snf-astakos-app/astakos/im/migrations/0015_auto__add_groupkind__add_astakosgroup__add_resourcemetadata__add_astak.py
index 53bb523..109ecbe 100644
--- a/snf-astakos-app/astakos/im/migrations/0015_auto__add_groupkind__add_astakosgroup__add_resourcemetadata__add_astak.py
+++ b/snf-astakos-app/astakos/im/migrations/0015_auto__add_groupkind__add_astakosgroup__add_resourcemetadata__add_astak.py
@@ -4,62 +4,45 @@ from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
 
-
 class Migration(SchemaMigration):
 
     def forwards(self, orm):
-
+        
         # Adding model 'GroupKind'
         db.create_table('im_groupkind', (
-            ('id', self.gf(
-                'django.db.models.fields.AutoField')(primary_key=True)),
-            ('name', self.gf('django.db.models.fields.CharField')
-             (unique=True, max_length=255, db_index=True)),
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255, db_index=True)),
         ))
         db.send_create_signal('im', ['GroupKind'])
 
         # Adding model 'AstakosGroup'
         db.create_table('im_astakosgroup', (
             ('group_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.Group'], unique=True, primary_key=True)),
-            ('kind', self.gf('django.db.models.fields.related.ForeignKey')
-             (to=orm['im.GroupKind'])),
+            ('kind', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.GroupKind'])),
             ('desc', self.gf('django.db.models.fields.TextField')(null=True)),
-            ('creation_date', self.gf('django.db.models.fields.DateTimeField')
-             (default=datetime.datetime(2012, 8, 3, 11, 26, 47, 642626))),
-            ('issue_date', self.gf(
-                'django.db.models.fields.DateTimeField')(null=True)),
-            ('expiration_date', self.gf(
-                'django.db.models.fields.DateTimeField')(null=True)),
-            ('moderation_enabled', self.gf(
-                'django.db.models.fields.BooleanField')(default=False)),
-            ('approval_date', self.gf('django.db.models.fields.DateTimeField')
-             (null=True, blank=True)),
-            ('estimated_participants', self.gf(
-                'django.db.models.fields.PositiveIntegerField')(null=True)),
+            ('creation_date', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime(2012, 12, 4, 9, 50, 9, 334623))),
+            ('issue_date', self.gf('django.db.models.fields.DateTimeField')(null=True)),
+            ('expiration_date', self.gf('django.db.models.fields.DateTimeField')(null=True)),
+            ('moderation_enabled', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('approval_date', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)),
+            ('estimated_participants', self.gf('django.db.models.fields.PositiveIntegerField')(null=True)),
         ))
         db.send_create_signal('im', ['AstakosGroup'])
 
         # Adding model 'ResourceMetadata'
         db.create_table('im_resourcemetadata', (
-            ('id', self.gf(
-                'django.db.models.fields.AutoField')(primary_key=True)),
-            ('key', self.gf('django.db.models.fields.CharField')
-             (unique=True, max_length=255, db_index=True)),
-            ('value', self.gf(
-                'django.db.models.fields.CharField')(max_length=255)),
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('key', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255, db_index=True)),
+            ('value', self.gf('django.db.models.fields.CharField')(max_length=255)),
         ))
         db.send_create_signal('im', ['ResourceMetadata'])
 
         # Adding model 'AstakosGroupQuota'
         db.create_table('im_astakosgroupquota', (
-            ('id', self.gf(
-                'django.db.models.fields.AutoField')(primary_key=True)),
-            ('limit', self.gf(
-                'django.db.models.fields.PositiveIntegerField')()),
-            ('resource', self.gf('django.db.models.fields.related.ForeignKey')
-             (to=orm['im.Resource'])),
-            ('group', self.gf('django.db.models.fields.related.ForeignKey')
-             (to=orm['im.AstakosGroup'], blank=True)),
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('limit', self.gf('django.db.models.fields.PositiveIntegerField')()),
+            ('resource', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.Resource'])),
+            ('group', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.AstakosGroup'], blank=True)),
         ))
         db.send_create_signal('im', ['AstakosGroupQuota'])
 
@@ -68,38 +51,27 @@ class Migration(SchemaMigration):
 
         # Adding model 'Resource'
         db.create_table('im_resource', (
-            ('id', self.gf(
-                'django.db.models.fields.AutoField')(primary_key=True)),
-            ('name', self.gf('django.db.models.fields.CharField')
-             (unique=True, max_length=255, db_index=True)),
-            ('service', self.gf('django.db.models.fields.related.ForeignKey')
-             (to=orm['im.Service'])),
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255, db_index=True)),
+            ('service', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.Service'])),
         ))
         db.send_create_signal('im', ['Resource'])
 
         # Adding M2M table for field meta on 'Resource'
         db.create_table('im_resource_meta', (
-            ('id', models.AutoField(
-                verbose_name='ID', primary_key=True, auto_created=True)),
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
             ('resource', models.ForeignKey(orm['im.resource'], null=False)),
-            ('resourcemetadata', models.ForeignKey(orm[
-             'im.resourcemetadata'], null=False))
+            ('resourcemetadata', models.ForeignKey(orm['im.resourcemetadata'], null=False))
         ))
-        db.create_unique(
-            'im_resource_meta', ['resource_id', 'resourcemetadata_id'])
+        db.create_unique('im_resource_meta', ['resource_id', 'resourcemetadata_id'])
 
         # Adding model 'Membership'
         db.create_table('im_membership', (
-            ('id', self.gf(
-                'django.db.models.fields.AutoField')(primary_key=True)),
-            ('person', self.gf('django.db.models.fields.related.ForeignKey')
-             (to=orm['im.AstakosUser'])),
-            ('group', self.gf('django.db.models.fields.related.ForeignKey')
-             (to=orm['im.AstakosGroup'])),
-            ('date_requested', self.gf('django.db.models.fields.DateField')
-             (default=datetime.datetime(2012, 8, 3, 11, 26, 47, 646518))),
-            ('date_joined', self.gf('django.db.models.fields.DateField')
-             (null=True, db_index=True)),
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('person', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.AstakosUser'])),
+            ('group', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.AstakosGroup'])),
+            ('date_requested', self.gf('django.db.models.fields.DateField')(default=datetime.datetime(2012, 12, 4, 9, 50, 9, 338510))),
+            ('date_joined', self.gf('django.db.models.fields.DateField')(null=True, db_index=True)),
         ))
         db.send_create_signal('im', ['Membership'])
 
@@ -108,14 +80,10 @@ class Migration(SchemaMigration):
 
         # Adding model 'AstakosUserQuota'
         db.create_table('im_astakosuserquota', (
-            ('id', self.gf(
-                'django.db.models.fields.AutoField')(primary_key=True)),
-            ('limit', self.gf(
-                'django.db.models.fields.PositiveIntegerField')()),
-            ('resource', self.gf('django.db.models.fields.related.ForeignKey')
-             (to=orm['im.Resource'])),
-            ('user', self.gf('django.db.models.fields.related.ForeignKey')
-             (to=orm['im.AstakosUser'])),
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('limit', self.gf('django.db.models.fields.PositiveIntegerField')()),
+            ('resource', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.Resource'])),
+            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.AstakosUser'])),
         ))
         db.send_create_signal('im', ['AstakosUserQuota'])
 
@@ -127,18 +95,15 @@ class Migration(SchemaMigration):
 
         # Adding M2M table for field owner on 'AstakosUser'
         db.create_table('im_astakosuser_owner', (
-            ('id', models.AutoField(
-                verbose_name='ID', primary_key=True, auto_created=True)),
-            ('astakosuser', models.ForeignKey(orm[
-             'im.astakosuser'], null=False)),
-            ('astakosgroup', models.ForeignKey(orm[
-             'im.astakosgroup'], null=False))
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('astakosuser', models.ForeignKey(orm['im.astakosuser'], null=False)),
+            ('astakosgroup', models.ForeignKey(orm['im.astakosgroup'], null=False))
         ))
-        db.create_unique(
-            'im_astakosuser_owner', ['astakosuser_id', 'astakosgroup_id'])
+        db.create_unique('im_astakosuser_owner', ['astakosuser_id', 'astakosgroup_id'])
 
-    def backwards(self, orm):
 
+    def backwards(self, orm):
+        
         # Removing index on 'Service', fields ['name']
         db.delete_index('im_service', ['name'])
 
@@ -178,6 +143,7 @@ class Migration(SchemaMigration):
         # Removing M2M table for field owner on 'AstakosUser'
         db.delete_table('im_astakosuser_owner')
 
+
     models = {
         'auth.group': {
             'Meta': {'object_name': 'Group'},
diff --git a/snf-astakos-app/astakos/im/migrations/0017_populate_resource_data.py b/snf-astakos-app/astakos/im/migrations/0017_populate_resource_data.py
index 987e5b4..04b8ded 100644
--- a/snf-astakos-app/astakos/im/migrations/0017_populate_resource_data.py
+++ b/snf-astakos-app/astakos/im/migrations/0017_populate_resource_data.py
@@ -2,16 +2,76 @@
 
 from south.v2 import DataMigration
 
+from astakos.im.settings import SERVICES
+
+import logging
+
+logger = logging.getLogger(__name__)
 
 class Migration(DataMigration):
 
     def forwards(self, orm):
-        "Obsolete migration."
-        return
+        "Write your forwards methods here."
+
+        try:
+            default = orm.AstakosGroup.objects.get(name='default')
+        except orm.AstakosGroup.DoesNotExist:
+            return
+
+        def create_policies(args):
+            sn, dict = args
+            url = dict.get('url')
+            resources = dict.get('resources') or ()
+            s, created = orm.Service.objects.get_or_create(
+                name=sn,
+                defaults={'url': url}
+            )
+            
+            for r in resources:
+                try:
+                    rn = r.pop('name', '')
+                    uplimit = r.pop('uplimit', None)
+                    r, created = orm.Resource.objects.get_or_create(
+                        service=s,
+                        name=rn,
+                        defaults=r)
+                except Exception, e:
+                    print "Cannot create resource ", rn
+                    continue
+                else:
+                    q, created = orm.AstakosGroupQuota.objects.get_or_create(
+                        group=default,
+                        resource=r,
+                        defaults={
+                            'uplimit':uplimit,
+                        }
+                    )
+        map(create_policies, SERVICES.iteritems())
 
     def backwards(self, orm):
-        "Obsolete migration."
-        return
+        try:
+            default = orm.AstakosGroup.objects.get(name='default')
+        except orm.AstakosGroup.DoesNotExist:
+            return
+
+        def destroy_policies(args):
+            sn, dict = args
+            url = dict.get('url')
+            resources = dict.get('resources') or ()
+            for r in resources:
+                rn = r.get('name', '')
+                try:
+                    q = orm.AstakosGroupQuota.objects.get(
+                        group=default,
+                        resource__name=rn)
+                    q.delete()
+                    q = orm.Resource.objects.get(service__name=sn, name=rn)
+                    q.delete()
+                except Exception, e:
+                    print "Cannot create resource ", rn
+                    continue
+
+        map(destroy_policies, SERVICES.iteritems())
 
     models = {
         'auth.group': {
diff --git a/snf-astakos-app/astakos/im/migrations/0018_auto__add_field_astakosgroup_homepage.py b/snf-astakos-app/astakos/im/migrations/0018_auto__add_field_astakosgroup_homepage.py
index 3632df1..92ce2b7 100644
--- a/snf-astakos-app/astakos/im/migrations/0018_auto__add_field_astakosgroup_homepage.py
+++ b/snf-astakos-app/astakos/im/migrations/0018_auto__add_field_astakosgroup_homepage.py
@@ -4,19 +4,20 @@ from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
 
-
 class Migration(SchemaMigration):
 
     def forwards(self, orm):
-
+        
         # Adding field 'AstakosGroup.homepage'
         db.add_column('im_astakosgroup', 'homepage', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True), keep_default=False)
 
-    def backwards(self, orm):
 
+    def backwards(self, orm):
+        
         # Deleting field 'AstakosGroup.homepage'
         db.delete_column('im_astakosgroup', 'homepage')
 
+
     models = {
         'auth.group': {
             'Meta': {'object_name': 'Group'},
diff --git a/snf-astakos-app/astakos/im/migrations/0020_auto__chg_field_astakosgroup_homepage.py b/snf-astakos-app/astakos/im/migrations/0020_auto__chg_field_astakosgroup_homepage.py
index feffd45..06eed7a 100644
--- a/snf-astakos-app/astakos/im/migrations/0020_auto__chg_field_astakosgroup_homepage.py
+++ b/snf-astakos-app/astakos/im/migrations/0020_auto__chg_field_astakosgroup_homepage.py
@@ -4,20 +4,19 @@ from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
 
-
 class Migration(SchemaMigration):
 
     def forwards(self, orm):
-
+        
         # Changing field 'AstakosGroup.homepage'
-        db.alter_column('im_astakosgroup', 'homepage', self.gf(
-            'django.db.models.fields.URLField')(max_length=255, null=True))
+        db.alter_column('im_astakosgroup', 'homepage', self.gf('django.db.models.fields.URLField')(max_length=255, null=True))
 
-    def backwards(self, orm):
 
+    def backwards(self, orm):
+        
         # Changing field 'AstakosGroup.homepage'
-        db.alter_column('im_astakosgroup', 'homepage', self.gf(
-            'django.db.models.fields.CharField')(max_length=255, null=True))
+        db.alter_column('im_astakosgroup', 'homepage', self.gf('django.db.models.fields.CharField')(max_length=255, null=True))
+
 
     models = {
         'auth.group': {
diff --git a/snf-astakos-app/astakos/im/migrations/0021_auto__add_field_astakosgroupquota_uplimit__add_field_astakosuserquota_.py b/snf-astakos-app/astakos/im/migrations/0021_auto__add_field_astakosgroupquota_uplimit__add_field_astakosuserquota_.py
index 688cfa6..99cfcf1 100644
--- a/snf-astakos-app/astakos/im/migrations/0021_auto__add_field_astakosgroupquota_uplimit__add_field_astakosuserquota_.py
+++ b/snf-astakos-app/astakos/im/migrations/0021_auto__add_field_astakosgroupquota_uplimit__add_field_astakosuserquota_.py
@@ -4,25 +4,26 @@ from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
 
-
 class Migration(SchemaMigration):
 
     def forwards(self, orm):
-
+        
         # Adding field 'AstakosGroupQuota.uplimit'
         db.add_column('im_astakosgroupquota', 'uplimit', self.gf('django.db.models.fields.BigIntegerField')(null=True), keep_default=False)
 
         # Adding field 'AstakosUserQuota.uplimit'
         db.add_column('im_astakosuserquota', 'uplimit', self.gf('django.db.models.fields.BigIntegerField')(null=True), keep_default=False)
 
-    def backwards(self, orm):
 
+    def backwards(self, orm):
+        
         # Deleting field 'AstakosGroupQuota.uplimit'
         db.delete_column('im_astakosgroupquota', 'uplimit')
 
         # Deleting field 'AstakosUserQuota.uplimit'
         db.delete_column('im_astakosuserquota', 'uplimit')
 
+
     models = {
         'auth.group': {
             'Meta': {'object_name': 'Group'},
diff --git a/snf-astakos-app/astakos/im/migrations/0024_auto__chg_field_astakosgroupquota_lim.py b/snf-astakos-app/astakos/im/migrations/0024_auto__chg_field_astakosgroupquota_lim.py
index e4fe68a..ff4cba2 100644
--- a/snf-astakos-app/astakos/im/migrations/0024_auto__chg_field_astakosgroupquota_lim.py
+++ b/snf-astakos-app/astakos/im/migrations/0024_auto__chg_field_astakosgroupquota_lim.py
@@ -4,28 +4,25 @@ from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
 
-
 class Migration(SchemaMigration):
 
     def forwards(self, orm):
-
+        
         # Changing field 'AstakosGroupQuota.limit'
-        db.alter_column('im_astakosgroupquota', 'limit', self.gf(
-            'django.db.models.fields.PositiveIntegerField')(null=True))
+        db.alter_column('im_astakosgroupquota', 'limit', self.gf('django.db.models.fields.PositiveIntegerField')(null=True))
 
         # Changing field 'AstakosUserQuota.limit'
-        db.alter_column('im_astakosuserquota', 'limit', self.gf(
-            'django.db.models.fields.PositiveIntegerField')(null=True))
+        db.alter_column('im_astakosuserquota', 'limit', self.gf('django.db.models.fields.PositiveIntegerField')(null=True))
+
 
     def backwards(self, orm):
-        pass
-#        # Changing field 'AstakosGroupQuota.limit'
-#         db.alter_column('im_astakosgroupquota', 'limit', self.gf(
-#             'django.db.models.fields.PositiveIntegerField')(default=None))
-#
-#        # Changing field 'AstakosUserQuota.limit'
-#         db.alter_column('im_astakosuserquota', 'limit', self.gf(
-#             'django.db.models.fields.PositiveIntegerField')(default=None))
+        
+        # Changing field 'AstakosGroupQuota.limit'
+        db.alter_column('im_astakosgroupquota', 'limit', self.gf('django.db.models.fields.PositiveIntegerField')(default=None))
+
+        # Changing field 'AstakosUserQuota.limit'
+        db.alter_column('im_astakosuserquota', 'limit', self.gf('django.db.models.fields.PositiveIntegerField')(default=None))
+
 
     models = {
         'auth.group': {
diff --git a/snf-astakos-app/astakos/im/migrations/0025_case_insensitive_emails.py b/snf-astakos-app/astakos/im/migrations/0025_case_insensitive_emails.py
index 9e530b6..3e03cc5 100644
--- a/snf-astakos-app/astakos/im/migrations/0025_case_insensitive_emails.py
+++ b/snf-astakos-app/astakos/im/migrations/0025_case_insensitive_emails.py
@@ -1,11 +1,10 @@
 # encoding: utf-8
 import datetime
 from south.db import db
-from south.v2 import DataMigration
+from south.v2 import SchemaMigration
 from django.db import models
 
-
-class Migration(DataMigration):
+class Migration(SchemaMigration):
 
     def forwards(self, orm):
         "Write your forwards methods here."
@@ -13,8 +12,10 @@ class Migration(DataMigration):
             u.email = u.email.lower()
             u.save()
 
+
     def backwards(self, orm):
-        "Write your backwards methods here."
+        pass
+
 
     models = {
         'auth.group': {
diff --git a/snf-astakos-app/astakos/im/migrations/0026_auto__add_field_resource_desc__add_field_resource_unit.py b/snf-astakos-app/astakos/im/migrations/0026_auto__add_field_resource_desc__add_field_resource_unit.py
index 789da9e..ef8c740 100644
--- a/snf-astakos-app/astakos/im/migrations/0026_auto__add_field_resource_desc__add_field_resource_unit.py
+++ b/snf-astakos-app/astakos/im/migrations/0026_auto__add_field_resource_desc__add_field_resource_unit.py
@@ -4,25 +4,26 @@ from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
 
-
 class Migration(SchemaMigration):
 
     def forwards(self, orm):
-
+        
         # Adding field 'Resource.desc'
         db.add_column('im_resource', 'desc', self.gf('django.db.models.fields.TextField')(null=True), keep_default=False)
 
         # Adding field 'Resource.unit'
         db.add_column('im_resource', 'unit', self.gf('django.db.models.fields.CharField')(max_length=255, null=True), keep_default=False)
 
-    def backwards(self, orm):
 
+    def backwards(self, orm):
+        
         # Deleting field 'Resource.desc'
         db.delete_column('im_resource', 'desc')
 
         # Deleting field 'Resource.unit'
         db.delete_column('im_resource', 'unit')
 
+
     models = {
         'auth.group': {
             'Meta': {'object_name': 'Group'},
diff --git a/snf-astakos-app/astakos/im/migrations/0031_auto__add_sessioncatalog__add_pendingthirdpartyuser__add_unique_pendin.py b/snf-astakos-app/astakos/im/migrations/0031_auto__add_sessioncatalog__add_pendingthirdpartyuser__add_unique_pendin.py
index b2469bc..26bc630 100644
--- a/snf-astakos-app/astakos/im/migrations/0031_auto__add_sessioncatalog__add_pendingthirdpartyuser__add_unique_pendin.py
+++ b/snf-astakos-app/astakos/im/migrations/0031_auto__add_sessioncatalog__add_pendingthirdpartyuser__add_unique_pendin.py
@@ -8,14 +8,6 @@ class Migration(SchemaMigration):
 
     def forwards(self, orm):
         
-        # Adding model 'SessionCatalog'
-        db.create_table('im_sessioncatalog', (
-            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('session_key', self.gf('django.db.models.fields.CharField')(max_length=40)),
-            ('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='sessions', null=True, to=orm['im.AstakosUser'])),
-        ))
-        db.send_create_signal('im', ['SessionCatalog'])
-
         # Adding model 'PendingThirdPartyUser'
         db.create_table('im_pendingthirdpartyuser', (
             ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
@@ -32,18 +24,26 @@ class Migration(SchemaMigration):
         # Adding unique constraint on 'PendingThirdPartyUser', fields ['provider', 'third_party_identifier']
         db.create_unique('im_pendingthirdpartyuser', ['provider', 'third_party_identifier'])
 
+        # Adding model 'SessionCatalog'
+        db.create_table('im_sessioncatalog', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('session_key', self.gf('django.db.models.fields.CharField')(max_length=40)),
+            ('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='sessions', null=True, to=orm['im.AstakosUser'])),
+        ))
+        db.send_create_signal('im', ['SessionCatalog'])
+
 
     def backwards(self, orm):
         
         # Removing unique constraint on 'PendingThirdPartyUser', fields ['provider', 'third_party_identifier']
         db.delete_unique('im_pendingthirdpartyuser', ['provider', 'third_party_identifier'])
 
-        # Deleting model 'SessionCatalog'
-        db.delete_table('im_sessioncatalog')
-
         # Deleting model 'PendingThirdPartyUser'
         db.delete_table('im_pendingthirdpartyuser')
 
+        # Deleting model 'SessionCatalog'
+        db.delete_table('im_sessioncatalog')
+
 
     models = {
         'auth.group': {
diff --git a/snf-astakos-app/astakos/im/migrations/0032_auto__add_astakosuserauthprovider__add_unique_astakosuserauthprovider_.py b/snf-astakos-app/astakos/im/migrations/0032_auto__add_astakosuserauthprovider__add_unique_astakosuserauthprovider_.py
index cb01f32..8aa941a 100644
--- a/snf-astakos-app/astakos/im/migrations/0032_auto__add_astakosuserauthprovider__add_unique_astakosuserauthprovider_.py
+++ b/snf-astakos-app/astakos/im/migrations/0032_auto__add_astakosuserauthprovider__add_unique_astakosuserauthprovider_.py
@@ -45,7 +45,7 @@ class Migration(SchemaMigration):
         db.delete_table('im_astakosuserauthprovider')
 
         # Changing field 'AstakosUser.affiliation'
-        db.alter_column('im_astakosuser', 'affiliation', self.gf('django.db.models.fields.CharField')(default='', max_length=255))
+        db.alter_column('im_astakosuser', 'affiliation', self.gf('django.db.models.fields.CharField')(default='', max_length=255, null=True))
 
         # Changing field 'AstakosUser.provider'
         db.alter_column('im_astakosuser', 'provider', self.gf('django.db.models.fields.CharField')(default='', max_length=255))
diff --git a/snf-astakos-app/astakos/im/migrations/0033_multiple_auth_providers.py b/snf-astakos-app/astakos/im/migrations/0033_multiple_auth_providers.py
index c298d16..09ec5f1 100644
--- a/snf-astakos-app/astakos/im/migrations/0033_multiple_auth_providers.py
+++ b/snf-astakos-app/astakos/im/migrations/0033_multiple_auth_providers.py
@@ -27,6 +27,7 @@ class Migration(DataMigration):
 
             user.save()
 
+
     models = {
         'auth.group': {
             'Meta': {'object_name': 'Group'},
@@ -35,7 +36,7 @@ class Migration(DataMigration):
             'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
         },
         'auth.permission': {
-            'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
             'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
             'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
@@ -48,9 +49,9 @@ class Migration(DataMigration):
             'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
             'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
-            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
-            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
             'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
             'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
             'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
@@ -58,7 +59,7 @@ class Migration(DataMigration):
             'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
         },
         'contenttypes.contenttype': {
-            'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
             'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
@@ -72,24 +73,51 @@ class Migration(DataMigration):
         },
         'im.approvalterms': {
             'Meta': {'object_name': 'ApprovalTerms'},
-            'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 11, 29, 13, 58, 8, 395739)', 'db_index': 'True'}),
+            'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 12, 4, 11, 35, 14, 103893)', 'db_index': 'True'}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
         },
+        'im.astakosgroup': {
+            'Meta': {'object_name': 'AstakosGroup', '_ormbases': ['auth.Group']},
+            'approval_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 12, 4, 11, 35, 14, 96747)'}),
+            'desc': ('django.db.models.fields.TextField', [], {'null': 'True'}),
+            'estimated_participants': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'expiration_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+            'group_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.Group']", 'unique': 'True', 'primary_key': 'True'}),
+            'homepage': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'issue_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+            'kind': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.GroupKind']"}),
+            'max_participants': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'moderation_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'policy': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.AstakosGroupQuota']", 'blank': 'True'})
+        },
+        'im.astakosgroupquota': {
+            'Meta': {'unique_together': "(('resource', 'group'),)", 'object_name': 'AstakosGroupQuota'},
+            'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosGroup']", 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'limit': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
+            'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}),
+            'uplimit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'})
+        },
         'im.astakosuser': {
-            'Meta': {'object_name': 'AstakosUser', '_ormbases': ['auth.User']},
+            'Meta': {'unique_together': "(('provider', 'third_party_identifier'),)", 'object_name': 'AstakosUser', '_ormbases': ['auth.User']},
             'activation_sent': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
             'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'astakos_groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.AstakosGroup']", 'symmetrical': 'False', 'through': "orm['im.Membership']", 'blank': 'True'}),
             'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
             'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
             'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
             'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
-            'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
-            'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
-            'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
-            'invitations': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
-            'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
-            'level': ('django.db.models.fields.IntegerField', [], {'default': '4'}),
+            'disturbed_quota': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
+            'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'invitations': ('django.db.models.fields.IntegerField', [], {'default': '100'}),
+            'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'level': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'owner': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'owner'", 'null': 'True', 'to': "orm['im.AstakosGroup']"}),
+            'policy': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.AstakosUserQuota']", 'symmetrical': 'False'}),
             'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
             'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
             'updated': ('django.db.models.fields.DateTimeField', [], {}),
@@ -97,7 +125,7 @@ class Migration(DataMigration):
         },
         'im.astakosuserauthprovider': {
             'Meta': {'unique_together': "(('identifier', 'module', 'user'),)", 'object_name': 'AstakosUserAuthProvider'},
-            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
             'affiliation': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'null': 'True', 'blank': 'True'}),
             'auth_backend': ('django.db.models.fields.CharField', [], {'default': "'astakos'", 'max_length': '255'}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
@@ -105,14 +133,27 @@ class Migration(DataMigration):
             'module': ('django.db.models.fields.CharField', [], {'default': "'local'", 'max_length': '255'}),
             'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'auth_providers'", 'to': "orm['im.AstakosUser']"})
         },
+        'im.astakosuserquota': {
+            'Meta': {'unique_together': "(('resource', 'user'),)", 'object_name': 'AstakosUserQuota'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'limit': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
+            'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}),
+            'uplimit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
+        },
         'im.emailchange': {
             'Meta': {'object_name': 'EmailChange'},
             'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
-            'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 11, 29, 13, 58, 8, 396491)'}),
+            'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 12, 4, 11, 35, 14, 105406)'}),
             'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchange_user'", 'unique': 'True', 'to': "orm['im.AstakosUser']"})
         },
+        'im.groupkind': {
+            'Meta': {'object_name': 'GroupKind'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'})
+        },
         'im.invitation': {
             'Meta': {'object_name': 'Invitation'},
             'code': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
@@ -120,10 +161,18 @@ class Migration(DataMigration):
             'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'inviter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations_sent'", 'null': 'True', 'to': "orm['im.AstakosUser']"}),
-            'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
+            'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
             'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
             'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
         },
+        'im.membership': {
+            'Meta': {'unique_together': "(('person', 'group'),)", 'object_name': 'Membership'},
+            'date_joined': ('django.db.models.fields.DateField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}),
+            'date_requested': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2012, 12, 4, 11, 35, 14, 101611)', 'blank': 'True'}),
+            'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosGroup']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
+        },
         'im.pendingthirdpartyuser': {
             'Meta': {'unique_together': "(('provider', 'third_party_identifier'),)", 'object_name': 'PendingThirdPartyUser'},
             'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
@@ -137,6 +186,22 @@ class Migration(DataMigration):
             'token': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
             'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
         },
+        'im.resource': {
+            'Meta': {'object_name': 'Resource'},
+            'desc': ('django.db.models.fields.TextField', [], {'null': 'True'}),
+            'group': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'meta': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.ResourceMetadata']", 'symmetrical': 'False'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
+            'service': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Service']"}),
+            'unit': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'})
+        },
+        'im.resourcemetadata': {
+            'Meta': {'object_name': 'ResourceMetadata'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
+            'value': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
         'im.service': {
             'Meta': {'object_name': 'Service'},
             'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
@@ -144,7 +209,7 @@ class Migration(DataMigration):
             'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
             'icon': ('django.db.models.fields.FilePathField', [], {'max_length': '100', 'blank': 'True'}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
             'url': ('django.db.models.fields.FilePathField', [], {'max_length': '100'})
         },
         'im.sessioncatalog': {
