Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ cython_debug/

# Mac
.DS_Store

# Project-specific ignores
local_settings.py
14 changes: 14 additions & 0 deletions dgpf1/dgpf1/facet_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ def lookup_replace_provider_id(facets: dict) -> dict:
"added to the database!")
bucket["custom_display_value"] = "Other"
return facets


def combine_info_group(facets: list) -> list:
"""Collapse Info_GroupID and Info_GroupName into a single 'Resource Group'
facet that filters by name. Drops the raw ID facet from display."""
combined = []
for facet in facets:
if facet["field_name"] == "Info_GroupID":
continue
if facet["field_name"] == "Info_GroupName":
facet = dict(facet)
facet["name"] = "Resource Group"
combined.append(facet)
return combined
42 changes: 42 additions & 0 deletions dgpf1/dgpf1/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def title(result):
return result[0]['Title']


def software_title(result):
return result[0].get('Name', 'Software Detail')


def general_info(result):
"""Return all basic information in the first gmeta entry"""
return result[0]
Expand Down Expand Up @@ -48,3 +52,41 @@ def detail_result_display_fields(result):
# If the date cannot be parsed, just leave it.
pass
return display_fields


def software_detail_result_display_fields(result):
possible_date_fields = ["CreationTime"]
info = general_info(result)
leading_fields = [
{"field_name": "Name"},
{"field_name": "Category"},
{"field_name": "Keywords"},
{"field_name": "SupportStatus", "display_name": "Support Status"},
{"field_name": "Version"},
{"field_name": "URL"},
{"field_name": "Organization_Name", "display_name": "Organization Name"},
{"field_name": "Organization_ID", "display_name": "Organization ID"},
{"field_name": "Info_GroupName", "display_name": "Resource Group"},
{"field_name": "Info_GroupID", "display_name": "Resource Group ID"},
{"field_name": "Info_ResourceName", "display_name": "Resource Name"},
{"field_name": "Info_ResourceID", "display_name": "Resource ID"},
]
trailing_fields = [
{"field_name": "HandleKey", "display_name": "Handle Key"},
{"field_name": "HandleType", "display_name": "Handle Type"},
{"field_name": "CreationTime", "display_name": "Creation Time"},
]
known_field_names = [fl["field_name"] for fl in leading_fields + trailing_fields]
other_fields = [{"field_name": f} for f in info if f not in known_field_names]
display_fields = leading_fields + other_fields + trailing_fields
for item in display_fields:
item["display_name"] = item.get("display_name", item["field_name"].replace("_", " "))
item["value"] = info.get(item["field_name"])
item["is_list"] = isinstance(item["value"], list)
if item["field_name"] in possible_date_fields:
try:
item["value"] = datetime.datetime.fromisoformat(item["value"].replace("Z", "+00:00")).strftime("%b %d %Y %H:%M:%S %Z%z")
item["is_list"] = False
except Exception:
pass
return display_fields
52 changes: 39 additions & 13 deletions dgpf1/dgpf1/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import json
import os
import sys
from dgpf1.fields import title, general_info, detail_result_display_fields
from dgpf1.fields import title, general_info, detail_result_display_fields, software_title, software_detail_result_display_fields
#import pdb
#pdb.set_trace()

Expand Down Expand Up @@ -79,8 +79,10 @@
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'libraries': {
'settings_value': 'templatetags.get_settings',
'urldecode': 'templatetags.custom_tags',
},
'context_processors': [
'django.template.context_processors.debug',
Expand All @@ -102,20 +104,21 @@
'default': {
'USER': CONF['DJANGO_USER'],
'PASSWORD': CONF['DJANGO_PASS'],
'HOST': os.environ.get('PGHOST', CONF.get('DB_HOSTNAME_WRITE', 'localhost')),
'HOST': os.environ.get('PGHOST', CONF.get('DB_HOSTNAME_WRITE', 'db')),
},
'sqlite3': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
# 'sqlite3': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
}

for db in DATABASES:
DATABASES[db]['NAME'] = CONF['DB_DATABASE']
DATABASES[db]['ENGINE'] = 'django.db.backends.postgresql'
DATABASES[db]['PORT'] = os.environ.get('PGPORT', CONF.get('DB_PORT', '5432'))
DATABASES[db]['CONN_MAX_AGE'] = 600 # Persist DB connections
DATABASES[db]['OPTIONS'] = {'options': '-c search_path=ed_dgpf1,public'}
if db == "default":
DATABASES[db]['NAME'] = CONF['DB_DATABASE']
DATABASES[db]['ENGINE'] = 'django.db.backends.postgresql'
DATABASES[db]['PORT'] = os.environ.get('PGPORT', CONF.get('DB_PORT', '5432'))
DATABASES[db]['CONN_MAX_AGE'] = 600 # Persist DB connections
DATABASES[db]['OPTIONS'] = {'options': '-c search_path=ed_dgpf1,public'}

# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -167,7 +170,8 @@
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = CONF['STATIC_ROOT']

STATIC_ROOT = BASE_DIR / 'static'
STATICFILES_DIRS = [BASE_DIR / 'staticfiles']

