コード例 #1
0
def handleprop(xmlprop):
    """Build up a single Property"""
    typetag = xmlprop.find("PropertyType")
    prop = Property(getfield(xmlprop, "Name"), getfield(xmlprop, "Definition"))

    typename = typetag.contents[1].name
    if SingleValueType.matchtype(typename):
        prop.datatype = getattr(xmlprop, "DataType", "type")

    elif EnumType.matchtype(typename):
        values = [field.next for field in typetag.find_all("EnumItem")]
        enum = EnumType(values)
        prop.datatype = enum

    elif ArrayType.matchtype(typename):
        values = [field.next for field in typetag.find_all("EnumItem")]
        array = ArrayType(values)
        prop.datatype = array

    elif TableType.matchtype(typename):
        print("table values not yet supported. Continuing...")

    elif ReferenceType.matchtype(typename):
        print("reference values not yet supported. Continuing...")

    else:
        print("unhandled prop type: {}".format(typetag.next))

    return prop
コード例 #2
0
def test_build_properties():
    props = Property.build(
        [["string", str], ["integer", int], "any",
         ["not_null", str, {
             'default': 'default'
         }],
         [
             "from_range", str, {
                 'validate': Property.is_in(['a', 'b', 'c']),
                 'default': 'c'
             }
         ],
         [
             "five_to_ten", int, {
                 'validate': Property.in_range(5, 10),
                 'default': 7
             }
         ], ["lower_case", str, {
             'set': lambda obj, x: x.lower()
         }],
         [
             "derived", int, {
                 'default':
                 lambda obj: None
                 if obj.integer is None else obj.integer * obj.five_to_ten
             }
         ]])
    assert len(props) == 8, ' failed to build properties'
コード例 #3
0
def test_default_value(default_value):
    value = default_value['value']
    default = default_value['default']
    message = default_value['message']
    prop = Property('test', None, {'default': default})
    assert prop.get_value(None, None) == default, 'default with %s' % message
    assert prop.get_value(None, value) == value, 'value with %s' % message
コード例 #4
0
def parse_address_search():
    """Parses the address for API call"""
    if request.args:
        raw_address_text = request.args.get("address-search")

    address_url_encode, citystatezip_url_encode, address_for_walkscore = create_address_url(raw_address_text)

    property_from_url, error_code = Property.generate_from_address(address=address_url_encode,
                        citystatezip=citystatezip_url_encode) 

    #instantiate a session
    if 'properties' not in session.keys():
        session['properties'] = []

    if error_code == Property.ERROR_OK:    
        if property_from_url.zpid not in session['properties']:
            session['properties'].append(property_from_url.zpid)
        
        this_property = Property.query.filter(Property.zpid == property_from_url.zpid).first()

        if this_property is None:
            db.session.add(property_from_url)
            db.session.commit()
    
        this_property = property_from_url 

        return render_template("address-confirmation.html", house=this_property)

    elif error_code == Property.ERROR_MANY:
        message = "Ambiguous Result. Please check your address and specify a unique property."
        return error_message_utility(message)

    else:
        message = "No property found. Please search again."
        return error_message_utility(message)
コード例 #5
0
 class EntityDerived(EntityData):
     _properties = Property.build([['x', int, {
         'default': 1
     }], ['y', int, {
         'default': 1
     }], ['z', int, {
         'default': lambda obj: obj.x + obj.y
     }]])
コード例 #6
0
 class EntitySetter(EntityData):
     _properties = Property.build([['x', int, {
         'set': setter
     }], ['y', int, {
         'set': setter
     }], ['z', int, {
         'default': 0
     }]])
コード例 #7
0
 class EntityDefaultClass(EntityData):
     _properties = Property.build([['name', str, {
         'default': 'Name'
     }], ['age', int, {
         'default': 21
     }], ['tags', None, {
         'default': ['x']
     }]])
