Commit 9a184f06 by David Ormsbee

Add comments, fix typo.

parent 26993248
...@@ -106,7 +106,7 @@ class Rubric(models.Model): ...@@ -106,7 +106,7 @@ class Rubric(models.Model):
InvalidOptionSelection: the selected options do not match the rubric. InvalidOptionSelection: the selected options do not match the rubric.
""" """
# Cache based on the content_hash, not the id. It's slighlty safer, and # Cache based on the content_hash, not the id. It's slightly safer, and
# we don't have to worry about invalidation of the cache while running # we don't have to worry about invalidation of the cache while running
# tests. # tests.
rubric_criteria_dict_cache_key = ( rubric_criteria_dict_cache_key = (
......
...@@ -105,6 +105,22 @@ class RubricSerializer(NestedModelSerializer): ...@@ -105,6 +105,22 @@ class RubricSerializer(NestedModelSerializer):
@classmethod @classmethod
def serialized_from_cache(cls, rubric, local_cache=None): def serialized_from_cache(cls, rubric, local_cache=None):
"""For a given `Rubric` model object, return a serialized version.
This method will attempt to use the cache if possible, first looking at
the `local_cache` dict you can pass in, and then looking at whatever
Django cache is configured.
Args:
rubric (Rubric): The Rubric model to get the serialized form of.
local_cach (dict): Mapping of `rubric.content_hash` to serialized
rubric dictionary. We include this so that we can call this
method in a loop.
Returns:
dict: `Rubric` fields as a dictionary, with `criteria` and `options`
relations followed.
"""
# Optional local cache you can send in (for when you're calling this # Optional local cache you can send in (for when you're calling this
# in a loop). # in a loop).
local_cache = local_cache or {} local_cache = local_cache or {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment