Esempio n. 1
0
    def get_toolbar(self):
        save_form_id = self.get_save_form_id()
        obj = self.get_object()
        delete_url = reverse_lazy("shuup_admin:task.delete",
                                  kwargs={"pk": obj.pk}) if obj.pk else None
        toolbar = get_default_edit_toolbar(self,
                                           save_form_id,
                                           delete_url=delete_url)

        if obj and obj.pk:
            if obj.status == TaskStatus.NEW:
                toolbar.append(
                    PostActionButton(
                        post_url=reverse_lazy("shuup_admin:task.set_status",
                                              kwargs=dict(pk=obj.pk)),
                        icon="fa fa-check",
                        name="status",
                        value=TaskStatus.IN_PROGRESS.value,
                        text=_("Set In Progress"),
                        extra_css_class="btn-success",
                    ))
            if obj.status == TaskStatus.IN_PROGRESS:
                toolbar.append(
                    PostActionButton(
                        post_url=reverse_lazy("shuup_admin:task.set_status",
                                              kwargs=dict(pk=obj.pk)),
                        icon="fa fa-check",
                        name="status",
                        value=TaskStatus.COMPLETED.value,
                        text=_("Set Completed"),
                        extra_css_class="btn-success",
                    ))
        return toolbar
Esempio n. 2
0
    def __init__(self, view):
        super(ProductVariationViewToolbar, self).__init__(view)

        if self.parent_product.variation_children.exists():
            self.append(
                PostActionButton(
                    post_url=self.request.path,
                    name="command",
                    value="unvariate",
                    confirm=
                    _("Are you sure? This will unlink all children and remove all variation variables."
                      ),
                    text=_("Clear variation"),
                    extra_css_class="btn-danger",
                    icon="fa fa-times"))
        if (self.parent_product.mode == ProductMode.VARIABLE_VARIATION_PARENT
                or ProductVariationVariable.objects.filter(
                    product=self.parent_product).exists()):
            self.append(
                PostActionButton(
                    post_url=self.request.path,
                    name="command",
                    value="simplify",
                    confirm=_(
                        "Are you sure? This will remove all variation variables, "
                        "converting children to direct links."),
                    text=_("Convert to simple variation"),
                    icon="fa fa-exchange",
                    extra_css_class="btn-info"))
Esempio n. 3
0
    def build_login_as_button(self):
        user = self.contact.user if hasattr(self.contact, "user") else None
        current_user = self.request.user
        if isinstance(user, get_user_model()):
            has_privileges = bool(
                getattr(current_user, "is_superuser", False)
                or getattr(current_user, "is_staff", False))
            can_impersonate = bool(has_privileges and user.is_active
                                   and not user.is_superuser)

            if can_impersonate and get_front_url() and not user.is_staff:
                self.append(
                    PostActionButton(
                        post_url=reverse("shuup_admin:user.login-as",
                                         kwargs={"pk": user.pk}),
                        text=_("Login as User"),
                        extra_css_class="btn-inverse",
                    ))
            elif can_impersonate and get_admin_url() and user.is_staff:
                self.append(
                    PostActionButton(
                        post_url=reverse("shuup_admin:user.login-as-staff",
                                         kwargs={"pk": user.pk}),
                        text=_("Login as Staff User"),
                        extra_css_class="btn-inverse",
                    ))
Esempio n. 4
0
    def build_renew_password_button(self):
        disable_reason = None

        if "shuup.front.apps.auth" not in settings.INSTALLED_APPS:
            disable_reason = _("The Shuup frontend is not enabled.")
        elif not self.user:
            disable_reason = _("Contact has no associated user.")
        elif not getattr(self.user, "email", None):
            disable_reason = _("User has no associated email.")

        self.append(
            PostActionButton(
                post_url=reverse("shuup_admin:contact.reset_password",
                                 kwargs={"pk": self.contact.pk}),
                name="pk",
                value=self.contact.pk,
                text=_(u"Reset password"),
                tooltip=_(u"Send a password renewal email."),
                confirm=
                _("Are you sure you wish to send a password recovery email to %s?"
                  ) % self.contact.email,
                icon="fa fa-undo",
                disable_reason=disable_reason,
                extra_css_class="btn-gray btn-inverse",
            ))
