def add(req): empty = [] username = req.session.get('username','') if req.POST: post = req.POST for i in post.keys(): if post[i] == '': empty.append(i + ' shouldn\'t be empty!') if len(empty) == 0: new_people = People( student_num = post["student_num"], name = post["name"], phone = post["phone"], email = post["email"], QQ = post["QQ"], address = post["address"], birthday = post["birthday"], master = username, ) if post["sex"] == "M": new_people.sex = True else: new_people.sex = False new_people.save() return render_to_response("add.html",{'empty':empty},context_instance = RequestContext(req))
def generate_random_identities(amount=1, gender=None, region=None, minlen=None, maxlen=None, ext=False): """ A function that returns a People instance, which contains a list of random Person instances. amount: The number of identities to generate. This should be an integer between 1 and 500 (inclusive). gender: The gender of the identities generated. This should be one of the following string literals: "male" or "female". region: The region of origin of the identities generated. The list of valid regions can be found in this file https://github.com/thm/uinames/blob/master/uinames.com/api/names.json. Generally, any lowercase country, spelled correctly will be valid. minlen: The minimum combined name and surname length of the identity. maxlen: The maximum combined name and surname length of the identity. ext: When specified, this will return extra data with each identity, including: age, title, phone, birthday, email, password, credit card, and a photo. """ params = { "amount": amount, "gender": gender, "region": region, "minlen": minlen, "maxlen": maxlen } if ext: params["ext"] = ext json = _send_raw("https://uinames.com/api/", params=params) return People([json]) if amount == 1 else People(json)
def post(self): data = request.json person = People(name=data['name'], age=data['age']) person.save() response = {'id': person.id, 'name': person.name, 'age': person.age} return response
def post(self,request,filename=None, format=None): uploadedFile = request.data['file'] for line in uploadedFile: data = line.split(',') newPeople = People(id=data[0],name=data[1],last_name=data[2]) newPeople.save() print line return Response(status=204)
def add_new_person(): body = json.loads(request.data) name = body.get('name',None) if name is None: return jsonify({'error':'name cannot be null'}) new_person = People(name=name) db.add(new_person) return jsonify({'result':new_person._dump()})
def test_find_all(mock, client): p1 = {'name': 'first', 'isAlive': True, 'placeId': 1} p2 = {'name': 'second', 'isAlive': False, 'placeId': 2} created1 = People(**p1) created2 = People(**p2) mock.return_value = [created1, created2] res = client.get('/people') assert res.status_code == 200 assert 2 == len(json.loads(res.get_data()))
def names_add(request): if request.method == 'GET': phtml = "<input type=\"text\" name=\"name\" value=\"\" /><input type=\"submit\" />" context_dict = {'title':"Who are you?",'msg':phtml,'action':"/names/add"} return render(request, 'form.html', context_dict) elif request.method == 'POST': new_person = People(name=request.POST['name']) new_person.save() return redirect('names') else: context_dict = {'title': "ERROR", 'msg':"Not a valid method."} return render(request, 'form.html', context_dict)
def getReplyXmlArc(msg): tplHeader = "<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><ArticleCount>%s</ArticleCount><Articles>" tplBody = "<item><Title><![CDATA[%s]]></Title><Description><![CDATA[%s]]></Description><PicUrl><![CDATA[%s]]></PicUrl><Url><![CDATA[%s]]></Url></item>" tplFooter = "</Articles></xml>" if msg['Event'] == 'subscribe': gw_id = msg['EventKey'][8:] elif msg['Event'] == 'SCAN': gw_id = msg['EventKey'] elif msg['Event'] == 'CLICK': if msg['EventKey'] == 'world': try: act = People.objects.get(OpenId=msg['FromUserName']) except People.DoesNotExist: data = "online error" return getReplyXml(msg, data) else: d = Device.objects.get(Gw_Id=act.Gw_Id) url = "http://" + d.Gw_Address + ":" + d.Gw_Port + "/wifidog/auth?token=" + act.Token data = '<a href="' + url + '">logon</a>' return getReplyXml(msg, data) else: data = msg['EventKey'] return getReplyXml(msg, data) else: gw_id = None return getReplyXml(msg, "none") if gw_id is not None: try: p = People.objects.get(OpenId=msg['FromUserName']) except People.DoesNotExist: tok = uuid.uuid1() p = People( Token=tok, OpenId=msg['FromUserName'], IsLogin=2, Gw_Id=gw_id, ) p.save() else: tok = p.Token url = getGwUrl(gw_id) + smart_str(tok) tplHeader = tplHeader % (msg['FromUserName'], msg['ToUserName'], str(int(time.time())), 'news', smart_str(1)) body = "" task_url = url image_url = "" body += tplBody % (smart_str(tok), "", image_url, task_url) tpl = tplHeader + body + tplFooter return tpl return getReplyXml(msg, "nerver present")
def people_add(): if request.method == 'POST': name = request.form['name'] birthday = request.form['birthday'] about = request.form['about'] social_media = request.form['social_media'] # calculate age today_date = date.today() date_format = "%Y-%m-%d" b_day = datetime.datetime.strptime(birthday, date_format) age = today_date.year - b_day.year - ( (today_date.month, today_date.day) < (b_day.month, b_day.day)) # insert data into DB p = People(name=name, birthday=birthday, age=age, about=about, social_media=social_media) db.session.add(p) db.session.commit() return redirect('/people/add') return render_template('people/add.html', OUR_APP_NAME=get_value('OUR_APP_NAME'), message='')
def addtowco(cardata): dt = cardata[5] dt = datetime.datetime.strptime(dt, '%m/%d/%y') dt = dt.date() towcolist = cardata[7].splitlines() towco = limit_text(towcolist[0]) addr1 = towcolist[1].title() addr2 = towcolist[2] phone = cardata[8] input = People(Company=towco, First=None, Middle=None, Last=None, Addr1=addr1, Addr2=addr2, Addr3=None, Idtype=None, Idnumber=None, Telephone=phone, Email=None, Associate1=None, Associate2=None, Date1=dt, Ptype='TowCo', Date2=None, Original=None, Temp1=None, Temp2="New", Accountid=None) db.session.add(input) db.session.commit()
def people_add(): if request.method == 'POST': name = request.form['name'] phone = request.form['phone'] mobile = request.form['mobile'] email = request.form['email'] linkedin = request.form['linkedin'] facebook = request.form['facebook'] twitter = request.form['twitter'] birthday = request.form['birthday'] notes = request.form['notes'] # calculate age today_date = date.today() date_format = "%Y-%m-%d" b_day = datetime.datetime.strptime(birthday, date_format) age = today_date.year - b_day.year - ( (today_date.month, today_date.day) < (b_day.month, b_day.day)) # insert data into DB person = People(name=name, phone=phone, mobile=mobile, email=email, linkedin=linkedin, facebook=facebook, twitter=twitter, age=age, birthday=birthday, notes=notes) db.session.add(person) db.session.commit() return redirect('/people/add') return render_template('people/add.html', OUR_APP_NAME=get_value('OUR_APP_NAME'), message='')
def names_add(request): if request.method == 'GET': phtml = "<input type=\"text\" name=\"name\" value=\"\" /><input type=\"submit\" />" context_dict = { 'title': "Who are you?", 'msg': phtml, 'action': "/names/add" } return render(request, 'form.html', context_dict) elif request.method == 'POST': new_person = People(name=request.POST['name']) new_person.save() return redirect('names') else: context_dict = {'title': "ERROR", 'msg': "Not a valid method."} return render(request, 'form.html', context_dict)
def create_person(person_data): person = People(**person_data) try: s.add(person) s.commit() except exc.SQLAlchemyError: s.rollback() raise
def addr_book(request): if request.POST: post = request.POST new_people = People( sm = post["sm"], name = post["name"], birthday = post["birthday"], phone = post["phone"], qq = post["qq"], email = post["email"], address = post["address"]) if post["sex"] == 'M': new_people.sex = True else: new_people.sex = False new_people.save() return render_to_response("address_book.html")
def getReplyXmlArc(msg): tplHeader = "<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><ArticleCount>%s</ArticleCount><Articles>" tplBody = "<item><Title><![CDATA[%s]]></Title><Description><![CDATA[%s]]></Description><PicUrl><![CDATA[%s]]></PicUrl><Url><![CDATA[%s]]></Url></item>" tplFooter ="</Articles></xml>" if msg['Event'] == 'subscribe': gw_id = msg['EventKey'][8:] elif msg['Event'] == 'SCAN': gw_id = msg['EventKey'] elif msg['Event'] == 'CLICK': if msg['EventKey'] == 'world': try: act = People.objects.get(OpenId = msg['FromUserName']) except People.DoesNotExist: data = "online error" return getReplyXml(msg,data) else: d = Device.objects.get(Gw_Id = act.Gw_Id) url ="http://"+d.Gw_Address+":"+d.Gw_Port+"/wifidog/auth?token=" + act.Token data = '<a href="'+url+'">logon</a>' return getReplyXml(msg,data) else: data = msg['EventKey'] return getReplyXml(msg,data) else: gw_id = None return getReplyXml(msg, "none") if gw_id is not None: try: p = People.objects.get(OpenId = msg['FromUserName']) except People.DoesNotExist: tok = uuid.uuid1() p = People(Token=tok, OpenId=msg['FromUserName'], IsLogin=2, Gw_Id=gw_id,) p.save() else: tok = p.Token url =getGwUrl(gw_id) + smart_str(tok) tplHeader =tplHeader % (msg['FromUserName'],msg['ToUserName'],str(int(time.time())),'news', smart_str(1)) body = "" task_url = url image_url = "" body += tplBody % (smart_str(tok),"",image_url,task_url) tpl = tplHeader+body+tplFooter return tpl return getReplyXml(msg,"nerver present")
def create_people(): request_body_people = request.get_json() newPeople = People(name=request_body_people["name"], last_name=request_body_people["last_name"], power=request_body_people["power"]) db.session.add(newPeople) db.session.commit() return jsonify(request_body_people), 200
def add_people(): request_body = request.get_json() person = People(id=request_body["id"], name=request_body["name"], gender=request_body["gender"], height=request_body["height"], mass=request_body["mass"], homeworld=request_body["homeworld"]) db.session.add(person) db.session.commit() return jsonify("Person added!"), 200
def addr_book(request): if request.POST: post = request.POST new_people = People( user=request.user, name=post["name"], number=post["number"], phone=post["phone"], email=post["email"], qq=post["qq"], birth=post["birth"], address=post["address"], ) if post["sex"] == "M": new_people.sex = True else: new_people.sex = False new_people.save() return render_to_response("import.html")
def add_people(): lista=[] for i in range(1,11): people = requests.get(f"https://www.swapi.tech/api/people/{i}").json()["result"]["properties"] lista.append(people) for request_body in lista: persona = People( name=request_body["name"], height=request_body["height"], mass=request_body["mass"], hair_color=request_body["hair_color"], skin_color=request_body["skin_color"], eye_color=request_body["eye_color"], birth_year=request_body["birth_year"], url=request_body["url"], created=request_body["created"], edited=request_body["edited"], homeworld=request_body["homeworld"], gender=request_body["gender"]) db.session.add(persona) db.session.commit() return jsonify("Characters were added"), 200
def test_xml_mods2etree_3(self): p = People(idref="PER_TCANNO", name="Taylor Cannon", kind="badass") p.save() et = xml_mods2etree() root = et.getroot() self.assertEqual(type(et), type(ET.ElementTree(""))) self.assertEqual(root.tag, "WorldCrises") crisis_cnt = 0 person_cnt = 0 org_cnt = 0 for child in list(root): if child.tag == "Crisis": crisis_cnt += 1 elif child.tag == "Organization": org_cnt += 1 elif child.tag == "Person": person_cnt += 1 self.assertEqual(crisis_cnt, 0) self.assertEqual(person_cnt, 1) self.assertEqual(org_cnt, 0)
def test_query_things_without_pictures(self): query_things_without_pictures() obama = People(name="Barack Obama", idref="PER_BROBMA") me = People(name="James Kunze", idref="PER_JAMESK") un = Organizations(name="United Nations", idref="ORG_UNINAT") cachemoney = Organizations(name="Cache Money", idref="ORG_CACHEM") aids = Crises(name="AIDS/HIV", idref="CRI_AIDSHI") phasethree = Crises(name="CS373 Project Phase 3", idref="CRI_PROJCT") pic1 = List_Item(list_type="Images", idref="PER_BROBMA", embed="obamapic.png") pic2 = List_Item(list_type="Images", idref="ORG_UNINAT", embed="unpic.png") pic3 = List_Item(list_type="Images", idref="CRI_AIDSHI", embed="aidspic.png") obama.save() me.save() un.save() cachemoney.save() aids.save() phasethree.save() pic1.save() pic2.save() pic3.save() result = query_things_without_pictures() self.assertEqual(len(result), 3) self.assertTrue(not ("PER_BROBMA",) in result) self.assertTrue(not ("ORG_UNINAT",) in result) self.assertTrue(not ("CRI_AIDSHI",) in result) self.assertTrue(("PER_JAMESK",) in result) self.assertTrue(("ORG_CACHEM",) in result) self.assertTrue(("CRI_PROJCT",) in result)
def test_search_one_word(self): fire = Crises(name="Arizona Wildfires", idref="CRI_AZWILD", date=date(2013, 8, 5)) china = Crises(name="Democracy in China", idref="CRI_CHINAD", date=date(2013, 8, 5)) civilwar = Crises(name="The Civil War", idref="CRI_CIVWAR", date=date(1960, 1, 1)) dracula = People(name="Dracula", idref="PER_DRACUL") firedp = Organizations(name="Arizona Fire Department", idref="ORG_FIREDP") fire.save() china.save() civilwar.save() dracula.save() firedp.save() self.assertEqual( search_one_word("Arizona", []), [ ("CRI_AZWILD", "Arizona Wildfires", "Arizona Wildfires"), ("ORG_FIREDP", "Arizona Fire Department", "Arizona Fire Department"), ], ) self.assertEqual( search_one_word("Fire", []), [ ("CRI_AZWILD", "Arizona Wildfires", "Arizona Wildfires"), ("ORG_FIREDP", "Arizona Fire Department", "Arizona Fire Department"), ], ) self.assertEqual(search_one_word("Extreme Elevator Riding", []), []) self.assertEqual(search_one_word("Dracula", []), [("PER_DRACUL", "Dracula", "Dracula")]) self.assertEqual( search_one_word("Fire", ["CRI_AZWILD"]), [("ORG_FIREDP", "Arizona Fire Department", "Arizona Fire Department")], ) self.assertEqual( search_one_word("Fire", ["ORG_FIREDP"]), [("CRI_AZWILD", "Arizona Wildfires", "Arizona Wildfires")] ) self.assertEqual(search_one_word("Fire", ["CRI_AZWILD", "ORG_FIREDP"]), []) self.assertEqual(search_one_word("Democracy in China", []), search_one_word("DeMoCrAcY In CHINA", []))
def test_query_crises_without_things(self): query_crises_without_things() vader = People(name="Darth Vader", idref="PER_DVADER") luke = People(name="Luke Skywalker", idref="PER_LUKESW") empire = Organizations(name="The Empire", idref="ORG_EMPIRE") war = Crises(name="Intergalactic War", idref="CRI_THEWAR") war.people.add(vader) war.people.add(luke) war.organizations.add(empire) vader.organizations.add(empire) stormtroopers = Crises(name="Stormtroopers are dumb", idref="CRI_TROOPR") stormtroopers.organizations.add(empire) rebellion = Crises(name="The Rebellion", idref="CRI_REBELS") rebellion.people.add(luke) problem = Crises(name="The prequels suck", idref="CRI_PREQEL") tired = Crises(name="making these tests is tiring i'm sorry for the dumb stuff", idref="CRI_IMBORD") orphan = People(name="person w/o thing", idref="PER_ORPHAN") vader.save() luke.save() empire.save() war.save() stormtroopers.save() rebellion.save() problem.save() tired.save() orphan.save() result = query_crises_without_things() self.assertEqual(len(result), 2) self.assertTrue(("CRI_PREQEL",) in result) self.assertTrue(("CRI_IMBORD",) in result) self.assertTrue(not ("PER_DVADER",) in result) self.assertTrue(not ("PER_LUKESW",) in result) self.assertTrue(not ("ORG_EMPIRE",) in result) self.assertTrue(not ("CRI_THEWAR",) in result) self.assertTrue(not ("CRI_TROOPR",) in result) self.assertTrue(not ("CRI_REBELS",) in result) self.assertTrue(not ("PER_ORPHAN",) in result)
def test_xml_etree2xml_1(self): dude = People(idref="PER_JAMESK", name="James Kunze", kind="Person who cleans up all your broken tests") dude.save() et = xml_mods2etree() xml_text = xml_etree2xml(et).decode("ascii") self.assertTrue(type(xml_text) is UnicodeType) obama = People(idref="PER_BROBMA", name="Barack Obama", kind="President") obama.save() et = xml_mods2etree() xml_text = xml_etree2xml(et).decode("ascii") self.assertTrue(type(xml_text) is UnicodeType)
def list_addAll(): body = request.get_json() people = body["people"] planet = body["planet"] vehicle = body["vehicle"] for p in people: people1 = People( name=p["Character name"], height=p["Character height"], mass=p["Character mass"], hair_color=p["Character hair_color"], skin_color=p["Character skin color"], eye_color=p["Character eye color"], birth_year=p["Character birth year"], gender=p["Character gender"], ) db.session.add(people1) for pl in planet: planet1 = Planet( planet_name=pl["Planet name"], rotation_period=pl["Rotation period"], orbital_period=pl["Orbital period"], diameter=pl["Diameter"], climate=pl["Climate"], gravity=pl["Gravity"], terrain=pl["Terrain"], population=pl["Population"], ) db.session.add(planet1) for v in planet: vehicle1 = Vehicle( vehicle_name=v["Vehicle name"], model=v["Model"], passenger=v["Passenger"], consumable=v["Consumable"], starship_class=v["Starship class"], lenght=v["Lenght"], cargo_capacity=v["Cargo capacity"], hyperdrive_rating=v["Hyperdrive rating"], ) db.session.add(vehicle1) db.session.commit()
def create_people_by_admin(): people = request.json # user = User(people["email"], people["password"], os.environ["ASTRA_CODE"]) user = User(None, None, os.environ["ASTRA_CODE"]) created_by_user_id = -1 if request.environ.__contains__('HTTP_AUTHORIZATION'): token = request.environ['HTTP_AUTHORIZATION'] if (token != 'Bearer null'): created_by_user_id = Utility.get_payload_from_jwt(token)["id"] person_found_by_aadhar = db.session.query(People).filter_by( aadhar_id=people["aadhar_id"]).first() if person_found_by_aadhar is not None: return jsonify(Resources.data["error_existing_aadhar_id"]) person_found_by_username = db.session.query(People).filter_by( username=people["username"]).first() if person_found_by_username is not None: return jsonify(Resources.data["error_existing_username"]) try: db.session.add(user) db.session.flush() except IntegrityError as e: return jsonify(Resources.data["error_existing_email"]) people = People(user.id, people["name"].lower(), None, Utility.get_date(people["dob"]), people["profile_pic"], people["id_front"], people["id_back"], people["father_name"].lower(), people["username"], created_by_user_id, people['contact'], people['pincode'], people['address'], people['email'], people["aadhar_id"]) try: db.session.add(people) db.session.commit() return jsonify( {"token": Utility.create_secret({ "id": user.id }).decode()}) except IntegrityError as e: db.session.rollback() return jsonify(Resources.data["error_existing_username_or_aadhar_id"])
def people_add(): if request.method == 'POST': name = request.form['name'] birthday = request.form['birthday'] age = age_from_birthday(birthday) about = request.form['about'] social_media = request.form['social_media'] p = People(name=name, about=about, birthday=birthday, social_media=social_media, age=age) db.session.add(p) db.session.commit() return redirect('/people/add') return render_template('people_add.html', OUR_APP_NAME=get_value('OUR_APP_NAME'), SECTION_ITEMS=get_value('SECTION_ITEMS'))
def people_post(): data = request.get_json() people = People(name=data["name"], height=data["height"], mass=data["mass"], hair_color=data["hair_color"], skin_color=data["skin_color"], eye_color=data["eye_color"], birth_year=data["birth_year"], gender=data["gender"], created=data["created"], edited=data["edited"], homeworld=data["homeworld"], url=data["url"]) db.session.add(people) db.session.commit() return jsonify("Message : Se adiciono el personaje!"), 200 return jsonify(request_body), 200
def addAll(): body = request.get_json() people = body['people'] planet = body['planet'] vehicle = body['vehicle'] for p in people: people1 = People(name=p["Character Name"], height=p["Character height"], mass=p["Character mass"], hair_color=p["Character hair color"], skin_color=p["Character skin color"], eye_color=p["Character eye color"], birth_year=p["Character birth year"], gender=p["Character gender"]) db.session.add(people1) for p in planet: planet1 = Planet(planet_name=pl["Planet name"], rotation_period=pl["rotation period"], orbital_period=pl["orbital period"], diameter=pl["diameter"], climate=pl["climate"], gravity=pl["gravity"], terrain=pl["terrain"], population=pl["population"]) db.session.add(planet1) for p in vehicle: vehicle1 = Vehicle(vehicle_name=v["vehicle name"], model=v["model"], passenger=v["passenger"], consumable=v["consumable"], starship_class=v["starship class"], lenght=v["lenght"], cargo_capacity=v["cargo capacity"], hyperdrive_rating=v["hyperdrive rating"]) db.session.add(vehicle1) db.session.commit()
def test_query_people_without_orgs(self): query_people_without_orgs() vader = People(name="Darth Vader", idref="PER_DVADER") luke = People(name="Luke Skywalker", idref="PER_LUKESW") empire = Organizations(name="The Empire", idref="ORG_EMPIRE") vader.organizations.add(empire) vader.save() luke.save() empire.save() result = query_people_without_orgs() self.assertEqual(len(result), 1) self.assertTrue(not (u"PER_DVADER",) in result) self.assertTrue(not (u"ORG_EMPIRE",) in result) self.assertTrue((u"PER_LUKESW",) in result)
def add_people(): body = request.json no_ktp = body['no_ktp'] name = body['name'] password = body['password'] email = body['email'] address = body['address'] try: people = People(no_ktp=no_ktp, name=name, password=password, email=email, address=address) db.session.add(people) db.session.commit() return (jsonify(body), 200) # return "People added. No.KTP={}".format(people.no_ktp), 200 except Exception as e: return (str(e)), 400
def test_query_people_with_red_cross_videos(self): redcross = Organizations(name="The Red Cross", idref="ORG_REDCRS") firedp = Organizations(name="Fire Department", idref="ORG_FIREDP") dracula = People(name="Dracula", idref="PER_DRACUL") fireman = People(name="Fireman", idref="PER_FIREMN") multitasker = People(name="Multitasker", idref="PER_MULTAS") joshmo = People(name="John Smith", idref="PER_BORING") lincoln = People(name="Abraham Lincoln", idref="PER_LINCLN") List_Item(list_type="Videos", idref="PER_DRACUL").save() List_Item(list_type="Videos", idref="PER_MULTAS").save() List_Item(list_type="Videos", idref="PER_LINCLN").save() dracula.organizations.add(redcross) fireman.organizations.add(firedp) multitasker.organizations.add(redcross) multitasker.organizations.add(firedp) redcross.save() firedp.save() dracula.save() fireman.save() multitasker.save() lincoln.save() result = query_people_with_red_cross_videos() self.assertEqual(len(result), 2) self.assertTrue(("PER_DRACUL",) in result) self.assertTrue(("PER_MULTAS",) in result) self.assertTrue(not ("PER_LINCLN",) in result) self.assertTrue(not ("PER_BORING",) in result) self.assertTrue(not ("PER_FIREMN",) in result) self.assertTrue(not ("ORG_REDCRS",) in result) self.assertTrue(not ("PER_FIREDP",) in result)
def test_query_obama(self): query_obama() obama = People(idref="PER_BROBMA", name="Barack Obama") steve = People(idref="PER_STEVEN", name="Steve") robert = People(idref="PER_ROBERT", name="Robert") moon = People(idref="PER_MOOOON", name="The Moon") picnic = Crises(idref="CRI_PICNIC", name="A Picnic") aliens = Organizations(idref="ORG_ALIENS", name="Aliens") obama.save() steve.save() robert.save() moon.save() picnic.save() aliens.save() picnic.people.add(obama) picnic.people.add(steve) obama.organizations.add(aliens) robert.organizations.add(aliens) result = query_obama() self.assertEqual(len(result), 3) self.assertTrue((u"PER_BROBMA",) in result) self.assertTrue((u"PER_STEVEN",) in result) self.assertTrue((u"PER_ROBERT",) in result) self.assertTrue(not (u"PER_MOOOON",) in result) self.assertTrue(not (u"CRI_PICNIC",) in result) self.assertTrue(not (u"ORG_ALIENS",) in result)
def isoB(indat): if request.method == 'POST': from viewfuncs import nonone, numcheck, newjo from viewfuncs import calendar7_weeks, txtfile, numcheckvec, d2s, erud, dataget_B, hv_capture, docuploader, get_def_bank from gledger_write import gledger_write, gledger_app_write # Initialize variables used in the python code that require a value username, bill, peep, cache, modata, modlink, fdata, adata, cdat, pb, passdata, vdata, caldays, daylist,\ weeksum, nweeks, filesel, docref, doctxt, bType, bClass, expdata, addjobselect, jobdata, modal, viewck, acceptthese,\ assdata, monlvec = var_start() divdat = Divisions.query.all() todaydt = datetime.datetime.today() today = todaydt.strftime('%Y-%m-%d') docref = ' ' doctxt = ' ' if indat == 'stay' or indat == 0: indat = '0' # Get all the variables appearing on the html page including button pushes match, vmod, modify2, viewo, addE, addE2, paybill, paybill2, unpay, printck, returnhit, deletehit, \ update, modlink, newbill, thisbill, newxfer, thisxfer, calendar, calupdate, incoming, datatable1, \ datatable2, copy, copy12, qpay, bill, cache, peep, uploadS, thismuch, vendmuch, thisbox0, thisbox1, thisbox2, \ thisbox3, thisbox4, thisbox5, thisbox6 = var_request() modlink, bill, peep = nonone(modlink), nonone(bill), nonone(peep) dlist = [datatable1, datatable2] leftscreen = 0 oid = 0 # Get varibles that may be selected from the selection boxes and dont override the button pushes hv, newbill, addE, copy, copy12, UploadS, newxfer, vmod, match, acceptthese, qpay, paybill, paybill2, printck, \ viewo, viewbill, viewck, deletehit, unpay, lbox, holdvec, err \ = get_selections(thismuch, vendmuch, thisbox0, thisbox1, thisbox2, thisbox3, thisbox4, thisbox5, thisbox6, newbill, vmod, paybill, printck) #Key variables may need to be altered based on the type of selection container in modlink: #modlink = 1 initial selection of an item to modify with update #modlink = 4 part of sequence in creating a new bill #modlink = 8 creating a new vendor during new bill process #modlink = 6 paying multiple bills with one check #modlink = 14 paying one bill with one check #after modification is started, if it is a bill and selection boxes are updated with onchange: #modlink = 7 modification to a bill for continuous modification until update button is used #modlink = 11 paying a bill #modlink = 12 quickpay (pay using default values) #modlink = 70 controls process of document uploading to establish a bill leftscreen = alterations(modlink, leftscreen) if returnhit is not None: modlink, leftscreen, indat = cleanup() # ____________________________________________________________________________________________________________________B.QuickBillPayTowing if incoming is not None: incoming_setup() # ____________________________________________________________________________________________________________________E.QuickBillPayTowing # ____________________________________________________________________________________________________________________B.Uploading if modlink == 4 and (newbill is None and thisbill is None and update is None): modlink, err, bill, docref = uploadsource(modlink, err, oid, docref, username) if modlink == 70: err, oid = docuploader('bill') modlink = 0 # ____________________________________________________________________________________________________________________E.Uploading # ____________________________________________________________________________________________________________________B.UpdateDatabasesSection if ( update is not None and modlink == 1 ) or modlink == 8 or modlink == 7 or modlink == 6 or modlink == 11 or modlink == 12 or modlink == 14: success = 1 if bill > 0: modata = Bills.query.get(bill) # if paying a bill there could be multiple link items to capture if modlink == 6: try: links = json.loads(modata.Link) except: links = 0 if links != 0: bill = links[0] modata = Bills.query.get(bill) #Modifying only the billing information (but getting the billing information if paying the bill if modlink == 7: err, docref, expdata, assdata, leftscreen, modlink, hv = modbill( bill, update, err, docref, expdata, assdata, leftscreen, modlink, hv) cdat = People.query.filter( People.Company == modata.Company).first() if cdat is not None: if cdat.Ptype == 'TowCo': hv[3] = '2' ifxfer = modata.bType if ifxfer == 'XFER': run_xfer(update, err) if modlink == 11 or modlink == 12 or modlink == 14: err, hv, docref, modlink = run_paybill( bill, update, err, hv, docref, username, modlink) if modal == 1: calendar = 1 modlink = 0 # create return status if update is not None and modlink != 6 and success: modlink = 0 leftscreen = 1 indat = '0' if modlink == 9 or modlink == 8: err, expdata, modlink, peep = modpeeps(peep, update, err, modlink, expdata) modata = People.query.get(peep) print(modata.Company) # _____________________________________________________________________________________________________________B.UpdateDatabasesSection bdata, cdata = dataget_B(hv[1], hv[0], hv[3]) # ____________________________________________________________________________________________________________________B.SearchFilters if acceptthese == 1: print('acceptthese', acceptthese) modlink = 0 # Check to see if these are all new jobs ready to be updated to ready status odervec = numcheckvec(bdata, 'bill') print(odervec) if len(odervec) > 0: for ix in odervec: bdat = Bills.query.get(ix) bdat.Temp2 = None db.session.commit() else: err.append('Must check at least one box to use this option') if modlink < 5: bill, peep, numchecked = numcheck(2, bdata, cdata, 0, 0, 0, ['bill', 'peep']) else: numchecked = 0 if uploadS is not None: print('Using uploadS') if bill > 0 and numchecked == 1: bdat = Bills.query.get(bill) jo = bdat.Jo cache = bdat.Cache filename2 = f'Source_{jo}_c{str(cache)}.pdf' err.append(f'File uploaded as {filename2}') #Provide a file name for the upload and store message: edat = LastMessage.query.filter( LastMessage.User == username).first() if edat is not None: edat.Err = json.dumps(err) db.session.commit() else: input = LastMessage(User=username, Err=json.dumps(err)) db.session.add(input) db.session.commit() modlink = 70 leftscreen = 1 mm3 = 0 else: err.append('No Bill Selected for Source Upload') err.append('Select One Box') # ____________________________________________________________________________________________________________________E.SearchFilters # ____________________________________________________________________________________________________________________B.Viewers if viewo == 1 and numchecked == 1: if bill > 0: modata = Bills.query.get(bill) viewtype = 'source' hv[2] = viewtype if modata.Original is not None: if len(modata.Original) > 5: docref = f'tmp/{scac}/data/vbills/{modata.Original}' leftscreen = 0 leftsize = 8 modlink = 0 err.append('Viewing document ' + docref) if viewo == 1 and numchecked != 1: err.append('Must check exactly one box to view source file') if viewck == 1 and numchecked == 1: if bill > 0: modata = Bills.query.get(bill) viewtype = 'check' hv[2] = viewtype if modata.Code1 is not None: if len(modata.Code1) > 5: docref = f'tmp/{scac}/data/vchecks/{modata.Code1}' leftscreen = 0 leftsize = 8 modlink = 0 err.append('Viewing check ' + docref) if viewck == 1 and numchecked != 1: err.append('Must check exactly one box to view checks') # ____________________________________________________________________________________________________________________E.Viewers # ____________________________________________________________________________________________________________________B.Modify Entries if vmod is not None and numchecked == 1: modlink, leftscreen, docref, expdata, modata = mod_init( err, bill, peep) # Modification coming from calendar if modify2 is not None: bill = nonone(modify2) modata = Bills.query.get(bill) modlink = 7 leftsize = 8 # ____________________________________________________________________________________________________________________E.Modify Entries # ____________________________________________________________________________________________________________________B.Add Entries if addE is not None: leftsize = 8 modlink = 9 # Remove any new starts that were not completed People.query.filter(People.Ptype == 'NewVendor').delete() # We will create a blank line and simply modify that by updating: input = People(Company='', First=None, Middle=None, Last=None, Addr1='', Addr2='', Addr3='', Idtype=None, Idnumber='', Telephone='', Email='', Associate1=None, Associate2=None, Date1=today, Date2=None, Original=None, Ptype='NewVendor', Temp1=None, Temp2=None, Accountid=None) db.session.add(input) db.session.commit() modata = People.query.filter(People.Ptype == 'NewVendor').first() peep = modata.id err.append('Enter Data for New Entity') expdata = Accounts.query.filter( Accounts.Type == 'Expense').order_by(Accounts.Name).all() if addE2 is not None: leftsize = 8 modlink = 8 # We will create a blank line and simply modify that by updating: hlist = hv_capture([ 'thiscomp', 'ctype', 'billacct', 'bamt', 'bdate', 'ddate', 'bdesc' ]) hv = hv[0:2] + hlist print(hv) # We will create a blank line and simply modify that by updating: input = People(Company='', First=None, Middle=None, Last=None, Addr1='', Addr2='', Addr3='', Idtype=None, Idnumber='', Telephone='', Email='', Associate1=None, Associate2=None, Date1=today, Date2=None, Original=None, Ptype='NewVendor', Temp1=None, Temp2=None, Accountid=None) db.session.add(input) db.session.commit() modata = People.query.filter(People.Ptype == 'NewVendor').first() peep = modata.id err.append('Enter Data for New Entity') expdata = Accounts.query.filter( Accounts.Type == 'Expense').order_by(Accounts.Name).all() # ____________________________________________________________________________________________________________________E.Add Entries # ____________________________________________________________________________________________________________________B.Delete an Entry if deletehit is not None and numchecked >= 1: if bill > 0: bdat = Bills.query.get(bill) try: orderid = nonone(bdat.Temp2) adat = Autos.query.get(orderid) if adat is not None: adata = Autos.query.filter( Autos.Orderid == adat.Orderid).all() for dat in adata: dat.Status = 'Novo' except: err.append('Delete problem') jo = bdat.Jo Gledger.query.filter(Gledger.Tcode == jo).delete() Bills.query.filter(Bills.id == bill).delete() db.session.commit() if peep > 0: peepvec = numcheckvec(cdata, 'peep') for peep in peepvec: People.query.filter(People.id == peep).delete() db.session.commit() bdata = Bills.query.order_by(Bills.bDate).all() cdata = People.query.filter((People.Ptype == 'Vendor') | (People.Ptype == 'TowCo')).order_by( People.Company).all() if deletehit is not None and numchecked == 0: err.append( 'Must have at least one item checked to use this option') # ____________________________________________________________________________________________________________________E.Delete an Entry # ____________________________________________________________________________________________________________________B.NewXfer.Billing if newxfer == 1: modlink = 3 err.append('Select Source Document from List') leftscreen = 0 expdata = Accounts.query.filter( (Accounts.Type != 'Expense') & (Accounts.Type != 'Income') & (~Accounts.Type.contains('Accounts'))).order_by( Accounts.Name).all() vdata = [today, today, '', ''] if newxfer is None and modlink == 3: leftscreen = 0 bdate = request.values.get('bdate') ddate = request.values.get('bdate') xamt = request.values.get('xamt') new_desc = request.values.get('desc') xferfrom = request.values.get('fromacct') xferto = request.values.get('toacct') if xamt is None: xamt = '0.00' vdata = [bdate, ddate, xamt, new_desc, xferfrom, xferto] print(vdata) expdata = Accounts.query.filter( (Accounts.Type != 'Expense') & (Accounts.Type != 'Income') & (~Accounts.Type.contains('Accounts'))).order_by( Accounts.Name).all() if thisxfer is not None: modlink = 0 sdate = request.values.get('bdate') if sdate is None or sdate == '': sdate = today fromacct = request.values.get('fromacct') toacct = request.values.get('toacct') adat = Accounts.query.filter(Accounts.Name == toacct).first() if adat is not None: cat = adat.Category sub = adat.Subcategory else: cat = None sub = None xamt = request.values.get('xamt') xamt = d2s(xamt) xdesc = request.values.get('xdesc') btype = 'XFER' nextjo = newjo(billxfrcode, today) co = nextjo[0] input = Bills(Jo=nextjo, Pid=0, Company=toacct, Memo=None, Description=xdesc, bAmount=xamt, Status='Paid', Cache=0, Original=None, Ref=None, bDate=sdate, pDate=sdate, pAmount=xamt, pMulti=None, pAccount=fromacct, bAccount=toacct, bType=btype, bCat=cat, bSubcat=sub, Link=None, User=username, Co=co, Temp1=None, Temp2=None, Recurring=0, dDate=today, pAmount2='0.00', pDate2=None, Code1=None, Code2=None, CkCache=0, QBi=0, iflag=0, PmtList=None, PacctList=None, RefList=None, MemoList=None, PdateList=None, CheckList=None, MethList=None) db.session.add(input) db.session.commit() modata = Bills.query.filter(Bills.Jo == nextjo).first() err = gledger_write('xfer', nextjo, toacct, fromacct) bill = modata.id leftscreen = 1 err.append('All is well') bdata = Bills.query.order_by(Bills.bDate).all() # ____________________________________________________________________________________________________________________E.NewXfer.Billing if copy == 1: if bill > 0 and numchecked == 1: # sdate=today.strftime('%Y-%m-%d') bdat = Bills.query.get(bill) thisdate = bdat.bDate nextdate = thisdate + datetime.timedelta(days=30) nextjo = newjo(billexpcode, today) input = Bills(Jo=nextjo, Pid=bdat.Pid, Company=bdat.Company, Memo=bdat.Memo, Description=bdat.Description, bAmount=bdat.bAmount, Status=bdat.Status, Cache=0, Original=bdat.Original, Ref=bdat.Ref, bDate=nextdate, pDate=None, pAmount='0.00', pMulti=None, pAccount=bdat.pAccount, bAccount=bdat.bAccount, bType=bdat.bType, bCat=bdat.bCat, bSubcat=bdat.bSubcat, Link=None, User=username, Co=bdat.Co, Temp1=None, Temp2='Copy', Recurring=0, dDate=today, pAmount2='0.00', pDate2=None, Code1=None, Code2=None, CkCache=0, QBi=0, iflag=0, PmtList=None, PacctList=None, RefList=None, MemoList=None, PdateList=None, CheckList=None, MethList=None) db.session.add(input) db.session.commit() err = gledger_write('newbill', nextjo, bdat.bAccount, bdat.pAccount) elif peep > 0 and numchecked == 1: # sdate=today.strftime('%Y-%m-%d') pdat = People.query.get(peep) input = People(Company=pdat.Company, First=pdat.First, Middle='Copy', Last=None, Addr1=pdat.Addr1, Addr2=pdat.Addr2, Addr3=pdat.Addr3, Idtype=pdat.Idtype, Idnumber=pdat.Idnumber, Telephone=pdat.Telephone, Email=pdat.Email, Associate1=pdat.Associate1, Associate2=pdat.Associate2, Date1=today, Date2=None, Original=None, Ptype='Vendor', Temp1=pdat.Temp1, Temp2=pdat.Temp2, Accountid=pdat.Accountid) db.session.add(input) db.session.commit() else: err.append('Must select one item to use this function') if copy12 is not None: if bill > 0 and numchecked == 1: # sdate=today.strftime('%Y-%m-%d') bdat = Bills.query.get(bill) thisdate = bdat.bDate year = thisdate.year month = thisdate.month day = thisdate.day while month < 12: month = month + 1 nextdate = datetime.datetime(year, month, day) nextjo = newjo(billexptype, today) input = Bills(Jo=nextjo, Pid=bdat.Pid, Company=bdat.Company, Memo=bdat.Memo, Description=bdat.Description, bAmount=bdat.bAmount, Status=bdat.Status, Cache=0, Original=bdat.Original, Ref=bdat.Ref, bDate=nextdate, pDate=None, pAmount='0.00', pMulti=None, pAccount=bdat.pAccount, bAccount=bdat.bAccount, bType=bdat.bType, bCat=bdat.bCat, bSubcat=bdat.bSubcat, Link=None, User=username, Co=bdat.Co, Temp1=None, Temp2='Copy', Recurring=0, dDate=today, pAmount2='0.00', pDate2=None, Code1=None, Code2=None, CkCache=0, QBi=0, iflag=0, PmtList=None, PacctList=None, RefList=None, MemoList=None, PdateList=None, CheckList=None, MethList=None) db.session.add(input) db.session.commit() err = gledger_write('newbill', nextjo, bdat.bAccount, bdat.pAccount) if qpay is not None: if bill > 0 and numchecked == 1: print('qpay entered!!') bdat = Bills.query.get(bill) bdat.pDate = bdat.bDate bdat.pAmount = bdat.bAmount bdat.Temp2 = '' bdat.Status = 'Paid' pacct = bdat.pAccount if pacct is None: pacct = get_def_bank(bdat) elif pacct == '0' or pacct == '1' or pacct == 0 or pacct == 1: pacct = get_def_bank(bdat) bdat.pAccount = pacct db.session.commit() # ____________________________________________________________________________________________________________________B.NewJob if newbill is not None: err, modlink, leftscreen, hv, expdata, vdata = newbill_init( err, hv) if newbill is None and modlink == 4: err, modlink, leftscreen, hv, expdata, vdata, assdata = newbill_passthru( err, hv, modlink) if thisbill is not None: err, modlink, leftscreen, bill = newbill_update( err, hv, modlink, username) bdata = Bills.query.order_by(Bills.bDate).all() # ____________________________________________________________________________________________________________________E.New Bill if unpay == 1: if numchecked == 1 and bill > 0: myb = Bills.query.get(bill) iflag = myb.iflag if iflag is None: iflag = 0 if iflag > 0: undolastpayment(bill) err.append( f'Unpaid Last Payment on Bill {myb.Jo} and removed from register' ) else: myb.Status = 'Unpaid' myb.pAmount = '0.00' db.session.commit() Gledger.query.filter((Gledger.Tcode == myb.Jo) & (Gledger.Type == 'PD')).delete() Gledger.query.filter((Gledger.Tcode == myb.Jo) & (Gledger.Type == 'PC')).delete() Gledger.query.filter((Gledger.Tcode == myb.Jo) & (Gledger.Type == 'XD')).delete() Gledger.query.filter((Gledger.Tcode == myb.Jo) & (Gledger.Type == 'XC')).delete() db.session.commit() err.append(f'Unpay Bill {myb.Jo} and remove from register') else: err.append('Must select one Bill to Unpay') if paybill is not None or paybill2 is not None or viewbill == 1: print('paybill', numchecked, modlink, bill) if numchecked == 1 and bill > 0: myb = Bills.query.get(bill) if viewbill == 1 and myb.Status == 'Paid': modlink = 15 if myb.iflag is None: myb.iflag = 0 if myb.iflag > 0: err, modlink, leftscreen, docref, prevpayvec = install_pay_init( bill, err, modlink) hv[19] = prevpayvec else: err, modlink, leftscreen, docref = pay_init( bill, err, modlink) modata = Bills.query.get(bill) if numchecked > 1 and bill > 0: err, modlink, lefscreen, docref = multi_pay_init( bill, err, modlink) modata = Bills.query.get(bill) if numchecked == 0 or bill == 0: err.append('Must check at least one bill for this selection') err.append(f'Numchecked = {numchecked}') bdata = Bills.query.order_by(Bills.bDate).all() if printck is not None or modlink == 6 or modlink == 14 or indat != '0': from viewfuncs import check_prep def multi_prep(bill): if bdat.Status == 'Paid-M': linkcode = bdat.Link sbdata = Bills.query.filter(Bills.Link == linkcode) link = linkcode.replace('Link+', '') items = link.split('+') links = [] [links.append(int(item)) for item in items] else: links = 0 sbdata = 0 if printck is not None and numchecked == 1: modlink = 14 elif printck is not None and numchecked > 1: modlink = 6 if indat != '0': bdat = Bills.query.filter(Bills.Jo == indat).first() bill = bdat.id modlink = 6 if numchecked == 1: modlink = 14 if (numchecked >= 1 and bill > 0 ) or modlink == 6 or modlink == 12 or modlink == 14: if modlink == 6 or modlink == 12 or modlink == 14: bdat = Bills.query.get(bill) try: bill_list = json.loads(bdat.Link) except: bill_list = [bill] billready, err, linkcode = check_prep(bill_list) else: bill_list = numcheckvec(bdata, 'bill') billready, err, linkcode = check_prep(bill_list) if billready == 1: from viewfuncs import check_inputs sbdata = Bills.query.filter(Bills.Link == linkcode).all() links = json.loads(linkcode) bdat = Bills.query.get(links[0]) pdat = People.query.get(bdat.Pid) ckcache = bdat.CkCache if ckcache is None or ckcache == 0: ckcache = 1 last_ckfile = f'Check_{bdat.Jo}_{bdat.Ref}_c{str(ckcache-1)}.pdf' ckfile = f'Check_{bdat.Jo}_{bdat.Ref}_c{str(ckcache)}.pdf' docref = f'tmp/{scac}/data/vchecks/{ckfile}' bdat.Code1 = ckfile ckcache = ckcache + 1 bdat.CkCache = ckcache pamount = bdat.pAmount if pamount == '0.00': bdat.pAmount = bdat.bAmount db.session.commit() ckstyle = request.values.get('ckstyle') if ckstyle is not None: hv[21] = ckstyle ckstyle = nonone(ckstyle) else: ckstyle = 1 err = check_inputs(bill_list) co = bdat.Co expdata = Accounts.query.filter(( (Accounts.Type == 'Expense') & (Accounts.Co == co)) | ( (Accounts.Type == 'Credit Card') & (Accounts.Co == co))).order_by( Accounts.Name).all() #modlink = 6 leftscreen = 0 modata = Bills.query.get(links[0]) pb = 1 if err[0] != 'All is Well': err.append( 'Check will not be displayed until above input items input or corrected' ) else: from writechecks import writechecks if pdat is not None: writechecks(bdat, pdat, docref, sbdata, links, ckstyle) ck_check = bdat.bType db.session.commit() pacct = bdat.pAccount #Only write to the ledger on update if update is not None: if pacct is not None and pacct != '0': print('check is', ck_check) if ck_check == 'Credit Card' or ck_check == 'XFER': print('Doing the Transfer') err = err = gledger_write( 'xfer', bdat.Jo, bdat.bAccount, bdat.pAccount) err.append( f'Ledger xfer for {bdat.Jo} to {bdat.bAccount} from {bdat.pAccount}' ) else: print('Paying the Bill') err = gledger_write( 'paybill', bdat.Jo, bdat.bAccount, bdat.pAccount) err.append( f'Ledger paid {bdat.Jo} to {bdat.bAccount} from {bdat.pAccount}' ) else: err.append( 'No Account for Fund Withdrawal') #Attempt to remove the previous cache copy: try: last_file = addpath( f'tmp/{scac}/data/vchecks/{last_ckfile}') os.remove(last_file) except: print(f'Could nor remove {last_file}') else: err.append( 'Must select exactly 1 Bill box to use this option.') # ____________________________________________________________________________________________________________________B.Matching if match is not None: if bill > 0 and peep > 0 and numchecked == 2: myo = Bills.query.get(bill) myp = People.query.get(peep) myo.Pid = peep myo.Company = myp.Company myo.Description = myp.Associate1 db.session.commit() if numchecked != 2: err.append('Must select exactly 2 boxes to use this option.') # ____________________________________________________________________________________________________________________E.Matching # ____________________________________________________________________________________________________________________B.Calendar.Billing if calendar is not None or calupdate is not None: leftscreen = 2 if calupdate is not None: waft = request.values.get('waft') wbef = request.values.get('wbef') waft = nonone(waft) wbef = nonone(wbef) nweeks = [wbef, waft] else: nweeks = [2, 2] caldays, daylist, weeksum = calendar7_weeks('Billing', nweeks) if calupdate is not None: for j in range(len(daylist)): ilist = daylist[j] if ilist: tid = ilist[0] fnum = 'note' + str(tid) fput = request.values.get(fnum) if len(fput) > 3: billno = f'{scac}_Bill_{str(tid)}' input = ChalkBoard(Jo=billno, creator=username, comments=fput, status=1) db.session.add(input) db.session.commit() caldays, daylist, weeksum = calendar7_weeks('Billing', nweeks) # ____________________________________________________________________________________________________________________E.Calendar.Billing if (modlink > 0 and bill > 0) or (modlink > 0 and peep > 0) or leftscreen == 0: leftsize = 8 elif leftscreen == 2: leftsize = 10 else: leftsize = 10 else: username, bill, peep, cache, modata, modlink, fdata, adata, cdat, pb, passdata, vdata, caldays, daylist,\ weeksum, nweeks, filesel, docref, doctxt, bType, bClass, expdata, addjobselect, jobdata, modal, viewck, acceptthese,\ assdata, monlvec = var_start() err = [] hv = [0] * 25 hv[0] = 'X' hv[1] = '1' from viewfuncs import nonone, erud, dataget_B leftscreen = 1 leftsize = 10 addjobselect = 0 dlist = ['on'] * 2 dlist[1] = 'off' jobdata = 0 modal = 0 expdata = 0 assdata = [0] divdat = Divisions.query.all() err.append('All is well') leftsize = 8 rightsize = 12 - leftsize today = datetime.date.today() critday = datetime.date.today() + datetime.timedelta(days=7) bdata, cdata = dataget_B(hv[1], hv[0], hv[3]) hv[23] = assdata acdata = Accounts.query.filter( (Accounts.Type == 'Bank') | (Accounts.Type == 'Credit Card') | (Accounts.Type == 'Current Liability')).order_by( Accounts.Name).all() err = erud(err) if expdata == 0: expdata = Accounts.query.filter(Accounts.Type == 'Expense').order_by( Accounts.Name).all() return username, divdat, hv, bdata, cdata, bill, peep, err, modata, adata, acdata, expdata, modlink, caldays, daylist, weeksum, nweeks, addjobselect, jobdata, modal, dlist, fdata, today, cdat, pb, critday, vdata, leftscreen, docref, doctxt, leftsize, cache, filesel
def post(self): data = request.json user = People(name=data['name'], age=data['age']) user.save() response = {'id': user.id, 'name': user.name, 'age': user.age} return response
def test_query_people_with_many_crises(self): query_people_with_many_crises() zero = People(name="boring person", idref="PER_BORING") one = People(name="Person in one crisis", idref="PER_ONECRI") two = People(name="Person in two crises", idref="PER_TWOCRI") three = People(name="Person in three crises", idref="PER_THRCRI") aids = Crises(name="AIDS/HIV", idref="CRI_AIDSHI") fire = Crises(name="Arizona Wildfires", idref="CRI_AZWILD") china = Crises(name="Democracy in China", idref="CRI_CHINAD") aids.people.add(one) aids.people.add(two) fire.people.add(two) aids.people.add(three) fire.people.add(three) china.people.add(three) zero.save() one.save() two.save() three.save() aids.save() fire.save() china.save() result = query_people_with_many_crises() self.assertEqual(len(result), 2) self.assertTrue(("PER_TWOCRI",) in result) self.assertTrue(("PER_THRCRI",) in result) self.assertTrue(not ("PER_ONECRI",) in result) self.assertTrue(not ("PER_BORING",) in result) self.assertTrue(not ("CRI_AIDSHI",) in result) self.assertTrue(not ("CRI_AZWILD",) in result) self.assertTrue(not ("CRI_CHINAD",) in result)
def insert_person(name, age): person = People(name=name, age=age) person.save() print(person)
def test_query_people_in_crises_after_millenium(self): civilwar = Crises(name="The Civil War", idref="CRI_CIVWAR", date=date(1960, 1, 1)) monday = Crises(name="Monday", idref="CRI_MONDAY", date=date(2013, 8, 5)) lincoln = People(name="Abraham Lincoln", idref="PER_LINCLN") me = People(name="James Kunze", idref="PER_JAMESK") time = People(name="Some Time Traveler", idref="PER_TIMETR") fiction = People(name="Uninvolved Bystander", idref="PER_FICTIO") civilwar.people.add(lincoln) civilwar.people.add(time) monday.people.add(me) monday.people.add(time) civilwar.save() monday.save() lincoln.save() me.save() time.save() fiction.save() result = query_people_in_crises_after_millenium() self.assertEqual(len(result), 2) self.assertTrue(("PER_JAMESK",) in result) self.assertTrue(("PER_TIMETR",) in result) self.assertTrue(not ("PER_LINCLN",) in result) self.assertTrue(not ("PER_FICTIO",) in result) self.assertTrue(not ("CRI_CIVWAR",) in result) self.assertTrue(not ("CRI_MONDAY",) in result)
def insert_person(): person = People(name='Craig', age=20) print(person) person.save()
def handle_peopleid(id): return jsonify(People.getPerson(id)), 200
def insert(request): status = None if request.method == 'POST': # save new post Usr_Name = request.POST.get('name', '') Usr_Mobile = request.POST.get('mobile', '') Usr_Remark = request.POST.get('remark', '') tags = request.POST.get('tags', '') pre_id = request.POST.get('pre_id', '') p_uuid = uuid.uuid1() p = People( Usr_Name=Usr_Name, Usr_Mobile=Usr_Mobile, Usr_Remark=Usr_Remark, active=0, isdel=0, uuid=p_uuid, ) p.save() for tag in tags.replace(u',', ',').split(','): try: t = Tags.objects.get(tag=tag) except Tags.DoesNotExist: newtag = Tags(tag=tag) newtag.save() p.tags.add(newtag) p.save() else: p.tags.add(t) p.save() if request.user.is_superuser: status = "ok" p.Cluster_id = 0 p.save() return render_to_response('usernet/index.html', { 'status': status, }, context_instance=RequestContext(request)) if pre_id == '': pre_id = request.user if pre_id != '': try: pre = People.objects.filter(Usr_Mobile=pre_id, active=1) except People.DoesNotExist: print "error" else: p.Prev_Usr = pre[0] p.Cluster_id = pre[0].Cluster_id p.save() status = "ok" # Get all posts from DB return render_to_response('usernet/index.html', { 'status': status, }, context_instance=RequestContext(request))
def insert(request): status=None if request.method == 'POST': # save new post Usr_Name = request.POST.get('name','') Usr_Mobile = request.POST.get('mobile','') Usr_Remark = request.POST.get('remark','') tags = request.POST.get('tags','') pre_id = request.POST.get('pre_id','') p_uuid = uuid.uuid1() p = People(Usr_Name = Usr_Name,Usr_Mobile = Usr_Mobile,Usr_Remark=Usr_Remark,active = 0,isdel = 0,uuid = p_uuid,) p.save() for tag in tags.replace(u',',',').split(','): try: t = Tags.objects.get(tag = tag) except Tags.DoesNotExist: newtag = Tags(tag=tag) newtag.save() p.tags.add(newtag) p.save() else: p.tags.add(t) p.save() if request.user.is_superuser: status="ok" p.Cluster_id = 0 p.save() return render_to_response('usernet/index.html', {'status':status,}, context_instance=RequestContext(request)) if pre_id =='': pre_id = request.user if pre_id != '': try: pre = People.objects.filter(Usr_Mobile = pre_id,active = 1) except People.DoesNotExist: print "error" else: p.Prev_Usr=pre[0] p.Cluster_id = pre[0].Cluster_id p.save() status="ok" # Get all posts from DB return render_to_response('usernet/index.html', {'status':status,}, context_instance=RequestContext(request))
def test_by_id(mock, client): person = {'name': 'name', 'isAlive': True, 'placeId': 1} created = People(**person) mock.return_value = created res = client.get('/people/1/') assert res.status_code == 200
def insert_person(): person = People(name='Nep', age=99) person.save() print(person)
if pdat is not None: pdat.Temp1 = 'Updated' db.session.commit() else: print('input for:', tow[jx].towcompany, tow[jx].addr1, tow[jx].addr2, tow[jx].phone) input = People(Ptype='TowCo', Company=tow[jx].towcompany, First='', Middle='', Last='', Addr1=tow[jx].addr1, Addr2=tow[jx].addr2, Addr3='', Idtype='', Idnumber='', Telephone=tow[jx].phone, Email='', Associate1=towacct, Associate2='', Date1=tow[jx].date1, Date2=None, Original='', Temp1='', Temp2='', Accountid=towid) db.session.add(input) db.session.commit() else: print( f'{tow[jx].orderid} with vin: {car[iy].vin} already in database' )
def handle_people(): return jsonify(People.getAllPeople()), 200
def load_data(): for planet in listplanets: new_planet = Planets() new_planet.name = planet["name"] new_planet.rotation_period = str(planet["rotation_period"]) new_planet.orbital_period = planet["orbital_period"] new_planet.diameter = planet["diameter"] new_planet.climate = planet["climate"] new_planet.gravity = planet["gravity"] new_planet.terrain = planet["terrain"] new_planet.surface_water = planet["surface_water"] new_planet.population = planet["population"] new_planet.url = planet["url"] db.session.add(new_planet) db.session.commit() for person in listpeople: new_person = People() new_person.name = person["name"] new_person.height = person["height"] new_person.hair_color = person["hair_color"] new_person.skin_color = person["skin_color"] new_person.eye_color = person["eye_color"] new_person.birth_year = person["birth_year"] new_person.gender = person["gender"] new_person.homeworld = person["homeworld"] new_person.url = person["url"] db.session.add(new_person) db.session.commit() response_body = {"msg": "loading... initial data to database... "} return jsonify(response_body), 200