Ejemplo n.º 1
0
    def add_to_cart(cls):
        """
        Adds the given item to the cart if it exists or to a new cart

        The form is expected to have the following data is post

            quantity    : decimal
            product     : integer ID
            action      : set (default), add

        Response:
            'OK' if X-HTTPRequest
            Redirect to shopping cart if normal request
        """
        form = AddtoCartForm(request.form)
        if request.method == "POST" and form.validate():
            cart = cls.open_cart(create_order=True)
            action = request.values.get("action", "set")
            if form.quantity.data <= 0:
                flash(_("Be sensible! You can only add real quantities to cart"))
                return redirect(url_for("nereid.cart.view_cart"))
            cls._add_or_update(cart.sale.id, form.product.data, form.quantity.data, action)
            if action == "add":
                flash(_("The product has been added to your cart"), "info")
            else:
                flash(_("Your cart has been updated with the product"), "info")
            if request.is_xhr:
                return jsonify(message="OK")

        return redirect(url_for("nereid.cart.view_cart"))
Ejemplo n.º 2
0
    def get_absolute_url(self, **kwargs):
        """
        Return the URL of the current product.

        This method works only under a nereid request context
        """
        return url_for('product.product.render', uri=self.uri, **kwargs)
Ejemplo n.º 3
0
    def get_absolute_url(self, **kwargs):
        """
        Return the URL of the current product.

        This method works only under a nereid request context
        """
        return url_for('product.product.render', uri=self.uri, **kwargs)
Ejemplo n.º 4
0
 def clear_cart(cls):
     """
     Clears the current cart and redirects to shopping cart page
     """
     cart = cls.open_cart()
     cart._clear_cart()
     flash(_("Your shopping cart has been cleared"))
     return redirect(url_for("nereid.cart.view_cart"))
Ejemplo n.º 5
0
    def get_url(self, name):
        """Return the url if within an active request context or return
        False values
        """
        if _request_ctx_stack.top is None:
            return None

        return url_for("nereid.static.file.send_static_file", folder=self.folder.name, name=self.name)
Ejemplo n.º 6
0
    def get_url(self, name):
        """Return the url if within an active request context or return
        False values
        """
        if _request_ctx_stack.top is None:
            return None

        return url_for('nereid.static.file.send_static_file',
                       folder=self.folder.name,
                       name=self.name)
Ejemplo n.º 7
0
 def add_to_wishlist(self):
     """Add the product to wishlist
     """
     user = request.nereid_user
     product = request.args.get('product', type=int)
     self.write(product, {'wishlist': [('add', [user.id])]})
     flash(_("The product has been added to wishlist"))
     if request.is_xhr:
         return 'OK'
     return redirect(url_for('nereid.user.render_wishlist'))
Ejemplo n.º 8
0
 def render(self):
     with NamedTemporaryFile(suffix=".xml") as buffer:
         buffer.write('<?xml version="1.0" encoding="UTF-8"?>\n')
         buffer.write('<sitemapindex ')
         buffer.write(
             'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n')
         for page in xrange(1, self.page_count + 1):
             loc = '<sitemap><loc>%s</loc></sitemap>\n'
             method = '%s.sitemap' % self.model.__name__
             buffer.write(loc % url_for(method, page=page, _external=True))
         buffer.write('</sitemapindex>')
         return send_file(buffer.name, cache_timeout=self.cache_timeout)
Ejemplo n.º 9
0
    def get_url(self, name):
        """Return the url if within an active request context or return
        False values
        """
        if _request_ctx_stack.top is None:
            return None

        if self.type == 'local':
            return url_for('nereid.static.file.send_static_file',
                           folder=self.folder.folder_name,
                           name=self.name)
        elif self.type == 'remote':
            return self.remote_path
Ejemplo n.º 10
0
 def render(self):
     with NamedTemporaryFile(suffix=".xml") as buffer:
         buffer.write('<?xml version="1.0" encoding="UTF-8"?>\n')
         buffer.write('<sitemapindex ')
         buffer.write(
             'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
         )
         for page in xrange(1, self.page_count + 1):
             loc = '<sitemap><loc>%s</loc></sitemap>\n'
             method = '%s.sitemap' % self.model._name
             buffer.write(loc % url_for(method, page=page, _external=True))
         buffer.write('</sitemapindex>')
         return send_file(buffer.name, cache_timeout=self.cache_timeout)
