models
AbstractOwnerModel
Bases: Model
Abstract model for representing an entity owned by a user with toggles for either allowing submissions for it and public access. Defaults to completely private by default.
Attributes:
Name | Type | Description |
---|---|---|
public |
bool
|
is this object public to any authenticated user? Default: False |
allow_submissions |
bool
|
allow other users to submit child objects? Default: False. Not implemented yet. |
owner |
User
|
The user that created this object. |
GroupStats
Bases: TimeStampedModel
An object for using to track usage stats for CharacterGroup
.
Attributes:
Name | Type | Description |
---|---|---|
group |
SourceGroup
|
The group this is collecting stats for. |
quotes_requested |
int
|
The number of times a quote from this object or its children has been requested. |
quotes_generated |
int
|
The number of times a markov quote has been generated for this or it's children. |
Quote
Bases: AbstractOwnerModel
, RulesModelMixin
, TimeStampedModel
A quote from a given source. A user must own the related source to add or delete a quote.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
Database primary key for the object. |
quote |
str
|
The quote text to use. You can use Markdown for styling. Must be <= 280 characters for tweets |
citation |
str | None
|
Optional description of quote source, e.g. episode number or book title. |
citation_url |
str | None
|
Optional accompanying URL for the citation. |
pub_date |
datetime | None
|
Date and time when the quote was published. |
source |
Source
|
The source of this quote. |
owner |
User
|
The user that created and owns this quote. |
created |
datetime
|
When this object was first created. Auto-generated. |
modified |
datetime
|
Last time this object was modified. Auto-generated. |
QuoteCorpusError
Bases: Exception
An exception raised when a quote corpus fails to generate.
QuoteStats
Bases: TimeStampedModel
A simple object used to track how often an individual quote is used.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
The database primary key of this object. |
quote |
Quote
|
The quote this stat relates to. |
times_used |
int
|
The number of times this has been used by an service such as random quote. |
created |
datetime
|
When this was created. |
modified |
datetime
|
When this was last modified. |
Source
Bases: AbstractOwnerModel
, RulesModelMixin
, TimeStampedModel
An individual source to attribute the quote to in the system, such as a character from a podcast/book, or a specific author. A user must be the owner of the related SourceGroup to add or delete a source.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
Database primary key for the object. |
name |
str
|
Unique name of a character within a |
group |
SourceGroup
|
The parent |
slug |
str
|
Slug made up of a generated version of the character name and the group slug prefix. |
description |
str
|
Description for the character. Markdown can be used for styling. |
allow_markov |
bool
|
Allow markov quotes to be requested from this character? Default False. |
owner |
User
|
The user that created and owns this character. |
public |
bool
|
Is the character public to other users? Defaults to False. |
allow_submissions |
bool
|
Allow other users to submit quotes for this character? Defaults to False. |
text_model |
MarkovTextModel | None
|
The current text_model. |
created |
datetime
|
When this object was first created. Auto-generated. |
modified |
datetime
|
Last time this object was modified. Auto-generated. |
description_rendered
property
Return the markdown rendered version of the description.
markov_ready
property
Conducts sanity checks to see if requesting a markov chain is feasible. Markov must be enabled for a character and there must be a sufficient corpus to generate a sentence from. Currently set at a minimum of 10 quotes.
Returns:
Type | Description |
---|---|
bool
|
If ready for markov requests. |
aadd_new_quote_to_model
async
aadd_new_quote_to_model(
quote_to_add: (
Quote | Iterable[Quote] | AsyncIterable[Quote]
),
) -> None
Allows adding a new quote to the source's (and group's) text model without parsing the whole corpus. Note that deleting or editing a quote will still require a full re-ingest of the corpus to remove old data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quote_to_add |
Quote | Iterable[Quote] | AsyncIterable[Quote]
|
A Quote instance, or an iterable of Quote instances to add to the source text model. |
required |
Source code in src/django_quotes/models.py
add_new_quote_to_model
Sync wrapper for aadd_new_quote_to_model
.
Allows adding a new quote to the source's text model without parsing the whole corpus.
Note that deleting or editing a quote will still require a full re-ingest of the corpus to remove old data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quote_to_add |
Quote
|
A quote to add to the source text model. |
required |
Source code in src/django_quotes/models.py
aupdate_markov_model
async
Process all quotes into the associated model.
Source code in src/django_quotes/models.py
get_markov_sentence
If valid, generate a markov sentence. If not, return None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_characters |
int | None
|
Maximum number of characters allowed in resulting sentence. |
280
|
tries |
int
|
Number of times django_markov may try to generate sentence. |
20
|
Returns:
Type | Description |
---|---|
str | None
|
The resulting sentence or None if a sentence could not be formed. |
Source code in src/django_quotes/models.py
get_random_quote
get_random_quote(
max_quotes_to_process: (
int | None
) = MAX_QUOTES_FOR_RANDOM_SET,
) -> Any | None
This actually not all that random. It's going to grab the quotes ordered ordered by how infrequently they've been returned, and then grab a random one in the set. But for our purposes, it's fine. If there aren't any quotes, it will return None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_quotes_to_process |
int | None
|
Maximum number of quotes to retrive before selecting at random. |
MAX_QUOTES_FOR_RANDOM_SET
|
Returns:
Type | Description |
---|---|
Quote | None
|
The quote object or None if no quotes found. |
Source code in src/django_quotes/models.py
save
Save and create slug, if missing.
SourceGroup
Bases: AbstractOwnerModel
, RulesModelMixin
, TimeStampedModel
An abstract group or source for a given set of quotes. Multiple sources, or Source objects, can belong to the same group. For example, a novel or series if you plan to quote the characters within individually.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
Database primary key for the object. |
name |
str
|
Human readable string to name the group. This will be converted to a slug prefix. |
description |
str
|
A description of the group for convenience. Markdown can be used here for styling. |
owner |
User
|
The user that created the group and therefore owns it. |
public |
bool
|
Is this group public or private. Defaults to False. |
allow_submissions |
bool
|
Allow other users to submit characters to this. Not yet implemented. |
slug |
str
|
A unique slug to represent this group. Generated automatically from name. |
text_model |
MarkovTextModel | None
|
The current text model. |
created |
datetime
|
When this object was first created. Auto-generated. |
modified |
datetime
|
Last time this object was modified. Auto-generated. |
description_rendered
property
Return the markdown rendered version of the description.
aupdate_markov_model
async
Updates the related MarkovTextModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
additional_model |
MarkovTextModel | None
|
An additional model to include in the combination. Useful for pre_save signals for a source that is newly enabling allow_markov. |
None
|
Source code in src/django_quotes/models.py
generate_markov_sentence
Generate a markov sentence based on quotes from markov enabled characters for the group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_characters |
int
|
Maximum characters allowed in the resulting sentence. |
280
|
tries |
int
|
Maximum number of tries django_markov should use to create the sentence. |
20
|
Returns:
Type | Description |
---|---|
str | None
|
The generated sentence or None if no sentence was possible for the number of tries. |
Source code in src/django_quotes/models.py
get_random_quote
Get a random quote object from any of the characters defined within the group. Prioritizes quotes that have been returned less often.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_quotes_to_process |
int | None
|
Maximum number of quotes to retrieve before selecting a random one. |
MAX_QUOTES_FOR_RANDOM_GROUP_SET
|
Returns:
Type | Description |
---|---|
Any
|
(Quote | None) Quote object or None if no quotes are found. |
Source code in src/django_quotes/models.py
markov_ready
Checks to see if there are Markov enabled sources and sufficient quotes.
Source code in src/django_quotes/models.py
markov_sources
refresh_from_db
Also reset cached properties.
Source code in src/django_quotes/models.py
save
Save and create slug if missing.
Source code in src/django_quotes/models.py
total_quotes
total_sources
update_markov_model
SourceStats
Bases: TimeStampedModel
An object for using to track usage stats for Character
.
Attributes:
Name | Type | Description |
---|---|---|
source |
Source
|
The source this is collecting stats for. |
quotes_requested |
int
|
The number of times a quote from this object or its children has been requested. |
quotes_generated |
int
|
The number of times a markov quote has been generated for this or it's children. |
TimeStampedModel
Bases: Model
Automatically adds a created and modified field.