diff --git a/core/models.py b/core/models.py index 6ffc52f9..94416c28 100755 --- a/core/models.py +++ b/core/models.py @@ -84,6 +84,19 @@ 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 + + #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 1cd134a0..c7923d1d 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -1138,10 +1138,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(): @@ -1149,7 +1147,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(): @@ -1158,11 +1156,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: