mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
Add type hints to loader
This commit is contained in:
parent
f57ca2f769
commit
4e51b34b53
1 changed files with 5 additions and 3 deletions
|
|
@ -1,3 +1,5 @@
|
|||
from typing import Optional, Tuple
|
||||
|
||||
from django.contrib.sites.models import Site
|
||||
from django.db import router
|
||||
from django.template import Origin, TemplateDoesNotExist
|
||||
|
|
@ -31,17 +33,17 @@ class Loader(BaseLoader):
|
|||
loader=self,
|
||||
)
|
||||
|
||||
def get_contents(self, origin):
|
||||
def get_contents(self, origin: Origin) -> str:
|
||||
content, _ = self._load_template_source(origin.template_name)
|
||||
return content
|
||||
|
||||
def _load_and_store_template(self, template_name, cache_key, site, **params):
|
||||
def _load_and_store_template(self, template_name: str, cache_key: str, site: Site, **params) -> Tuple[str, str]:
|
||||
template = Template.objects.get(name__exact=template_name, **params)
|
||||
db = router.db_for_read(Template, instance=template)
|
||||
display_name = f"dbtemplates:{db}:{template_name}:{site.domain}"
|
||||
return set_and_return(cache_key, template.content, display_name)
|
||||
|
||||
def _load_template_source(self, template_name, template_dirs=None):
|
||||
def _load_template_source(self, template_name: str, template_dirs: Optional[str] = None) -> Tuple[str, str]:
|
||||
# The logic should work like this:
|
||||
# * Try to find the template in the cache. If found, return it.
|
||||
# * Now check the cache if a lookup for the given template
|
||||
|
|
|
|||
Loading…
Reference in a new issue