Commit ecc9856b authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Replace last_application_synced with last_application_approved

parent 616f987f
...@@ -1256,22 +1256,19 @@ class ProjectApplication(models.Model): ...@@ -1256,22 +1256,19 @@ class ProjectApplication(models.Model):
if self.state != PENDING: if self.state != PENDING:
raise PermissionDenied(_(PROJECT_ALREADY_ACTIVE)) raise PermissionDenied(_(PROJECT_ALREADY_ACTIVE))
now = datetime.now()
precursor = self.precursor_application precursor = self.precursor_application
try: try:
project = precursor.project project = precursor.project
project.application = self
prev_approval_date = project.last_approval_date
project.last_approval_date = datetime.now()
project.save()
except: except:
kwargs = { project = Project()
'application':self, project.creation_date = now
'creation_date':datetime.now(),
'last_approval_date':datetime.now(),
}
project = _create_object(Project, **kwargs)
project.accept_member(self.owner, approval_user) project.accept_member(self.owner, approval_user)
project.last_application_approved = self
project.last_approval_date = now
project.save()
p = precursor p = precursor
while p: while p:
p.state = REPLACED p.state = REPLACED
...@@ -1281,6 +1278,8 @@ class ProjectApplication(models.Model): ...@@ -1281,6 +1278,8 @@ class ProjectApplication(models.Model):
self.state = APPROVED self.state = APPROVED
self.save() self.save()
transaction.commit()
notification = build_notification( notification = build_notification(
settings.SERVER_EMAIL, settings.SERVER_EMAIL,
[self.owner.email], [self.owner.email],
...@@ -1291,32 +1290,22 @@ class ProjectApplication(models.Model): ...@@ -1291,32 +1290,22 @@ class ProjectApplication(models.Model):
notification.send() notification.send()
rejected = self.project.sync() rejected = self.project.sync()
if rejected: if not rejected:
# revert to precursor project.application = self
if precursor:
project.application = precursor
project.last_approval_date = prev_approval_date
project.save()
rejected = project.sync()
if rejected:
raise Exception(_(astakos_messages.QH_SYNC_ERROR))
else:
project.last_application_synced = self
project.save() project.save()
class Project(models.Model): class Project(models.Model):
application = models.OneToOneField(ProjectApplication, related_name='project') application = models.OneToOneField(
ProjectApplication, related_name='project', null=True, blank=True)
creation_date = models.DateTimeField() creation_date = models.DateTimeField()
last_approval_date = models.DateTimeField(null=True) last_approval_date = models.DateTimeField(null=True)
termination_start_date = models.DateTimeField(null=True) termination_start_date = models.DateTimeField(null=True)
termination_date = models.DateTimeField(null=True) termination_date = models.DateTimeField(null=True)
members = models.ManyToManyField(AstakosUser, through='ProjectMembership') members = models.ManyToManyField(AstakosUser, through='ProjectMembership')
membership_dirty = models.BooleanField(default=False) membership_dirty = models.BooleanField(default=False)
last_application_synced = models.OneToOneField( last_application_approved = models.OneToOneField(
ProjectApplication, related_name='last_project', null=True, blank=True ProjectApplication, related_name='last_project')
)
@property @property
...@@ -1373,7 +1362,7 @@ class Project(models.Model): ...@@ -1373,7 +1362,7 @@ class Project(models.Model):
@property @property
def is_synchronized(self): def is_synchronized(self):
return self.last_application_synced == self.application and \ return self.last_application_approved == self.application and \
not self.membership_dirty and \ not self.membership_dirty and \
(not self.termination_start_date or termination_date) (not self.termination_start_date or termination_date)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment