Cat breeds
This commit is contained in:
@ -4,7 +4,7 @@ from .complex_form.views import (
|
||||
RouteModuleHandleView,
|
||||
WarehouseManagementHandleView,
|
||||
)
|
||||
from .filter_list import FilterListView
|
||||
from .filter_list import FilterListFilterView, FilterListView
|
||||
from .form_validation import FormValidationView
|
||||
from .home import HomeView
|
||||
from .swap import SwapView
|
||||
|
||||
@ -1,7 +1,61 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from project.main.cat_breeds import CatBreed, cat_breeds
|
||||
from project.main.views.demo_view_base import DemoViewBase
|
||||
|
||||
|
||||
def get_countries() -> list[str]:
|
||||
return sorted(set([c.country for c in cat_breeds if len(c.country)]))
|
||||
|
||||
|
||||
def filter_cat_breeds(
|
||||
breed_filter: Optional[str] = None, country_filter: Optional[str] = None
|
||||
) -> list[CatBreed]:
|
||||
if not breed_filter and not country_filter:
|
||||
return cat_breeds
|
||||
|
||||
result = []
|
||||
for breed in cat_breeds:
|
||||
# if (not breed_filter or breed_filter.lower() in breed.name.lower()) or (
|
||||
# not country_filter or country_filter == breed.country
|
||||
# ):
|
||||
if not breed_filter or breed_filter.lower() in breed.name.lower():
|
||||
result.append(breed)
|
||||
return result
|
||||
|
||||
|
||||
class FilterListView(DemoViewBase):
|
||||
template_name = "main/filter_list.html"
|
||||
active_section = "filter-list"
|
||||
title = "Filter List"
|
||||
|
||||
def get_context_data(self, **kwargs) -> dict[str, Any]:
|
||||
context_data = super().get_context_data(**kwargs)
|
||||
|
||||
context_data.update(
|
||||
{
|
||||
"cat_breeds": filter_cat_breeds(),
|
||||
"countries": get_countries(),
|
||||
}
|
||||
)
|
||||
return context_data
|
||||
|
||||
|
||||
class FilterListFilterView(DemoViewBase):
|
||||
template_name = "main/filter_list_content.html"
|
||||
|
||||
def get_context_data(self, **kwargs) -> dict[str, Any]:
|
||||
context_data = super().get_context_data(**kwargs)
|
||||
|
||||
cat_breeds = filter_cat_breeds(
|
||||
breed_filter=self.request.GET.get("breed"),
|
||||
country_filter=self.request.GET.get("country"),
|
||||
)
|
||||
|
||||
context_data.update(
|
||||
{
|
||||
"cat_breeds": cat_breeds,
|
||||
"countries": get_countries(),
|
||||
}
|
||||
)
|
||||
return context_data
|
||||
|
||||
Reference in New Issue
Block a user