def test_populate_farmers(self): self.assertEqual(0, Farmer.query().count()) response = self.app.get('/import/') self.assertEqual(200, response.status_code) self.assertEqual({'status': 'done'}, json.loads(response.body)) self.assertGreater(Farmer.query().count(), 0) self.assertEqual(1, Node.query().count())
def add(): data = dict(request.form.items()) if data.get('username', None): Farmer.add( username=data.get('username', 'janelodipo'), email=data.get('email', '*****@*****.**'), phone=data.get('phone', 10), ) return render_template('farmers.html')
def add(): data = dict(request.form.items()) if data.get('username', None): Farmer.add( username=data.get('username', 'faryda'), email=data.get('email', '*****@*****.**'), phone=data.get('phone', 10), password=data.get('password', 'farida01'), ) return render_template('farmers.html')
def create_ship(): # calling Farmer here like a function return a new object farmer_1 = Farmer('Ragnar') farmer_2 = Farmer('Rollo', age=25) # multiline works for: [], (), {} without \ line continuation escape. farmers = [farmer_1, farmer_2] ship = Ship(farmers) print(f"{len(ship)}") print(f"{ship[-1]}") print(f"{bool(ship)}") print(f"{farmer_2.name} is {farmer_2.age} years old") print(farmer_2.travel.__annotations__) print(farmer_2.travel('Paris')) print(give_farmer_a_sword(farmer_2))
def insert_farmer(): if g.user and g.user[4] == 'P': if request.method == 'POST': #Generating a new id for the farmer new_id = gen_new_id(request.form['state'], request.form['district_name'], 'F') if new_id == None: return render_template('500.hmtl') #Inserting the farmer details into the database new_farmer = Farmer( new_id, request.form['name'], request.form['size'], request.form['contact_no'], request.form['aadhar_no'], request.form['village_name'], code.get( request.form['state'])[int(request.form['district_name']) - 1], request.form['state']) db.session.add(new_farmer) db.session.commit() flash('Farmer details added succesfully!') district = code.get('AN') ind = list(range(1, len(district) + 1)) district_name = list(zip(ind, district)) return render_template('/patwari/insert_farmer.html', state=list(zip(state.values(), state.keys())), district_name=district_name) else: return render_template('404.html')
def test_farmers_populated_already(self): Farmer().put() response = self.app.get('/import/') self.assertEqual(200, response.status_code) self.assertEqual( {'status': 'already_populated'}, json.loads(response.body)) self.assertEqual(1, Farmer.query().count())
def get(self): # If we've already imported farmers, don't bother to import them from # the JSON file. if Farmer.query().count() > 0: return self.json_response({'status': 'already_populated'}) with open('attendees.json') as attendees_file: attendees = json.loads(attendees_file.read()) farmers = [] for name, cell_number in attendees.iteritems(): first_name, last_name = name.split(' ') farmers.append(Farmer( first_name=first_name, last_name=last_name, cell_number=cell_number, house_number=cell_number, farmer_id=generate_farmer_id(), verified=True, dob=datetime.datetime.now() - datetime.timedelta(days=20 * 365), address='Computer Science Postgrab Lab', alias=generate_alias(first_name, last_name), farmer_idx=random.randint(1, 100000), parish='UWI', main_activity='Farming', )) node = Node(node_id='Tomatoes') ndb.put_multi(farmers + [node]) for _ in range(50): DataPoint( temperature=random.randint(40, 90), pressure=random.randint(20, 30), humidity=random.randint(65, 100), light=random.randint(0, 100), saturation=random.randint(30, 90), parent=node.key, ).put() message = """ Low light on tomato patch. Low barometric pressure. Possibility of rain. """ for farmer in farmers: send_sms(farmer.cell_number, message) return self.json_response({'status': 'done'})
def lists(): models.initialize() farmers = Farmer.select() return render_template("farmer_list.html", farmers=farmers)