Skip to content

Commit

Permalink
[Fixes #12456] Fix test and instance initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed Aug 1, 2024
1 parent 74bdc5b commit 3154734
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion geonode/documents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def download_urls(self, **kwargs):
super().download_urls()
return [
{
"url": self.instance.download_url,
"url": self.instance.download_url if not self.instance.doc_url else self.instance.doc_url,
"ajax_safe": self.instance.download_is_ajax_safe,
},
]
11 changes: 3 additions & 8 deletions geonode/resource/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ class BaseResourceHandler(ABC):

REGISTRY = []

def __init__(self) -> None:
self.instance = None
def __init__(self, instance=None) -> None:
self.instance = instance

def __str__(self):
return f"{self.__module__}.{self.__class__.__name__}"

Check warning on line 21 in geonode/resource/handler.py

View check run for this annotation

Codecov / codecov/patch

geonode/resource/handler.py#L21

Added line #L21 was not covered by tests

def __repr__(self):
return self.__str__()

Check warning on line 24 in geonode/resource/handler.py

View check run for this annotation

Codecov / codecov/patch

geonode/resource/handler.py#L24

Added line #L24 was not covered by tests

@classmethod
def init_class(cls, instance):
cls.instance = instance

@classmethod
def register(cls):
BaseResourceHandler.REGISTRY.append(cls)
Expand All @@ -41,8 +37,7 @@ def get_handler_by_instance(self, instance):
"""
for handler in self.get_registry():
if handler.can_handle(instance):
self.init_class(instance)
return handler()
return handler(instance)
logger.error("No handlers found for the given resource")
return self

Expand Down

0 comments on commit 3154734

Please # to comment.