示例#1
0
文件: formats.py 项目: viona/Easyshop
    def getFormats(self, effective=True):
        """Returns either the first object with formats enabled or the shop
        content object
        """
        object = self.context
        if effective == True:
            while IShop.providedBy(object) == False:
                try:
                    fi = IFormats(object)
                except TypeError:
                    pass
                else:
                    if fi.formats["enabled"] == True:
                        break

                if base_hasattr(object, "getParentCategory") and \
                   object.getParentCategory() is not None:
                    object = object.getParentCategory()
                else:
                    object = object.aq_inner.aq_parent

        fi = IFormats(object)

        try:
            lines_per_page = int(fi.formats["lines_per_page"])
        except (TypeError, ValueError):
            lines_per_page = 1

        try:
            products_per_line = int(fi.formats["products_per_line"])
        except (TypeError, ValueError):
            products_per_line = 2

        try:
            product_height = int(fi.formats["product_height"])
        except (TypeError, ValueError):
            product_height = 0

        return {
            "enabled": fi.formats["enabled"],
            "lines_per_page": lines_per_page,
            "products_per_line": products_per_line,
            "product_height": product_height,
            "image_size": fi.formats["image_size"],
            "text": fi.formats["text"],
            "title": fi.formats["title"],
            "chars": fi.formats["chars"],
        }
示例#2
0
    def saveFormatter(self):
        """
        """
        fi = IFormats(self.context)
        f = fi.setFormats(self.request)

        referer = self.request.get("HTTP_REFERER", "")
        if referer.find("thank-you") != -1:
            url = referer
        else:
            url = self.context.absolute_url()

        self.request.response.redirect(url)
示例#3
0
    def saveFormatter(self, portlethash):
        """
        """
        fi = IFormats(self.context)
        fi.setFormats(self.request.form)
        
        kss_core  = self.getCommandSet("core")
        kss_zope  = self.getCommandSet("zope")
        kss_plone = self.getCommandSet("plone")
        
        layout = self.request.form.get("layout")

        if layout == "categories-view":
            kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("categories-list"),
                                    manager="easyshop.categories-manager",
                                    name="easyshop.categories-viewlet")

        elif layout == "products-view":
            kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"),
                                    manager="easyshop.products-manager",
                                    name="easyshop.products-viewlet")

        elif layout == "product-selector-view":
            kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"),
                                    manager="easyshop.product-selector-manager",
                                    name="easyshop.product-selector-viewlet")                                    

        # For easyshop.easyarticle
        elif layout == "overview":
            kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"),
                                    manager="easyshop.products-manager",
                                    name="easyshop.products-viewlet")

        # For easyshop.easyarticle
        elif layout == "ps-view":
            kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"),
                                    manager="easyshop.ps-manager",
                                    name="easyshop.ps-viewlet")

        # else:
        #     kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"),
        #                             manager="easyshop.search-results-manager",
        #                             name="easyshop.search-results-viewlet")

        kss_plone.refreshPortlet(portlethash)
示例#4
0
 def getFormatInfo(self):
     """
     """
     return IFormats(self.context).getFormats()
示例#5
0
 def afterSetUp(self):
     """
     """
     super(TestFormatterInfos, self).afterSetUp()
     self.fi_1 = IFormats(self.shop)
     self.fi_2 = IFormats(self.shop.categories.category_1)
示例#6
0
    def getSelector(self):
        """
        """
        mtool = getToolByName(self.context, "portal_membership")
        catalog = getToolByName(self.context, "portal_catalog")

        fi = IFormats(self.context).getFormats()
        products_per_line = fi.get("products_per_line")

        lines = []
        products = []
        for index, product in enumerate(self.context.getRefs()):

            if mtool.checkPermission("View", product) is None:
                continue

            # Price
            cm = ICurrencyManagement(self.context)
            p = IPrices(product)

            # Effective price
            price = p.getPriceForCustomer()
            price = cm.priceToString(price,
                                     symbol="symbol",
                                     position="before",
                                     suffix=None)

            # Standard price
            standard_price = p.getPriceForCustomer(effective=False)
            standard_price = cm.priceToString(standard_price,
                                              symbol="symbol",
                                              position="before",
                                              suffix=None)

            # image
            image = IImageManagement(product).getMainImage()
            if image is not None:
                image = "%s/image_%s" % (image.absolute_url(),
                                         fi.get("image_size"))

            # Text
            temp = fi.get("text")
            if temp == "description":
                text = product.getDescription()
            elif temp == "short_text":
                text = product.getShortText()
            elif temp == "text":
                text = product.getText()
            else:
                text = ""

            # Title
            temp = fi.get("title")
            if temp == "title":
                title = product.Title()
            elif temp == "short_title":
                title = product.getShortTitle()

            try:
                chars = int(fi.get("chars"))
            except (ValueError, TypeError):
                chars = 0

            if (chars != 0) and (len(title) > chars):
                title = title[:chars]
                title += "..."

            if (index + 1) % products_per_line == 0:
                klass = "last"
            else:
                klass = "notlast"

            products.append({
                "title": title,
                "url": product.absolute_url(),
                "for_sale": product.getForSale(),
                "price": price,
                "standard_price": standard_price,
                "image": image,
                "text": text,
                "class": klass,
            })

            if (index + 1) % products_per_line == 0:
                lines.append(products)
                products = []

        # the rest
        lines.append(products)

        return {
            "edit_url": "%s/base_edit" % self.context.absolute_url(),
            "show_title": self.context.getShowTitle(),
            "title": self.context.Title(),
            "lines": lines,
            "products_per_line": products_per_line,
            "product_height": fi.get("product_height"),
            "td_width": "%s%%" % (100 / products_per_line),
        }
示例#7
0
 def getFormatInfo(self):
     """
     """
     fi = IFormats(self.context)
     return fi.getFormats(effective=False)
示例#8
0
 def getFormatInfo(self):
     """
     """
     # Could be overwritten to provide fixed category views.
     return IFormats(self.context).getFormats()
示例#9
0
 def getFormats(self):
     """
     """
     # Could be overwritten to provide fixed category views.
     # s. DemmelhuberShop
     return IFormats(self.context).getFormats()