def __init__(self, cols=None, defaults=None): if self.DEBUG_MRO: self.registerMessage(" ") if cols is None: cols = [] if defaults is None: defaults = {} extra_cols = ["ID", "FROM", "TO", "RNS", "RPS", "WNS", "WPS", "XRNS", "XRPS", "XWNS", "XWPS"] cols = listUtils.combineLists(cols, extra_cols) super(CSVParse_Special, self).__init__(cols, defaults) self.objectIndexer = self.getObjectID
def __init__(self, cols, defaults, schema, **kwargs): if self.DEBUG_MRO: self.registerMessage('CSVParse_Gen_Tree') taxoSubs = kwargs.pop('taxoSubs', {}) itemSubs = kwargs.pop('itemSubs', {}) extra_defaults = OrderedDict([ ('CVC', '0'), ('code', ''), ('name', ''), ('fullname', ''), ('description', ''), ('HTML Description', ''), ('imglist', []) ]) extra_taxoSubs = OrderedDict([ ('', ''), ]) extra_itemSubs = OrderedDict([ ('Hot Pink', 'Pink'), ('Hot Lips (Red)', 'Red'), ('Hot Lips', 'Red'), ('Silken Chocolate (Bronze)', 'Bronze'), ('Silken Chocolate', 'Bronze'), ('Moon Marvel (Silver)', 'Silver'), ('Dusty Gold', 'Gold'), ('Screen Printed', ''), ('Embroidered', ''), ]) extra_cols = [schema] cols = listUtils.combineLists( cols, extra_cols ) defaults = listUtils.combineOrderedDicts( defaults, extra_defaults ) super(CSVParse_Gen_Tree, self).__init__( cols, defaults, **kwargs) # CSVParse_Gen_Mixin.__init__(self, schema) metaWidth = kwargs.get('metaWidth', 2) assert metaWidth >= 2, "metaWidth must be greater than 2 for a GEN subclass" self.schema = schema self.taxoSubs = listUtils.combineOrderedDicts( taxoSubs, extra_taxoSubs ) self.itemSubs = listUtils.combineOrderedDicts( itemSubs, extra_itemSubs ) self.taxoRegex = SanitationUtils.compileRegex(self.taxoSubs) self.itemRegex = SanitationUtils.compileRegex(self.itemSubs) if self.DEBUG_GEN: self.registerMessage("taxoDepth: {}".format(self.taxoDepth), 'CSVParse_Gen_Tree.__init__') self.registerMessage("itemDepth: {}".format(self.itemDepth), 'CSVParse_Gen_Tree.__init__') self.registerMessage("maxDepth: {}".format(self.maxDepth), 'CSVParse_Gen_Tree.__init__') self.registerMessage("metaWidth: {}".format(self.metaWidth), 'CSVParse_Gen_Tree.__init__') self.registerMessage("schema: {}".format(self.schema), 'CSVParse_Gen_Tree.__init__')
def __init__(self, cols, defaults, **kwargs): # super(CSVParse_Base, self).__init__() # Registrar.__init__(self) if self.DEBUG_MRO: self.registerMessage('CSVParse_Base') extra_cols = [] extra_defaults = OrderedDict() self.limit = kwargs.pop('limit', None) self.cols = listUtils.combineLists( cols, extra_cols ) self.defaults = listUtils.combineOrderedDicts( defaults, extra_defaults ) self.objectIndexer = self.getObjectRowcount self.clearTransients()
def __init__(self, cols=[], defaults={}): extra_cols = [ 'ID', 'Qty. Base', 'Rule Mode', 'Roles', 'Min ( Buy )', 'Max ( Receive )', 'Discount Type', 'Discount', 'Repeating', 'Meaning'] extra_defaults = { 'Discount Type':'PDSC', 'Rule Mode': 'BULK' } cols = listUtils.combineLists(cols, extra_cols) defaults = listUtils.combineOrderedDicts(extra_defaults, defaults) super(CSVParse_Dyn, self).__init__( cols, defaults, \ taxoDepth=1, itemDepth=1, metaWidth=0) self.taxoIndexer = self.getObjectIndex
def __init__(self, cols=[], defaults={}, contact_schema=None, filterItems=None, limit=None): if self.DEBUG_MRO: self.registerMessage(" ") extra_cols = [ # 'ABN', 'Added to mailing list', 'Address 1', 'Address 2', 'Agent', 'Birth Date', # 'book_spray_tan', 'Book-a-Tan Expiry', 'Business Type', 'Canvasser', '' # 'post_status' ] extra_defaults = OrderedDict( [ # ('post_status', 'publish'), # ('last_import', importName), ] ) cols = listUtils.combineLists(cols, extra_cols) defaults = listUtils.combineOrderedDicts(defaults, extra_defaults) super(CSVParse_User, self).__init__(cols, defaults, limit) self.contact_schema = contact_schema self.filterItems = filterItems
def __init__(self, cols={}, defaults={}, schema='MY', importName="", \ taxoSubs={}, itemSubs={}, taxoDepth=3, itemDepth=2, metaWidth=2): if self.DEBUG_MRO: self.registerMessage(' ') extra_cols = [ 'WNRC', 'RNRC', 'HTML Description' ] extra_defaults = OrderedDict([ ('Sell', 'S'), ('Tax Code When Sold', 'GST'), ('Sell Price Inclusive', 'X'), ('Income Acct', '41000'), ('Use Desc. On Sale', ''), ('Inactive Item', 'N'), ]) extra_taxoSubs = OrderedDict([ ('', ''), ]) extra_itemSubs = OrderedDict([ ('Body Butter with Shimmer', 'Body Butter w/ Shimmer'), ('Tan Saver Body Wash', 'Body Wash'), ('Full Body Moisturizer', 'Moisturizer'), ('Moisturizing Body Milk', 'Body Milk'), ('Hair Brush', 'Brush'), ('Training Session', 'Session'), ('Skin Trial Pack', "Pack"), ('Trial Pack', "Pack"), ('Starter Package', 'Pack'), ('Sample Pack', "Pack"), ('Evaluation Package', 'Pack'), ('Spare Pot & Hose', 'Pot, Hose'), ('Spare Pots & Hose', 'Pots, Hose'), ('spare pot + Hose', 'pot, hose'), ('spare pots + Hose', 'pots, hose'), ('extraction fans', 'xfan'), ('Low Voltage', 'LV'), ('Double Sided', '2Sided'), ('TechnoTan', 'TT'), ('VuTan', 'VT'), ('EzeBreathe', 'EZB'), ('Sticky Soul', 'SS'), ('My Tan', 'MT'), ('TanSense', 'TS'), ('Tanning Advantage', 'TA'), ('Tanbience', 'TB'), ('Mosaic Minerals', 'MM'), ('Removal', 'Rem.'), ('Remover', 'Rem.'), ('Application', 'App.'), ('Peach & Vanilla', 'P&V'), ('Tamarillo & Papaya', 'T&P'), ('Tamarillo', 'TAM'), ('Lavander & Rosmary', 'L&R'), ('Lavender & Rosemary', 'L&R'), ('Coconut & Lime', 'C&L'), ('Melon & Cucumber', 'M&C'), ('Coconut Cream', 'CC'), ('Black & Silver', 'B&S'), ('Black & Gold', 'B&G'), ('Hot Pink', 'PNK'), ('Hot Lips (Red)', 'RED'), ('Hot Lips Red', 'RED'), ('Hot Lips', 'RED'), ('Silken Chocolate (Bronze)', 'BRZ'), ('Silken Chocolate', 'BRZ'), ('Moon Marvel (Silver)', 'SLV'), ('Dusty Gold', 'GLD'), ('Black', 'BLK'), ('Light Blue', 'LBLU'), ('Dark Blue', 'DBLU'), ('Blue', 'BLU'), ('Green', 'GRN'), ('Pink', 'PNK'), ('White', 'WHI'), ('Grey', 'GRY'), ('Peach', 'PEA'), ('Bronze', 'BRZ'), ('Silver', 'SLV'), ('Gold', 'GLD'), ('Red', 'RED'), ('Cyclone', 'CYC'), ('Classic', 'CLA'), ('Premier', 'PRE'), ('Deluxe', 'DEL'), ('ProMist Cube', 'CUBE'), ('ProMist', 'PRO'), ('Mini Mist', 'MIN'), ('Choc Fudge', 'CFdg.'), ('Choc Mousse', 'Cmou'), ('Ebony', 'Ebny.'), ('Creme Caramel', 'CCarm.'), ('Caramel', 'Carm.'), ('Cappuccino', 'Capp.'), ('Evaluation', 'Eval.'), ('Package', 'Pack'), ('Sample', 'Samp.'), ('sample', 'Samp.'), ('Tan Care', 'TCare'), ('After Care', "ACare"), ('A-Frame', 'AFrm'), ('X-Frame', 'XFrm'), ('Tear Drop Banner', 'TDBnr'), ('Roll Up Banner', 'RUBnr'), ('Hose Fitting', 'Fit.'), ('Magnetic', 'Mag.'), ('Option ', 'Opt.'), ('Style ', 'Sty.'), ('Insert and Frame', 'ins. frm.'), ('Insert Only', 'ins.'), ('Insert', 'ins.'), ('insert', 'ins.'), ('Frame', 'frm.'), ('Foundation', 'Found.'), ('Economy', 'Econ.'), ('Medium-Dark', 'MDark'), ('Medium Dark', 'MDark'), ('Medium', 'Med.'), ('medium', 'med.'), ('Extra Dark', 'XDark'), ('Extra-Dark', 'XDark'), ('Dark', 'Dark'), ('Tanning', 'Tan.'), ('Extra Small', 'XSml.'), ('Small', 'Sml.'), ('Extra Large', 'XLge.'), ('Large', 'Lge.'), ('Ladies', 'Ld.'), ('Mens', 'Mn.'), ('Non Personalized', 'Std.'), ('Personalized', 'Per.'), ('personalized', 'per.'), ('Personalised', 'Per.'), ('personalised', 'per.'), ('Custom Designed', 'Cust.'), ('Refurbished', 'Refurb.'), ('Compressor', 'Cmpr.'), ('Spray Gun', 'Gun'), ('Permanent', 'Perm.'), ('Shimmering', 'Shim.'), ('Screen Printed', 'SP'), ('Embroidered', 'Embr.'), ('Athletic', 'Athl.'), ('Singlet', 'Sing.'), ('Solution', 'Soln.'), ('Flash Tan', 'FTan'), ('Original', 'Orig.'), ('Exfoliating', 'Exfo.'), ('Disposable', 'Disp.'), ('Retractable', 'Ret.'), ('Synthetic', 'SYN'), ('Natural', 'NAT'), ('Bayonet', 'BAY'), ('Hexagonal', 'Hex.'), ('Product Pack', 'PrPck'), ('Complete', 'Compl.'), ('Fanatic', 'Fan.'), ('one', '1'), ('One', '1'), ('two', '2'), ('Two', '2'), ('three', '3'), ('Three', '3'), ('four', '4'), ('Four', '4'), # ('for', '4'), ('five', '5'), ('Five', '5'), ('six', '6'), ('Six', '6'), ('seven', '7'), ('seven', '7'), ('eight', '8'), ('Eight', '8'), ('nine', '9'), ('Nine', '9'), (' Plus', '+'), (' - ', ' '), (' Pack / ', ' x '), ('with', 'w/'), ('With', 'w/'), ('Box of', 'Box/'), (' Fitting for ', ' Fit '), (' Fits ', ' Fit '), (' and ', ' & '), (' And ', ' & '), # (' (2hr)', ''), (' (sachet)', ''), (' (pump bottle)', ''), (' Bottle with Flip Cap', ''), (' (jar)', ''), (' (tube)', ''), (' (spray)', ''), (' \xe2\x80\x94 ', ' '), ]) if not importName: importName = time.strftime("%Y-%m-%d %H:%M:%S") cols = listUtils.combineLists( cols, extra_cols ) defaults = listUtils.combineOrderedDicts( defaults, extra_defaults ) taxoSubs = listUtils.combineOrderedDicts( taxoSubs, extra_taxoSubs ) itemSubs = listUtils.combineOrderedDicts( itemSubs, extra_itemSubs ) if not schema: schema = "MY" super(CSVParse_MYO, self).__init__( cols, defaults, schema, \ taxoSubs, itemSubs, taxoDepth, itemDepth, metaWidth) if self.DEBUG_MYO: self.registerMessage( "csvparse initialized with cols: %s" % SanitationUtils.coerceUnicode(extra_cols))
def initContactObjects(self, data): # emails_kwargs = OrderedDict(filter(None, [\ # ((key, data.get(value)) if data.get(value) else None) for key, value in\ # { # 'email' : 'E-mail', # 'personal_email': 'Personal E-mail', # }.items() # ])) # # self['E-mails'] = EmailFields( # **emails_kwargs # ) name_kwargs = OrderedDict( filter( None, [ ((key, data.get(value)) if data.get(value) else None) for key, value in { "first_name": "First Name", "middle_name": "Middle Name", "family_name": "Surname", "name_prefix": "Name Prefix", "name_suffix": "Name Suffix", "contact": "Contact", "company": "Company", "city": "City", "country": "Country", "state": "State", }.items() ], ) ) self["Name"] = ContactName(**name_kwargs) assert self["Name"] is not None, "contact is missing mandatory fields: something went wrong" address_kwargs = OrderedDict( filter( None, [ ((key, data.get(value)) if data.get(value) else None) for key, value in { "line1": "Address 1", "line2": "Address 2", "city": "City", "postcode": "Postcode", "state": "State", "country": "Country", "company": "Company", }.items() ], ) ) self["Address"] = ContactAddress(**address_kwargs) # print "ADDRESS: ", self['Address'] alt_address_kwargs = OrderedDict( filter( None, [ ((key, data.get(value)) if data.get(value) else None) for key, value in { "line1": "Home Address 1", "line2": "Home Address 2", "city": "Home City", "postcode": "Home Postcode", "state": "Home State", "country": "Home Country", "company": "Company", }.items() ], ) ) self["Home Address"] = ContactAddress(**alt_address_kwargs) # print "HOME ADDRESS: ", self['Home Address'] phone_kwargs = OrderedDict( filter( None, [ ((key, data.get(value)) if data.get(value) else None) for key, value in { "mob_number": "Mobile Phone", "tel_number": "Phone", "fax_number": "Fax", "mob_pref": "Mobile Phone Preferred", "tel_pref": "Phone Preferred", }.items() ], ) ) self["Phone Numbers"] = ContactPhones(**phone_kwargs) social_media_kwargs = OrderedDict( filter( None, [ ((key, data.get(value)) if data.get(value) else None) for key, value in { "facebook": "Facebook Username", "twitter": "Twitter Username", "gplus": "GooglePlus Username", "instagram": "Instagram Username", "website": "Web Site", }.items() ], ) ) self["Social Media"] = SocialMediaFields(**social_media_kwargs) emails = [] if data.get("E-mail"): emails = listUtils.combineLists(emails, SanitationUtils.findallEmails(data["E-mail"])) if data.get("Personal E-mail"): emails = listUtils.combineLists(emails, SanitationUtils.findallEmails(data.get("Personal E-mail"))) self["E-mail"] = emails.pop(0) if emails else None self["Personal E-mail"] = ", ".join(emails) urls = [] if data.get("Web Site"): urls = listUtils.combineLists(urls, SanitationUtils.findallURLs(data["Web Site"])) self["Web Site"] = urls.pop(0) if urls else None # if not self['Emails'].valid: # self['emails_reason'] = '\n'.join(filter(None, [ # self['Emails'].reason, # ])) if not self["Address"].valid or not self["Home Address"].valid: self["address_reason"] = "\n".join( filter( None, [ "ADDRESS: " + self["Address"].reason if not self["Address"].valid else None, "HOME ADDRESS: " + self["Home Address"].reason if not self["Home Address"].valid else None, ], ) ) if not self["Name"].valid: self["name_reason"] = "\n".join(filter(None, [self["Name"].reason])) if not self["Phone Numbers"].valid: self["phone_reason"] = "\n".join(filter(None, [self["Phone Numbers"].reason])) if not self["Social Media"].valid: self["social_reason"] = "\n".join(filter(None, [self["Social Media"].reason]))