Пример #1
0
    def test_model_unit(self):
        """Test to make sure that Unit is working properly.
        """

        unit_type = Property(name="unit_type", value="section")
        number = 1

        unit = Unit()

        unit.properties = [unit_type]
        unit.number = number

        assert unit.number == number

        sentence = Sentence()
        sentence.words = [Word(word="hello"), Word(word="world")]
        prop = Property(name="title", value="Hello World")

        unit.sentences.append(sentence)
        unit.properties.append(prop)

        assert unit.sentences == [sentence]
        assert unit.properties.all() == [unit_type, prop]

        unit.save()
        prop.save()

        retrieved_prop = Property.query.filter(Property.name=="title").\
            filter(Property.value == "Hello World").first()

        assert retrieved_prop.unit.type == "unit"
        assert retrieved_prop.unit.number == unit.number
Пример #2
0
    def test_model_unit(self):
        """Test to make sure that Unit is working properly.
        """

        unit_type = Property(name="unit_type", value="section")
        number = 1

        unit = Unit()

        unit.properties = [unit_type]
        unit.number = number

        assert unit.number == number

        sentence = Sentence()
        sentence.words = [Word(lemma="hello"), Word(lemma="world")]
        prop = Property(name="title", value="Hello World")

        unit.sentences.append(sentence)
        unit.properties.append(prop)

        assert unit.sentences == [sentence]
        assert unit.properties.all() == [unit_type, prop]

        unit.save()
        prop.save()

        retrieved_prop = Property.query.filter(Property.name=="title").\
            filter(Property.value == "Hello World").first()

        assert retrieved_prop.unit.type == "unit"
        assert retrieved_prop.unit.number == unit.number
Пример #3
0
def new_property():
    form = PropertyForm()
    if form.validate_on_submit():

        description = form.content.data
        rent = form.rent.data
        if rent < 20001:
            rent_category = '_0_to_20'
        elif rent < 40001:
            rent_category = '_20_to_40'
        elif rent < 60001:
            rent_category = '_40_to_60'
        else:
            rent_category = 'above_60'

        location = form.location.data
        owner_id = current_user._get_current_object().id
        new_property = Property(description=description,
                                rent=rent,
                                rent_category=rent_category,
                                location=location,
                                owner_id=owner_id)
        new_property.save()
        return redirect(url_for('new_property'))

    return render_template('create_property.html', form=form)
Пример #4
0
	def build(self) -> Property:
		property = Property(Id=self._id,
							Name=self._name,
							CallFunction=self._callFunction,
							Parameters={},  # TODO: fix this
							Value=self._value,
							Type=self._type,
							Class=self._class,
							Comparable=self._comparable,
							Category=self._category)
		property.save()
		return property
Пример #5
0
def add_property(request):
    if request.method == "POST":
        name = request.POST.get('name')
        address = request.POST.get('address')

        user = request.user
        title = Property(name=name, address=address, owner=user)
        title.save()

        return redirect('owner_site')

    user = request.user
    name = user.username
    return render(request, 'add_prop.html', {"name": name})
Пример #6
0
def properties(db, federal_unity, property, city, neighbourhood, street,
               location):
    property2 = Property(price=75000.0,
                         area=55,
                         location=location,
                         url="http://site.com")
    db.session.add(property2)
    property3 = Property(price=110000.0,
                         area=80,
                         location=location,
                         url="http://site.com")
    db.session.add(property3)
    db.session.commit()

    return [property, property2, property3]
def create_property():
  payload = request.get_json()
  prep = f"{payload['address1']} {payload['address2']} {payload['city']} {payload['zipCode']}"
  coords = find_coordinates(prep)
  try:
    new_property = Property(
      owner_id=current_user.id,
      private=payload['private'],
      nightly_rate_usd=payload['nightlyRate'],
      address1=payload['address1'],
      address2=payload['address2'],
      city=payload['city'],
      zip_code=payload['zipCode'],
      latitude=coords['latitude'],
      longitude=coords['longitude'],
      listing_title=payload['listingTitle'],
      description=payload['description'],
      check_in=payload['checkIn'],
      check_out=payload['checkOut'],
      guest_spots=payload['guestSpots']
    )
    db.session.add(new_property)
    db.session.commit()
    return jsonify({'success': True, 'id': new_property.id})
  except:
    return jsonify({'success': False})
