democrasite.webiscite.managers module

Managers for the webiscite app models.

class democrasite.webiscite.managers.BillManager(*args, **kwargs)

Bases: Manager, Generic

annotate_user_vote(user: User, queryset: QuerySet | None = None)

Annotate a queryset with the given user’s vote on each bill.

Parameters:
  • user – The user whose vote to annotate

  • queryset – The queryset to annotate; defaults to self.get_queryset()

Returns:

The queryset annotated with a user_vote field (True/False/None)

create_from_github(pull_request: PullRequest, desc: str, author_uid: str) T | None

Validate and create a Bill from a GitHub pull request

Parameters:
  • pull_request – The pull request instance to associate with the bill

  • desc – The description of the bill (pull request body)

  • author_uid – The GitHub UID of the pull request author

Returns:

The new bill instance, or None if the author has no linked account

get_queryset()

Return a queryset with related models pre-fetched and vote amounts added.

All Bill querysets include total_votes, yes_count, yes_percent, no_count and no_percent annotations, prefetch pull_request and author, and are ordered by creation date.

class democrasite.webiscite.managers.PullRequestManager(*args, **kwargs)

Bases: Manager, Generic

create_from_github(pr: dict[str, Any]) T

Create or update a PullRequest from a GitHub pull request payload

Parameters:

pr – The pull request data from the GitHub API

Returns:

The new or updated pull request instance