Jump to >

reviewboard.accounts.trophies

class TrophyType[source]

Bases: object

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]

Bases: reviewboard.accounts.trophies.TrophyType

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).

category = 'milestone'[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.

title = 'Milestone Trophy'[source]
image_urls = {'1x': '/static/rb/images/trophies/sparkly.png', '2x': '/static/rb/images/trophies/sparkly@2x.png'}[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 = 33[source]

The width of the base image.

image_height = 35[source]

The height of the base image.

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

display_format_str = '%(recipient)s got review request #%(review_request_id)d!'[source]
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

__annotations__ = {}
class FishTrophy[source]

Bases: reviewboard.accounts.trophies.TrophyType

A fish trophy.

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

category = 'fish'[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 = 'Fish Trophy'[source]

The name of the trophy.

image_urls = {'1x': '/static/rb/images/trophies/fish.png', '2x': '/static/rb/images/trophies/fish@2x.png'}[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 = 33[source]

The width of the base image.

image_height = 37[source]

The height of the base image.

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

display_format_str = '%(recipient)s got a fish trophy!'[source]
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

__annotations__ = {}
class UnknownTrophy[source]

Bases: reviewboard.accounts.trophies.TrophyType

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.

name = 'Unknown Trophy'[source]

The name of the trophy.

__annotations__ = {}
class TrophyRegistry[source]

Bases: djblets.registries.registry.Registry

lookup_attrs = ('category',)[source]

A list of attributes that items can be looked up by.

default_errors = {'already_registered': 'Could not register trophy type %(item)s. This trophy type is already registered or its category conflicts with another trophy.', 'attribute_registered': 'Could not register trophy type %(item)s: Another trophy type (%(duplicate)s) is already registered with the same category.', 'invalid_attribute': '"%(attr_name)s" is not a registered lookup attribute.', 'load_entry_point': 'Could not load entry point %(entry_point)s: %(error)s.', 'missing_attribute': 'Could not register %(item)s: it does not have a "%(attr_name)s" attribute.', 'not_registered': 'No trophy type was found matching "%(attr_value)s".', 'unregister': 'Could not unregister trophy type %(item)s: This trophy type was not yet registered.'}[source]

The default error formatting strings.

If subclasses need to provide additional errors that can be overridden, they should copy DEFAULT_ERRORS and set their copy on the subclass as this attribute.

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

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

The registry of available trophies.