Revision 123be68a

b/snf-astakos-app/astakos/im/migrations/0052_auto__del_field_project_deactivation_start_date__add_field_project_sta.py
1
# encoding: utf-8
2
import datetime
3
from south.db import db
4
from south.v2 import SchemaMigration
5
from django.db import models
6

  
7
class Migration(SchemaMigration):
8

  
9
    def forwards(self, orm):
10
        
11
        # Deleting field 'Project.deactivation_start_date'
12
        db.delete_column('im_project', 'deactivation_start_date')
13

  
14
        # Adding field 'Project.state'
15
        db.add_column('im_project', 'state', self.gf('django.db.models.fields.IntegerField')(default=256, db_index=True), keep_default=False)
16

  
17

  
18
    def backwards(self, orm):
19
        
20
        # Adding field 'Project.deactivation_start_date'
21
        db.add_column('im_project', 'deactivation_start_date', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)
22

  
23
        # Deleting field 'Project.state'
24
        db.delete_column('im_project', 'state')
25

  
26

  
27
    models = {
28
        'auth.group': {
29
            'Meta': {'object_name': 'Group'},
30
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
31
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
32
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
33
        },
34
        'auth.permission': {
35
            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
36
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
37
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
38
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
39
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
40
        },
41
        'auth.user': {
42
            'Meta': {'object_name': 'User'},
43
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
44
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
45
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
46
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
47
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
48
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
49
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
50
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
51
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
52
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
53
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
54
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
55
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
56
        },
57
        'contenttypes.contenttype': {
58
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
59
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
60
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
61
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
62
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
63
        },
64
        'im.additionalmail': {
65
            'Meta': {'object_name': 'AdditionalMail'},
66
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
67
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
68
            'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
69
        },
70
        'im.approvalterms': {
71
            'Meta': {'object_name': 'ApprovalTerms'},
72
            'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 1, 9, 15, 12, 22, 561243)', 'db_index': 'True'}),
73
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
74
            'location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
75
        },
76
        'im.astakosuser': {
77
            'Meta': {'object_name': 'AstakosUser', '_ormbases': ['auth.User']},
78
            'activation_sent': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
79
            'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
80
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
81
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
82
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
83
            'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
84
            'disturbed_quota': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
85
            'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
86
            'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
87
            'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
88
            'invitations': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
89
            'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
90
            'level': ('django.db.models.fields.IntegerField', [], {'default': '4'}),
91
            'policy': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.AstakosUserQuota']", 'symmetrical': 'False'}),
92
            'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
93
            'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
94
            'updated': ('django.db.models.fields.DateTimeField', [], {}),
95
            'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'}),
96
            'uuid': ('django.db.models.fields.CharField', [], {'max_length': '255', 'unique': 'True', 'null': 'True'})
97
        },
98
        'im.astakosuserauthprovider': {
99
            'Meta': {'ordering': "('module', 'created')", 'unique_together': "(('identifier', 'module', 'user'),)", 'object_name': 'AstakosUserAuthProvider'},
100
            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
101
            'affiliation': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'null': 'True', 'blank': 'True'}),
102
            'auth_backend': ('django.db.models.fields.CharField', [], {'default': "'astakos'", 'max_length': '255'}),
103
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
104
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
105
            'identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
106
            'info_data': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'}),
107
            'module': ('django.db.models.fields.CharField', [], {'default': "'local'", 'max_length': '255'}),
108
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'auth_providers'", 'to': "orm['im.AstakosUser']"})
109
        },
110
        'im.astakosuserquota': {
111
            'Meta': {'unique_together': "(('resource', 'user'),)", 'object_name': 'AstakosUserQuota'},
112
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
113
            'limit': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
114
            'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}),
115
            'uplimit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}),
116
            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
117
        },
118
        'im.emailchange': {
119
            'Meta': {'object_name': 'EmailChange'},
120
            'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}),
121
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
122
            'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
123
            'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 1, 9, 15, 12, 22, 562025)'}),
124
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchanges'", 'unique': 'True', 'to': "orm['im.AstakosUser']"})
125
        },
126
        'im.invitation': {
127
            'Meta': {'object_name': 'Invitation'},
128
            'code': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
129
            'consumed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
130
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
131
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
132
            'inviter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations_sent'", 'null': 'True', 'to': "orm['im.AstakosUser']"}),
133
            'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
134
            'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
135
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
136
        },
