def save(self, user, commit=True): proposal = super(ProposalForm, self).save(commit=False) if not self.is_edit: proposal.creator = user if user.is_authenticated() else None proposal.discussion_time = int(self.cleaned_data["discussion_time"]) proposal = self._additional_save_operations(proposal) assert commit, "can't save form without commit because of many-to-manyfield" proposal.save() # save before the many-to-manyfield gets created for tag in Tag.objects.all(): if tag in self.cleaned_data["tags"]: proposal.tags.add(tag) # if tag is already added, this has no effect elif tag in proposal.tags.all(): proposal.tags.remove(tag) proposal.save() ## build history proposal.build_history(editing_user=user) # creates a historical record clone and a VotablePostHistory ## add event ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage=proposal.voting_stage, ) ## broadcast on social media if not self.is_edit: posttotwitter("A new proposal for the programme: " + proposal.title + " " + settings.DOMAIN_NAME + reverse('proposals-detail', kwargs={'proposal_slug': proposal.slug})) return proposal
def save(self, user, commit=True): proposal = super(ProposalForm, self).save(commit=False) if not self.is_edit: proposal.creator = user if user.is_authenticated() else None proposal.discussion_time = int(self.cleaned_data["discussion_time"]) proposal = self._additional_save_operations(proposal) assert commit, "can't save form without commit because of many-to-manyfield" proposal.save() # save before the many-to-manyfield gets created for tag in Tag.objects.all(): if tag in self.cleaned_data["tags"]: proposal.tags.add( tag) # if tag is already added, this has no effect elif tag in proposal.tags.all(): proposal.tags.remove(tag) proposal.save() ## build history proposal.build_history( editing_user=user ) # creates a historical record clone and a VotablePostHistory ## add event ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage=proposal.voting_stage, ) ## broadcast on social media if not self.is_edit: posttotwitter("A new proposal for the programme: " + proposal.title + " " + settings.DOMAIN_NAME + reverse('proposals-detail', kwargs={'proposal_slug': proposal.slug})) return proposal
def progress_voting_stage(proposal_id, new_voting_stage): self.proposals[proposal_id].voting_stage = new_voting_stage self.proposals[proposal_id].save() ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=self.proposals[proposal_id], new_voting_stage=new_voting_stage, )
def make_proposal(name, **kwargs): proposal = PositionProposal( title=name, slug=name, position_text="{} text".format(name), **kwargs ) proposal.save() self.proposals[name] = proposal ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage='DISCUSSION', )
def handle_noargs(self, *args, **kwargs): # don't run a concurrent script twice if concurrent(): return voting_cnt = 0 constraints_cnt = 0 finished_cnt = 0 expired_cnt = 0 for proposal in Proposal.objects.filter( ~Q(voting_stage="APPROVED"), ~Q(voting_stage="REJECTED"), ~Q(voting_stage="EXPIRED") ): if proposal.shouldStartVoting(): proposal.voting_stage = "VOTING" proposal.voting_date = timezone.now() voting_cnt += 1 proposal.mail_sent = False posttotwitter( "VOTING BOOTS ARE OPEN: " + proposal.title + " " + settings.DOMAIN_NAME + reverse("proposals-detail", kwargs={"proposal_slug": proposal.slug}) ) proposal.save() ## add event ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage=proposal.voting_stage ) elif ( proposal.voting_stage == "DISCUSSION" and proposal.minimalContraintsAreMet() and not proposal.voting_date ): proposal.voting_date = proposal.estimatedVotingDate constraints_cnt += 1 proposal.mail_sent = False proposal.save() elif proposal.shouldBeFinished(): Command.doVoteCount(proposal) if proposal.isApproved(): proposal.execute() proposal.expire_date = timezone.now() proposal.voting_stage = "APPROVED" if proposal.isApproved() else "REJECTED" finished_cnt += 1 if proposal.voting_stage == "APPROVED": posttotwitter( '"' + proposal.title + '" made it in the program! ' + settings.DOMAIN_NAME + reverse("proposals-detail", kwargs={"proposal_slug": proposal.slug}) ) else: posttotwitter( '"' + proposal.title + '" was rejected! ' + settings.DOMAIN_NAME + reverse("proposals-detail", kwargs={"proposal_slug": proposal.slug}) ) proposal.mail_sent = False proposal.save() ## add event ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage=proposal.voting_stage ) elif proposal.shouldExpire(): proposal.expire_date = timezone.now() proposal.voting_stage = "EXPIRED" expired_cnt += 1 proposal.mail_sent = False proposal.save() ## add event ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage=proposal.voting_stage ) self.stdout.write("Successfully updated:\n") self.stdout.write("{} proposals to the voting phase\n".format(voting_cnt)) self.stdout.write("{} proposals have met minimal constraints\n".format(constraints_cnt)) self.stdout.write("{} proposals to the finished phase\n".format(finished_cnt)) self.stdout.write("{} proposals expired\n".format(expired_cnt))
def handle_noargs(self, *args, **kwargs): # don't run a concurrent script twice if concurrent(): return voting_cnt = 0 constraints_cnt = 0 finished_cnt = 0 expired_cnt = 0 for proposal in Proposal.objects.filter( ~Q(voting_stage='APPROVED'), ~Q(voting_stage='REJECTED'), ~Q(voting_stage='EXPIRED'), ): if proposal.shouldStartVoting(): proposal.voting_stage = 'VOTING' proposal.voting_date = timezone.now() voting_cnt += 1 proposal.mail_sent = False posttotwitter("VOTING BOOTS ARE OPEN: " + proposal.title + " " + settings.DOMAIN_NAME + reverse('proposals-detail', kwargs={'proposal_slug': proposal.slug})) proposal.save() ## add event ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage=proposal.voting_stage, ) elif proposal.voting_stage == 'DISCUSSION' and proposal.minimalContraintsAreMet( ) and not proposal.voting_date: proposal.voting_date = proposal.estimatedVotingDate constraints_cnt += 1 proposal.mail_sent = False proposal.save() elif proposal.shouldBeFinished(): Command.doVoteCount(proposal) if proposal.isApproved(): proposal.execute() proposal.expire_date = timezone.now() proposal.voting_stage = 'APPROVED' if proposal.isApproved( ) else 'REJECTED' finished_cnt += 1 if proposal.voting_stage == 'APPROVED': posttotwitter( "\"" + proposal.title + "\" made it in the program! " + settings.DOMAIN_NAME + reverse('proposals-detail', kwargs={'proposal_slug': proposal.slug})) else: posttotwitter( "\"" + proposal.title + "\" was rejected! " + settings.DOMAIN_NAME + reverse('proposals-detail', kwargs={'proposal_slug': proposal.slug})) proposal.mail_sent = False proposal.save() ## add event ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage=proposal.voting_stage, ) elif proposal.shouldExpire(): proposal.expire_date = timezone.now() proposal.voting_stage = 'EXPIRED' expired_cnt += 1 proposal.mail_sent = False proposal.save() ## add event ProposalLifeCycleEvent.new_event_and_create_listeners_and_email_queue_entries( proposal=proposal, new_voting_stage=proposal.voting_stage, ) self.stdout.write('Successfully updated:\n') self.stdout.write( '{} proposals to the voting phase\n'.format(voting_cnt)) self.stdout.write('{} proposals have met minimal constraints\n'.format( constraints_cnt)) self.stdout.write( '{} proposals to the finished phase\n'.format(finished_cnt)) self.stdout.write('{} proposals expired\n'.format(expired_cnt))