def post(self): doc = minidom.parse(self.request.body_file) ModelName = doc.documentElement.tagName logging.info('ModelName==>%s<=' % (ModelName)) if ModelName == 'Person': try: Nr = doc.getElementsByTagName("Nr")[0].childNodes[0].data except: Nr = None root = db.Key.from_path('Persons', 'root') rec = Person.get_or_insert('%s' % (Nr), parent=root) for attr_name, value in Person.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() if ModelName == 'Medlog': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None try: Nr = doc.getElementsByTagName("Nr")[0].childNodes[0].data except: Nr = None root = db.Key.from_path('Persons', 'root', 'Person', '%s' % (Nr)) rec = Medlog.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Medlog.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Pbsforsendelse': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootPbsforsendelse', 'root') rec = Pbsforsendelse.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Pbsforsendelse.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Tilpbs': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootTilpbs', 'root') rec = Tilpbs.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Tilpbs.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Fak': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None try: Nr = doc.getElementsByTagName("Nr")[0].childNodes[0].data except: Nr = None root = db.Key.from_path('Persons', 'root', 'Person', '%s' % (Nr)) rec = Fak.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Fak.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() rec.addMedlog() elif ModelName == 'Rykker': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None try: Nr = doc.getElementsByTagName("Nr")[0].childNodes[0].data except: Nr = None root = db.Key.from_path('Persons', 'root', 'Person', '%s' % (Nr)) rec = Rykker.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Rykker.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Overforsel': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None try: Nr = doc.getElementsByTagName("Nr")[0].childNodes[0].data except: Nr = None root = db.Key.from_path('Persons', 'root', 'Person', '%s' % (Nr)) rec = Overforsel.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Overforsel.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Pbsfiles': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootPbsfiles', 'root') rec = Pbsfiles.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Pbsfiles.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Pbsfile': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootPbsfile', 'root') rec = Pbsfile.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Pbsfile.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Frapbs': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootFrapbs', 'root') rec = Frapbs.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Frapbs.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Bet': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootBet', 'root') rec = Bet.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Bet.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Betlin': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None try: Nr = doc.getElementsByTagName("Nr")[0].childNodes[0].data except: Nr = None root = db.Key.from_path('Persons', 'root', 'Person', '%s' % (Nr)) rec = Betlin.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Betlin.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() rec.addMedlog() elif ModelName == 'Aftalelin': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None try: Nr = doc.getElementsByTagName("Nr")[0].childNodes[0].data except: Nr = None root = db.Key.from_path('Persons', 'root', 'Person', '%s' % (Nr)) rec = Aftalelin.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Aftalelin.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Indbetalingskort': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None try: Nr = doc.getElementsByTagName("Nr")[0].childNodes[0].data except: Nr = None root = db.Key.from_path('Persons', 'root', 'Person', '%s' % (Nr)) rec = Indbetalingskort.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Indbetalingskort.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Sftp': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootSftp', 'root') rec = Sftp.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Sftp.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Infotekst': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootInfotekst', 'root') rec = Infotekst.get_or_insert('%s' % (Id), parent=root) rec.Id = int(Id) rec.Navn = doc.getElementsByTagName("Navn")[0].childNodes[0].data txt = doc.getElementsByTagName("Msgtext")[0].childNodes[0].data rec.Msgtext = doc.getElementsByTagName( "Msgtext")[0].childNodes[0].data rec.put() elif ModelName == 'Sysinfo': try: Vkey = doc.getElementsByTagName("Vkey")[0].childNodes[0].data except: Vkey = None root = db.Key.from_path('rootSysinfo', 'root') rec = Sysinfo.get_or_insert('%s' % (Vkey), parent=root) for attr_name, value in Sysinfo.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'Kreditor': try: Id = doc.getElementsByTagName("Id")[0].childNodes[0].data except: Id = None root = db.Key.from_path('rootKreditor', 'root') rec = Kreditor.get_or_insert('%s' % (Id), parent=root) for attr_name, value in Kreditor.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() elif ModelName == 'NrSerie': try: Nrserienavn = doc.getElementsByTagName( "Nrserienavn")[0].childNodes[0].data except: Nrserienavn = None rec = NrSerie.get_or_insert('%s' % (Nrserienavn)) for attr_name, value in NrSerie.__dict__.iteritems(): if isinstance(value, db.Property): attr_type = value.__class__.__name__ if not attr_type in ['_ReverseReferenceProperty']: val = self.attr_val(doc, attr_name, attr_type) logging.info('%s=%s' % (attr_name, val)) try: setattr(rec, attr_name, val) except: setattr(rec, attr_name, None) logging.info('==>%s<==>%s<==' % (attr_name, attr_type)) rec.put() self.response.out.write('Status: 404')
def read042(self, sektion, transkode, rec): fortegn = None belobmun = None belob = None # -- pbssektionnr # -- pbstranskode # - transkode 0236, gennemført automatisk betaling # - transkode 0237, afvist automatisk betaling # - transkode 0238, afmeldt automatisk betaling # - transkode 0239, tilbageført betaling # -- debitorkonto if sektion == '0211': Nr = int(rec[33:40] ) Debitorkonto = rec[25:40] elif sektion == '0215': Nr = int(rec[37:44] ) Debitorkonto = rec[29:44] else: Nr = None Debitorkonto = None betlinid = nextval('Betlinid') root_betlin = db.Key.from_path('Persons','root','Person','%s' % (Nr)) self.m_rec_betlin = Betlin.get_or_insert('%s' % (betlinid), parent=root_betlin) self.m_rec_betlin.Id = betlinid self.m_rec_betlin.Pbssektionnr = sektion self.m_rec_betlin.Pbstranskode = transkode self.m_rec_betlin.Nr = Nr self.m_rec_betlin.Debitorkonto = Debitorkonto # -- aftalenr if sektion == '0211': self.m_rec_betlin.Aftalenr = int(rec[40:49] ) else: self.m_rec_betlin.Aftalenr = None # -- pbskortart if sektion == '0215': self.m_rec_betlin.Pbskortart = rec[44:46] else: self.m_rec_betlin.Pbskortart = None # -- pbsgebyrbelob if sektion == '0215': fortegn = int(rec[46:46+1] ) belob = int(rec[47:47+5] ) belobmun = float(belob / 100) if fortegn == 0: self.m_rec_betlin.Pbsgebyrbelob = float(0) elif fortegn == 1: self.m_rec_betlin.Pbsgebyrbelob = belobmun else: self.m_rec_betlin.Pbsgebyrbelob = float(0) else: self.m_rec_betlin.Pbsgebyrbelob = float(0) # -- betalingsdato if sektion == '0211': if rec[49:55] != '000000': self.m_rec_betlin.Betalingsdato = datetime.strptime('20' + rec[53:55] + '-' + rec[51:53] + '-' + rec[49:51], "%Y-%m-%d").date() else: self.m_rec_betlin.Betalingsdato = None elif sektion == '0215': if rec[52:58] != '000000': self.m_rec_betlin.Betalingsdato = datetime.strptime('20' + rec[56:58] + '-' + rec[54:56] + '-' + rec[52:54], "%Y-%m-%d").date() else: self.m_rec_betlin.Betalingsdato = None else: self.m_rec_betlin.Betalingsdato = None # -- belob if sektion == '0211': fortegn = int(rec[55:56] ) belob = int(rec[56:69] ) belobmun = float(belob / 100) if fortegn == 0: self.m_rec_betlin.Belob = float(0) elif fortegn == 1: self.m_rec_betlin.Belob = belobmun elif fortegn == 2: self.m_rec_betlin.Belob = (belobmun * -1) else: self.m_rec_betlin.Belob = None elif sektion == '0215': fortegn = int(rec[58:59] ) belob = int(rec[59:72] ) belobmun = float(belob / 100) if fortegn == 0: self.m_rec_betlin.Belob = float(0) elif fortegn == 1: self.m_rec_betlin.Belob = belobmun else: self.m_rec_betlin.Belob = None else: self.m_rec_betlin.Belob = None # -- faknr if sektion == '0211': self.m_rec_betlin.Faknr = int('0' + rec[69:78].strip()) elif sektion == '0215': self.m_rec_betlin.Faknr = int('0' + rec[72:81].strip()) else: self.m_rec_betlin.Faknr = None # -- pbsarkivnr if sektion == '0215': self.m_rec_betlin.Pbsarkivnr = rec[81:103] else: self.m_rec_betlin.Pbsarkivnr = None # -- indbetalingsdato if rec[103:109] != '000000': self.m_rec_betlin.Indbetalingsdato = datetime.strptime('20' + rec[107:109] + '-' + rec[105:107] + '-' + rec[103:105], "%Y-%m-%d").date() else: self.m_rec_betlin.Indbetalingsdato = None # -- bogforingsdato if rec[109:115] != '000000': self.m_rec_betlin.Bogforingsdato = datetime.strptime('20' + rec[113:115] + '-' + rec[111:113] + '-' + rec[109:111], "%Y-%m-%d").date() else: self.m_rec_betlin.Bogforingsdato = None # -- indbetalingsbelob if sektion == '0211': fortegn = int(rec[55:56] ) belob = int(rec[115:128] ) belobmun = float(belob / 100) if fortegn == 0: self.m_rec_betlin.Indbetalingsbelob = 0 elif fortegn == 1: self.m_rec_betlin.Indbetalingsbelob = belobmun elif fortegn == 2: self.m_rec_betlin.Indbetalingsbelob = (belobmun * -1) else: self.m_rec_betlin.Indbetalingsbelob = None elif sektion == '0215': fortegn = int(rec[58:59] ) belob = int(rec[115:128] ) belobmun = float(belob / 100) if fortegn == 0: self.m_rec_betlin.Indbetalingsbelob = float(0) elif fortegn == 1: self.m_rec_betlin.Indbetalingsbelob = belobmun else: self.m_rec_betlin.Indbetalingsbelob = None else: self.m_rec_betlin.Indbetalingsbelob = None # Find or Create Bet record for wrec_bet in self.m_rec_frapbs.listBet: if wrec_bet.Pbssektionnr == sektion and wrec_bet.Transkode == transkode and wrec_bet.Bogforingsdato == self.m_rec_betlin.Bogforingsdato: self.m_rec_bet = wrec_bet break else: betid = nextval('Betid') root_bet = db.Key.from_path('rootBet','root') self.m_rec_bet = Bet.get_or_insert('%s' % (betid), parent=root_bet) self.m_rec_bet.Id = betid self.m_rec_bet.Pbssektionnr = sektion self.m_rec_bet.Transkode = transkode self.m_rec_bet.Bogforingsdato = self.m_rec_betlin.Bogforingsdato self.m_rec_bet.Frapbsref = self.m_rec_frapbs.key() self.m_rec_bet.put() # Add Betlin self.m_rec_betlin.Betref = self.m_rec_bet.key() self.m_rec_betlin.put()