Commit 4d659bd5 authored by Patrick's avatar Patrick

Replace lists filters with dropdown on admin products list

parent c79519d5
......@@ -4,12 +4,13 @@ from __future__ import unicode_literals
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from repanier.const import *
# Filters in the right sidebar of the change list page of the admin
from django.contrib.admin import SimpleListFilter
from repanier.models import Producer, Product, LUT_DepartmentForCustomer, Customer, CustomerInvoice, ProducerInvoice, \
Permanence
Permanence, LUT_ProductionMode
from repanier.tools import sint
......@@ -77,6 +78,57 @@ class ProductFilterByDepartmentForThisProducer(SimpleListFilter):
return queryset
class ProductFilterByProductioMode(SimpleListFilter):
title = _("production modes")
parameter_name = 'production_mode'
template = 'admin/production_mode_filter.html'
def lookups(self, request, model_admin):
return [(p.id, p.short_name) for p in
LUT_ProductionMode.objects.filter(is_active=True)
]
def queryset(self, request, queryset):
if self.value():
return queryset.filter(production_mode=self.value())
else:
return queryset
class ProductFilterByPlacement(SimpleListFilter):
title = _("product_placement")
parameter_name = 'placement'
template = 'admin/placement_filter.html'
def lookups(self, request, model_admin):
return [(p[0], p[1]) for p in
LUT_PRODUCT_PLACEMENT
]
def queryset(self, request, queryset):
if self.value():
return queryset.filter(placement=self.value())
else:
return queryset
class ProductFilterByVatLevel(SimpleListFilter):
title = _("vat_level")
parameter_name = 'vat_level'
template = 'admin/vat_level_filter.html'
def lookups(self, request, model_admin):
return [(p[0], p[1]) for p in
settings.LUT_VAT
]
def queryset(self, request, queryset):
if self.value():
return queryset.filter(vat_level=self.value())
else:
return queryset
class PurchaseFilterByCustomer(SimpleListFilter):
title = _("customer")
parameter_name = 'customer'
......
......@@ -20,7 +20,8 @@ from import_export.widgets import ForeignKeyWidget
from parler.admin import TranslatableAdmin
from parler.forms import TranslatableModelForm
from repanier.admin.admin_filter import ProductFilterByDepartmentForThisProducer, ProductFilterByProducer
from repanier.admin.admin_filter import ProductFilterByDepartmentForThisProducer, ProductFilterByProducer, \
ProductFilterByProductioMode, ProductFilterByPlacement, ProductFilterByVatLevel
from repanier.const import *
from repanier.models import Product, \
LUT_ProductionMode, LUT_DepartmentForCustomer, Producer
......@@ -291,10 +292,10 @@ class ProductAdmin(ImportExportMixin, TranslatableAdmin):
'wrapped',
ProductFilterByProducer,
ProductFilterByDepartmentForThisProducer,
'production_mode',
'placement',
ProductFilterByProductioMode,
ProductFilterByPlacement,
'limit_order_quantity_to_stock',
'vat_level')
ProductFilterByVatLevel)
actions = [
'flip_flop_select_for_offer_status',
'duplicate_product'
......
{% load staticfiles i18n %}
<link href="{% static "easy_select2/vendor/select2/css/select2.min.css" %}" type="text/css" media="screen" rel="stylesheet" />
<link href="{% static "easy_select2/css/easy_select2.css" %}" type="text/css" media="screen" rel="stylesheet" />
<script type="text/javascript">var go_from_select = function(opt) { window.location = window.location.pathname + opt };</script>
<script type="text/javascript" src="{% static "easy_select2/js/init.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/js/easy_select2.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/js/lookup_override.1.8.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/vendor/select2/js/select2.min.js" %}"></script>
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
<ul class="admin-filter-{{ title|cut:' ' }}">
{% if choices|slice:"1:" %}
<li>
<select style="width: 95%;" id="id_filter_placement"
onchange="go_from_select(this.options[this.selectedIndex].value)">
{% for choice in choices %}
<option{% if choice.selected %} selected="selected"{% endif %}
value="{{ choice.query_string|iriencode }}">{{ choice.display }}</option>
{% endfor %}
</select>
<div class="field-easy-select2"
style="display:none"
id="id_filter_placement"
></div>
</li>
{% else %}
{% for choice in choices %}
<li{% if choice.selected %} class="selected"{% endif %}>
<a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
{% endfor %}
{% endif %}
</ul>
\ No newline at end of file
{% load staticfiles i18n %}
<link href="{% static "easy_select2/vendor/select2/css/select2.min.css" %}" type="text/css" media="screen" rel="stylesheet" />
<link href="{% static "easy_select2/css/easy_select2.css" %}" type="text/css" media="screen" rel="stylesheet" />
<script type="text/javascript">var go_from_select = function(opt) { window.location = window.location.pathname + opt };</script>
<script type="text/javascript" src="{% static "easy_select2/js/init.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/js/easy_select2.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/js/lookup_override.1.8.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/vendor/select2/js/select2.min.js" %}"></script>
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
<ul class="admin-filter-{{ title|cut:' ' }}">
{% if choices|slice:"1:" %}
<li>
<select style="width: 95%;" id="id_filter_production_mode"
onchange="go_from_select(this.options[this.selectedIndex].value)">
{% for choice in choices %}
<option{% if choice.selected %} selected="selected"{% endif %}
value="{{ choice.query_string|iriencode }}">{{ choice.display }}</option>
{% endfor %}
</select>
<div class="field-easy-select2"
style="display:none"
id="id_filter_production_mode"
></div>
</li>
{% else %}
{% for choice in choices %}
<li{% if choice.selected %} class="selected"{% endif %}>
<a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
{% endfor %}
{% endif %}
</ul>
\ No newline at end of file
{% load staticfiles i18n %}
<link href="{% static "easy_select2/vendor/select2/css/select2.min.css" %}" type="text/css" media="screen" rel="stylesheet" />
<link href="{% static "easy_select2/css/easy_select2.css" %}" type="text/css" media="screen" rel="stylesheet" />
<script type="text/javascript">var go_from_select = function(opt) { window.location = window.location.pathname + opt };</script>
<script type="text/javascript" src="{% static "easy_select2/js/init.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/js/easy_select2.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/js/lookup_override.1.8.js" %}"></script>
<script type="text/javascript" src="{% static "easy_select2/vendor/select2/js/select2.min.js" %}"></script>
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
<ul class="admin-filter-{{ title|cut:' ' }}">
{% if choices|slice:"1:" %}
<li>
<select style="width: 95%;" id="id_filter_vat_level"
onchange="go_from_select(this.options[this.selectedIndex].value)">
{% for choice in choices %}
<option{% if choice.selected %} selected="selected"{% endif %}
value="{{ choice.query_string|iriencode }}">{{ choice.display }}</option>
{% endfor %}
</select>
<div class="field-easy-select2"
style="display:none"
id="id_filter_vat_level"
></div>
</li>
{% else %}
{% for choice in choices %}
<li{% if choice.selected %} class="selected"{% endif %}>
<a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
{% endfor %}
{% endif %}
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment