|
@ -63,9 +63,7 @@ class LabeledResourse(resources.ModelResource): |
|
|
fields = self.get_fields() |
|
|
fields = self.get_fields() |
|
|
if self.selected_fields: |
|
|
if self.selected_fields: |
|
|
fields = [ |
|
|
fields = [ |
|
|
f |
|
|
f for f in fields if self.get_field_name(f) in self.selected_fields |
|
|
for f in fields |
|
|
|
|
|
if self.get_field_name(f) in self.selected_fields |
|
|
|
|
|
] |
|
|
] |
|
|
return fields |
|
|
return fields |
|
|
|
|
|
|
|
@ -84,9 +82,7 @@ class ValueLabeledResource(LabeledResourse): |
|
|
|
|
|
|
|
|
class CartExportMixin(ExportMixin): |
|
|
class CartExportMixin(ExportMixin): |
|
|
to_encoding = "utf-8" |
|
|
to_encoding = "utf-8" |
|
|
import_export_change_list_template = ( |
|
|
import_export_change_list_template = "admin/cart/change_list_cart_export.html" |
|
|
"admin/cart/change_list_cart_export.html" |
|
|
|
|
|
) |
|
|
|
|
|
export_form_class = ExportFormFields |
|
|
export_form_class = ExportFormFields |
|
|
_cart_session_name = None |
|
|
_cart_session_name = None |
|
|
_cart_viewing_name = None |
|
|
_cart_viewing_name = None |
|
@ -157,11 +153,9 @@ class CartExportMixin(ExportMixin): |
|
|
@csrf_protect_m |
|
|
@csrf_protect_m |
|
|
def add_to_cart(self, request, queryset): |
|
|
def add_to_cart(self, request, queryset): |
|
|
if request.POST.get("select_across", "0") == "0": |
|
|
if request.POST.get("select_across", "0") == "0": |
|
|
selected_ids = set( |
|
|
selected_ids = set(request.POST.getlist(helpers.ACTION_CHECKBOX_NAME, [])) |
|
|
request.POST.getlist(helpers.ACTION_CHECKBOX_NAME, []) |
|
|
|
|
|
) |
|
|
|
|
|
else: |
|
|
else: |
|
|
selected_ids = set(map(str, queryset.values_list("id", flat=True))) |
|
|
selected_ids = set(map(str, queryset.values_list("pk", flat=True))) |
|
|
|
|
|
|
|
|
if self._cart_session_name in request.session: |
|
|
if self._cart_session_name in request.session: |
|
|
cart_ids = set(request.session[self._cart_session_name]) |
|
|
cart_ids = set(request.session[self._cart_session_name]) |
|
@ -173,18 +167,14 @@ class CartExportMixin(ExportMixin): |
|
|
if quant: |
|
|
if quant: |
|
|
cart_ids.update(selected_ids) |
|
|
cart_ids.update(selected_ids) |
|
|
request.session[self._cart_session_name] = list(cart_ids) |
|
|
request.session[self._cart_session_name] = list(cart_ids) |
|
|
self.message_user( |
|
|
self.message_user(request, _("%s itens adicionados no carrinho") % quant) |
|
|
request, _("%s itens adicionados no carrinho") % quant |
|
|
|
|
|
) |
|
|
|
|
|
else: |
|
|
else: |
|
|
self.message_user( |
|
|
self.message_user( |
|
|
request, _("Os itens selecionados já estavam no carrinho") |
|
|
request, _("Os itens selecionados já estavam no carrinho") |
|
|
) |
|
|
) |
|
|
return HttpResponseRedirect(".") |
|
|
return HttpResponseRedirect(".") |
|
|
|
|
|
|
|
|
add_to_cart.short_description = _( |
|
|
add_to_cart.short_description = _("Armazenar itens no carrinho para exportar") |
|
|
"Armazenar itens no carrinho para exportar" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@csrf_protect_m |
|
|
@csrf_protect_m |
|
|
def remove_from_cart(self, request, queryset): |
|
|
def remove_from_cart(self, request, queryset): |
|
@ -195,12 +185,10 @@ class CartExportMixin(ExportMixin): |
|
|
if request.POST.get("select_across", "0") == "0": |
|
|
if request.POST.get("select_across", "0") == "0": |
|
|
remove_ids = set(request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)) |
|
|
remove_ids = set(request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)) |
|
|
else: |
|
|
else: |
|
|
remove_ids = set(map(str, queryset.values_list("id", flat=True))) |
|
|
remove_ids = set(map(str, queryset.values_list("pk", flat=True))) |
|
|
cart_ids = set(request.session[self._cart_session_name]) |
|
|
cart_ids = set(request.session[self._cart_session_name]) |
|
|
|
|
|
|
|
|
request.session[self._cart_session_name] = list( |
|
|
request.session[self._cart_session_name] = list(cart_ids.difference(remove_ids)) |
|
|
cart_ids.difference(remove_ids) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
self.message_user( |
|
|
self.message_user( |
|
|
request, |
|
|
request, |
|
@ -281,14 +269,10 @@ class CartExportReportMixin(CartExportMixin): |
|
|
class ReturnMixin: |
|
|
class ReturnMixin: |
|
|
_return_path = None |
|
|
_return_path = None |
|
|
|
|
|
|
|
|
def changeform_view( |
|
|
def changeform_view(self, request, object_id=None, form_url="", extra_context=None): |
|
|
self, request, object_id=None, form_url="", extra_context=None |
|
|
|
|
|
): |
|
|
|
|
|
if "_return" in request.GET: |
|
|
if "_return" in request.GET: |
|
|
self._return_path = request.GET.get("_return") |
|
|
self._return_path = request.GET.get("_return") |
|
|
return super().changeform_view( |
|
|
return super().changeform_view(request, object_id, form_url, extra_context) |
|
|
request, object_id, form_url, extra_context |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def response_post_save_add(self, request, obj): |
|
|
def response_post_save_add(self, request, obj): |
|
|
if self._return_path: |
|
|
if self._return_path: |
|
|