Skip to content

Commit

Permalink
Merge pull request #94 from SpokaneTech/add-list-all-to-sidebar
Browse files Browse the repository at this point in the history
#93: Add list all links to side bar
  • Loading branch information
joeriddles authored Apr 7, 2024
2 parents 98bf3a0 + 2bf4d93 commit 352ef2d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/templates/spokanetech/htmx/build_sidebar.htm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% if item.htmx_link is False %}
<a href="{{ item.list_all_url}}" class="sidebar-link ms-4">All {{ item.model_name }}</a>
{% else %}
<a hx-get="{{ item.list_all_url }}" hx-target="#{{ item.htmx_target }}" class="sidebar-link ms-4">All {{ item.model_name }}</a>
<a hx-get="{{ item.list_all_url }}" hx-target="#{{ item.htmx_target }}" hx-push-url="true" class="sidebar-link ms-4">All {{ item.model_name }}</a>
{% endif %}
</li>
{% endif %}
Expand Down
15 changes: 0 additions & 15 deletions src/web/templates/web/list_tech_groups.html

This file was deleted.

8 changes: 3 additions & 5 deletions src/web/templates/web/partials/table/table_events.htm
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{% load markdownify %}
<table data-toggle="table">
{% load web_extras markdownify %}
<table class="table table-bordered table-hover" data-toggle="table">
<thead>
<th>Name</th>
<th>Group</th>
<th>Description</th>
<th>When</th>
<th>Duration</th>
<th>Location</th>
Expand All @@ -17,11 +16,10 @@
<td>
<a href="{{ event.group.get_absolute_url }}">{{ event.group }}</a>
</td>
<td>{{ event.description|markdownify }}</td>
<td data-testid="date_time">
{% include 'spokanetech/partials/human_readable_datetime.htm' with object=event only %}
</td>
<td>{{ event.duration }} hour{{ event.duration|pluralize }}</td>
<td>{% if event.duration %}{{ event.duration|timedelta }}{% endif %}</td>
<td>{{ event.location }}</td>
</tr>
{% endfor %}
Expand Down
23 changes: 23 additions & 0 deletions src/web/templates/web/partials/table/table_tech_groups.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% load markdownify %}
<table class="table table-bordered table-hover" data-toggle="table">
<thead>
<th>Name</th>
<th>Homepage</th>
</thead>
<tbody>
{% for object in queryset %}
<tr>
<td>
<a href="{{ object.get_absolute_url }}">
{% if object.icon %}<span class="pe-2 {{ object.icon|safe }}"></span>{% endif %}{{ object.name }}
</a>
</td>
<td>
{% if object.homepage %}
<a href="{{ object.homepage }}" target="_blank">{{ object.homepage }}</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
2 changes: 1 addition & 1 deletion src/web/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_list_tech_groups(client: Client):

# Assert
assert response.status_code == 200
assert response.context["groups"].get().pk == tech_group.pk
assert response.context["queryset"].get().pk == tech_group.pk


@pytest.mark.django_db
Expand Down
6 changes: 3 additions & 3 deletions src/web/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from web import views

from django.urls import path

from web import views

app_name = "web"

urlpatterns = [
path("", views.Index.as_view(), name="index"),
path("set_timezone/", views.set_timezone, name="set_timezone"),
path("events", views.ListEvents.as_view(), name="events"),
path("groups", views.list_tech_groups, name="list_tech_groups"),
path("groups", views.ListTechGroup.as_view(), name="list_tech_groups"),
path("groups/<int:pk>", views.DetailTechGroup.as_view(), name="get_tech_group"),
path("events/<int:pk>", views.DetailEvent.as_view(), name="get_event"),
path("build_sidebar", views.BuildSidebar.as_view(), name="build_sidebar"),
Expand Down
27 changes: 22 additions & 5 deletions src/web/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any

from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.template import loader
from django.urls import reverse_lazy
from django.utils import timezone
from django.views.decorators.http import require_http_methods
from django.views.generic import DetailView
Expand Down Expand Up @@ -38,7 +38,7 @@ def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)


class ListEvents(HandyHelperListView):
class ListEvents(HtmxViewMixin, HandyHelperListView):
title = "Events"
base_template = "spokanetech/base.html"
table = "web/partials/table/table_events.htm"
Expand All @@ -47,6 +47,11 @@ def __init__(self, **kwargs: Any) -> None:
self.queryset = Event.objects.filter(date_time__gte=timezone.now()).order_by("date_time")
super().__init__(**kwargs)

def get(self, request, *args, **kwargs):
if self.is_htmx():
self.template_name = "handyhelpers/generic/bs5/generic_list_content.htm"
return super().get(request, *args, **kwargs)


class DetailEvent(HtmxViewMixin, DetailView):
model = Event
Expand All @@ -66,9 +71,19 @@ def get(self, request, *args, **kwargs):
return super().get(request, *args, **kwargs)


def list_tech_groups(request: HttpRequest) -> HttpResponse:
groups = TechGroup.objects.all()
return render(request, "web/list_tech_groups.html", {"groups": groups})
class ListTechGroup(HtmxViewMixin, HandyHelperListView):
title = "Tech Groups"
base_template = "spokanetech/base.html"
table = "web/partials/table/table_tech_groups.htm"

def __init__(self, **kwargs: Any) -> None:
self.queryset = TechGroup.objects.filter(enabled=True)
super().__init__(**kwargs)

def get(self, request, *args, **kwargs):
if self.is_htmx():
self.template_name = "handyhelpers/generic/bs5/generic_list_content.htm"
return super().get(request, *args, **kwargs)


class BuildSidebar(BuildModelSidebarNav):
Expand All @@ -79,10 +94,12 @@ class BuildSidebar(BuildModelSidebarNav):
menu_item_list = [
{
"queryset": Event.objects.filter(date_time__gte=timezone.now()).order_by("date_time"),
"list_all_url": reverse_lazy("web:events"),
"icon": """<i class="fa-solid fa-calendar-day"></i>""",
},
{
"queryset": TechGroup.objects.filter(enabled=True).order_by("name"),
"list_all_url": reverse_lazy("web:list_tech_groups"),
"icon": """<i class="fa-solid fa-people-group"></i>""",
},
]
Expand Down

0 comments on commit 352ef2d

Please sign in to comment.