def gen_poll(self): from poll.models import Poll poll = Poll() candidates = list(self.profile.all()) for elected in self.elected.all(): try: candidates.remove(elected) except ValueError: pass # Option A: candidates <= available posts -> yes/no/abstention if len(candidates) <= self.posts - self.elected.count(): poll.optiondecision = True else: poll.optiondecision = False # Option B: candidates == 1 -> yes/no/abstention #if self.profile.count() == 1: # poll.optiondecision = True #else: # poll.optiondecision = False poll.assignment = self poll.description = self.polldescription poll.save() for candidate in candidates: poll.add_option(candidate) return poll
def gen_poll(self, user=None): """ Generates a poll object for the application """ from poll.models import Poll poll = Poll(optiondecision=True, \ application=self) poll.save() poll.add_option(self) self.writelog(_("Poll created"), user) return poll