def on_change_with_uri(self, vals): if vals.get('name'): if not vals.get('uri'): vals['uri'] = slugify(vals['name']) return vals['uri'] else: return {}
def on_change_with_uri(self): """ If the URI is empty and the name is there, slugify name into URI """ if self.name and not self.uri: return slugify(self.name) return self.uri
def on_change_with_uri(self): """ If the URI is empty, slugify template name into URI """ if not self.uri and self.template: return slugify(self.template.name) return self.uri
def on_change_with_folder_name(self): """ Fills the name field with a slugified name """ if self.get('name'): if not self.get('folder_name'): self['folder_name'] = slugify(self['name']) return self['folder_name']
def on_change_with_slug(self): """ On change the name and slug, ensure that the slug field is auto filled with a generated slug, if the field is empty """ if not self.slug: self.slug = slugify(self.get_rec_name('rec_name')) return self.slug
def on_change_with_folder_name(self, vals): """ Fills the name field with a slugified name """ if vals.get('name'): if not vals.get('folder_name'): vals['folder_name'] = slugify(vals['name']) return vals['folder_name']
def make_uri(self, name, parent): """Construct a URI and return it.""" full_name = u'' if parent: full_name += "%s-" % self.get_rec_name([parent.id], None)[parent.id] full_name += name full_name.replace('/', '-') return slugify(full_name)
def on_change_with_uri(self): """Slugifies the full name of a category to make the uri on change of product name. Slugification will occur only if there is no uri filled from before. """ if self.name and not self.uri: full_name = (self.parent and self.parent.rec_name or '') \ + self.name return slugify(full_name) return self.uri
def _get_or_create_icecat_if_not_exists(cls, icecat_id): """ Build TreeNode hierarchy for given category :param icecat_id: ICECAT category ID :returns: Node activerecord for icecat_id """ data = cls._get_icecat_categorieslist_data() node = cls.search([('icecat_id', '=', icecat_id)]) if node: # node already exists, simply return node, = node elif icecat_id == 1: # Create root node as it does not exist node, = cls.create([{ 'name': 'ICECAT Categories', # since no name set in XML file 'type_': 'catalog', 'slug': slugify('ICECAT Categories'), 'icecat_id': icecat_id }]) else: category, = data.xpath( 'Category[@ID="%d"]' % icecat_id ) name, = category.xpath('Name[@langid="1"]') name = name.get('Value') node, = cls.create([{ 'name': name, 'type_': 'catalog', 'slug': slugify(name), 'icecat_id': icecat_id }]) node._save_icecat_category_alternate_lang(data) # get parent object and recursively create the tree parent, = category.xpath('ParentCategory') parent_node = cls._get_or_create_icecat_if_not_exists( int(parent.attrib.get('ID')) ) cls.write([node], {'parent': parent_node}) return node
def _get_or_create_icecat_if_not_exists(cls, icecat_id): """ Build TreeNode hierarchy for given category :param icecat_id: ICECAT category ID :returns: Node activerecord for icecat_id """ data = cls._get_icecat_categorieslist_data() node = cls.search([('icecat_id', '=', icecat_id)]) if node: # node already exists, simply return node, = node elif icecat_id == 1: # Create root node as it does not exist node, = cls.create([{ 'name': 'ICECAT Categories', # since no name set in XML file 'type_': 'catalog', 'slug': slugify('ICECAT Categories'), 'icecat_id': icecat_id }]) else: category, = data.xpath('Category[@ID="%d"]' % icecat_id) name, = category.xpath('Name[@langid="1"]') name = name.get('Value') node, = cls.create([{ 'name': name, 'type_': 'catalog', 'slug': slugify(name), 'icecat_id': icecat_id }]) node._save_icecat_category_alternate_lang(data) # get parent object and recursively create the tree parent, = category.xpath('ParentCategory') parent_node = cls._get_or_create_icecat_if_not_exists( int(parent.attrib.get('ID'))) cls.write([node], {'parent': parent_node}) return node
def validate_uri(self, field): BlogPost = Pool().get('blog.post') if not field.data and not self.data['title']: return field.process_data(slugify(field.data or self.data['title'])) domain = [('uri', '=', field.data)] if Transaction().context.get('blog_id'): # blog_id in context means editing form domain.append(('id', '!=', Transaction().context['blog_id'])) if BlogPost.search(domain): raise ValidationError( 'Blog with the same URL exists. Please change title or modify')
def validate_uri(self, field): BlogPost = Pool().get('blog.post') if not field.data and not self.data['title']: return field.process_data(slugify(field.data or self.data['title'])) domain = [('uri', '=', field.data)] if Transaction().context.get('blog_id'): # blog_id in context means editing form domain.append(('id', '!=', Transaction().context['blog_id'])) if BlogPost.search(domain): raise ValidationError( 'Blog with the same URL exists. Please change title or modify' )
def update_uri(cls, categories): """Update the uri of the category from the complete name. """ for category in categories: cls.write([category], {'uri': slugify(category.rec_name)})
def on_change_title(self): res = {} if self.title and not self.uri: res['uri'] = slugify(self.title) return res
def on_change_title(self): res = {} if self.title and not self.unique_name: res['unique_name'] = slugify(self.title) return res
def on_change_title(self): if self.title and not self.unique_name: self.unique_name = slugify(self.title)
def on_change_with_uri(self): if self.title and not self.uri: return slugify(self.title) return self.uri
def on_change_name(self): res = {} if self.name and not self.unique_identifier: res['unique_identifier'] = slugify(self.name) return res
def on_change_title(self): if self.title and not self.uri: self.uri = slugify(self.title)
def on_change_title(self): res = {} if self.title and not self.unique_name: res['title'] = slugify(self.title) return res
def update_uri(cls, browse_nodes): """ Update the uri of the browse node from the rec_name. """ for browse_node in browse_nodes: cls.write([browse_node], {'uri': slugify(browse_node.rec_name)})