Skip to content

Commit

Permalink
reworked list views:
Browse files Browse the repository at this point in the history
* removed cards
* removed not needed columns
* wrapped all search fields into BS-Accordions
  • Loading branch information
csae8092 committed Jul 12, 2024
1 parent 7df8e6a commit 8611b85
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 29 deletions.
2 changes: 1 addition & 1 deletion env.default
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DEBUG=False
DEBUG=True
SECRET_KEY=Whateveryouwantbutchangeforproduction
POSTGRES_DB=histogis
POSTGRES_USER=postgres
Expand Down
14 changes: 10 additions & 4 deletions histogis/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@

SECRET_KEY = os.environ.get("SECRET_KEY", "TZRHHwasdfsadfdsafkljlxö7639827249324GV")

DEBUG = os.environ.get("DEBUG", True)
DEBUG = os.environ.get("DEBUG", False)

if DEBUG:
CACHE_TIMEOUT = 0
else:
CACHE_TIMEOUT = None

# CACHES = {
# "default": {
# "BACKEND": "django.core.cache.backends.db.DatabaseCache",
# "LOCATION": "my_cache_table",
# "TIMEOUT": CACHE_TIMEOUT,
# }
# }

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
"LOCATION": "my_cache_table",
"TIMEOUT": CACHE_TIMEOUT,
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
}
}

Expand Down
37 changes: 21 additions & 16 deletions shps/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Fieldset
from crispy_forms.bootstrap import Accordion, AccordionGroup
from crispy_bootstrap5.bootstrap5 import BS5Accordion
from crispy_forms.bootstrap import AccordionGroup

from leaflet.forms.widgets import LeafletWidget