137
        'im.pendingthirdpartyuser': {
138
            'Meta': {'unique_together': "(('provider', 'third_party_identifier'),)", 'object_name': 'PendingThirdPartyUser'},
139
            'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
140
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
141
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
142
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
143
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
144
            'info': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'}),
145
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
146
            'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
147
            'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
148
            'token': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
149
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
150
        },
151
        'im.project': {
152
            'Meta': {'object_name': 'Project'},
153
            'application': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'project'", 'unique': 'True', 'to': "orm['im.ProjectApplication']"}),
154
            'creation_date': ('django.db.models.fields.DateTimeField', [], {}),
155
            'deactivation_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
156
            'deactivation_reason': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
157
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
158
            'last_approval_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
159
            'members': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.AstakosUser']", 'through': "orm['im.ProjectMembership']", 'symmetrical': 'False'}),
160
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80', 'db_index': 'True'}),
161
            'state': ('django.db.models.fields.IntegerField', [], {'default': '256', 'db_index': 'True'})
162
        },
163
        'im.projectapplication': {
164
            'Meta': {'object_name': 'ProjectApplication'},
165
            'applicant': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'projects_applied'", 'to': "orm['im.AstakosUser']"}),
166
            'comments': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
167
            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
168
            'end_date': ('django.db.models.fields.DateTimeField', [], {}),
169
            'homepage': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True'}),
170
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
171
            'issue_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
172
            'limit_on_members_number': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
173
            'member_join_policy': ('django.db.models.fields.IntegerField', [], {}),
174
            'member_leave_policy': ('django.db.models.fields.IntegerField', [], {}),
175
            'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
176
            'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'projects_owned'", 'to': "orm['im.AstakosUser']"}),
177
            'precursor_application': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['im.ProjectApplication']", 'unique': 'True', 'null': 'True', 'blank': 'True'}),
178
            'resource_grants': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.ProjectResourceGrant']", 'blank': 'True'}),
179
            'start_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
180
            'state': ('django.db.models.fields.CharField', [], {'default': "'Pending'", 'max_length': '80'})
181
        },
182
        'im.projectmembership': {
183
            'Meta': {'unique_together': "(('person', 'project'),)", 'object_name': 'ProjectMembership'},
184
            'acceptance_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'db_index': 'True'}),
185
            'application': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'memberships'", 'null': 'True', 'to': "orm['im.ProjectApplication']"}),
186
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
187
            'leave_request_date': ('django.db.models.fields.DateField', [], {'null': 'True'}),
188
            'pending_application': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'pending_memebrships'", 'null': 'True', 'to': "orm['im.ProjectApplication']"}),
189
            'pending_serial': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'db_index': 'True'}),
190
            'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}),
191
            'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Project']"}),
192
            'request_date': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2013, 1, 9, 15, 12, 22, 564984)'}),
193
            'state': ('django.db.models.fields.IntegerField', [], {'default': '0'})
194
        },
195
        'im.projectmembershiphistory': {
196
            'Meta': {'object_name': 'ProjectMembershipHistory'},
197
            'date': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime.now'}),
198
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
199
            'person': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
200
            'project': ('django.db.models.fields.BigIntegerField', [], {}),
201
            'reason': ('django.db.models.fields.IntegerField', [], {}),
202
            'serial': ('django.db.models.fields.BigIntegerField', [], {})
203
        },
204
        'im.projectresourcegrant': {
205
            'Meta': {'unique_together': "(('resource', 'project_application'),)", 'object_name': 'ProjectResourceGrant'},
206
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
207
            'member_capacity': ('synnefo.lib.db.intdecimalfield.IntDecimalField', [], {'default': '100000000000000000000000000000000L', 'max_digits': '38', 'decimal_places': '0'}),
208
            'member_export_limit': ('synnefo.lib.db.intdecimalfield.IntDecimalField', [], {'default': '100000000000000000000000000000000L', 'max_digits': '38', 'decimal_places': '0'}),
209
            'member_import_limit': ('synnefo.lib.db.intdecimalfield.IntDecimalField', [], {'default': '100000000000000000000000000000000L', 'max_digits': '38', 'decimal_places': '0'}),
210
            'project_application': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.ProjectApplication']", 'null': 'True'}),
211
            'project_capacity': ('synnefo.lib.db.intdecimalfield.IntDecimalField', [], {'default': '100000000000000000000000000000000L', 'max_digits': '38', 'decimal_places': '0'}),
212
            'project_export_limit': ('synnefo.lib.db.intdecimalfield.IntDecimalField', [], {'default': '100000000000000000000000000000000L', 'max_digits': '38', 'decimal_places': '0'}),
213
            'project_import_limit': ('synnefo.lib.db.intdecimalfield.IntDecimalField', [], {'default': '100000000000000000000000000000000L', 'max_digits': '38', 'decimal_places': '0'}),
214
            'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"})
215
        },