Ejemplo n.º 11
0
    def get_url(self, name):
        """Return the url if within an active request context or return
        False values
        """
        if _request_ctx_stack.top is None:
            return None

        if self.type == 'local':
            return url_for(
                'nereid.static.file.send_static_file',
                folder=self.folder.folder_name, name=self.name
            )
        elif self.type == 'remote':
            return self.remote_path
Ejemplo n.º 12
0
    def add_to_wishlist(cls):
        """
        Add the product to wishlist

        .. versionchanged::2.6.0.1

            Only POST method can now be used to add products to wishlist.
        """
        cls.write(
            [cls(request.form.get('product', type=int))],
            {'wishlist': [('add', [request.nereid_user.id])]}
        )
        if request.is_xhr:
            return 'OK'
        flash(_("The product has been added to wishlist"))
        return redirect(url_for('nereid.user.render_wishlist'))
Ejemplo n.º 13
0
    def get_url(self, ids, name):
        """Return the url if within an active request context or return
        False values
        """
        res = {}.fromkeys(ids, False)
        if _request_ctx_stack.top is None:
            return res

        for f in self.browse(ids):
            if f.type == 'local':
                res[f.id] = url_for(
                    'nereid.static.file.send_static_file',
                    folder=f.folder.folder_name, name=f.name
                )
            elif f.type == 'remote':
                res[f.id] = f.remote_path
        return res
Ejemplo n.º 14
0
 def _menu_item_to_dict(self, menu_item):
     """
     :param menu_item: Active record of the menu item
     """
     if hasattr(menu_item, 'reference') and getattr(menu_item, 'reference'):
         model, id = getattr(menu_item, 'reference').split(',')
         if int(id):
             reference, = Pool().get(model).browse([int(id)])
             uri = url_for('%s.render' % reference._name, uri=reference.uri)
         else:
             uri = getattr(menu_item, self.uri_field.name)
     else:
         uri = getattr(menu_item, self.uri_field.name)
     return {
             'name' : getattr(menu_item, self.title_field.name),
             'uri' : uri,
         }
Ejemplo n.º 15
0
 def _menu_item_to_dict(self, menu_item):
     """
     :param menu_item: Active record of the menu item
     """
     if hasattr(menu_item, 'reference') and getattr(menu_item, 'reference'):
         model, id = getattr(menu_item, 'reference').split(',')
         if int(id):
             reference, = Pool().get(model)(int(id))
             uri = url_for('%s.render' % reference.__name__,
                           uri=reference.uri)
         else:
             uri = getattr(menu_item, self.uri_field.name)
     else:
         uri = getattr(menu_item, self.uri_field.name)
     return {
         'name': getattr(menu_item, self.title_field.name),
         'uri': uri,
     }
Ejemplo n.º 16
0
    def delete_from_cart(cls, line):
        """
        Delete a line from the cart. The required argument in POST is:

            line_id : ID of the line

        Response: 'OK' if X-HTTPRequest else redirect to shopping cart
        """
        SaleLine = Pool().get("sale.line")

        sale_line = SaleLine(line)
        assert sale_line.sale.id == cls.open_cart().sale.id
        SaleLine.delete([sale_line])
        flash(_("The order item has been successfully removed"))

        if request.is_xhr:
            return jsonify(message="OK")

        return redirect(url_for("nereid.cart.view_cart"))
Ejemplo n.º 17
0
 def get_absolute_url(self, **kwargs):
     return url_for(
         'nereid.cms.article.render', uri=self.uri, **kwargs
     )
Ejemplo n.º 18
0
 def get_absolute_url(self, **kwargs):
     return url_for(
         'nereid.cms.article.category.render',
         uri=self.unique_name, **kwargs
     )
Ejemplo n.º 19
0
 def get_absolute_url(self, **kwargs):
     return url_for(
         'nereid.cms.article.render', uri=self.uri, **kwargs
     )
Ejemplo n.º 20
0
 def get_absolute_url(self, **kwargs):
     return url_for(
         'nereid.cms.article.category.render',
         uri=self.unique_name, **kwargs
     )
Ejemplo n.º 21
0
 def get_absolute_url(self, **kwargs):
     return url_for(
         'product.category.render', uri=self.uri, **kwargs
     )
Ejemplo n.º 22
0
 def get_absolute_url(self, product, **kwargs):
     return url_for(
         'product.product.render', uri=product.uri, **kwargs)