Esempio n. 5
0
    def get_context_data(self, **kwargs):
        context = super(OrderCreateRefundView, self).get_context_data(**kwargs)
        context["title"] = _("Create Refund -- %s") % context["order"]
        context["toolbar"] = Toolbar([
            PostActionButton(
                icon="fa fa-check-circle",
                form_id="create_refund",
                text=_("Create Refund"),
                extra_css_class="btn-success",
            ),
            URLActionButton(
                url=reverse("shuup_admin:order.create-full-refund",
                            kwargs={"pk": self.object.pk}),
                icon="fa fa-dollar",
                text=_("Refund Entire Order"),
                extra_css_class="btn-info",
                disable_reason=_("This order already has existing refunds")
                if self.object.has_refunds() else None),
        ])

        # Setting the line_numbers choices dynamically creates issues with the blank formset,
        # So adding that to the context to be rendered manually
        context["line_number_choices"] = self._get_line_number_choices()
        context["json_line_data"] = [
            self._get_line_data(self.object.shop, line)
            for line in self.object.lines.all()
        ]

        return context
Esempio n. 6
0
    def get_context_data(self, **kwargs):
        context = super(AddonListView, self).get_context_data(**kwargs)
        context["toolbar"] = Toolbar([
            PostActionButton(
                icon="fa fa-save",
                form_id="addon_list",
                text=_("Save addon changes"),
                extra_css_class="btn-success",
            ),
            NewActionButton(
                reverse("shuup_admin:addon.upload"),
                text=_("Upload new addon"),
                extra_css_class="btn-info",
                icon="fa fa-upload",
            )
        ])
        if self.request.GET.get("reload"):
            context["toolbar"].append(
                URLActionButton(
                    reverse("shuup_admin:addon.reload"),
                    text=_("Reload application"),
                    extra_css_class="btn-warning",
                    icon="fa fa-refresh",
                ))

        return context
Esempio n. 7
0
    def get_context_data(self, **kwargs):
        context = super(OrderCreateRefundView, self).get_context_data(**kwargs)
        context["title"] = _("Create Refund -- %s") % context["order"]
        context["toolbar"] = Toolbar([
            PostActionButton(
                icon="fa fa-check-circle",
                form_id="create_refund",
                text=_("Create Refund"),
                extra_css_class="btn-success",
            )
        ], view=self)

        # Allowing full refunds for suppliers would block the refunds for
        # rest of the suppliers since full refund can only be created once
        supplier = context["supplier"] = get_supplier(self.request)
        if not supplier:
            context["toolbar"].append(
                URLActionButton(
                    url=reverse("shuup_admin:order.create-full-refund", kwargs={"pk": self.object.pk}),
                    icon="fa fa-dollar",
                    text=_("Refund Entire Order"),
                    extra_css_class="btn-info",
                    disable_reason=_("This order already has existing refunds") if self.object.has_refunds() else None
                )
            )

        # Setting the line_numbers choices dynamically creates issues with the blank formset,
        # So adding that to the context to be rendered manually
        context["line_number_choices"] = self._get_line_number_choices(supplier)

        lines = lines = self.object.lines.all()
        if supplier:
            lines = lines.filter(supplier=supplier)
        context["json_line_data"] = [self._get_line_data(self.object, line) for line in lines]
        return context
Esempio n. 8
0
    def get_context_data(self, **kwargs):
        context = super(ScriptEditView, self).get_context_data(**kwargs)
        if self.object.pk:
            buttons = []

            edit_button_title = _("Edit Script Contents")

            # this script was created through a template
            # so show an option to easily edit the template
            if self.object.template:
                template_cls = get_identifier_to_object_map(
                    SCRIPT_TEMPLATES_PROVIDE_CATEGORY).get(
                        self.object.template)

                # check whether is possible to edit the script through the template editor
                if template_cls and template_cls(
                        self.object).can_edit_script():
                    # change the editor button title to advanced mode
                    edit_button_title = _("Edit Script (advanced)")

                    buttons.append(
                        URLActionButton(
                            text=_("Edit Template"),
                            icon="fa fa-pencil-square-o",
                            extra_css_class="btn-primary",
                            url=reverse(
                                "shuup_admin:notify.script-template-edit",
                                kwargs={"pk": self.object.pk}),
                        ))

            buttons.insert(
                0,
                URLActionButton(
                    text=edit_button_title,
                    icon="fa fa-pencil",
                    extra_css_class="btn-primary",
                    url=reverse("shuup_admin:notify.script.edit-content",
                                kwargs={"pk": self.object.pk}),
                ),
            )

            buttons.insert(
                1,
                PostActionButton(
                    post_url=reverse("shuup_admin:notify.script.delete",
                                     kwargs={"pk": self.object.pk}),
                    text=_("Delete"),
                    icon="fa fa-trash",
                    extra_css_class="btn-danger",
                    confirm=_(
                        'Are you sure you wish to delete "%s" notification?') %
                    self.object,
                    required_permissions=("notify.script.delete", ),
                ),
            )

            context["toolbar"] = Toolbar(buttons, view=self)
        return context
