-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from unicef/feature/remotes
Feature/remotes
- Loading branch information
Showing
217 changed files
with
11,339 additions
and
26,820 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Any | ||
|
||
import django.dispatch | ||
from django.core.cache import cache | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
|
||
class CacheManager: | ||
def __init__(self): | ||
self.active = True | ||
|
||
def init(self): | ||
pass | ||
|
||
def invalidate(self, key): | ||
cache_invalidate.send(CacheManager, key=key) | ||
|
||
def get(self, key): | ||
if not self.active: | ||
return None | ||
data = cache.get(key) | ||
cache_get.send(CacheManager, key=key, hit=bool(data)) | ||
return data | ||
|
||
def set(self, key: str, value: Any, **kwargs): | ||
cache_set.send(CacheManager, key=key) | ||
return cache.set(key, value, **kwargs) | ||
|
||
# def _build_key_from_request(self, request): | ||
# if state.tenant and state.program: | ||
# return f"{state.tenant.slug}:{state.program.pk}: | ||
# {slugify(request.path)}:{slugify(str(sorted(request.GET)))}" | ||
# return "" | ||
# | ||
# def store(self, request, value): | ||
# key = self._build_key_from_request(request) | ||
# cache_store.send(CacheManager, key=key, request=request, value=value) | ||
# self.set(key, value) | ||
# | ||
# def retrieve(self, request): | ||
# key = self._build_key_from_request(request) | ||
# if data := cache.get(key): | ||
# return pickle.loads(data) | ||
# return None | ||
|
||
|
||
cache_manager = CacheManager() | ||
|
||
cache_get = django.dispatch.Signal() | ||
cache_set = django.dispatch.Signal() | ||
cache_store = django.dispatch.Signal() | ||
cache_invalidate = django.dispatch.Signal() | ||
|
||
|
||
@receiver(post_save) | ||
def update_cache(sender, instance, **kwargs): | ||
cache_manager.invalidate(sender) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .. import env | ||
|
||
TAILWIND_APP_NAME = "country_workspace.workspaces.theme" | ||
TAILWIND_DEV_MODE = env("TAILWIND_DEV_MODE") | ||
TAILWIND_CSS_PATH = "css/styles.css" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.apps import AppConfig | ||
|
||
from .geo import Admin1Choice, Admin2Choice, Admin3Choice, Admin4Choice, CountryChoice | ||
|
||
|
||
class Config(AppConfig): | ||
name = __name__.rpartition(".")[0] | ||
verbose_name = "Country Workspace" | ||
|
||
def ready(self) -> None: | ||
from hope_flex_fields.attributes.registry import attributes_registry | ||
from hope_flex_fields.registry import field_registry | ||
|
||
from .remotes.country import CountryAttributeHandler | ||
|
||
attributes_registry.register(CountryAttributeHandler) | ||
field_registry.register(CountryChoice) | ||
field_registry.register(Admin1Choice) | ||
field_registry.register(Admin2Choice) | ||
field_registry.register(Admin3Choice) | ||
field_registry.register(Admin4Choice) |
Oops, something went wrong.