def apply_patch(store): store.execute(""" CREATE TABLE product_manufacturer ( id serial NOT NULL PRIMARY KEY, te_created_id bigint UNIQUE REFERENCES transaction_entry(id), te_modified_id bigint UNIQUE REFERENCES transaction_entry(id), name text UNIQUE ); ALTER TABLE product ADD COLUMN manufacturer_id bigint REFERENCES product_manufacturer(id); """) alikes = {} for name, in store.execute("""SELECT DISTINCT(manufacturer) FROM product ORDER BY manufacturer;""").get_all(): if not name or not name.strip(): continue # If a manufacturer with a similar name have already been created, use # that instead. key = strip_accents(name.strip().lower()) if key in alikes: m = alikes[key] else: m = ProductManufacturer(store=store, name=name.strip()) alikes[key] = m store.execute(""" UPDATE product set manufacturer_id = ? WHERE manufacturer = ? """, (m.id, name)) store.execute("""ALTER TABLE product DROP COLUMN manufacturer;""")
def _filter_results(self, text): text = strip_accents(text) query = text.lower() query = query.split() self._reset_results() if not query: # Nothing to look for return for param in self._parameters: group = strip_accents(param.group).lower() desc = strip_accents(param.short_desc).lower() group_matches = all(i in group for i in query) desc_matches = all(i in desc for i in query) if not group_matches and not desc_matches: self.results.remove(param)
def _parse_row(sellable, columns): data = [] for col in columns: value = kgetattr(sellable, col) if value is None: value = '' elif isinstance(value, str): # XXX: glabels is not working with unicode caracters value = strip_accents(value) data.append(value) return data
def append_tag(self, tag, value, mandatory=True, cdata=False): if value in [None, ''] and not mandatory: # If the tag is not mandatory and the value is empty, # dont add the tag to the xml. return if cdata and value is not None: value = etree.CDATA(str(value)) elif value is not None: value = escape(strip_accents(str(value).strip())) if hasattr(self, 'NAMESPACE'): tag = etree.SubElement(self, '{%s}%s' % (self.NAMESPACE, tag)) else: tag = etree.SubElement(self, tag) tag.text = value
def generate_filizola_file(store): content = [] content.append(diversos) for sellable in store.find(Sellable): try: # We can only send sellables whose code can be converted to integer code = int(sellable.code) except ValueError: continue if sellable.unit_description == 'Kg': unit = 'p' # peso else: unit = 'u' # unidade content.append("%06d%s%-22s%07d%03d%126s%04d" % ( code, unit, str(strip_accents(sellable.description))[:22], int(sellable.price * 100), 0, '', 0, )) if platform.system() == 'Windows': dest_dir = os.path.join('C:\\', 'Filizola') else: # The software filizola provides is for windows, so on linux, it will # probably be running through wine (even though it didn't work properly # under wine). dest_dir = os.path.join('~', '.wine', 'drive_c', 'Filizola') dest_dir = os.path.expanduser(dest_dir) if not os.path.exists(dest_dir): os.makedirs(dest_dir) dest = os.path.join(dest_dir, 'CADTXT.TXT') with open(dest, 'w') as fh: fh.write('\n'.join(content)) return dest
def as_string(self): """Formats this field to its string representation""" value = self.get_value() # cnab fields are always None if self.name not in ['cnab', '_']: assert value is not None, self.name if self.type is str: value = strip_accents(str(value or '')).ljust(self.size)[:self.size] elif self.type is int: value = str(value or 0).rjust(self.size, '0') assert len(value) == self.size, (self.name, value, len(value), self.size) elif self.type is Decimal: value = value or 0 value = str(int(value * (10**self.decimals))) value = str(value).rjust(self.size, '0') assert len(value) == self.size, (value, len(value), self.size) return value or ''
def test_strip_accents(accented_string, stripped_string): assert strip_accents(accented_string) == stripped_string