def __init__(self, view): super(ProductVariationViewToolbar, self).__init__() self.view = view self.parent_product = view.object self.request = view.request get_default_edit_toolbar(self.view, "product_form", with_split_save=False, toolbar=self) 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-minus")) 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-minus"))
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" ))
def get_toolbar(self): order = self.object if order.is_canceled(): return toolbar = Toolbar() 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("shoop_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("shoop_admin:order.create-shipment", kwargs={"pk": order.pk}), extra_css_class="btn-info" )) toolbar.append(PostActionButton( post_url=reverse("shoop_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("shoop_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("shoop_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
def build_renew_password_button(self): disable_reason = None if "shoop.front.apps.auth" not in settings.INSTALLED_APPS: disable_reason = _("The Shoop 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("shoop_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", ))
def get_toolbar(self): order = self.object toolbar = Toolbar() 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("shoop_admin:order.create-shipment", kwargs={"pk": order.pk}), extra_css_class="btn-info")) toolbar.append( PostActionButton( post_url=reverse("shoop_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")) # TODO: Add extensibility to action_button_groups? return toolbar
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("shoop_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("shoop_admin:addon.reload"), text=_("Reload application"), extra_css_class="btn-warning", icon="fa fa-refresh", )) return context
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
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", ))
def get_context_data(self, **kwargs): context = super(ProductMediaEditView, self).get_context_data(**kwargs) context["title"] = _("Edit Media: %s") % self.object context["toolbar"] = Toolbar([ PostActionButton( icon="fa fa-save", form_id="media_form", text=_("Save"), extra_css_class="btn-success", ), ]) return context
def get_context_data(self, **kwargs): context = super(OrderCreatePaymentView, self).get_context_data(**kwargs) context["title"] = _("Create Payment -- %s") % context["order"] context["toolbar"] = Toolbar([ PostActionButton( icon="fa fa-check-circle", form_id="create_payment", text=_("Create Payment"), extra_css_class="btn-success", ), ]) return context
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"))
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
def _build_existing_user(self): user = self.user change_password_button = DropdownItem(url=reverse( "shoop_admin:user.change-password", kwargs={"pk": user.pk}), text=_(u"Change Password"), icon="fa fa-exchange") reset_password_button = DropdownItem( url=reverse("shoop_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( "shoop_admin:user.change-permissions", kwargs={"pk": user.pk}), text=_(u"Edit Permissions"), icon="fa fa-lock") 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("shoop_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( "shoop_admin:contact.new") + "?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", ))