def post(): try: cdr = xmltodict.parse(request.data) if isinstance(cdr['records']['record'], list): for record in cdr['records']['record']: instance = getattr(cdrs, str(record['@type']))(record) Record.create(data=json.dumps(instance.__dict__)) else: instance = getattr(cdrs, str(cdr['records']['record']['@type']))( cdr['records']['record']) Record.create(data=json.dumps(instance.__dict__)) return ('', 204) except: print('Parser failure!') return ('', 204)
def addRecord(nameIn, activityIn, recordIn, yearIn, numberIn, moreInfoIn): #import the Activity and Record model from models.py from models import Activity, Record #get the ID of the record that is selected activityID = Activity.get(Activity.activityName == activityIn) #create record record = Record.create(person=nameIn, activity=activityID.id, record=recordIn, number=numberIn, year=yearIn, moreInformation=moreInfoIn) record.save()
def visit(self, ip_addr, v_string): if v_string in sys_conf.mconfig['vrecord']['vtype']: vtype = Vtype.select().where(Vtype.name == v_string)[0] tdate = self._today_check() ip = self._ip_check(ip_addr) # check Record t_sql = Record.select().where(Record.vtype == vtype, Record.vdate == tdate, Record.ip == ip) if t_sql.count(): ret = t_sql[0] ret.times += 1 ret.save() else: ret = Record.create(vtype=vtype, vdate=tdate, ip=ip, times=1) return ret else: return []