Revision a9ba418f snf-astakos-app/astakos/im/models.py
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
1171 | 1171 |
-1: _('Not a member'), |
1172 | 1172 |
} |
1173 | 1173 |
|
1174 |
class Chain(models.Model): |
|
1175 |
chain = models.AutoField(primary_key=True) |
|
1176 |
|
|
1177 |
def new_chain(): |
|
1178 |
c = Chain.objects.create() |
|
1179 |
chain = c.chain |
|
1180 |
c.delete() |
|
1181 |
return chain |
|
1182 |
|
|
1183 |
|
|
1174 | 1184 |
class ProjectApplication(models.Model): |
1175 | 1185 |
PENDING, APPROVED, REPLACED, UNKNOWN = 'Pending', 'Approved', 'Replaced', 'Unknown' |
1176 | 1186 |
applicant = models.ForeignKey( |
... | ... | |
1186 | 1196 |
related_name='projects_owned', |
1187 | 1197 |
db_index=True) |
1188 | 1198 |
|
1199 |
chain = models.IntegerField(db_index=True) |
|
1189 | 1200 |
precursor_application = models.OneToOneField('ProjectApplication', |
1190 | 1201 |
null=True, |
1191 | 1202 |
blank=True, |
... | ... | |
1287 | 1298 |
return None |
1288 | 1299 |
|
1289 | 1300 |
def _get_project_for_update(self): |
1290 |
precursor = self |
|
1291 |
while precursor: |
|
1292 |
try: |
|
1293 |
objects = Project.objects.select_for_update() |
|
1294 |
project = objects.get(application=precursor) |
|
1295 |
return project |
|
1296 |
except Project.DoesNotExist: |
|
1297 |
pass |
|
1298 |
precursor = precursor.precursor_application |
|
1299 |
|
|
1300 |
return None |
|
1301 |
try: |
|
1302 |
objects = Project.objects.select_for_update() |
|
1303 |
project = objects.get(id=self.chain) |
|
1304 |
return project |
|
1305 |
except Project.DoesNotExist: |
|
1306 |
return None |
|
1301 | 1307 |
|
1302 | 1308 |
def approve(self, approval_user=None): |
1303 | 1309 |
""" |
... | ... | |
1335 | 1341 |
new_project = False |
1336 | 1342 |
if project is None: |
1337 | 1343 |
new_project = True |
1338 |
project = Project(creation_date=now) |
|
1344 |
project = Project(id=self.chain, creation_date=now)
|
|
1339 | 1345 |
|
1340 | 1346 |
project.name = new_project_name |
1341 | 1347 |
project.application = self |
... | ... | |
1365 | 1371 |
if precursor is not None: |
1366 | 1372 |
precursor.state = ProjectApplication.REPLACED |
1367 | 1373 |
precursor.save() |
1374 |
application.chain = precursor.chain |
|
1375 |
else: |
|
1376 |
application.chain = new_chain() |
|
1368 | 1377 |
|
1369 | 1378 |
application.save() |
1370 | 1379 |
application.resource_policies = resource_policies |
Also available in: Unified diff