Skip to content

Is Poll Votable Checker

Class used to check if poll is votable.

IsPollVotableChecker

A class that contains all the checks to ensure a poll is votable now.

Each method, makes a check and returns True if the check is passed, False otherwise.

Source code in apps/votes_results/classes/vote/is_poll_votable_checker.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class IsPollVotableChecker:
    """
    A class  that contains all the checks to ensure a poll is votable now.

    Each method, makes a check and returns True if the check is passed, False otherwise.
    """

    poll: PollModel = None

    def load_poll(self, poll_id) -> bool:
        """Load the poll with the given id (ensure it exists)"""

        if poll_id is None:
            return False

        try:
            self.poll: PollModel = PollService.get_poll_by_id(poll_id)
            return True
        except PollDoesNotExistException:
            return False

    def is_poll_open_for_votes(self) -> bool:
        """Check if curr date is in the dates interval where poll is open for vote"""
        return self.poll.is_open() and not self.poll.is_closed()

    def is_poll_votable_through_method(self, votemethod: PollModel.PollType) -> bool:
        """Check if the poll is votable through the given method"""

        if self.poll.poll_type == votemethod:
            return True # same vote method --> OK

        # else I check the special case "votable also w MJ"
        return self.poll.is_votable_w_so_and_mj()

is_poll_open_for_votes()

Check if curr date is in the dates interval where poll is open for vote

Source code in apps/votes_results/classes/vote/is_poll_votable_checker.py
27
28
29
def is_poll_open_for_votes(self) -> bool:
    """Check if curr date is in the dates interval where poll is open for vote"""
    return self.poll.is_open() and not self.poll.is_closed()

is_poll_votable_through_method(votemethod)

Check if the poll is votable through the given method

Source code in apps/votes_results/classes/vote/is_poll_votable_checker.py
31
32
33
34
35
36
37
38
def is_poll_votable_through_method(self, votemethod: PollModel.PollType) -> bool:
    """Check if the poll is votable through the given method"""

    if self.poll.poll_type == votemethod:
        return True # same vote method --> OK

    # else I check the special case "votable also w MJ"
    return self.poll.is_votable_w_so_and_mj()

load_poll(poll_id)

Load the poll with the given id (ensure it exists)

Source code in apps/votes_results/classes/vote/is_poll_votable_checker.py
15
16
17
18
19
20
21
22
23
24
25
def load_poll(self, poll_id) -> bool:
    """Load the poll with the given id (ensure it exists)"""

    if poll_id is None:
        return False

    try:
        self.poll: PollModel = PollService.get_poll_by_id(poll_id)
        return True
    except PollDoesNotExistException:
        return False