democrasite.webiscite.models module

Models for the webiscite app

class democrasite.webiscite.models.Bill(*args, **kwargs)

Bases: TimeStampedModel

Model for a proposal to merge a particular pull request into the main branch

Parameters:
  • id (BigAutoField) – Primary key: ID

  • created (AutoCreatedField) – Created

  • modified (AutoLastModifiedField) – Modified

  • name (CharField) – Name

  • description (TextField) – Description

  • status (CharField) – Status. The current status of the bill

  • constitutional (BooleanField) – Constitutional. True if this bill is an amendment to the constitution

Relationship fields:

Parameters:

Reverse relationships:

Parameters:

vote (Reverse ForeignKey from Vote) – All votes of this bill (related name of bill)

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

author

Type: ForeignKey to User

Author (related name: bill)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
author_id

Internal field, use author instead.

close(status: Status = Bill.Status.CLOSED) None

Close the bill and disable its submit task

constitutional

Type: BooleanField

Constitutional. True if this bill is an amendment to the constitution

A wrapper for a deferred-loading field. When the value is read from this

created

Type: AutoCreatedField

Created

A wrapper for a deferred-loading field. When the value is read from this

description

Type: TextField

Description

A wrapper for a deferred-loading field. When the value is read from this

get_absolute_url() str

Returns URL to view this Bill instance

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)

Finds next instance based on created. See get_next_by_FOO() for more information.

get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)

Finds next instance based on modified. See get_next_by_FOO() for more information.

get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)

Finds previous instance based on created. See get_previous_by_FOO() for more information.

get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)

Finds previous instance based on modified. See get_previous_by_FOO() for more information.

get_status_display(*, field=<django.db.models.CharField: status>)

Shows the label of the status. See get_FOO_display() for more information.

get_update_url() str

Returns URL to update this Bill instance

get_vote_url() str

Returns URL for the current user to vote on this Bill instance

history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>
id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

log(msg, *args, level=20)
modified

Type: AutoLastModifiedField

Modified

A wrapper for a deferred-loading field. When the value is read from this

name

Type: CharField

Name

A wrapper for a deferred-loading field. When the value is read from this

no_count = 0
no_percent = 0
objects = <democrasite.webiscite.managers.BillManager object>
publish() None

Transition a draft bill to open, enabling voting and scheduling submission

pull_request

Type: ForeignKey to PullRequest

Pull request (related name: bill)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
pull_request_id

Internal field, use pull_request instead.

save(*args, **kwargs)

Overriding the save method in order to make sure that modified field is updated even if it is not given as a parameter to the update field argument.

save_without_historical_record(*args, **kwargs)

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

status

Type: CharField

Status. The current status of the bill

Choices:

  • draft

  • open

  • approved

  • amended

  • rejected

  • failed

  • closed

submit() None

Check if the bill has enough votes to pass and update the status

total_votes = 0
user_supports(user: User) bool | None

Returns whether the given user supports, opposes, or has not voted on this bill

Parameters:

user – The user to check

Returns:

True if the user supports the bill, False if they oppose it, and None if they have not voted

vote(user: User, *, support: bool) None

Sets the given user’s vote based on the support parameter

If the user already voted the way the method would set, their vote is removed from the bill (i.e. if the user previously voted yes and support is True, their vote is removed)

Parameters:
  • user (User) – The user voting on the bill

  • support (bool) – Whether the user supports the bill

Raises:

ClosedBillVoteError – If the bill is not open for voting

vote_set

Type: Reverse ForeignKey from Vote

All votes of this bill (related name of bill)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

votes

Type: ManyToManyField to User

Votes (related name: votes)

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager

yes_count = 0
yes_percent = 0
exception democrasite.webiscite.models.ClosedBillVoteError

Bases: Exception

class democrasite.webiscite.models.PullRequest(*args, **kwargs)

Bases: TimeStampedModel

Local representation of a pull request on Github