Пример #8
0
def property():
    """ For displaying the form to add a new property"""
    myform = UploadForm()
    # Validate file upload on submit
    #print(request)
    if request.method == 'POST' and myform.validate_on_submit():
        # Get file data and save to your uploads folder
        photo = myform.upload.data
        filefolder = app.config['UPLOAD_FOLDER']
        filename = secure_filename(photo.filename)
        photo.save(os.path.join(filefolder,filename))
        flash('File Saved', 'success')

        title = myform.title.data
        bed = myform.bedroom.data
        bath = myform.bathroom.data
        loc = myform.location.data
        price = myform.price.data
        types = myform.types.data
        des = myform.description.data

        price = format (price, ',f')
        
        prop = Property (title, bed, bath, loc, price, types, des, filename)
        #print(prop)
        db.session.add(prop)
        db.session.commit()
        flash('New user was successfully added')

        return redirect(url_for('properties'))
    return render_template('upload.html', form = myform)
Пример #9
0
def property():
    form = PropertyForm()
    if request.method == 'GET':
        return render_template('property.html', form=form)
    elif request.method == "POST":
        if form.validate_on_submit:
            title = form.title.data
            numBeds = form.bedrooms.data
            location = form.location.data
            price = form.price.data
            desc = form.description.data
            propertyType = form.houseType.data
            numBath = form.bathrooms.data
            file = request.files['photo']
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            newProperty = Property(title, numBeds, numBath, location, price,
                                   desc, filename, propertyType)

            db.session.add(newProperty)
            db.session.commit()

            flash("Property Sucessfully added")
            return redirect(url_for('properties'))
        else:
            flash("Data entered not valid")
Пример #10
0
def newproperty():
    form = PropertyForm()

    if request.method == 'POST' and form.validate_on_submit():
        title = form.title.data
        bedroom = form.bedroom.data
        bathroom = form.bathroom.data
        location = form.location.data
        price = form.price.data
        type = form.type.data
        description = form.description.data

        img = form.photo.data
        img_filename = secure_filename(img.filename)
        img.save(os.path.join(app.config['UPLOAD_FOLDER'], img_filename))

        add_property = Property(title, bedroom, bathroom, location, price,
                                type, description, img_filename)
        db.session.add(add_property)
        db.session.commit()

        flash('New property added!', 'success')
        return redirect(url_for('properties'))

    return render_template('property.html', form=form)
Пример #11
0
def new_property():
    form = forms.PropertyForm()
    if request.method == 'POST':
        # Validate form on submit
        if form.validate_on_submit():
            photoData = form.photo.data
            photo = secure_filename(photoData.filename)

            prop = Property(title=form.title.data,
                            description=form.description.data,
                            rooms=form.rooms.data,
                            bath=form.bath.data,
                            price=form.price.data,
                            propType=form.propType.data,
                            location=form.location.data,
                            photo=photo)
            db.session.add(prop)
            db.session.commit()
            #save property photo to folder
            photoData.save(os.path.join(app.config['UPLOAD_FOLDER'], photo))

            flash('File Saved', 'success')
            return redirect(url_for('properties'))

    return render_template('new_property.html', form=form)
Пример #12
0
def property():
    form = PropertyForm()
    upload_folder = app.config['UPLOAD_FOLDER']

    if request.method == "POST" and form.validate_on_submit():
        title = form.title.data
        description = form.description.data
        number_of_rooms = form.number_of_bedrooms.data
        number_of_bathrooms = form.number_of_bathrooms.data
        price = form.price.data
        property_type = form.property_type.data
        location = form.location.data
        photo = form.photo.data
        filename = secure_filename(photo.filename)

        # Create new property
        new_property = Property(title, description, number_of_rooms,
                                number_of_bathrooms, price, property_type,
                                location, filename)

        # Add to db
        db.session.add(new_property)
        db.session.commit()
        photo.save(os.path.join(upload_folder, filename))

        flash("Property was added successfully", 'success')
        return redirect(url_for('properties'))
    flash_errors(form)
    return render_template('new_property.html', form=form)
