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_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("wshop_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("wshop_admin:addon.reload"), text=_("Reload application"), extra_css_class="btn-warning", icon="fa fa-refresh", )) return context
def build_renew_password_button(self): disable_reason = None if "wshop.front.apps.auth" not in settings.INSTALLED_APPS: disable_reason = _("The Wshop 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("wshop_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 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(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 get_context_data(self, **kwargs): context = super(SystemSettingsView, self).get_context_data(**kwargs) context["toolbar"] = Toolbar([ PostActionButton( icon="fa fa-save", form_id="settings_form", text=_("Save system settings"), extra_css_class="btn-success", ) ]) return context
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
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 _build_cancel_button(self): self.append(PostActionButton( post_url=reverse("wshop_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" ))
def _build_set_complete_button(self): self.append(PostActionButton( post_url=reverse("wshop_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" ))
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 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()", ) ]) context["defaults"] = "|".join([ self.settings.get_settings_key(c.id) for c in self.settings.default_columns ]) return context
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("wshop_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, line) for line in self.object.lines.all()] return context
def _build_existing_user(self): user = self.user change_password_button = DropdownItem( url=reverse("wshop_admin:user.change-password", kwargs={"pk": user.pk}), text=_(u"Change Password"), icon="fa fa-exchange" ) reset_password_button = DropdownItem( url=reverse("wshop_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("wshop_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("wshop_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("wshop_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("wshop_admin:user.login-as", kwargs={"pk": user.pk}), text=_(u"Login as User"), extra_css_class="btn-gray" ))