216
        'im.resource': {
217
            'Meta': {'unique_together': "(('name', 'service'),)", 'object_name': 'Resource'},
218
            'desc': ('django.db.models.fields.TextField', [], {'null': 'True'}),
219
            'group': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}),
220
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
221
            'meta': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.ResourceMetadata']", 'symmetrical': 'False'}),
222
            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
223
            'service': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Service']"}),
224
            'unit': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'})
225
        },
226
        'im.resourcemetadata': {
227
            'Meta': {'object_name': 'ResourceMetadata'},
228
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
229
            'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
230
            'value': ('django.db.models.fields.CharField', [], {'max_length': '255'})
231
        },
232
        'im.serial': {
233
            'Meta': {'object_name': 'Serial'},
234
            'serial': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
235
        },
236
        'im.service': {
237
            'Meta': {'ordering': "('order',)", 'object_name': 'Service'},
238
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
239
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
240
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
241
            'icon': ('django.db.models.fields.FilePathField', [], {'max_length': '100', 'blank': 'True'}),
242
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
243
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
244
            'order': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
245
            'url': ('django.db.models.fields.FilePathField', [], {'max_length': '100'})
246
        },
247
        'im.sessioncatalog': {
248
            'Meta': {'object_name': 'SessionCatalog'},
249
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
250
            'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
251
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sessions'", 'null': 'True', 'to': "orm['im.AstakosUser']"})
252
        }
253
    }
254

  
255
    complete_apps = ['im']
b/snf-astakos-app/astakos/im/models.py
1392 1392
        unique_together = ("resource", "project_application")
1393 1393

  
1394 1394

  
1395
class ProjectManager(ForUpdateManager):
1396

  
1397
    def deactivating_projects(self):
1398
        return self.filter(state__gt=Project.ACTIVE)
1399

  
1400
    def _q_terminated(self):
1401
        return Q(state=Project.TERMINATED) | Q(state=Project.TERMINATING)
1402

  
1403
    def terminated_projects(self):
1404
        q = self._q_terminated()
1405
        return self.filter(q)
1406

  
1407
    def not_terminated_projects(self):
1408
        q = ~self._q_terminated()
1409
        return self.filter(q)
1410

  
1395 1411
class Project(models.Model):
1396 1412

  
1397 1413
    application                 =   models.OneToOneField(
......
1404 1420
                                            through='ProjectMembership')
1405 1421

  
1406 1422
    deactivation_reason         =   models.CharField(max_length=255, null=True)
1407
    deactivation_start_date     =   models.DateTimeField(null=True)
1408 1423
    deactivation_date           =   models.DateTimeField(null=True)
1409 1424

  
1410 1425
    creation_date               =   models.DateTimeField()
......
1413 1428
                                            db_index=True,
1414 1429
                                            unique=True)
1415 1430

  
1416
    TERMINATED  =   'TERMINATED'
1417
    SUSPENDED   =   'SUSPENDED'
1431
    ACTIVE      = 1 << 8
1432
    TERMINATED  = 1
1433
    SUSPENDED   = 2
1418 1434

  
1419
    objects     =   ForUpdateManager()
1435
    INACTIVE    = 0
1436
    TERMINATING = TERMINATED | ACTIVE
1437
    SUSPENDING  = SUSPENDED | ACTIVE
1438

  
1439
    state                       =   models.IntegerField(default=ACTIVE,
1440
                                                        db_index=True)
1441

  
1442
    objects     =   ProjectManager()
1420 1443

  
1421 1444
    def __str__(self):
1422 1445
        return _("<project %s '%s'>") % (self.id, self.application.name)
1423 1446

  
1424 1447
    __repr__ = __str__
1425 1448

  
1426
    def is_deactivating(self):
1427
        return bool(self.deactivation_start_date)
1428 1449

  
1429
    def is_deactivated_synced(self):
1430
        return bool(self.deactivation_date)
1450
    ### Internal state manipulation
1431 1451

  
1432
    def is_deactivated(self):
1433
        return self.is_deactivated_synced() or self.is_deactivating()
1452
    def _active_bit(self):
1453
        return self.state & self.ACTIVE
1434 1454

  
1435
    def is_still_approved(self):
1436
        return bool(self.last_approval_date)
1455
    def is_active_bit(self):
1456
        return self._active_bit() == self.ACTIVE