Пример #13
0
def property():
    form = PropertyForm()

    if request.method == 'POST':
        image = request.files['photo']
        filename = secure_filename(image.filename)
        image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        title = form.title.data
        description = form.description.data
        rooms = form.rooms.data
        bathrooms = form.bathrooms.data
        price = form.price.data
        location = form.location.data
        propertyType = form.propertyType.data

        newProperty = Property(title=title,
                               description=description,
                               rooms=rooms,
                               bathrooms=bathrooms,
                               price=price,
                               location=location,
                               propType=propertyType,
                               photo=filename)
        db.session.add(newProperty)
        db.session.commit()

        properties = Property.query.all()
        flash('Succcessfully Added')
        return redirect(url_for('properties', properties=properties))

    return render_template('property.html', form=form)
Пример #14
0
def get_properties():
    all_properties = Property.query.all()
    num = db.session.query(Property).count()
    total_mv = db.session.query(func.sum(Property.MarketValue))
    total_cost = db.session.query(func.sum(Property.Cost))
    pl_result = db.session.query(func.sum(Property.MarketValue -
                                          Property.Cost))

    form = PropertyFrom()
    if request.method == 'POST':
        if form.PropertyID.data:
            current_property = Property.query.get(form.PropertyID.data)
            current_property.PropertyName = form.PropertyName.data
            current_property.City = form.City.data
            current_property.MarketValue = form.MarketValue.data
            current_property.Cost = form.Cost.data
            db.session.commit()
            flash('Update a property successfully', 'success')
        else:
            new_property = Property(PropertyName=form.PropertyName.data,
                                    City=form.City.data,
                                    MarketValue=form.MarketValue.data,
                                    Cost=form.Cost.data)
            db.session.add(new_property)
            db.session.commit()
            flash('Add a property successfully', 'success')
        return redirect(url_for('get_properties'))

    return render_template('properties.html',
                           all_properties=all_properties,
                           num=num,
                           total_mv=total_mv,
                           total_cost=total_cost,
                           pl_result=pl_result,
                           form=form)
Пример #15
0
def newProperty():
    # Instantiate your form class
    form = PropertyForm()
    # Validate file upload on submit
    if request.method == 'POST':
        if form.validate_on_submit():
            # Get file data and save to your uploads folder
            title = form.title.data
            desc = form.desc.data
            room = form.room.data
            bathroom = form.bathroom.data
            price = form.price.data
            proptype = form.proptype.data
            location = form.location.data
            photo = form.photo.data
            filename = secure_filename(photo.filename)
            prop = Property(title=title,
                            desc=desc,
                            room=room,
                            bathroom=bathroom,
                            price=price,
                            proptype=proptype,
                            location=location,
                            photo=filename)
            if prop is not None:
                db.session.add(prop)
                db.session.commit()
                photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                flash('Property Added Succesfully.', 'success')
                return redirect(url_for("properties"))
            else:
                flash('Property was not added.', 'danger')
    return render_template('new_property.html', form=form)
Пример #16
0
def property():
    filefolder = './uploads'
    form = PropForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            title = form.title.data
            description = form.description.data
            bed = form.numBedroom.data
            bath = form.numBathroom.data
            location = form.location.data
            price = float(form.price.data)
            type = form.type.data

            image = form.propImage.data
            filename = secure_filename(image.filename)
            image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            prop = Property(title, description, bed, bath, location, price,
                            type, filename)
            print(prop.title)
            print(prop.type)

            db.session.add(prop)
            db.session.commit()
        else:
            print(form.errors)
        return redirect(url_for('home'))
    return render_template('property.html', form=form)
