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 usingqualifies()
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.
- 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_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:
- 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, orFalse
if not.- Return type:
- format_display_text(request, trophy, **kwargs)[source]¶
Format the display text for the trophy.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request from the client.trophy (
reviewboard.accounts.models.Trophy
) – The trophy instance.**kwargs (
dict
) – Additional keyword arguments to use for formatting.
- Returns:
The rendered text.
- Return type:
- class MilestoneTrophy[source]¶
Bases:
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.
- 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_height = 35[source]¶
The height of the base image.
It is recommended to use a height of 48px max.
- 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, orFalse
if not.- Return type:
- __annotations__ = {}¶
- class FishTrophy[source]¶
Bases:
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.
- 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_height = 37[source]¶
The height of the base image.
It is recommended to use a height of 48px max.
- 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, orFalse
if not.- Return type:
- __annotations__ = {}¶
- class UnknownTrophy[source]¶
Bases:
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.
- __annotations__ = {}¶
- class TrophyRegistry[source]¶
Bases:
Registry
- lookup_attrs: Sequence[str] = ('category',)[source]¶
A list of attributes that items can be looked up by.
- default_errors: RegistryErrorsDict = {'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.- Type:
- register(**kwargs)[source]¶
Register a new trophy type.
- Parameters:
trophy_type (
type
) – The trophy type (subclass ofTrophyType
) 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 ofTrophyType
) 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:
- 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
ofTrophyType
- __annotations__ = {'_items': 'Set[RegistryItemType]', '_populated': 'bool', '_registry': 'Dict[str, Dict[object, RegistryItemType]]', 'already_registered_error_class': 'Type[AlreadyRegisteredError]', 'default_errors': 'RegistryErrorsDict', 'errors': 'RegistryErrorsDict', 'item_name': 'Optional[str]', 'lookup_attrs': 'Sequence[str]', 'lookup_error_class': 'Type[ItemLookupError]'}¶
- __parameters__ = ()¶