Skip to content

Commit

Permalink
Add Filters to the Products under View Product Type (#11321)
Browse files Browse the repository at this point in the history
* initial add of filters

* remove unneeded things

* mostly the same

* small tweaks

* fix access error

* fix access error add product

---------

Co-authored-by: Cody Maffucci <[email protected]>
  • Loading branch information
hblankenship and Maffooch authored Dec 4, 2024
1 parent b201a19 commit 5cff5bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
11 changes: 8 additions & 3 deletions dojo/product_type/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from dojo.authorization.authorization import user_has_permission
from dojo.authorization.authorization_decorators import user_has_global_permission, user_is_authorized
from dojo.authorization.roles_permissions import Permissions
from dojo.filters import ProductTypeFilter
from dojo.filters import ProductFilter, ProductFilterWithoutObjectLookups, ProductTypeFilter
from dojo.forms import (
Add_Product_Type_GroupForm,
Add_Product_Type_MemberForm,
Expand All @@ -38,6 +38,7 @@
async_delete,
get_page_items,
get_setting,
get_system_setting,
is_title_in_breadcrumbs,
)

Expand All @@ -51,7 +52,6 @@


def product_type(request):

prod_types = get_authorized_product_types(Permissions.Product_Type_View)
name_words = prod_types.values_list("name", flat=True)

Expand Down Expand Up @@ -123,12 +123,17 @@ def view_product_type(request, ptid):
groups = get_authorized_groups_for_product_type(pt, Permissions.Product_Type_View)
global_groups = get_authorized_global_groups_for_product_type(pt, Permissions.Product_Type_View)
products = get_authorized_products(Permissions.Product_View).filter(prod_type=pt)
products = get_page_items(request, products, 25)
filter_string_matching = get_system_setting("filter_string_matching", False)
filter_class = ProductFilterWithoutObjectLookups if filter_string_matching else ProductFilter
prod_filter = filter_class(request.GET, queryset=products, user=request.user)
products = get_page_items(request, prod_filter.qs, 25)

add_breadcrumb(title=page_name, top_level=False, request=request)
return render(request, "dojo/view_product_type.html", {
"name": page_name,
"pt": pt,
"products": products,
"prod_filter": prod_filter,
"groups": groups,
"members": members,
"global_groups": global_groups,
Expand Down
31 changes: 19 additions & 12 deletions dojo/templates/dojo/view_product_type.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,28 @@ <h3 class="pull-left">{% trans "Description" %}</h3>
<div class="panel-heading">
<div class="clearfix">
<h4 class="pull-left">{% trans "Products" %}</h4>
{% if pt|has_object_permission:"Product_Type_Add_Product" %}
<div class="dropdown pull-right">
<div class="btn-group">
<button class="btn btn-primary dropdown-toggle" type="button" label="Actions" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
<span class="fa-solid fa-bars"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dropdownMenu1">
<li>
<a class="" href="{% url 'add_product_to_product_type' pt.id %}">
<i class="fa-solid fa-plus"></i> {% trans "Add Product" %}</a>
</li>
</ul>
<button name="Show Filters" id="show-filters" data-toggle="collapse" data-target="#the-filters" class="btn btn-primary toggle-filters"> <i class="fa-solid fa-filter"></i> <i class="caret"></i> </button>
{% if pt|has_object_permission:"Product_Type_Add_Product" %}
<button name="Add Product" class="btn btn-primary dropdown-toggle" type="button" label="Actions" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
<span class="fa-solid fa-bars"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dropdownMenu1">
<li>
<a class="" href="{% url 'add_product_to_product_type' pt.id %}">
<i class="fa-solid fa-plus"></i> {% trans "Add Product" %}</a>
</li>
</ul>
{% endif %}
</div>
</div>
{% endif %}
</div>
</div>
<div id="the-filters" class="is-filters panel-body collapse {% if prod_filter.form.has_changed %}in{% endif %}">
{% include "dojo/filter_snippet.html" with form=prod_filter.form %}
</div>
{% if products %}
<div class="clearfix pagination-in-panel">
{% include "dojo/paging_snippet.html" with page=products page_size=True %}
Expand Down Expand Up @@ -325,3 +329,6 @@ <h3 class="panel-title"><span class="fa-solid fa-circle-info fa-fw" aria-hidden=
</div>
</div>
{% endblock %}
{% block postscript %}
{% include "dojo/filter_js_snippet.html" %}
{% endblock %}

0 comments on commit 5cff5bc

Please sign in to comment.