Пример #17
0
def property():
    """Render the website's property page."""
    # Instantiate your form class
    form = NewPropertyForm()
    # Validate file upload on submit

    if request.method == 'POST':
        if form.validate_on_submit():
            # Extract form data
            title = form.title.data
            description = form.description.data
            rooms = form.totalRooms.data
            bathrooms = form.totalBathrooms.data
            price = form.price.data
            propertyType = form.propertyType.data
            location = form.location.data
            photo = form.photo.data
            photo_name = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'],
                                    photo_name))  # Save photo to upload folder
            '''Add new property to db and commit'''
            newProperty = Property(title, description, rooms, bathrooms, price,
                                   propertyType, location, photo_name)
            db.session.add(newProperty)
            db.session.commit()

            flash(f'Your {propertyType} was added successfully!', 'success')
            return redirect(url_for('properties'))
        flash_errors(form)
    return render_template('property_form.html', form=form)
Пример #18
0
def prop():
    form = PropertyForm()
    if request.method == "POST" and form.validate_on_submit():
        title = form.title.data
        description = form.description.data
        rooms = form.rooms.data
        bathrooms = form.bathrooms.data
        price = form.price.data
        ptype = form.ptype.data
        location = form.location.data
        photo = request.files['photo']
        if photo and allowed_file(photo.filename):
            filename = secure_filename(photo.filename)
            prop = Property(title, description, rooms, bathrooms, price, ptype,
                            location, filename)
            db.session.add(prop)
            db.session.commit()
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            flash('Property added successfully', 'success')
            return redirect('/properties')
        else:
            flash("Photo must be either png or jpg.")
    else:
        flash_errors(form)
    return render_template("add_property.html", form=form)
Пример #19
0
def property():
    print('propTest')
    myform = PropertyForm()
    print('propTest1')
    if request.method == 'POST':
        print("method is post")
        if myform.validate_on_submit():
            #Add data from form
            print('This is the true test')
            propTitle = myform.propTitle.data
            description = myform.description.data
            roomNum = myform.roomNum.data
            bathroomNum = myform.bathroomNum.data
            price = myform.price.data
            propType = myform.propType.data
            location = myform.location.data
            image = myform.file.data
            filename = secure_filename(image.filename)
            image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            newProp = Property(propTitle, description, roomNum, bathroomNum,
                               price, propType, location, filename)
            db.session.add(newProp)
            db.session.commit()

            flash('The property was added successfully!')
            return redirect(url_for('home'))
    else:
        flash_errors(myform)
    return render_template('property.html', form=myform)
Пример #20
0
def add_property():
    form = PropertyForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                title = form.title.data
                bedroom_count = int(form.bathroom_count.data)
                bathroom_count = int(form.bathroom_count.data)
                location = form.location.data
                price = float(form.price.data)
                type = form.type.data
                description = form.description.data
                photo = form.photo.data
                photo_path = secure_filename(photo.filename)
                photo.save(
                    os.path.join(app.config['UPLOAD_FOLDER'], photo_path))
                prop = Property(title, bedroom_count, bathroom_count, location,
                                price, type, description, photo_path)
                db.session.add(prop)
                db.session.commit()
                flash('Property saved successfully', 'success')
                return redirect(url_for('show_properties'))
            except Exception as e:
                print(e)
                flash('Something went wrong', 'danger')
        else:
            flash_errors(form)

    return render_template('add_property.html', form=form)
Пример #21
0
def property(db, federal_unity, city, neighbourhood, street, location):
    property = Property(price=50000.0,
                        area=40,
                        location=location,
                        url="http://site.com")
    db.session.add(property)
    db.session.commit()
    return property
Пример #22
0
 def _baseProperty(self):
     baseProperty = Property()
     baseProperty.Category = self.Category
     baseProperty.Class = self.TemplateClass.value
     baseProperty.CallFunction = "execute"
     baseProperty.Parameters = {}
     return baseProperty
