-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds generic search thumbnail retrieval #10266
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
993f5a0
Adds generic search thumbnail retrieval
aarongundel 5abda8d
PR feedback, fix for manifest URL
aarongundel ff164e3
updates auto-formatting for black
aarongundel 5d99e54
updates auto-formatting
aarongundel 95a7f25
Merge branch 'dev/7.5.x' into search-thumbnails
aarongundel b72989f
Update the catch block to catch additional exception if the resource …
aarongundel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,16 @@ | ||
import base64 | ||
import copy | ||
import re | ||
from typing import List, Tuple | ||
from urllib.error import HTTPError | ||
from requests.exceptions import ConnectionError | ||
import requests | ||
from urllib.parse import urlparse, urlunparse | ||
|
||
|
||
class SearchThumbnailFetcher(object): | ||
def __init__(self, resource): | ||
self.resource = resource | ||
|
||
def get_thumbnail(self, retrieve=False): | ||
pass |
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,34 @@ | ||
import logging | ||
from typing import Callable | ||
from arches.app.models.resource import Resource | ||
|
||
from arches.app.utils.search_thumbnail_fetcher import SearchThumbnailFetcher | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SearchThumbnailFetcherFactory(object): | ||
registry = {} | ||
|
||
@classmethod | ||
def register(cls, name: str): | ||
def inner_wrapper(wrapped_class: SearchThumbnailFetcher) -> Callable: | ||
if name in cls.registry: | ||
logger.warning("Search Thumbnail Fetcher %s already exists. Will replace it", name) | ||
cls.registry[name] = wrapped_class | ||
return wrapped_class | ||
|
||
return inner_wrapper | ||
|
||
@classmethod | ||
def create_thumbnail_fetcher(cls, resource_id: str, **kwargs) -> SearchThumbnailFetcher: | ||
"""Factory command to create the template engine""" | ||
try: | ||
resource = Resource.objects.get(resourceinstanceid=resource_id) | ||
search_thumbnail_fetcher_class = cls.registry[str(resource.graph_id)] | ||
search_thumbnail_fetcher = search_thumbnail_fetcher_class(resource, **kwargs) | ||
return search_thumbnail_fetcher | ||
except KeyError: | ||
return None # there is no thumbnail fetcher registered for the graph requested | ||
except Resource.DoesNotExist: | ||
return None # there is no resource with this ID. This is rare, but can happen if there are issues with the index. |
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,31 @@ | ||
from django.views.generic import View | ||
from django.http import HttpResponse, HttpResponseNotFound | ||
from arches.app.utils.search_thumbnail_fetcher_factory import SearchThumbnailFetcherFactory | ||
|
||
|
||
class ThumbnailView(View): | ||
def head(self, request, resource_id): | ||
fetcher = self.get_thumbnail_fetcher(resource_id) | ||
if fetcher is None: | ||
return HttpResponseNotFound() | ||
thumbnail = fetcher.get_thumbnail(False) | ||
if thumbnail is not None: | ||
return HttpResponse() | ||
else: | ||
return HttpResponseNotFound() | ||
|
||
def get(self, request, resource_id): | ||
fetcher = self.get_thumbnail_fetcher(resource_id) | ||
if fetcher is None: | ||
return HttpResponseNotFound() | ||
|
||
thumbnail = fetcher.get_thumbnail(True) | ||
if thumbnail is not None: | ||
return HttpResponse(thumbnail[0], content_type=thumbnail[1]) | ||
else: | ||
return HttpResponseNotFound() | ||
|
||
def get_thumbnail_fetcher(self, resource_id): | ||
factory = SearchThumbnailFetcherFactory() | ||
fetcher = factory.create_thumbnail_fetcher(resource_id) | ||
return fetcher |
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 |
---|---|---|
|
@@ -66,6 +66,7 @@ | |
|
||
ELASTICSEARCH_HTTP_PORT = 9200 # this should be in increments of 200, eg: 9400, 9600, 9800 | ||
SEARCH_BACKEND = "arches.app.search.search.SearchEngine" | ||
SEARCH_THUMBNAILS = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also be added to the project template's settings file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
# see http://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.Elasticsearch | ||
ELASTICSEARCH_HOSTS = [{"scheme": "https", "host": "localhost", "port": ELASTICSEARCH_HTTP_PORT}] | ||
|
||
|
@@ -744,6 +745,7 @@ | |
def JSON_LD_FIX_DATA_FUNCTION(data, jsdata, model): | ||
return jsdata | ||
|
||
|
||
########################################## | ||
### END RUN TIME CONFIGURABLE SETTINGS ### | ||
########################################## | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice to have an example, but because this file isn't yet wired in as a default, I think it would be better to remove this here and add it to the docs.