Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Filters to the Products under View Product Type #11321

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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>
hblankenship marked this conversation as resolved.
Show resolved Hide resolved
hblankenship marked this conversation as resolved.
Show resolved Hide resolved
{% if pt|has_object_permission:"Product_Type_Add_Product" %}
<button class="btn btn-primary dropdown-toggle" type="button" label="Actions" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
hblankenship marked this conversation as resolved.
Show resolved Hide resolved
<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 %}