From b07afdc97ded511c6f6c19d6cc2c526192cc41f5 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 28 Sep 2012 17:44:08 -0400 Subject: [PATCH 1/2] fixing bug: successful campaigns were relaunchable. --- core/models.py | 12 ++++++++++++ frontend/views.py | 7 +------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/models.py b/core/models.py index 6ffc52f9..b8893360 100755 --- a/core/models.py +++ b/core/models.py @@ -84,6 +84,18 @@ class Claim(models.Model): user = models.ForeignKey(User, related_name="claim", null=False ) status = models.CharField(max_length=7, choices= STATUSES, default='pending') + def can_open_new(self): + # whether a campaign can be opened for this claim + + #must be an active claim + if self.status != 'active': + return False + #can't already be a campaign + for campaign in self.campaigns: + if campaign.status in ['ACTIVE','INITIALIZED', 'SUCCESSFUL']: + return False + return True + class RightsHolder(models.Model): created = models.DateTimeField(auto_now_add=True) email = models.CharField(max_length=100, blank=True) diff --git a/frontend/views.py b/frontend/views.py index a8615418..a6cb9d00 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -1161,10 +1161,8 @@ def rh_tools(request): claim.campaigns = claim.work.campaigns.all() else: claim.campaigns = [] - claim.can_open_new=False if claim.work.last_campaign_status in ['ACTIVE','INITIALIZED'] else True for campaign in claim.campaigns: if campaign.status in ['ACTIVE','INITIALIZED']: - claim.can_open_new=False if request.method == 'POST' and request.POST.has_key('edit_managers_%s'% campaign.id) : campaign.edit_managers_form=EditManagersForm( instance=campaign, data=request.POST, prefix=campaign.id) if campaign.edit_managers_form.is_valid(): @@ -1172,7 +1170,7 @@ def rh_tools(request): campaign.edit_managers_form = EditManagersForm(instance=campaign, prefix=campaign.id) else: campaign.edit_managers_form=EditManagersForm(instance=campaign, prefix=campaign.id) - if claim.status == 'active' and claim.can_open_new: + if claim.can_open_new: if request.method == 'POST' and request.POST.has_key('work') and int(request.POST['work']) == claim.work.id : claim.campaign_form = OpenCampaignForm(request.POST) if claim.campaign_form.is_valid(): @@ -1181,11 +1179,8 @@ def rh_tools(request): new_campaign.target = D(settings.UNGLUEIT_MINIMUM_TARGET) new_campaign.save() claim.campaign_form.save_m2m() - claim.can_open_new=False else: claim.campaign_form = OpenCampaignForm(data={'work': claim.work, 'name': claim.work.title, 'userid': request.user.id, 'managers_1': request.user.id}) - else: - claim.can_open_new=False campaigns = request.user.campaigns.all() new_campaign = None for campaign in campaigns: From 5fe7e6350871cb71cc5f1989931f9c4162a001bd Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 1 Oct 2012 09:48:57 -0400 Subject: [PATCH 2/2] not sure why it also worked without this --- core/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/models.py b/core/models.py index b8893360..94416c28 100755 --- a/core/models.py +++ b/core/models.py @@ -84,6 +84,7 @@ class Claim(models.Model): user = models.ForeignKey(User, related_name="claim", null=False ) status = models.CharField(max_length=7, choices= STATUSES, default='pending') + @property def can_open_new(self): # whether a campaign can be opened for this claim