Jump to >

reviewboard.accounts.trophies

class TrophyType[source]

Base class for a type of trophy.

Trophies are achievements that can be awarded to users based on some aspect of a review request. When a review request is filed, each registered trophy type (managed by the trophies registry) will be checked using qualifies() to see if the trophy can be awarded. If so, the trophy will be recorded and shown on the review request page.

A trophy should include a displayable name, a category (essentially the ID of the trophy), and details for the trophy image.

category = None[source]

The category of the trophy.

This is the string ID of the trophy. For historical reasons, it’s referred to as a category and not an ID.

name = None[source]

The name of the trophy.

image_urls = {}[source]

URLs for the trophy images.

This is a dictionary of images, where each key is a resolution specifier (1x, 2x, etc.), and the value is a URL.

Each must have widths/heights that are multipliers on the base width/height for the 1x specifier.

image_width = None[source]

The width of the base image.

image_height = None[source]

The height of the base image.

It is recommended to use a height of 48px max.

get_display_text(trophy)[source]

Return the text to display in the trophy banner.

Parameters

trophy (reviewboard.accounts.models.Trophy) – The stored trophy information.

Returns

The display text for the trophy banner.

Return type

unicode

qualifies(review_request)[source]

Return whether this trophy should be given to this review request.

Parameters

review_request (reviewboard.reviews.models.ReviewRequest) – The review request to check for the trophy.

Returns

True if the trophy should be given, or False if not.

Return type

bool

format_display_text(request, trophy, **kwargs)[source]

Format the display text for the trophy.

Parameters
Returns

The rendered text.

Return type

unicode

class MilestoneTrophy[source]

A milestone trophy.

It is awarded if review request ID is greater than 1000 and is a non-zero digit followed by only zeroes (e.g. 1000, 5000, 10000).

qualifies(review_request)[source]

Return whether this trophy should be given to this review request.

Parameters

review_request (reviewboard.reviews.models.ReviewRequest) – The review request to check for the trophy.

Returns

True if the trophy should be given, or False if not.

Return type

bool

class FishTrophy[source]

A fish trophy.

Give a man a fish, he’ll waste hours trying to figure out why.

qualifies(review_request)[source]

Return whether this trophy should be given to this review request.

Parameters

review_request (reviewboard.reviews.models.ReviewRequest) – The review request to check for the trophy.

Returns

True if the trophy should be given, or False if not.

Return type

bool

class UnknownTrophy[source]

A trophy with an unknown category.

The data for this trophy exists in the database but its category does not match the category of any registered trophy types.

class TrophyRegistry[source]
register(**kwargs)[source]

Register a new trophy type.

Parameters

trophy_type (type) – The trophy type (subclass of TrophyType) to register.

Raises
unregister(**kwargs)[source]

Unregister a trophy type.

Parameters

trophy_type (type) – The trophy type (subclass of TrophyType) to unregister.

Raises

djblets.registries.errors.ItemLookupError – This trophy type was not registered.

get_for_category(category)[source]

Return the TrophyType instance matching a given trophy category.

If there’s no registered trophy for the category, UnknownTrophy will be returned.

Parameters

category (unicode) – The stored category for the trophy.

Returns

The trophy matching the given category.

Return type

TrophyType

get_defaults()[source]

Return the default trophies for the registry.

This is used internally by the parent registry class to populate the list of default, buit-in trophies available to review requests.

Returns

The list of default trophies.

Return type

list of TrophyType

trophies_registry = <reviewboard.accounts.trophies.TrophyRegistry object>[source]

The registry of available trophies.