1437 1457

  
1438
    def is_active(self):
1439
        return not(self.is_deactivated())
1458
    def is_active_strict(self):
1459
        return self.state == self.ACTIVE
1460

  
1461
    def is_modulo_active(self, s):
1462
        return self.state & (~self.ACTIVE) == s
1463

  
1464
    def set_modulo_active(self, s):
1465
        self.state = s | self._active_bit()
1466

  
1467
    def set_inactive(self):
1468
        self.state &= (~self.ACTIVE)
1469

  
1470
    def is_deactivating(self, reason=None):
1471
        return (self.is_active_bit() and
1472
                (self.is_modulo_active(reason) if reason
1473
                 else not self.is_active_strict()))
1474

  
1475
    def is_deactivated_synced(self, reason=None):
1476
        if reason:
1477
            return self.state == reason
1478
        return not self.is_active_bit()
1479

  
1480
    def is_deactivated(self, reason=None):
1481
        return (self.is_deactivated_synced(reason) or
1482
                self.is_deactivating(reason))
1483

  
1484

  
1485
    ### Deactivation calls
1486

  
1487
    def set_deactivation_date(self):
1488
        self.deactivation_date = datetime.now()
1489

  
1490
    def deactivate(self):
1491
        self.set_deactivation_date()
1492
        self.set_inactive()
1493

  
1494
    def terminate(self):
1495
        self.deactivation_reason = 'TERMINATED'
1496
        self.set_modulo_active(self.TERMINATED)
1497
        self.save()
1498

  
1499

  
1500
    ### Logical checks
1440 1501

  
1441 1502
    def is_inconsistent(self):
1442 1503
        now = datetime.now()
1443 1504
        dates = [self.creation_date,
1444 1505
                 self.last_approval_date,
1445
                 self.deactivation_start_date,
1446 1506
                 self.deactivation_date]
1447 1507
        return any([date > now for date in dates])
1448 1508

  
1449
    def set_deactivation_start_date(self):
1450
        self.deactivation_start_date = datetime.now()
1509
    def is_active(self):
1510
        return self.is_active_strict()
1451 1511

  
1452
    def set_deactivation_date(self):
1453
        self.deactivation_start_date = None
1454
        self.deactivation_date = datetime.now()
1512
    @property
1513
    def is_alive(self):
1514
        return self.is_active()
1515

  
1516
    @property
1517
    def is_terminated(self):
1518
        return self.is_deactivated(self.TERMINATED)
1519

  
1520
    @property
1521
    def is_suspended(self):
1522
        return False
1455 1523

  
1456 1524
    def violates_resource_grants(self):
1457 1525
        return False
......
1461 1529
        return (len(self.approved_members) + adding >
1462 1530
                application.limit_on_members_number)
1463 1531

  
1464
    @property
1465
    def is_alive(self):
1466
        return self.is_active()
1532

  
1533
    ### Other
1467 1534

  
1468 1535
    @property
1469 1536
    def approved_memberships(self):
......
1510 1577
        m = ProjectMembership.objects.get(person=user, project=self)
1511 1578
        m.remove()
1512 1579

  
1513
    def terminate(self):
1514
        self.set_deactivation_start_date()
1515
        self.deactivation_reason = self.TERMINATED
1516
        self.save()
1517

  
1518
    @property
1519
    def is_terminated(self):
1520
        return (self.is_deactivated() and
1521
                self.deactivation_reason == self.TERMINATED)
1522

  
1523
    @property
1524
    def is_suspended(self):
1525
        return False
1526

  
1527 1580
class ProjectMembership(models.Model):
1528 1581

  
1529 1582
    person              =   models.ForeignKey(AstakosUser)
......
1793 1846
    REMOVING = ProjectMembership.REMOVING
1794 1847

  
1795 1848
    psfu = Project.objects.select_for_update()
1796
    projects = psfu.filter(deactivation_start_date__isnull=False)
1849
    projects = psfu.deactivating_projects()
1797 1850

  
1798 1851
    if not projects:
1799 1852
        return
......
1835 1888
    sync_finish_serials([serial])
1836 1889

  
1837 1890
    # finalize deactivating projects
1838
    deactivating_projects = psfu.filter(deactivation_start_date__isnull=False)
1891
    deactivating_projects = psfu.deactivating_projects()
1839 1892
    for project in deactivating_projects:
1840 1893
        objects = project.projectmembership_set.select_for_update()
1841 1894
        memberships = list(objects.filter(Q(state=ACCEPTED) |

Also available in: Unified diff