Revision fdafae27 snf-astakos-app/astakos/im/models.py
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
1256 | 1256 |
if self.state != PENDING: |
1257 | 1257 |
raise PermissionDenied(_(PROJECT_ALREADY_ACTIVE)) |
1258 | 1258 |
|
1259 |
now = datetime.now() |
|
1259 | 1260 |
precursor = self.precursor_application |
1260 | 1261 |
try: |
1261 | 1262 |
project = precursor.project |
1262 |
project.application = self |
|
1263 |
prev_approval_date = project.last_approval_date |
|
1264 |
project.last_approval_date = datetime.now() |
|
1265 |
project.save() |
|
1266 | 1263 |
except: |
1267 |
kwargs = { |
|
1268 |
'application':self, |
|
1269 |
'creation_date':datetime.now(), |
|
1270 |
'last_approval_date':datetime.now(), |
|
1271 |
} |
|
1272 |
project = _create_object(Project, **kwargs) |
|
1264 |
project = Project() |
|
1265 |
project.creation_date = now |
|
1273 | 1266 |
project.accept_member(self.owner, approval_user) |
1274 |
|
|
1267 |
|
|
1268 |
project.last_application_approved = self |
|
1269 |
project.last_approval_date = now |
|
1270 |
project.save() |
|
1271 |
|
|
1275 | 1272 |
p = precursor |
1276 | 1273 |
while p: |
1277 | 1274 |
p.state = REPLACED |
... | ... | |
1281 | 1278 |
self.state = APPROVED |
1282 | 1279 |
self.save() |
1283 | 1280 |
|
1281 |
transaction.commit() |
|
1282 |
|
|
1284 | 1283 |
notification = build_notification( |
1285 | 1284 |
settings.SERVER_EMAIL, |
1286 | 1285 |
[self.owner.email], |
... | ... | |
1291 | 1290 |
notification.send() |
1292 | 1291 |
|
1293 | 1292 |
rejected = self.project.sync() |
1294 |
if rejected: |
|
1295 |
# revert to precursor |
|
1296 |
if precursor: |
|
1297 |
project.application = precursor |
|
1298 |
project.last_approval_date = prev_approval_date |
|
1299 |
project.save() |
|
1300 |
|
|
1301 |
rejected = project.sync() |
|
1302 |
if rejected: |
|
1303 |
raise Exception(_(astakos_messages.QH_SYNC_ERROR)) |
|
1304 |
else: |
|
1305 |
project.last_application_synced = self |
|
1293 |
if not rejected: |
|
1294 |
project.application = self |
|
1306 | 1295 |
project.save() |
1307 | 1296 |
|
1308 | 1297 |
|
1309 | 1298 |
class Project(models.Model): |
1310 |
application = models.OneToOneField(ProjectApplication, related_name='project') |
|
1299 |
application = models.OneToOneField( |
|
1300 |
ProjectApplication, related_name='project', null=True, blank=True) |
|
1311 | 1301 |
creation_date = models.DateTimeField() |
1312 | 1302 |
last_approval_date = models.DateTimeField(null=True) |
1313 | 1303 |
termination_start_date = models.DateTimeField(null=True) |
1314 | 1304 |
termination_date = models.DateTimeField(null=True) |
1315 | 1305 |
members = models.ManyToManyField(AstakosUser, through='ProjectMembership') |
1316 | 1306 |
membership_dirty = models.BooleanField(default=False) |
1317 |
last_application_synced = models.OneToOneField( |
|
1318 |
ProjectApplication, related_name='last_project', null=True, blank=True |
|
1319 |
) |
|
1307 |
last_application_approved = models.OneToOneField( |
|
1308 |
ProjectApplication, related_name='last_project') |
|
1320 | 1309 |
|
1321 | 1310 |
|
1322 | 1311 |
@property |
... | ... | |
1373 | 1362 |
|
1374 | 1363 |
@property |
1375 | 1364 |
def is_synchronized(self): |
1376 |
return self.last_application_synced == self.application and \
|
|
1365 |
return self.last_application_approved == self.application and \
|
|
1377 | 1366 |
not self.membership_dirty and \ |
1378 | 1367 |
(not self.termination_start_date or termination_date) |
1379 | 1368 |
|
Also available in: Unified diff