def listing(): if request.method == 'GET': lid = request.args.get('listId') if not lid: return render_template('notfound.html') listing = list_coll.find_one(dict(_id=lid)) if not listing: return render_template('notfound.html') if 'cllink' in listing and listing['cllink']: return render_template('showcllisting.html', listing=listing) else: return render_template('showlisting.html', listing=listing) elif request.method == 'POST': # TODO form validation # title and desc are required. # one of email and phone is required. lst = Listing( title=request.form.get('title'), desc=request.form.get('desc'), price=request.form.get('price'), email=request.form.get('email'), phone=request.form.get('phone'), cllink=request.form.get('cllink') ) lst.save(list_coll) if lst.cllink: return render_template('showcllisting.html', listing=lst) else: return render_template('showlisting.html', listing=lst)
def testUpdateListing(self): listing = Listing.new({ "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" }).save() assert listing.id != None listing.update({ "title": "title", "base_price": 111, "currency": "EUR", "market": "lisbon", "host_name": "Will Smith" }) updated = Listing.find_by_id(listing.id) assert listing.id == updated.id assert updated.title == 'title' assert updated.base_price == 111 assert updated.currency == "EUR" assert updated.market == 'lisbon' assert updated.host_name == 'Will Smith'
def listings(): if request.method == "POST": data = request.get_json() listing = Listing.new(data) try: return jsonify(listing.save()) except ValidationError as e: return jsonify({'errors': e.args[0]}), 422 elif request.method == 'GET': args = dict(request.args) return jsonify(Listing.filter(args))
def run(): with open('./listing-details.csv') as csv_file: reader = csv.DictReader(csv_file) count = 0 for row in reader: row['location'] = [float(row['lng']), float(row['lat'])] row.pop("lng", None) row.pop("lat", None) listing = Listing(**row) listing.save() count += 1 print "saved %d items" % (count)
def listing(id): try: if request.method == "GET": return jsonify(Listing.find_by_id(id)) elif request.method == "PUT": data = request.get_json() current_listing = Listing.find_by_id(id) current_listing.update(data) return jsonify(current_listing) elif request.method == "DELETE": return jsonify(Listing.find_by_id(id).delete()) except RecordNotFound as e: return jsonify({'error': e.args[0]}), 404 except ValidationError as e: return jsonify({'errors': [e.args[0]]}), 422
def scrape_listing(url): eprint(url) writer = csv.writer(sys.stdout) response = requests.get(url) listing = Listing(response.content) writer.writerow([ url, listing.post_id, listing.title, listing.listed_date, listing.price, listing.location, listing.city, listing.state, listing.description, listing.registered, listing.category, listing.manufacturer, listing.caliber, listing.action, listing.firearm_type, listing.party, listing.img, ','.join(listing.related.related_ids), listing.related.number_of_listings, ])
def testFind(self): listing = Listing.new({ "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" }).save() assert Listing.find_by_id(listing.id).to_dict() == { "id": listing.id, "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" }
def listing_calendar(id): args = dict(request.args) currency = args.get('currency') try: current_listing = Listing.find_by_id(id) calendar = GetListingCalendar(current_listing).get_calendar(currency) return jsonify(calendar) except RecordNotFound as e: return jsonify({'error': e.args[0]}), 404
def testGetListings(self): Listing.new({ "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" }).save() listings = Listing.all() assert len(listings) == 1 assert listings[0].to_dict() == { "id": listings[0].id, "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" }
def testCreateListing(self): listing = Listing.new({ "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" }) listing.save() assert listing.id != None assert listing.title == 'Comfortable Room In Cozy Neighborhood' assert listing.base_price == 867 assert listing.currency == "USD" assert listing.market == 'san-francisco' assert listing.host_name == 'John Smith'
class State(ViewModel): def __init__(self): self.model = Listing() def get_listings(self, addr=None): # assure was not set to empty str... if addr == '': addr = None return (self.model.get_listings(addr)) def hydrate(self, data): data['listing_address'] = self.get_address() data['listing_owner'] = self.get_owner() data['listings'] = self.get_listings() return data
def testFailedUpdate(self): listing = Listing.new({ "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" }).save() with self.assertRaises(ValidationError): listing.update({ "title": "title", "base_price": 111, "currency": "EUR", "market": "jerusalem", "host_name": "Will Smith" })
class Detail(ViewModel): def __init__(self): self.model = Listing() def is_listed(self, hash): return str(self.model.is_listed(hash)) def get_listing(self, hash): l = self.model.get_listing(hash) if len(l) > 0: # format a string to make sense in the view popup l_str = 'Owner: {0}\nSupply: {1}' return l_str.format(*l) else: return 'None' def list(self, hash, gas_price): return self.transact(self.model.list(hash, gas_price)) def withdraw_from_listing(self, hash, amount, gas_price): return self.transact( self.model.withdraw_from_listing(hash, amount, gas_price)) def resolve_application(self, hash, gas_price): return self.transact(self.model.resolve_application(hash, gas_price)) def claim_access_reward(self, hash, gas_price): return self.transact(self.model.claim_access_reward(hash)) def challenge(self, hash, gas_price): return self.transact(self.model.challenge(hash, gas_price)) def resolve_challenge(self, hash, gas_price): return self.transact(self.model.resolve_challenge(hash, gas_price)) def exit(self, hash, gas_price): return self.transact(self.model.exit(hash, gas_price))
def generate_listing(): origin = vars(Location("Townsend", "54175", "WI")) destination = vars(Location("Beverly Hills", "90210", "CA")) partner_reference_id = "multi-car" trailer_type = "OPEN" vehicles = [ vars(Vehicle("5", 2008, "nissan", "altima", 1, False, "CAR")), vars(Vehicle("6", 2014, "toyota", "camry", 1, True, "CAR")) ] has_in_op_vehicle = False available_date = "2021-12-31" desired_delivery_date = "2021-12-31" cod = vars(Cod("1600", "CHECK", "DELIVERY")) bla = vars(Price(cod, "1600")) price = {'cod': cod, 'total': '1600'} price_two = json.loads( json.dumps(Price(cod, "1600"), default=lambda o: o.__dict__)) return Listing(origin, destination, partner_reference_id, desired_delivery_date, trailer_type, vehicles, has_in_op_vehicle, available_date, price)
def extract_listing_from_response(response: Response): listing = Listing(**response.json()) return listing
def __init__(self): self.model = Listing()
def testFiltering(self): listing = Listing.new({ "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" }).save() assert Listing.filter({'market': 'lisbon'}) == [] assert Listing.filter({'market': 'san-francisco'}) == [listing] assert Listing.filter({'currency': 'USD'}) == [listing] assert Listing.filter({ 'currency': 'USD', 'market': 'san-francisco' }) == [listing] assert Listing.filter({'currency': 'USD', 'market': 'lisbon'}) == [] assert Listing.filter({'base_price.gt': 500}) == [listing] assert Listing.filter({'base_price.lt': 500}) == [] assert Listing.filter({'base_price.gte': 867}) == [listing] assert Listing.filter({'base_price.lte': 867}) == [listing] assert Listing.filter({'base_price.gte': 868}) == [] assert Listing.filter({'base_price.lte': 866}) == [] assert Listing.filter({'base_price.e': 867}) == [listing] assert Listing.filter({'base_price.e': 865}) == [] assert Listing.filter({ 'base_price.gt': 800, 'currency': 'USD', 'market': 'san-francisco' }) == [listing]
def testNotFound(self): with self.assertRaises(RecordNotFound): Listing.find_by_id("wrong-uuid-offf-thee-object")
def generate_fake_listing(): with open("resources/listing.json") as listing_file: listing = Listing(**json.load(listing_file)) return ListingFaker().generate_listing()