Trunk: Website module filtering by product category on shop

Bug #1271143 reported by Ana Juaristi Olalde
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Low
Fabien Meghazi (OpenERP)

Bug Description

Add a product
Assing to a category
Create same category for public website.

On frontend activate "show category" on filters

Publish products from several categories.

On frontend push category (on left column) to filter products included on it shows the error:
server error page not found.

Related branches

Revision history for this message
Ivan Yelizariev (yelizariev) wrote :

I have the same problem.

Some time on left column is used link like http://localhost:8069/shop/category/-4/ which return 404 error.

But if I remove "-" ( http://localhost:8069/shop/category/4/ ) link return correct page

Revision history for this message
Ivan Yelizariev (yelizariev) wrote :

It happens when category name has only "special" chars (see sligify function at addons/website/models/website.py).
Such chars are removed and we get url http://localhost:8069/shop/category/-4/ , but ModelConverter (see addons/website/models/ir_http.py ) cannot route such url. The one can convert only urls like that:

http://localhost:8069/shop/category/some-category-name-4/
http://localhost:8069/shop/category/4/

So the solution is to patch slug funtion at addons/website/models/website.py:

=== modified file 'website/models/website.py'
*** website/models/website.py 2014-02-13 12:06:02 +0000
--- website/models/website.py 2014-02-16 14:13:47 +0000
***************
*** 80,100 ****
      specialless = re.sub(r'[^-_A-Za-z0-9]', '', spaceless)
      return specialless[:max_length]

  def slug(value):
      if isinstance(value, orm.browse_record):
          # [(id, name)] = value.name_get()
          id, name = value.id, value[value._rec_name]
      else:
          # assume name_search result tuple
          id, name = value
! return "%s-%d" % (slugify(name), id)

  def urlplus(url, params):
      return werkzeug.Href(url)(params or None)

  class website(osv.osv):
      def _get_menu_website(self, cr, uid, ids, context=None):
          # IF a menu is changed, update all websites
          return self.search(cr, uid, [], context=context)

      def _get_menu(self, cr, uid, ids, name, arg, context=None):
--- 80,104 ----
      specialless = re.sub(r'[^-_A-Za-z0-9]', '', spaceless)
      return specialless[:max_length]

  def slug(value):
      if isinstance(value, orm.browse_record):
          # [(id, name)] = value.name_get()
          id, name = value.id, value[value._rec_name]
      else:
          # assume name_search result tuple
          id, name = value
! name = slugify(name)
! if name:
! return "%s-%d" % (slugify(name), id)
! else:
! return str(id)

  def urlplus(url, params):
      return werkzeug.Href(url)(params or None)

  class website(osv.osv):
      def _get_menu_website(self, cr, uid, ids, context=None):
          # IF a menu is changed, update all websites
          return self.search(cr, uid, [], context=context)

      def _get_menu(self, cr, uid, ids, name, arg, context=None):

Changed in openobject-addons:
assignee: nobody → Fabien Meghazi (OpenERP) (fme)
Revision history for this message
Fabien Meghazi (OpenERP) (fme) wrote :

Fixed in trunk.

Note that you can

$ pip install python-slugify

in order to have better support for special characters

Changed in openobject-addons:
importance: Undecided → Low
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.