Compare commits

..

No commits in common. "78be4d2728b139a4b501e6b52fe64c25a352ad09" and "acd0ade1ad39d4c95edf3f84d11b5ddf564865b0" have entirely different histories.

5 changed files with 4 additions and 52 deletions

View file

@ -25,7 +25,7 @@
<excludeFolder url="file://$MODULE_DIR$/.ruff_cache" />
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.12 (charasheet)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.11 (charasheet)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">

View file

@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.11 (charasheet)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (charasheet)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (charasheet)" project-jdk-type="Python SDK" />
</project>

View file

@ -130,7 +130,7 @@ class Capability(DocumentedModel, TimeStampedModel, models.Model):
@property
def capability_points_cost(self) -> int:
if self.path.category == Path.Category.PROFILE and self.rank in [1, 2]:
if self.rank in [1, 2]:
return 1
return 2

View file

@ -14,7 +14,6 @@ from django_extensions.db.models import TimeStampedModel
from character.models import Capability, Path
from character.models.dice import Dice
from character.models.equipment import Weapon
from character.models.utils import cache_on_instance
from common.models import DocumentedModel, UniquelyNamedModel
@ -414,13 +413,7 @@ class Character(models.Model):
@property
def capability_points_used(self) -> int:
return sum(
cap.capability_points_cost
for cap in self.capabilities.select_related("path").only(
"rank",
"path__category",
)
)
return sum(cap.capability_points_cost for cap in self.capabilities.only("rank"))
@property
def capability_points_remaining(self) -> int:
@ -472,15 +465,12 @@ class Character(models.Model):
pk__in=self.states.all().values_list("pk", flat=True),
)
@cache_on_instance()
def managed_by(self, user):
return self in Character.objects.managed_by(user)
@cache_on_instance()
def mastered_by(self, user):
return self in Character.objects.mastered_by(user)
@cache_on_instance()
def owned_by(self, user):
return self in Character.objects.owned_by(user)

View file

@ -1,38 +0,0 @@
import functools
def cache_on_instance():
def wrapper(func):
@functools.wraps(func)
def inner(self, arg):
cache_name = func.__name__
if (cached := _get_cache_value(self, cache_name, arg)) is not None:
return cached
res = func(self, arg)
_set_cache_value(self, cache_name, arg, res)
return res
return inner
return wrapper
def _get_cache_value(obj, cache_name: str, key: str) -> any:
cache_name += "_cache"
cache = getattr(obj, cache_name, None)
if cache is None:
cache = {}
setattr(obj, cache_name, cache)
return None
return cache.get(key)
def _set_cache_value(obj, cache_name: str, key: str, value: any):
cache_name += "_cache"
cache = getattr(obj, cache_name)
if cache is None:
cache = {}
setattr(obj, cache_name, cache)
cache[key] = value