コード例 #1
0
ファイル: app.py プロジェクト: jedestep/gatechffs
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)
コード例 #2
0
    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'
コード例 #3
0
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))
コード例 #4
0
ファイル: listings_migration.py プロジェクト: lita/opendoor
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)
コード例 #5
0
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
コード例 #6
0
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,
    ])
コード例 #7
0
    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"
        }
コード例 #8
0
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
コード例 #9
0
    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"
        }
コード例 #10
0
 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'
コード例 #11
0
ファイル: state.py プロジェクト: computablelabs/compas
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
コード例 #12
0
    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"
            })
コード例 #13
0
ファイル: detail.py プロジェクト: computablelabs/compas
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))
コード例 #14
0
    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)
コード例 #15
0
 def extract_listing_from_response(response: Response):
     listing = Listing(**response.json())
     return listing
コード例 #16
0
ファイル: state.py プロジェクト: computablelabs/compas
 def __init__(self):
     self.model = Listing()
コード例 #17
0
    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]
コード例 #18
0
 def testNotFound(self):
     with self.assertRaises(RecordNotFound):
         Listing.find_by_id("wrong-uuid-offf-thee-object")
コード例 #19
0
 def generate_fake_listing():
     with open("resources/listing.json") as listing_file:
         listing = Listing(**json.load(listing_file))
     return ListingFaker().generate_listing()