Пример #23
0
 def setProperty(self, property: Property, value=None) -> any:
     if property.Type == TypeEnum.Read_Only:
         raise Exception(u"Property '{0}' is read-only".format(property))
     functionName = property.CallFunction
     deviceId = property.Device.Id
     callFunction = self.getProducedDeviceFunction(deviceId, functionName)
     parsedValue = property.Parser.ToObject(value)
     property.Parameters[u"Value"] = parsedValue
     kwargs = dict(property.Parameters)
     self.__logger.info(
         u"Calling '{0}' function of {1} device with arguments {2}".format(
             functionName, property.Device, kwargs))
     return callFunction(**kwargs)
Пример #24
0
    def test_model_property(self):
        """Test to make sure that Property is working properly.
        """

        prop = Property()

        name = "title"
        value = "Hello World"

        prop.name = name
        prop.value = value

        assert prop.name == name
        assert prop.value == value

        prop.save()

        retrieved_prop = Property.query.filter(name=="title").\
            filter(value == "Hello World").first()

        assert retrieved_prop.name == prop.name
        assert retrieved_prop.value == prop.value
Пример #25
0
def myproperty():
    pform = PropertyFrom()
    if request.method == 'POST' and  pform.validate_on_submit():
        myimage = pform.photo.data
        myfilename = secure_filename(myimage.filename)
        myimage.save(os.path.join(app.config['UPLOAD_FOLDER'], myfilename))

        db.session.add(Property(pform.title.data, pform.description.data, pform.rooms.data, pform.bath.data, pform.price.data, pform.ptype.data, pform.location.data, myfilename))
        db.session.commit()
        
        flash('Property Added', 'success')
        return redirect(url_for('properties'))
    return render_template("property.html", form=pform)
Пример #26
0
def property():
    form = PropertyForm()

    if form.validate_on_submit():
        photo = form.photo.data
        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        property = Property(form.name.data, form.nobed.data, form.nobath.data, form.location.data, form.price.data, form.type.data, form.description.data, filename)
        db.session.add(property)
        db.session.commit()
        flash('Property Successfully Added', 'success')
        return redirect(url_for("properties"))

    return render_template('property.html', form=form)
def add_property(m_id):
    print("REQUEST!", request.data)
    form = PropertyAddForm()
    print("MEMBER ID!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", m_id)
    if request.method == "POST":
        print("ATTEMPTING TO POST!!")
        if form.validate_on_submit:
            data = form.data
            print("DATA!!!!!", data)
            # property_list = []
            # property_check = Property.query.all()

            # idx = 0
            # for prop in property_check:
            #     property_list.append(property_check[idx].name)
            #     idx+=1

            # if data['value'] in property_list:
            #     print("IF STATEMENT TRIGGERED!!!!!!!!!!!!!!!!!!!!")
            #     existing_property = Property.query.filter(Property.name == data['value']).one()
            #     print("WHAT IS THIS????????????", existing_property)
            #     print("existing property id", existing_property.id, existing_property.name)
            #     new_property = existing_property

            #     # new_property = existing_property(
            #     #     name=existing_property.name,
            #     #     is_checked=data['isChecked'],
            #     # )
            # else:
            # print("ELSE STATEMENT TRIGGERED")
            new_property = Property(
                name=data['value'],
                is_checked=data['isChecked'],
            )
            db.session.add(new_property)
            db.session.commit()

            # new_property.id somehow is "None"
            print("PROP!!!!!!!!", new_property.id, new_property.name,
                  new_property.is_checked)
            # print("PROP ASSOCIATION!!!!!", new_member_property.id, new_member_property.member_id, new_member_property.property_id)

            new_member_property = Member_Property(member_id=m_id,
                                                  property_id=new_property.id)

            db.session.add(new_member_property)
            db.session.commit()

    return {"Message": "Property Added Successfully!"}, 200
Пример #28
0
def add_property():
    form = PropertyForm()
    if request.method == 'POST' and form.validate_on_submit():
        title = request.form['title']
        rooms = request.form['bedrooms']
        bathrooms = request.form['bathrooms']
        location = request.form['location']
        price = request.form['price']
        prop_type = request.form['houseType']
        description = request.form['description']
        filename = save_photos(form.photo.data)
        prop = Property(title, description, rooms, bathrooms, price, prop_type,
                        location, filename)
        db.session.add(prop)
        db.session.commit()
        return redirect(url_for('display_properties'))
    return render_template('add_property.html', form=form)