Parameters:
  • created (AutoCreatedField) – Created

  • modified (AutoLastModifiedField) – Modified

  • number (IntegerField) – Primary key: Pull request number

  • title (CharField) – Title

  • additions (IntegerField) – Additions. Lines added

  • deletions (IntegerField) – Deletions. Lines removed

  • diff_url (URLField) – Diff url. URL to the diff of the pull request

  • author_name (CharField) – Author name

  • draft (BooleanField) – Draft. Whether the pull request is a draft on GitHub

  • status (CharField) – Status. State of the PR on Github

  • sha (CharField) – Sha. Unique identifier of PR commit

Reverse relationships:

Parameters:

bill (Reverse ForeignKey from Bill) – All bills of this pull request (related name of pull_request)

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

additions

Type: IntegerField

Additions. Lines added

A wrapper for a deferred-loading field. When the value is read from this

author_name

Type: CharField

Author name

A wrapper for a deferred-loading field. When the value is read from this

bill_set

Type: Reverse ForeignKey from Bill

All bills of this pull request (related name of pull_request)

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager

close() Bill | None

Mark the pull request and the associated bill closed if it was open

Parameters:

pr_num – The number of the pull request to close

Returns:

The bill associated with the pull request, if it was open

created

Type: AutoCreatedField

Created

A wrapper for a deferred-loading field. When the value is read from this

deletions

Type: IntegerField

Deletions. Lines removed

A wrapper for a deferred-loading field. When the value is read from this

Return base url of PR by removing “.diff” extension

diff_url

Type: URLField

Diff url. URL to the diff of the pull request

A wrapper for a deferred-loading field. When the value is read from this

draft

Type: BooleanField

Draft. Whether the pull request is a draft on GitHub

A wrapper for a deferred-loading field. When the value is read from this

get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)

Finds next instance based on created. See get_next_by_FOO() for more information.

get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)

Finds next instance based on modified. See get_next_by_FOO() for more information.

get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)

Finds previous instance based on created. See get_previous_by_FOO() for more information.

get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)

Finds previous instance based on modified. See get_previous_by_FOO() for more information.

get_status_display(*, field=<django.db.models.CharField: status>)

Shows the label of the status. See get_FOO_display() for more information.

history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>
log(msg, *args, level=20)
modified

Type: AutoLastModifiedField

Modified

A wrapper for a deferred-loading field. When the value is read from this

number

Type: IntegerField

Primary key: Pull request number

A wrapper for a deferred-loading field. When the value is read from this

objects = <democrasite.webiscite.managers.PullRequestManager object>
save_without_historical_record(*args, **kwargs)

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

sha

Type: CharField

Sha. Unique identifier of PR commit

A wrapper for a deferred-loading field. When the value is read from this

status

Type: CharField

Status. State of the PR on Github

Choices:

  • closed

  • open

title

Type: CharField

Title

A wrapper for a deferred-loading field. When the value is read from this

class democrasite.webiscite.models.Vote(*args, **kwargs)

Bases: Model

A vote for or against a bill, with a timestamp

Parameters:

Relationship fields:

Parameters:
exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

bill

Type: ForeignKey to Bill

Bill (related name: vote)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
bill_id

Internal field, use bill instead.

get_next_by_when(*, field=<django.db.models.DateTimeField: when>, is_next=True, **kwargs)

Finds next instance based on when. See get_next_by_FOO() for more information.

get_previous_by_when(*, field=<django.db.models.DateTimeField: when>, is_next=False, **kwargs)

Finds previous instance based on when. See get_previous_by_FOO() for more information.

history = <django.db.models.manager.HistoryManagerFromHistoricalQuerySet object>
id

Type: BigAutoField

Primary key: ID

A wrapper for a deferred-loading field. When the value is read from this

objects = <django.db.models.Manager object>
save_without_historical_record(*args, **kwargs)

Save the model instance without creating a historical record.

Make sure you know what you’re doing before using this method.

support

Type: BooleanField

Support

A wrapper for a deferred-loading field. When the value is read from this

user

Type: ForeignKey to User

User (related name: vote)

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')
user_id

Internal field, use user instead.

when

Type: DateTimeField

When

A wrapper for a deferred-loading field. When the value is read from this