# Default primary key field type
Expand Down Expand Up @@ -289,8 +293,30 @@
('general_info', general_info),
('detail_result_display_fields', detail_result_display_fields),
],
},
'access-software-v4': {
'name': 'ACCESS Software Catalog - Beta catalog v4',
'uuid': '3cc4aeec-55a5-4cd6-96d1-8531aef88e83',
'facets': [
{'name': 'Category', 'field_name': 'Category'},
{'name': 'Keywords', 'field_name': 'Keywords'},
{'name': 'Support Status', 'field_name': 'SupportStatus'},
{'name': 'Organization', 'field_name': 'Organization_Name'},
{'name': 'Resource Group', 'field_name': 'Info_GroupName'},
{'name': 'Resource', 'field_name': 'Info_ResourceName'},
],
'facet_modifiers': [
'globus_portal_framework.modifiers.facets.drop_empty',
# 'dgpf1.facet_modifiers.combine_info_group',
],
'fields': [
('title', software_title),
('general_info', general_info),
('detail_result_display_fields', software_detail_result_display_fields),
],
'template_override_dir': 'access-software-v4',
}
}

PROJECT_TITLE = 'Search Pilot'
APP_VERSION = CONF.get('APP_VERSION', '')
APP_VERSION = CONF.get('APP_VERSION', '')
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

{% load static %}
{% load urldecode %}
{% block headextras %}{% endblock %}

<div class="row">
<div class="col-md-8">
<h3 class="h3">Results
{% if search.total %}
<a href="{% url 'download-as-html' globus_portal_framework.index %}" class="btn btn-default">
<i class="fas fa-download"></i>
</a>
{% endif %}
</h3>

{% if search.total %}
<h6 class="h6">{{search.total}} software items found</h6>
{% endif %}
</div>
</div>

<div id="search-result" class="search-result">
{% for result in search.search_results %}
<div class="card my-3">
<div class="card-header">
<h3 class="search-title">
<a href="{% url 'detail' globus_portal_framework.index result.subject %}">{{result.title|default:result.subject|urldecode}}</a>
</h3>
</div>
<div class="card-body">
{% if result.general_info.Description %}
<p class="card-text">{{ result.general_info.Description }}</p>
{% endif %}
</div>
</div>
{% endfor %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends 'globus-portal-framework/v2/detail-base.html' %}


{% block breadcrumb_items %}
<li class="breadcrumb-item"><a class="h5" href="{% url 'index-selection' %}">{{globus_portal_framework.project_title}}</a></li>
<li class="breadcrumb-item"><a class="h5" href="{% url 'search' globus_portal_framework.index %}">{{globus_portal_framework.index_data.name}}</a></li>
<li class="breadcrumb-item active"><a class="h5">{{title|default:'Software Detail'}}</a></li>
{% endblock %}


{% block detail_body %}

<div class="row">
<div class="col-md-12">

{% block detail_search_content %}
<h3 class="text-center mb-5">{{ title|default:'Software' }} — Properties</h3>

{% load urldecode %}
<table class="table table-striped table-bordered">
<tbody>
{% for item in detail_result_display_fields %}
{% if item.value %}
<tr>
<td class="fw-semibold text-nowrap" style="width:30%">{{ item.display_name }}</td>
<td>
{% if item.field_name == "URL" %}
<a href="{{ item.value }}" target="_blank" rel="noopener noreferrer">{{ item.value }}</a>
{% elif item.is_list %}
<ul class="mb-0 ps-3">
{% for v in item.value %}<li>{{ v }}</li>{% endfor %}
</ul>
{% else %}
{{ item.value }}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>

<h5 class="text-center my-4 text-muted">Globus Search Metadata</h5>
{% include 'globus-portal-framework/v2/components/detail-globus-search-metadata.html' %}
{% endblock %}

</div>
</div>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% load urldecode %}
<table class="table table-striped table-bordered">
<tbody>
{% block detail_general_metadata %}
<tr>{{ request.path|urldecode }}</tr>
{% for item in detail_result_display_fields %}
<tr>
<td>{{item.display_name}}</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

{% load urldecode %}
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td><b>subject</b></td>
<td>{{ subject }}</td>
<td>{{ subject|urldecode }}</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load static %}

{% load static %}
{% load urldecode %}
{% block headextras %}{% endblock %}

<div class="row">
Expand All @@ -23,14 +24,14 @@ <h6 class="h6">{{search.total}} training items found</h6>
<div class="card my-3">
<div class="card-header">
<h3 class="search-title">
<a href="{% url 'detail' globus_portal_framework.index result.subject %}">{{result.all.0.Title|default:'Result'}}</a>
<a href="{% url 'detail' globus_portal_framework.index result.subject %}">{{result.subject|urldecode}}</a>
</h3>
</div>
<div class="card-body">
<table class="table table-sm borderless">
<tbody>
<tr>
{{result.all.0.Abstract|safe}}
{{result.all.0.Abstract|default:result.all.0.Description|safe}}
<!-- {% for formatted_result in result.formatted_search_results %}-->
<!-- <th>{{formatted_result.Title}}</th>-->
<!-- {% endfor %}-->
Expand Down
10 changes: 10 additions & 0 deletions dgpf1/templatetags/custom_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django import template
from urllib.parse import unquote

register = template.Library()

@register.filter
def urldecode(value):
if value is None:
return value
return unquote(value)