Skip to content

Commit

Permalink
Fix structure and collection in URL query
Browse files Browse the repository at this point in the history
  • Loading branch information
henhuy committed Apr 2, 2024
1 parent b2f4094 commit 9451277
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project tries to adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- structure and collection in URL query

## [0.5.0] - 2024-03-22
### Added
- selection view for selecting structure and collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h3>Related processes:</h3>
<ul>
{% for process in processes %}
<li>
<a href="{% url 'django_energysystem_viewer:processes' collection_name=collection_name %}?process={{ process }}">{{ process }}</a>
<a href="{% url 'django_energysystem_viewer:processes' %}?collection={{ collection_name }}&structure={{ structure_name }}&process={{ process }}">{{ process }}</a>
</li>
{% endfor %}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2>{{ group.grouper }}</h2>
{% for artifact in group.list %}
<li>
<button class="btn btn-link"
hx-get="/collection/{{ collection_name }}/artifact/{{ artifact.group }}/{{ artifact.artifact }}/{{ artifact.version }}/data"
hx-get="/energysystem/artifact/{{ artifact.group }}/{{ artifact.artifact }}/{{ artifact.version }}/data?collection={{ collection_name }}"
hx-target="#artifact-detail">{{ artifact.artifact }} ({{ artifact.version }})</button>
</li>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h3>Related artifacts:</h3>
<ul>
{% for artifact in artifacts %}
<li>
<a href="{% url 'django_energysystem_viewer:artifacts' collection_name=collection_name %}?group={{ artifact.group }}&artifact={{ artifact.artifact }}">{{ artifact.artifact }}</a>
<a href="{% url 'django_energysystem_viewer:artifacts' %}?collection={{ collection_name }}&structure={{ structure_name }}&group={{ artifact.group }}&artifact={{ artifact.artifact }}">{{ artifact.artifact }}</a>
</li>
{% endfor %}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1>Collection "{{ collection_name }}"</h1>
{% for process in processes %}
<li>
<button class="btn btn-link"
hx-get="/collection/{{ collection_name }}/process/{{ process }}/data"
hx-get="/energysystem/process/{{ process }}/data?collection={{ collection_name }}"
hx-target="#process-detail">{{ process }}</button>
</li>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ <h1>Selections:</h1>
{% csrf_token %}
<div>
<label for="structures">Structure</label>
<select class="form-select" id="structures" name="structures">
<select class="form-select" id="structure" name="structure">
{% for structure in structure_list %}<option label="{{ structure }}">{{ structure }}</option>{% endfor %}
</select>
</div>
<div>
<label for="collections">Collection</label>
<select class="form-select" id="collections" name="collections">
<label for="collection">Collection</label>
<select class="form-select" id="collection" name="collection">
{% for collection in collection_list %}<option label="{{ collection }}">{{ collection }}</option>{% endfor %}
</select>
</div>
Expand Down
10 changes: 5 additions & 5 deletions django_energysystem_viewer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
path("energysystem/abbreviation/", views.abbreviations, name="abbreviations"),
path("energysystem/abbreviation_meaning/", views.abbreviation_meaning),
path("energysystem/aggregation/", views.AggregationView.as_view(), name="aggregations"),
path("collection/processes/", views.ProcessesView.as_view(), name="processes"),
path("energysystem/processes/", views.ProcessesView.as_view(), name="processes"),
path(
"collection/<str:collection_name>/process/<str:process_name>/data/",
"energysystem/process/<str:process_name>/data/",
views.ProcessDetailView.as_view(),
),
path("collection/artifacts/", views.ArtifactsView.as_view(), name="artifacts"),
path("energysystem/artifacts/", views.ArtifactsView.as_view(), name="artifacts"),
path(
"collection/<str:collection_name>/artifact/<str:group_name>/<str:artifact_name>/data/",
"energysystem/artifact/<str:group_name>/<str:artifact_name>/data/",
views.ArtifactDetailView.as_view(),
),
path(
"collection/<str:collection_name>/artifact/<str:group_name>/<str:artifact_name>/<str:version>/data/",
"energysystem/artifact/<str:group_name>/<str:artifact_name>/<str:version>/data/",
views.ArtifactDetailView.as_view(),
),
]
18 changes: 10 additions & 8 deletions django_energysystem_viewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_excel_data(file: str, sheet: str):


def network(request):
structure_name = request.GET.get("structures")
structure_name = request.GET.get("structure")
process_set = get_excel_data(structure_name, "Process_Set")
unique_processes = process_set["process"].unique()

Expand Down Expand Up @@ -75,7 +75,7 @@ def network_graph(request):


def abbreviations(request):
structure_name = request.GET.get("structures")
structure_name = request.GET.get("structure")
abbreviations = get_excel_data(structure_name, "Abbreviations")
abbreviation_list = abbreviations["abbreviations"].unique()
return render(
Expand Down Expand Up @@ -103,13 +103,13 @@ class AggregationView(TemplateView):
template_name = "django_energysystem_viewer/aggregation.html"

def get_context_data(self, **kwargs):
structure_name = self.request.GET.get("structures")
structure_name = self.request.GET.get("structure")
return {"structure_name": structure_name}


class ProcessDetailMixin:
def get_context_data(self, **kwargs):
collection_name = self.request.GET.get("collections")
collection_name = self.request.GET["collection"]
collection_url = collection.get_collection_meta(collection_name)["name"]
process_name = kwargs.get("process_name", self.request.GET.get("process"))
if not process_name:
Expand All @@ -133,9 +133,11 @@ class ProcessesView(ProcessDetailMixin, TemplateView):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
collection_name = self.request.GET.get("collections")
collection_name = self.request.GET.get("collection")
processes = collection.get_processes_from_collection(collection_name)
context = {"collection_name": collection_name, "processes": processes, "banner_data": collection_name}
context["collection_name"] = collection_name
context["processes"] = processes
context["banner_data"] = collection_name
return context


Expand All @@ -147,7 +149,7 @@ class ArtifactsView(TemplateView):
template_name = "django_energysystem_viewer/artifacts.html"

def get_context_data(self, **kwargs):
collection_name = self.request.GET.get("collections")
collection_name = self.request.GET.get("collection")
collection_url = collection.get_collection_meta(collection_name)["name"]
artifacts = collection.get_artifacts_from_collection(collection_name)
context = {
Expand Down Expand Up @@ -175,7 +177,7 @@ class ArtifactDetailView(TemplateView):
template_name = "django_energysystem_viewer/artifact_detail.html"

def get_context_data(self, **kwargs):
collection_name = kwargs["collection_name"]
collection_name = self.request.GET["collection"]
group_name = kwargs["group_name"]
artifact_name = kwargs["artifact_name"]
version = kwargs.get("version")
Expand Down

0 comments on commit 9451277

Please sign in to comment.