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 = u'milestone'[source]
title = u'Milestone Trophy'[source]
image_urls = {u'1x': u'/static/rb/images/trophies/sparkly.png', u'2x': u'/static/rb/images/trophies/sparkly@2x.png'}[source]
image_width = 33[source]
image_height = 35[source]
display_format_str = u'%(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
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 = u'fish'[source]
name = u'Fish Trophy'[source]
image_urls = {u'1x': u'/static/rb/images/trophies/fish.png', u'2x': u'/static/rb/images/trophies/fish@2x.png'}[source]
image_width = 33[source]
image_height = 37[source]
display_format_str = u'%(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
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 = u'Unknown Trophy'[source]
class TrophyRegistry[source]

Bases: djblets.registries.registry.Registry

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

Register a new trophy type.

Parameters:

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

Raises:
  • djblets.registries.errors.RegistrationError – The TrophyType.category value is missing on the trophy.
  • djblets.registries.errors.AlreadyRegisteredError – This trophy type, or another with the same category, was already registered.
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.