Esempio n. 1
0
 def duplicate_product(self, request, queryset):
     if 'cancel' in request.POST:
         user_message = _("Action canceled by the user.")
         user_message_level = messages.INFO
         self.message_user(request, user_message, user_message_level)
         return None
     product = queryset.order_by('?').first()
     if product is None or product.is_box:
         user_message = _("Action canceled by the system.")
         user_message_level = messages.ERROR
         self.message_user(request, user_message, user_message_level)
         return None
     if 'apply' in request.POST:
         if "producers" in request.POST:
             producers = request.POST.getlist("producers")
             if len(producers) == 1:
                 producer = Producer.objects.filter(id=producers[0]).order_by('?').first()
                 if producer is not None:
                     user_message, user_message_level = task_product.admin_duplicate(queryset, producer)
                     self.message_user(request, user_message, user_message_level)
                 return None
         user_message = _("You must select one and only one producer.")
         user_message_level = messages.ERROR
         self.message_user(request, user_message, user_message_level)
         return None
     return render(
         request,
         'repanier/confirm_admin_duplicate_product.html', {
             'sub_title'           : _("Please, confirm the action : duplicate product"),
             'action_checkbox_name': admin.ACTION_CHECKBOX_NAME,
             'action'              : 'duplicate_product',
             'product'             : product,
             'producers'           : Producer.objects.filter(is_active=True)
         })
Esempio n. 2
0
 def duplicate_product(self, request, queryset):
     if 'cancel' in request.POST:
         user_message = _("Action canceled by the user.")
         user_message_level = messages.INFO
         self.message_user(request, user_message, user_message_level)
         return
     product = queryset.first()
     if 'apply' in request.POST:
         if "producers" in request.POST:
             producers = request.POST.getlist("producers", [])
             if len(producers) == 1:
                 producer = Producer.objects.filter(
                     id=producers[0]).order_by('?').first()
                 if producer is not None:
                     user_message, user_message_level = task_product.admin_duplicate(
                         queryset, producer)
                     self.message_user(request, user_message,
                                       user_message_level)
                 return
         user_message = _("You must select one and only one producer.")
         user_message_level = messages.ERROR
         self.message_user(request, user_message, user_message_level)
         return
     return render(
         request, 'repanier/confirm_admin_duplicate_product.html', {
             'sub_title':
             _("Please, confirm the action : duplicate product"),
             'action_checkbox_name': admin.ACTION_CHECKBOX_NAME,
             'action': 'duplicate_product',
             'product': product,
             'producers': Producer.objects.filter(is_active=True)
         })
Esempio n. 3
0
    def duplicate_product(self, request, product_id, product):
        if "apply" in request.POST:
            if "producers" in request.POST:
                producers = request.POST.getlist("producers", [])
                if len(producers) == 1:
                    producer = (
                        Producer.objects.filter(id=producers[0]).order_by("?").first()
                    )
                    if producer is not None:
                        user_message, user_message_level = task_product.admin_duplicate(
                            product, producer
                        )
                        self.message_user(request, user_message, user_message_level)
                    return HttpResponseRedirect(self.get_redirect_to_change_list_url())
            user_message = _("You must select one and only one producer.")
            user_message_level = messages.ERROR
            self.message_user(request, user_message, user_message_level)
            return HttpResponseRedirect(self.get_redirect_to_change_list_url())
        template_name = get_repanier_template_name(
            "admin/confirm_duplicate_product.html"
        )

        return render(
            request,
            template_name,
            {
                **self.admin_site.each_context(request),
                "action_checkbox_name": admin.ACTION_CHECKBOX_NAME,
                "action": "duplicate_product",
                "product": product,
                "producers": Producer.objects.filter(is_active=True),
            },
        )
Esempio n. 4
0
 def duplicate_product(self, request, queryset):
     if "cancel" in request.POST:
         user_message = _("Action canceled by the user.")
         user_message_level = messages.INFO
         self.message_user(request, user_message, user_message_level)
         return
     product = queryset.first()
     if "apply" in request.POST:
         if "producers" in request.POST:
             producers = request.POST.getlist("producers", [])
             if len(producers) == 1:
                 producer = (Producer.objects.filter(
                     id=producers[0]).order_by("?").first())
                 if producer is not None:
                     user_message, user_message_level = task_product.admin_duplicate(
                         queryset, producer)
                     self.message_user(request, user_message,
                                       user_message_level)
                 return
         user_message = _("You must select one and only one producer.")
         user_message_level = messages.ERROR
         self.message_user(request, user_message, user_message_level)
         return
     template_name = get_repanier_template_name(
         "confirm_admin_duplicate_product.html")
     return render(
         request,
         template_name,
         {
             "sub_title":
             _("Please, confirm the action : duplicate product"),
             "action_checkbox_name": admin.ACTION_CHECKBOX_NAME,
             "action": "duplicate_product",
             "product": product,
             "producers": Producer.objects.filter(is_active=True),
         },
     )