Jump to >

reviewboard.accounts.trophies

class TrophyType(title=None, image_url=None, image_width=None, image_height=None)[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.

__init__(title=None, image_url=None, image_width=None, image_height=None)[source]

Initialize the trophy.

This accepts deprecated arguments for the trophy information. Subclasses should instead define the appropriate attributes on the class body.

Parameters:
  • title (unicode, optional) –

    The name of the trophy.

    Subclasses should instead set name.

    Deprecated since version 3.0.

  • image_url (unicode, optional) –

    The URL of the trophy.

    Subclasses should instead set image_urls.

    Deprecated since version 3.0.

  • image_width (int, optional) –

    The width of the image.

    Subclasses should instead set image_width.

    Deprecated since version 3.0.

  • image_height (int, optional) –

    The height of the image.

    Subclasses should instead set image_height.

    Deprecated since version 3.0.

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(title=None, image_url=None, image_width=None, image_height=None)[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(title=None, image_url=None, image_width=None, image_height=None)[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(title=None, image_url=None, image_width=None, image_height=None)[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:
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.

register_trophy(trophy)[source]

Register a TrophyType subclass.

This will register a type of trophy. Review Board will use it to calculate and display possible trophies.

Only TrophyType subclasses are supported.

Deprecated since version 3.0: This is deprecated in favor of calling trophies_registry.register.

Parameters:

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

Raises:
  • TypeError – The provided trophy to register is not a TrophyType subclass.
  • KeyError – The trophy could not be registered.
unregister_trophy(trophy)[source]

Unregister a TrophyType subclass.

This will unregister a previously registered type of trophy.

Only TrophyType subclasses are supported. The class must have been registered beforehand or a ValueError will be thrown.

Deprecated since version 3.0: This is deprecated in favor of calling trophies_registry.unregister.

Parameters:

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

Raises:
  • TypeError – The provided trophy to register is not a TrophyType subclass.
  • ValueError – The trophy could not be unregistered.
get_registered_trophy_types()[source]

Return all registered trophy types.

Deprecated since version 3.0: This is deprecated in favor of iterating through trophies_registry.

Returns:The list of all registered trophies.
Return type:list of TrophyType