Пример #29
0
def create_property():
    payload = request.get_json()
    errors = []
    if not payload['address1']:
        errors.append('Please provide a primary street address')
    if not payload['city']:
        errors.append('Please provide a city')
    if not payload['zipCode']:
        errors.append('Please provide a zip code')
    if not payload['listingTitle']:
        errors.append('Please provide a title')
    if not payload['description']:
        errors.append('Please provide a description')
    if not payload['checkIn']:
        errors.append('Please provide a check-in time')
    if not payload['checkOut']:
        errors.append('Please provide a check-out time')
    if not payload['guestSpots']:
        errors.append('Please provide a maximum number of guests')
    if len(errors):
        return {'errors': errors}
    prep = f"{payload['address1']} {payload['address2']} {payload['city']} {payload['zipCode']}"
    coords = find_coordinates(prep)
    if not coords or not coords['latitude'] or not coords['longitude']:
        return {
            'errors':
            ['Sorry, our system wasn\'t able to locate that address ']
        }
    new_property = Property(owner_id=current_user.id,
                            private=payload['private'],
                            nightly_rate_usd=payload['nightlyRate'],
                            address1=payload['address1'],
                            address2=payload['address2'],
                            city=payload['city'],
                            zip_code=payload['zipCode'],
                            latitude=coords['latitude'],
                            longitude=coords['longitude'],
                            listing_title=payload['listingTitle'],
                            description=payload['description'],
                            check_in=payload['checkIn'],
                            check_out=payload['checkOut'],
                            guest_spots=payload['guestSpots'])
    db.session.add(new_property)
    db.session.commit()
    return {'success': True, 'id': new_property.id}
Пример #30
0
def property():
    form=MyForm()
    if request.method == 'POST' and form.validate_on_submit():
        #photo=request.files['photo']
        photo=form.photo.data
        filename=secure_filename(photo.filename)
        typevalue=dict(form.propertyType.choices).get(form.propertyType.data)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        property=Property(request.form['title'],request.form['description'], request.form['rooms'],
        request.form['bathroom'],request.form['price'],
        request.form['propertyType'], request.form['location'], filename)
        #photo1=request.file['photo'].read()
        db.session.add(property)
        db.session.commit()
        flash('Propery was sucessfully added', 'success')
        return redirect(url_for('properties'))
    flash_errors(form)
    return render_template('property.html',form=form)
Пример #31
0
def property():
    form = PropertyForm()
    if request.method == 'POST' and form.validate_on_submit():
        title = request.form['title']
        desc = request.form['desc']
        rooms = int(request.form['rooms'])
        bath = int(request.form['bath'])
        price = float(request.form['price'])
        type = request.form['type']
        location = request.form['location']
        photo = request.files['photo']
        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        property = Property(title, rooms, bath, location, price, type, desc,
                            filename)
        db.session.add(property)
        db.session.commit()
        flash('Property information successfully added', 'success')
        return redirect(url_for('properties'))
    return render_template('property.html', form=form)
Пример #32
0
def property():
    form = Propertyform()

    # Validate profile info on submit
    if request.method == 'POST':
    
        # Get image data and save to upload folder
        photo = request.files['photo']
        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        
        
        
        
        
        # Get the rest of the profile data
        title = form.title.data
        descript = form.descript.data
        room = form.room.data
        bathroom = form.bathroom.data
        price = form.price.data
        location = form.location.data
        propertyT = form.propertyT.data

        # Save data to database
        newProperty = Property(title=title, 
        descript=descript, room=room, 
        bathroom=bathroom, price=price, 
        location=location, propertyT=propertyT,
         photo=filename )
        db.session.add(newProperty)
        db.session.commit()
        



        properties =Property.query.all()
        flash('Succcessfully Added')
        return redirect(url_for('properties', properties=properties))
    return render_template('property.html', form = form)
Пример #33
0
def init_data():
    Property.insert_items()
    Role.insert_roles()
    User.init_users()