Commit 02f2536b authored by Patrick's avatar Patrick

Do not allow to access products of a de activated producer

parent 6c2e7850
......@@ -19,7 +19,7 @@ class ProductFilterByProducer(SimpleListFilter):
# right admin sidebar.
title = _("producers")
# Parameter for the filter that will be used in the URL query.
parameter_name = 'producer'
parameter_name = 'producer_id'
template = 'admin/producer_filter.html'
def lookups(self, request, model_admin):
......
......@@ -297,7 +297,7 @@ class ProductAdmin(ImportExportMixin, TranslatableAdmin):
'limit_order_quantity_to_stock',
ProductFilterByVatLevel)
actions = [
# 'flip_flop_select_for_offer_status',
'flip_flop_select_for_offer_status',
'duplicate_product'
]
......@@ -361,7 +361,7 @@ class ProductAdmin(ImportExportMixin, TranslatableAdmin):
duplicate_product.short_description = _('duplicate product')
def get_list_display(self, request):
producer_id = sint(request.GET.get('producer', 0))
producer_id = sint(request.GET.get('producer_id', 0))
if producer_id != 0:
producer_queryset = Producer.objects.filter(id=producer_id).order_by('?')
producer = producer_queryset.first()
......@@ -424,8 +424,8 @@ class ProductAdmin(ImportExportMixin, TranslatableAdmin):
preserved_filters = request.GET.get('_changelist_filters', None)
if preserved_filters:
param = dict(parse_qsl(preserved_filters))
if 'producer' in param:
producer_id = param['producer']
if 'producer_id' in param:
producer_id = param['producer_id']
if producer_id:
producer_queryset = Producer.objects.filter(id=producer_id).order_by('?')
if 'department_for_customer' in param:
......@@ -567,6 +567,7 @@ class ProductAdmin(ImportExportMixin, TranslatableAdmin):
def get_queryset(self, request):
queryset = super(ProductAdmin, self).get_queryset(request)
return queryset.filter(is_box=False, is_membership_fee=False,
producer__is_active=True,
translations__language_code=translation.get_language())
def get_import_formats(self):
......
......@@ -105,12 +105,14 @@ class Producer(models.Model):
def get_products(self):
# This producer may have product's list
changeproductslist_url = urlresolvers.reverse(
'admin:repanier_product_changelist',
)
link = '<a href="%s?is_active__exact=1&producer=%s" class="btn addlink">&nbsp;%s</a>' \
% (changeproductslist_url, str(self.id), _("his_products"))
return link
if self.is_active:
changeproductslist_url = urlresolvers.reverse(
'admin:repanier_product_changelist',
)
link = '<a href="%s?is_active__exact=1&producer_id=%s" class="btn addlink">&nbsp;%s</a>' \
% (changeproductslist_url, str(self.id), _("his_products"))
return link
return EMPTY_STRING
get_products.short_description = (_("link to his products"))
get_products.allow_tags = True
......
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