コード例 #8
0
    class EntityValidate(EntityData):
        _properties = Property.build([['x', int, {
            'default': 1
        }], ['y', int, {
            'default': 1
        }]])

        def __init__(self, data=None, keep_valid=False):
            super().__init__(data=data)
            self._keep_valid = keep_valid

        def is_valid(self):
            return self.x + self.y >= 2
コード例 #9
0
def save_search():
    save_type = request.form.get('save_type')
    save_data = request.form.get('save_data')
    address_url = request.form.get('save_url')
    searches_url = request.form.get('searches_url')
    # Parsing the unicode into a dictionary.
    save_data = ast.literal_eval(save_data)
    if session.get('user_id'):
        if save_type == 'search':
            search = Search(user_id=session.get('user_id'),
                            zipcode=save_data.get('zipcode'),
                            city=save_data.get('city'),
                            state=save_data.get('state'),
                            trans_type=save_data.get('trans_type'),
                            max_no_bed=save_data.get('max_no_bed'),
                            min_no_bed=save_data.get('min_no_bed'),
                            min_no_bath=save_data.get('min_no_bath'),
                            max_no_bath=save_data.get('max_no_bath'),
                            price_from=save_data.get('price_from'),
                            price_to=save_data.get('price_to'),
                            trans_date_from=save_data.get('trans_date_from'),
                            trans_date_to=save_data.get('trans_date_to'),
                            property_type=save_data.get('property_type'),
                            saved_date=datetime.datetime.now(),
                            saved_by_user=True,
                            search_url=searches_url)

            db.session.add(search)
            db.session.commit()

        if save_type == 'address':
            save_data = request.form.get('save_data')
            save_data = ast.literal_eval(save_data)
            # print save_data
            _property = Property(user_id=session.get('user_id'),
                                 property_id=save_data.get('property_id'),
                                 address=save_data.get('address'),
                                 latitude=float(save_data.get('latitude')),
                                 longitude=float(save_data.get('longitude')),
                                 no_of_beds=int(save_data.get('no_of_room')),
                                 no_of_baths=float(
                                     save_data.get('no_of_bath')),
                                 saved_date=datetime.datetime.now(),
                                 saved_by_user=True,
                                 prop_url=address_url)
            db.session.add(_property)
            db.session.commit()

    return jsonify({'Result': save_data})
コード例 #10
0
ファイル: app.py プロジェクト: deathping1994/radius
def property(post_id=None):
	if request.method == "GET":
		if post_id is not None:
			obj = Property.get_by_id(post_id)
			if obj:
				return Response(obj.json, status=200)
			return Response(status=404)
		else:
			limit = request.get('limit',10)
			objs = Property.get_all(limit)
			resp = [obj for obj in objs]
			return Response(json.dumps(resp), status=200)
	if request.method == "POST":
		lat = request.form.get('lat')
		lon = request.form.get('lon')
		price = request.form.get('price')
		bath = request.form.get('bath')
		bed = request.form.get('lat')
		if not (lat and lon and price and bath and bed):
			return Response(json.dumps({'msg':"Missing required parameter"}),status="400")
		obj = Property(lat,lon,bed,bath,price)
		obj.save()
		return Response(obj.json, status=201)
コード例 #11
0
 class CreateEntityClass(EntityData):
     _properties = Property.build(['name', 'age', 'tags'])
コード例 #12
0
def test_valid_matches(valid_matches):
    matches = Property.matches(valid_matches['regex'])
    assert matches(None, valid_matches['value']
                   ) == valid_matches['expected'], valid_matches['message']
コード例 #13
0
def test_valid_in_prop(valid_in_prop):
    in_prop = Property.in_prop('prop')
    assert in_prop(valid_in_prop, valid_in_prop['value']
                   ) == valid_in_prop['expected'], valid_in_prop['message']
コード例 #14
0
def test_is_in(valid_is_in):
    is_in = Property.is_in(valid_is_in['list'])
    assert is_in(None, valid_is_in['value']
                 ) == valid_is_in['expected'], valid_in_range['message']
コード例 #15
0
def test_valid_in_range(valid_in_range):
    in_range = Property.in_range(valid_in_range['min'], valid_in_range['max'],
                                 valid_in_range['inclusive'])
    assert in_range(None, valid_in_range['value']
                    ) == valid_in_range['expected'], valid_in_range['message']
コード例 #16
0
    def post(self):
        data = request.json
        property_obj = Property()

        partnership = data.get('id_partnership', None)
        if not partnership:
            raise BadRequest('Id partnership is Mandatory')
        floor = data.get('floor', None)
        ph = data.get('ph', None)
        block = data.get('block', None)
        lot = data.get('lot', None)

        property_obj.id_partnership = partnership
        if not floor:
            property_obj.floor = None
        else:
            property_obj.floor = floor
        if not ph:
            property_obj.ph = None
        else:
            property_obj.ph = ph
        if not block:
            property_obj.block = None
        else:
            property_obj.block = block
        if not lot:
            property_obj.lot = None
        else:
            property_obj.lot = lot

        try:
            db.session.add(property_obj)
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            print(str(e))
            raise InternalServerError("Unable to store a new property")

        property_last_insert = Property.query.order_by(
            Property.id.desc()).first()
        property_last_insert_data = self.property_schema.dump(
            property_last_insert).data

        return jsonify({'Property': property_last_insert_data})
コード例 #17
0
def test_property():
    prop = Property('test')
    assert not prop.required, 'Default property is not required'
コード例 #18
0
 class Populated(Entity):
     _properties = Property.build([['name', str, {
         'default': 'no name'
     }], ['age', int, {
         'default': 0
     }]])
コード例 #19
0
def test_property_string():
    prop = Property('test', str)
    assert prop.set_value(None, 'xxx') == 'xxx', 'Property set to str failed'
コード例 #20
0
    def init_properties(self):
        rows = []
        if not Property.query.filter_by(id='1').first():
            date_created = datetime.now()
            rows.append(
                Property(id_partnership='1',
                         floor='0',
                         ph='A',
                         block=None,
                         lot=None))  #Id 1
            rows.append(
                Property(id_partnership='1',
                         floor='0',
                         ph='B',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='1',
                         floor='0',
                         ph='C',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='1',
                         floor='1',
                         ph='A',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='1',
                         floor='1',
                         ph='B',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='1',
                         floor='1',
                         ph='C',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='1',
                         floor='1',
                         ph='D',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='2',
                         floor='0',
                         ph='A',
                         block=None,
                         lot=None))  #Id 8
            rows.append(
                Property(id_partnership='2',
                         floor='1',
                         ph='A',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='2',
                         floor='1',
                         ph='B',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='2',
                         floor='2',
                         ph='A',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='2',
                         floor='2',
                         ph='B',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='2',
                         floor='3',
                         ph='A',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='2',
                         floor='3',
                         ph='B',
                         block=None,
                         lot=None))
            rows.append(
                Property(id_partnership='3',
                         floor=None,
                         ph=None,
                         block='8',
                         lot='81'))  #Id 15
            rows.append(
                Property(id_partnership='3',
                         floor=None,
                         ph=None,
                         block='8',
                         lot='82'))
            rows.append(
                Property(id_partnership='3',
                         floor=None,
                         ph=None,
                         block='8',
                         lot='83'))
            rows.append(
                Property(id_partnership='3',
                         floor=None,
                         ph=None,
                         block='10',
                         lot='107'))
            rows.append(
                Property(id_partnership='3',
                         floor=None,
                         ph=None,
                         block='10',
                         lot='108'))
            rows.append(
                Property(id_partnership='3',
                         floor=None,
                         ph=None,
                         block='10',
                         lot='109'))

        try:
            db.session.bulk_save_objects(rows)
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            raise e