Esempio n. 9
0
 def build_deactivate_button(self):
     return PostActionButton(
         post_url=self.request.path,
         name="set_is_active",
         value="0" if self.contact.is_active else "1",
         icon="fa fa-times-circle",
         text=_(u"Deactivate Contact") if self.contact.is_active else _(u"Activate Contact"),
         extra_css_class="dropdown-item btn-danger",
     )
Esempio n. 10
0
 def get_toolbar(self):
     toobar = Toolbar([
         PostActionButton(
             icon="fa fa-check-circle",
             form_id="gdpr_form",
             text=_("Save"),
             extra_css_class="btn-success",
         )
     ], view=self)
     return toobar
Esempio n. 11
0
 def build_deactivate_button(self):
     self.append(
         PostActionButton(
             post_url=self.request.path,
             name="set_is_active",
             value="0" if self.contact.is_active else "1",
             icon="fa fa-times-circle",
             text=_(u"Deactivate Contact")
             if self.contact.is_active else _(u"Activate Contact"),
             extra_css_class="btn-gray",
         ))
Esempio n. 12
0
 def __init__(self, view):
     super(ProductPackageViewToolbar, self).__init__(view)
     if self.parent_product.get_package_child_to_quantity_map():
         self.append(
             PostActionButton(post_url=self.request.path,
                              name="command",
                              value="clear_package",
                              confirm=self.confirm_text,
                              text=self.button_text,
                              extra_css_class="btn-danger",
                              icon="fa fa-times"))
Esempio n. 13
0
 def get_context_data(self, **kwargs):
     context = super(AddonUploadView, self).get_context_data(**kwargs)
     context["toolbar"] = Toolbar([
         PostActionButton(
             icon="fa fa-upload",
             form_id="upload_form",
             text=_("Upload"),
             extra_css_class="btn-success",
         )
     ])
     return context
Esempio n. 14
0
 def get_context_data(self, **kwargs):
     context = super(SystemSettingsView, self).get_context_data(**kwargs)
     context["toolbar"] = Toolbar([
         PostActionButton(
             icon="fa fa-check-circle",
             form_id="settings_form",
             text=_("Save system settings"),
             extra_css_class="btn-success",
         )
     ])
     return context
Esempio n. 15
0
 def get_context_data(self, **kwargs):
     context = super(OrderAddressEditView, self).get_context_data(**kwargs)
     context["title"] = _("Edit Addresses -- %s") % context["order"]
     context["toolbar"] = Toolbar([
         PostActionButton(
             icon="fa fa-check-circle",
             form_id="edit-addresses",
             text=_("Edit Addresses"),
             extra_css_class="btn-success",
         ),
     ])
     return context
Esempio n. 16
0
 def get_context_data(self, **kwargs):
     context = super(ProductCrossSellEditView, self).get_context_data(**kwargs)
     context["title"] = _("Edit Cross-Sell: %s") % self.object
     context["toolbar"] = Toolbar([
         PostActionButton(
             icon="fa fa-save",
             form_id="xsell_form",
             text=_("Save"),
             extra_css_class="btn-success",
         ),
     ])
     return context
Esempio n. 17
0
 def get_context_data(self, **kwargs):
     context = super(OrderCreateShipmentView, self).get_context_data(**kwargs)
     context["title"] = _("Create Shipment -- %s") % context["order"]
     context["toolbar"] = Toolbar([
         PostActionButton(
             icon="fa fa-check-circle",
             form_id="create_shipment",
             text=_("Create Shipment"),
             extra_css_class="btn-success",
         ),
     ], view=self)
     return context
Esempio n. 18
0
 def _build_cancel_button(self):
     self.append(
         PostActionButton(
             post_url=reverse("shuup_admin:order.set-status",
                              kwargs={"pk": self.order.pk}),
             name="status",
             value=OrderStatus.objects.get_default_canceled().pk,
             text=_("Cancel Order"),
             icon="fa fa-trash",
             disable_reason=(
                 _("Paid, shipped, or canceled orders cannot be canceled")
                 if not self.order.can_set_canceled() else None),
             extra_css_class="btn-danger btn-inverse"))
