2020-01-21 06:35:58 +00:00
|
|
|
from django.utils import six
|
|
|
|
|
|
|
|
from judge.ratings import rating_class, rating_name, rating_progress
|
|
|
|
from . import registry
|
|
|
|
|
|
|
|
|
|
|
|
def _get_rating_value(func, obj):
|
|
|
|
if obj is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if isinstance(obj, six.integer_types):
|
|
|
|
return func(obj)
|
|
|
|
else:
|
|
|
|
return func(obj.rating)
|
|
|
|
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
@registry.function("rating_class")
|
2020-01-21 06:35:58 +00:00
|
|
|
def get_rating_class(obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return _get_rating_value(rating_class, obj) or "rate-none"
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
@registry.function(name="rating_name")
|
2020-01-21 06:35:58 +00:00
|
|
|
def get_name(obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return _get_rating_value(rating_name, obj) or "Unrated"
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
@registry.function(name="rating_progress")
|
2020-01-21 06:35:58 +00:00
|
|
|
def get_progress(obj):
|
|
|
|
return _get_rating_value(rating_progress, obj) or 0.0
|
|
|
|
|
|
|
|
|
|
|
|
@registry.function
|
2022-05-14 17:57:27 +00:00
|
|
|
@registry.render_with("user/rating.html")
|
2020-01-21 06:35:58 +00:00
|
|
|
def rating_number(obj):
|
2022-05-14 17:57:27 +00:00
|
|
|
return {"rating": obj}
|