Expand Down Expand Up @@ -85,11 +86,15 @@ def __init__(self, *args, **kwargs):
self.form_class = "genericFilterForm"
self.form_method = "GET"
self.form_tag = False
self.add_input(Submit("Filter", "Search"))
self.layout = Layout(
Fieldset("Basic search options", "name", css_id="basic_search_fields"),
Accordion(
AccordionGroup("Advanced search", "description", css_id="more"),
BS5Accordion(
AccordionGroup("Basic Search", "name", css_id="basic_search_fields"),
AccordionGroup(
"Advanced search",
"description",
css_id="extended",
),
always_open=True,
),
)

Expand Down Expand Up @@ -121,23 +126,23 @@ def __init__(self, *args, **kwargs):
self.form_class = "genericFilterForm"
self.form_method = "GET"
self.form_tag = False
self.add_input(Submit("Filter", "Search"))
self.layout = Layout(
Fieldset(
"Basic search options",
"all_name",
"name",
"alt_name",
css_id="basic_search_fields",
),
Accordion(
BS5Accordion(
AccordionGroup(
"Basic Search",
"all_name",
"name",
"alt_name",
css_id="basic_search_fields",
),
AccordionGroup(
"Advanced search",
"start_date",
"end_date",
"administrative_unit",
"source",
css_id="more",
css_id="extended",
),
),
always_open=True,
)
)
5 changes: 0 additions & 5 deletions shps/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
class TempSpatialTable(tables.Table):
id = tables.LinkColumn("shapes:shape_detail", args=[A("pk")], verbose_name="ID")
name = tables.LinkColumn("shapes:shape_detail", args=[A("pk")], verbose_name="Name")
source = tables.Column()
part_of = tables.Column()
administrative_unit = tables.Column()

class Meta:
model = TempSpatial
sequence = (
"id",
"name",
"part_of",
)
attrs = {"class": "table table-responsive table-hover"}

Expand All @@ -24,7 +20,6 @@ class SourceTable(tables.Table):
name = tables.LinkColumn(
"shapes:source_detail", args=[A("pk")], verbose_name="Name"
)
administrative_unit = tables.Column()

class Meta:
model = Source
Expand Down
62 changes: 62 additions & 0 deletions shps/templates/shps/generic_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{% extends "webpage/base.html" %}
{% load static %}
{% load django_tables2 %}
{% load browsing_extras %}
{% load crispy_forms_field %}
{% load crispy_forms_tags %}
{% block title %} Browse {{ class_name }} {% endblock %}
{% block scriptHeader %}

{% endblock %}
{% block content %}

<div class="container">

<h1 class="text-center p-4">
Browse {% class_definition %} {% block list_title %} {% endblock %}
</h1>
{% if user.is_authenticated %}
<div class="d-grid gap-2">
<a class="btn btn-primary float-center ms-5 me-5" href="{{ create_view_link }}">Create new {{ class_name }}</a>
</div>
{% endif %}

<div class="row">
<div class="col-md-4">
{% block customView %}{% endblock %}
{% block create_button %}{% endblock %}
<!--Search mask-->
{% load django_tables2 crispy_forms_tags %}
<form action="." class="uniForm" method="get">
{% crispy filter.form filter.form.helper %}
{% include 'shps/partials/column_selector.html' %}
<div class="d-grid gap-2 pt-2" aria-label="Search or reset search">
<button type="submit" class="btn btn-primary">Submit</button>
<a class="btn btn-primary" href=".">Reset</a>
</div>
</form>
{% include 'browsing/partials/chart_form.html' %}
</div>
<div class="col-md-8" id="results">
{% with table.paginator.count as total %}
<h2 class="text-center">{{ total }} Result(s)</h2>
{% endwith %}
{% block table %}
{% include 'browsing/partials/table.html' %}
{% endblock table %}
{% block pagination.allpages %}
{% include 'browsing/partials/pagination.html' %}
{% endblock pagination.allpages %}
<div class="float-end">
{% include "browsing/partials/download_menu.html" %}
</div>
</div>
</div>
</div>


{% endblock %}
{% block scripts2 %}
<script src="{% static 'browsing/js/set-form-attributes.js' %}"></script>
<script src="{% static 'browsing/js/filter-for-blank-fields.js' %}"></script>
{% endblock scripts2 %}
33 changes: 33 additions & 0 deletions shps/templates/shps/partials/column_selector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="accordion" id="columnTogglerAccordion">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#columnTogglerAccordionOne" aria-expanded="false"
aria-controls="columnTogglerAccordionOne">
Display additional columns
</button>
</h2>
<div id="columnTogglerAccordionOne" class="accordion-collapse collapse"
data-bs-parent="#columnTogglerAccordion">
<div class="accordion-body">
{% if togglable_colums %}
<select class="form-control mb-3" size="12" multiple name="columns" id="column_selector">
{% for key, value in togglable_colums.items %}
{% if key == 'merge' and user.is_authenticated and enable_merge %}
<option value="{{ key }}">
{{ value }}
</option>
{% elif key == 'merge' and not user.is_authenticated %}
{% elif key != 'merge' %}
<option value="{{ key }}">
{{ value }}
</option>
{% endif %}
{% endfor %}
</select>
{% else %}
{% endif %}
</div>
</div>
</div>
</div>
5 changes: 4 additions & 1 deletion shps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class TempSpatialListView(GenericListView):
"start_date",
"end_date",
]
exclude_columns = ["geom",]

template_name = "shps/generic_list.html"

def get_context_data(self, **kwargs):
context = super(TempSpatialListView, self).get_context_data()
Expand Down Expand Up @@ -147,8 +150,8 @@ class SourceListView(GenericListView):
init_columns = [
"id",
"name",
"part_of",
]
template_name = "shps/generic_list.html"


class SourceDetailView(DetailView):
Expand Down
3 changes: 1 addition & 2 deletions webpage/static/webpage/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ a:hover {
}

.collapsed {
background-color: var(--histogis-main);
color: #fff;
border-color: var(--histogis-main);
}

0 comments on commit 8611b85

Please sign in to comment.