Esempio n. 19
0
 def _build_set_complete_button(self):
     self.append(
         PostActionButton(
             post_url=reverse("shuup_admin:order.set-status",
                              kwargs={"pk": self.order.pk}),
             name="status",
             value=OrderStatus.objects.get_default_complete().pk,
             text=_("Set Complete"),
             icon="fa fa-check-circle",
             disable_reason=(
                 _("This order can not be set as complete at this point")
                 if not self.order.can_set_complete() else None),
             extra_css_class="btn-success"))
Esempio n. 20
0
    def __init__(self, view):
        super(ProductPackageViewToolbar, self).__init__(view)

        if self.parent_product.get_package_child_to_quantity_map():
            self.append(
                PostActionButton(
                    post_url=self.request.path,
                    name="command",
                    value="clear_package",
                    confirm=
                    _("Are you sure? This will remove all products from package."
                      ),
                    text=_("Clear package"),
                    extra_css_class="btn-danger",
                    icon="fa fa-times"))
Esempio n. 21
0
    def get_toolbar(self):
        if has_installed("shuup.gdpr"):
            if self.object and self.object.pk and self.object.page_type == PageType.GDPR_CONSENT_DOCUMENT:
                return Toolbar([
                    PostActionButton(
                        icon="fa fa-save",
                        form_id=self.get_save_form_id(),
                        text=_("Publish New Version"),
                        extra_css_class="btn-success",
                        confirm=
                        _("This action will publish a new version of this GDPR document. "
                          +
                          "All users should consent again to this new version. Are you sure?"
                          ))
                ])

        return super(PageEditView, self).get_toolbar()
Esempio n. 22
0
 def get_context_data(self, **kwargs):
     context = super(ListSettingsView, self).get_context_data(**kwargs)
     context["toolbar"] = Toolbar([
         PostActionButton(
             icon="fa fa-save",
             form_id="settings_form",
             text=_("Save"),
             extra_css_class="btn-success",
         ),
         JavaScriptActionButton(
             icon="fa fa-cog",
             text=_("Reset Defaults"),
             onclick="resetDefaultValues()",
         )
     ], view=self)
     context["defaults"] = "|".join([self.settings.get_settings_key(c.id) for c in self.settings.default_columns])
     return context
Esempio n. 23
0
    def get_context_data(self, **kwargs):
        context = super(AddonUploadConfirmView, self).get_context_data(**kwargs)

        with zipfile.ZipFile(self.get_addon_path()) as zf:
            context["filenames"] = sorted(zf.namelist())
            pkg_info_path = first(filename for filename in context["filenames"] if filename.endswith("PKG-INFO"))
            if pkg_info_path:
                context["pkg_info"] = zf.read(pkg_info_path).decode("UTF-8", "replace")

        context["toolbar"] = Toolbar([
            PostActionButton(
                icon="fa fa-download",
                form_id="install_form",
                text=_("Install Addon"),
                extra_css_class="btn-success",
            )
        ])
        return context
Esempio n. 24
0
 def get_toolbar(self):
     product_type = self.get_object()
     save_form_id = self.get_save_form_id()
     delete_url = reverse_lazy("shuup_admin:product_type.delete",
                               kwargs={"pk": product_type.pk
                                       }) if product_type.pk else None
     toolbar = get_default_edit_toolbar(self, save_form_id)
     if not delete_url:
         return toolbar
     toolbar.append(
         PostActionButton(
             post_url=delete_url,
             text=_(u"Delete"),
             icon="fa fa-trash",
             extra_css_class="btn-danger",
             confirm=
             _("Are you sure you wish to delete %s? Warrning: all related products will disappear from storefront until new value for product type is set!"
               ) % product_type,  # noqa
             required_permissions=()))
     return toolbar
