Skip to content

Commit

Permalink
swtich url to data_url
Browse files Browse the repository at this point in the history
  • Loading branch information
romer8 committed Oct 15, 2024
1 parent 4dfd646 commit 39854a6
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
Binary file added hydroshare_resources_app/static/images/apps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 1 addition & 9 deletions hydroshare_resources_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
def get_dict_with_attribute(list_of_dicts, attribute, value):
# Loop through each dictionary in the list
for dictionary in list_of_dicts:
# logging.warning(dictionary)
# if attribute in dictionary:
# logging.warning(dictionary[attribute])
# Check if the attribute exists in the dictionary and has the specified value
if attribute in dictionary and dictionary[attribute] == value:
return dictionary # Return the dictionary if found
Expand All @@ -22,12 +19,9 @@ def get_dict_with_attribute(list_of_dicts, attribute, value):


def get_most_recent_date(date_local_resource, date_api):
# logging.warning(f'{date_local_resource} , {date_api}')

# Convert strings to datetime objects
date_time_local_resource = datetime.datetime.fromisoformat(date_local_resource[:-1])
date_time_api = datetime.datetime.fromisoformat(date_api[:-1])
# logging.warning(f'{date_time_local_resource} , {date_time_api}')
# Compare the datetime objects
if date_time_local_resource > date_time_api:
return False
Expand All @@ -38,14 +32,13 @@ def get_most_recent_date(date_local_resource, date_api):


def update_resource(resource, hs, instance):
# logging.warning(science_metadata_json)
single_resource = {}
if resource["resource_type"] == "ToolResource":
science_metadata_json = hs.getScienceMetadata(resource["resource_id"])
# logging.warning(f'{science_metadata_json}')
image_url = science_metadata_json.get(
"app_icon", instance.placeholder_image
).get("value", instance.placeholder_image)
).get("data_url", instance.placeholder_image)
web_site_url = (
""
if not science_metadata_json.get("app_home_page_url", "")
Expand Down Expand Up @@ -99,7 +92,6 @@ def update_resource(resource, hs, instance):
"resource_type": resource["resource_type"],
"resource_url": resource["resource_url"],
}
# logging.warning(single_resource)
return single_resource


Expand Down
13 changes: 0 additions & 13 deletions hydroshare_resources_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ def hydroshare_resources_view(request):
body = json.loads(body_unicode)

instance = HydroShareResourcesList.objects.get(id=body["instance_id"])
# logger.warning(instance.updated_version)
keywords = []
json_resources = {"resources": []}
# logging.warning(instance.user,instance.password)
if instance.tags:
keywords = instance.tags.split(",")
# logging.warning(keywords)
if instance.user != "" and instance.password != "":
auth = HydroShareAuthBasic(username=instance.user, password=instance.password)
hs = HydroShare(auth=auth)
Expand All @@ -49,9 +46,6 @@ def hydroshare_resources_view(request):
matching_resource_model = get_dict_with_attribute(
resources_model, "resource_id", resource_api["resource_id"]
)
# logging.warning("this is a matching_resource_model")
# logging.warning(matching_resource_model)

# If resource found locally, then check last update date
if matching_resource_model:
is_recent_date = get_most_recent_date(
Expand All @@ -62,27 +56,20 @@ def hydroshare_resources_view(request):
if (
is_recent_date
): # If the resource retrieved from api is more recent, then update resource
# logging.warning("resource has a more recent version")
single_resource = update_resource(resource_api, hs, instance)
# logging.warning(single_resource)
json_resources["resources"].append(single_resource)
instance.resources = json_resources

else: # resource is the same, then retrive the resource saved locally
# logging.warning("resource is the same")

single_resource = matching_resource_model
json_resources["resources"].append(single_resource)
instance.resources = json_resources
# If the resource is not here then create one
else:
# logging.warning(resource)
# logging.warning("resource is new, creating now")
single_resource = update_resource(resource_api, hs, instance)
json_resources["resources"].append(single_resource)

instance.resources = json_resources
# logging.warning(json_resources)

instance.save(update_fields=["resources"])
return JsonResponse(json_resources)
Expand Down

0 comments on commit 39854a6

Please sign in to comment.