Esempio n. 25
0
    def get_toolbar(self):
        order = self.object
        toolbar = Toolbar()
        toolbar.append(
            URLActionButton(text=_("Create Refund"),
                            icon="fa fa-dollar",
                            disable_reason=_("This order cannot be refunded")
                            if not order.can_create_refund() else None,
                            url=reverse("shuup_admin:order.create-refund",
                                        kwargs={"pk": order.pk}),
                            extra_css_class="btn-info"))

        toolbar.append(
            URLActionButton(
                text=_("Create Payment"),
                icon="fa fa-money",
                disable_reason=_("This order cannot be paid at this point")
                if order.is_paid() else None,
                url=reverse("shuup_admin:order.create-payment",
                            kwargs={"pk": order.pk}),
                extra_css_class="btn-info"))

        toolbar.append(
            URLActionButton(text=_("Create Shipment"),
                            icon="fa fa-truck",
                            disable_reason=_("There are no products to ship")
                            if not order.get_unshipped_products() else None,
                            url=reverse("shuup_admin:order.create-shipment",
                                        kwargs={"pk": order.pk}),
                            extra_css_class="btn-info"))

        toolbar.append(
            PostActionButton(
                post_url=reverse("shuup_admin:order.set-status",
                                 kwargs={"pk": order.pk}),
                name="status",
                value=OrderStatus.objects.get_default_complete().pk,
                text=_("Set Complete"),
                icon="fa fa-check-circle",
                disable_reason=(
                    _("This order can not be set as complete at this point")
                    if not order.can_set_complete() else None),
                extra_css_class="btn-success"))

        toolbar.append(
            PostActionButton(
                post_url=reverse("shuup_admin:order.set-status",
                                 kwargs={"pk": order.pk}),
                name="status",
                value=OrderStatus.objects.get_default_canceled().pk,
                text=_("Cancel Order"),
                icon="fa fa-trash",
                disable_reason=(
                    _("Paid, shipped, or canceled orders cannot be canceled")
                    if not order.can_set_canceled() else None),
                extra_css_class="btn-danger btn-inverse"))
        toolbar.append(
            URLActionButton(
                text=_("Edit order"),
                icon="fa fa-money",
                disable_reason=_("This order cannot modified at this point")
                if not order.can_edit() else None,
                url=reverse("shuup_admin:order.edit", kwargs={"pk": order.pk}),
                extra_css_class="btn-info"))

        for button in get_provide_objects("admin_order_toolbar_button"):
            toolbar.append(button(order))

        return toolbar
Esempio n. 26
0
    def _build_existing_user(self):
        user = self.user
        change_password_button = DropdownItem(url=reverse(
            "shuup_admin:user.change-password", kwargs={"pk": user.pk}),
                                              text=_(u"Change Password"),
                                              icon="fa fa-exchange")
        reset_password_button = DropdownItem(
            url=reverse("shuup_admin:user.reset-password",
                        kwargs={"pk": user.pk}),
            disable_reason=(_("User has no email address")
                            if not getattr(user, 'email', '') else None),
            text=_(u"Send Password Reset Email"),
            icon="fa fa-envelope")
        permissions_button = DropdownItem(
            url=reverse("shuup_admin:user.change-permissions",
                        kwargs={"pk": user.pk}),
            text=_(u"Edit Permissions"),
            icon="fa fa-lock",
            required_permissions=["auth.change_permission"])
        menu_items = [
            change_password_button, reset_password_button, permissions_button,
            DropdownDivider()
        ]

        person_contact = PersonContact.objects.filter(user=user).first()
        if person_contact:
            contact_url = reverse("shuup_admin:contact.detail",
                                  kwargs={"pk": person_contact.pk})
            menu_items.append(
                DropdownItem(
                    url=contact_url,
                    icon="fa fa-search",
                    text=_(u"Contact Details"),
                ))
        else:
            contact_url = reverse("shuup_admin:contact.new"
                                  ) + "?type=person&user_id=%s" % user.pk
            menu_items.append(
                DropdownItem(
                    url=contact_url,
                    icon="fa fa-plus",
                    text=_(u"New Contact"),
                    tooltip=_(
                        "Create a new contact and associate it with this user")
                ))
        self.append(
            DropdownActionButton(
                menu_items,
                icon="fa fa-star",
                text=_(u"Actions"),
                extra_css_class="btn-info",
            ))
        if not user.is_active:
            self.append(
                PostActionButton(
                    post_url=self.request.path,
                    name="set_is_active",
                    value="1",
                    icon="fa fa-check-circle",
                    text=_(u"Activate User"),
                    extra_css_class="btn-gray",
                ))
        else:
            self.append(
                PostActionButton(
                    post_url=self.request.path,
                    name="set_is_active",
                    value="0",
                    icon="fa fa-times-circle",
                    text=_(u"Deactivate User"),
                    extra_css_class="btn-gray",
                ))

        if (self.request.user.is_superuser and get_front_url()
                and user.is_active and not user.is_superuser
                and not user.is_staff):
            self.append(
                PostActionButton(post_url=reverse("shuup_admin:user.login-as",
                                                  kwargs={"pk": user.pk}),
                                 text=_(u"Login as User"),
                                 extra_css_class="btn-gray"))