Beispiel #1
0
def add_property():
    form = PropertyForm()
    if request.method == 'POST' and form.validate_on_submit():
        # Get form data
        title = form.property_title.data
        description = form.description.data
        no_bedrooms = form.no_bedrooms.data
        no_bathrooms = form.no_bathrooms.data
        price = form.price.data
        location = form.location.data
        property_type = form.property_type.data
        photo = form.property_photo.data

        # Save the photo
        photo_path = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], photo_path))

        # Store the property to the database
        property_model = PropertyModel(title, no_bedrooms, no_bathrooms,
                                       description, price, location,
                                       property_type, photo_path)

        db.session.add(property_model)
        db.session.commit()

        # Redirect to properties page
        flash('Saved Property', 'success')
        return redirect(url_for('get_properties'))
    else:
        flash_errors(form)
    return render_template('property.html', form=form)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
0
def property():
    myform = PropertyForm()
    if request.method == 'POST' and myform.validate_on_submit():

        property_title = myform.property_title.data
        description = myform.description.data
        rooms = myform.rooms.data
        bathrooms = myform.bathrooms.data
        price = myform.price.data
        property_type = myform.property_type.data
        location = myform.location.data
        #photo=myform.photo.data

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

        propt = NewProperty(request.form['property_title'],
                            request.form['description'], request.form['rooms'],
                            request.form['bathrooms'], request.form['price'],
                            request.form['property_type'],
                            request.form['location'], filename)
        db.session.add(propt)
        db.session.commit()

        flash('Property successfully added', 'success')
        return redirect(url_for('properties'))

    return render_template('property.html', form=myform)
Beispiel #5
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)
Beispiel #6
0
def property():
    """Render the website's property page."""
    form = PropertyForm()
    if request.method == 'POST' and form.validate_on_submit():
        title = form.title.data
        desc = form.description.data
        nobed = form.nobed.data
        nobath = form.nobed.data
        location = form.location.data
        price = form.price.data
        property_type = form.property_type.data
        photo = form.photo.data

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

        prop = PropertyProfile(title, desc, nobed, nobath, location, price,
                               property_type, filename)
        db.session.add(prop)
        db.session.commit()

        flash('Property successfully added.', 'success')
        return redirect(url_for('properties'))
    else:
        flash_errors(form)
    return render_template('property.html', form=form)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
0
def property():
    form = PropertyForm()
    ptype = ['House', 'Apartment']
    if request.method == "POST":
        if form.validate_on_submit:
            photo = form.photo.data
            filename = secure_filename(photo.filename)
            #print(filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            user = PropertyProfile(ptitle=form.ptitle.data,
                                   pdescription=form.description.data,
                                   rooms=form.rooms.data,
                                   bathrooms=form.bathrooms.data,
                                   price=form.price.data,
                                   ptype=form.ptype.data,
                                   location=form.location.data,
                                   filename=filename)
            db.session.add(user)
            db.session.commit()
            flash("Property Added")
            return redirect(url_for("properties"))

        else:
            flash("Something went wrong.Try Again")

    return render_template("property.html", form=form, ptype=ptype)
Beispiel #10
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)
Beispiel #11
0
def property():
    form=PropertyForm()
    if request.method=='POST' and form.validate_on_submit():
        title=form.title.data
        bedroom_num=form.bedroom_num.data
        bathroom_num=form.bathroom_num.data
        location=form.location.data
        price=form.price.data
        types=form.types.data
        description=form.description.data

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

         

        propert= UserProp(title, bedroom_num, bathroom_num, location,price,types,description,filename)
        db.session.add(propert)
        db.session.commit()

        flash('Property Added Successfully', 'success')
        return redirect(url_for('properties'))
    
    return render_template('property.html', form=form)
Beispiel #12
0
def add_property():

    form = PropertyForm()

    if (request.method == 'POST'):
        if form.validate_on_submit() == True:

            title = request.form["title"]
            propertyDescription = request.form["propertyDescription"]
            Bedrooms = request.form["bedrooms"]
            Bathrooms = request.form["bathrooms"]
            price = request.form["price"]
            propertytype = request.form["propertytype"]
            location = request.form["location"]
            filename = uploadPhoto(form.photo.data)

            prop = Properties(title, propertyDescription, Bedrooms, Bathrooms,
                              price, propertytype, location, filename)

            db.session.add(prop)
            db.session.commit()

            flash('Property added')
        else:
            flash('Property not Added')
        return redirect(url_for("properties"))
    return render_template("add_property.html", form=form)
Beispiel #13
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)
Beispiel #14
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)
Beispiel #15
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)
Beispiel #16
0
def property():
    form = PropertyForm()
    if request.method == "POST" and form.validate_on_submit():
        title = form.title.data
        desc = form.desc.data
        numOfBed = form.numOfBed.data
        numOfBath = form.numOfBath.data
        pric = form.pric.data
        proptype = form.proptype.data
        location = form.location.data
        pic = form.pic.data
        filename = secure_filename(pic.filename)
        pic.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        userproperty = UserProperty(title, desc, numOfBed, numOfBath, pric,
                                    proptype, location, filename)
        db.session.add(userproperty)
        db.session.commit()
        flash("Property successfully created", category="success")
        return redirect(url_for('properties'))
    return render_template("property.html", form=form)
Beispiel #17
0
def property():
    form = PropertyForm()
    if request.method == "POST" and form.validate_on_submit():
        photo = form.photo.data
        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        user = UserProperties(title=request.form['title'],
                              description=request.form['description'],
                              bedrooms=request.form['bedrooms'],
                              bathrooms=request.form['bathrooms'],
                              price=request.form['price'],
                              types=request.form['types'],
                              location=request.form['location'],
                              photo=filename)

        db.session.add(user)
        db.session.commit()

        flash('Property Saved', 'success')
        return redirect(url_for('properties'))
    return render_template('property.html', form=form)
Beispiel #18
0
def property():
    pform = PropertyForm()
    if request.method == "POST":

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

        new_property = RealEstate(title=pform.title.data,
                                  bedroom=pform.no_bed.data,
                                  bathroom=pform.no_bath.data,
                                  location=pform.location.data,
                                  price=pform.price.data,
                                  types=pform.types.data,
                                  descrp=pform.descrp.data,
                                  photo=filename)

        db.session.add(new_property)
        db.session.commit()
        flash('Property Added', 'success')
        return redirect(url_for('properties'))
    return render_template('property.html', form=pform)
Beispiel #19
0
def property():
    form = PropertyForm()

    # Validate profile info on submit
    if request.method == 'POST':
        if form.validate_on_submit():

            # Save image to upload folder
            photo = request.files['photo']
            filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            # Extract data for the profile data
            property_title = form.property_title.data
            description = form.description.data
            bedrooms = form.bedrooms.data
            bathrooms = form.bathrooms.data
            price = form.price.data
            location = form.location.data
            property_type = form.property_type.data

            # Save data to database
            property_model = PropertyModel(title=property_title,
                                           description=description,
                                           bedrooms=bedrooms,
                                           bathrooms=bathrooms,
                                           price=price,
                                           location=location,
                                           property_type=property_type,
                                           photo=photo)

            db.session.add(property_model)
            db.session.commit()

            # Redirect to properties page
            flash('Property successfully saved')
            return redirect(url_for('get_properties', properties=properties))
        flash_errors(form)
    return render_template('property.html', form=form)
Beispiel #20
0
def add_property():
    """Form for adding properties"""

    # Initialize the property form
    form = PropertyForm()

    if request.method == 'POST':
        if form.validate_on_submit():
            property_title = form.property_title.data
            description = form.description.data
            no_bedrooms = form.no_bedrooms.data
            no_bathrooms = form.no_bathrooms.data
            price = form.price.data
            location = form.location.data
            property_type = form.property_type.data
            photo = form.photo.data

            property_photo = secure_filename(photo.filename)
            path_joined = os.path.join(
                app.config['UPLOAD_FOLDER'], property_photo)
            photo.save(path_joined)
            property_model = PropertyModel(
                title=property_title,
                description=description,
                price=price,
                location=location,
                no_bedrooms=no_bedrooms,
                no_bathrooms=no_bathrooms,
                property_type=property_type,
                property_photo=property_photo)

            db.session.add(property_model)
            db.session.commit()

            flash('Saved property', 'success')
            return redirect(url_for('property_catalogue'))
        flash_errors(form)
    return render_template('add_property.html', form=form)
Beispiel #21
0
def add_property():
    """Form for adding properties"""

    # Initialize the property form
    form = PropertyForm()

    if request.method == 'POST':
        if form.validate_on_submit():
            title = form.title.data
            description = form.description.data
            num_of_beds = form.num_of_beds.data
            num_of_baths = form.num_of_baths.data
            price = form.price.data
            location = form.location.data
            propertyType = form.propertyType.data
            photo = form.photo.data
            photo_path = secure_filename(photo.filename)
            path_joined = os.path.join(app.config['UPLOAD_FOLDER'], photo_path)
            print(path_joined)
            photo.save(path_joined)

            property_model = PropertyModel(title=title,
                                           description=description,
                                           num_of_beds=num_of_beds,
                                           num_of_baths=num_of_baths,
                                           price=price,
                                           location=location,
                                           propertyType=propertyType,
                                           path_joined=path_joined)

            db.session.add(property_model)
            db.session.commit()

            # Redirect to properties page
            flash('Property successfully saved', 'success')
            return redirect(url_for('get_properties'))
        flash_errors(form)
    return render_template('property.html', form=form)
Beispiel #22
0
def property():
    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
        proptype = form.proptype.data
        location = form.location.data
        photo = form.photo.data
        filename = secure_filename(photo.filename)

        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        propertydisplay = Property(title, description, rooms, bathrooms, price,
                                   proptype, location, filename)

        db.session.add(propertydisplay)
        db.session.commit()

        flash("Property successfully created", category="success")
        return redirect(url_for('properties'))
    return render_template("propertyform.html", form=form)
Beispiel #23
0
def property():
    """Form for new property."""
    form = PropertyForm()
    if request.method == 'POST' and form.validate_on_submit():
        title = form.title.data
        bedroomnum = form.bedrooms.data
        bathroomnum = form.bathrooms.data
        location = form.location.data
        price = form.price.data
        type = form.type.data
        description = form.description.data
        photo = form.photo.data
        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        property = PropertyB(title, bedrooms, bathrooms, location, price, type,
                             desc, filename)
        db.session.add(property)
        db.session.commit()
        flash('Property added successfully', 'success')
        return redirect(url_for('properties'))

    return render_template('property.html', form=form)
def property():
    form= PropertyForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            title=form.title.data
            num_bedrooms=form.num_bedrooms.data
            num_bathrooms=form.num_bathrooms.data
            location=form.location.data
            price=form.price.data
            propertytype=form.propertytype.data
            description=form.description.data
            photo=form.photo.data
            filename=secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
            property_list=PropertyList(title,num_bedrooms,num_bathrooms,location,
                                        price,propertytype,description,filename)
            db.session.add(property_list)
            db.session.commit()

            flash("Property was successfully added", "success")
            return redirect(url_for('properties'))
        flash_errors(form)
    return render_template('property.html',form=form)
Beispiel #25
0
def property():
    pf = PropertyForm()
    if request.method == 'POST':
        if pf.validate_on_submit():
            title = pf.title.data
            num_bedrooms = pf.num_bedrooms.data
            num_bathrooms = pf.num_bathrooms.data
            location = pf.location.data
            price = pf.price.data
            property_type = pf.property_type.data
            description = pf.description.data
            photo = photo_save(pf.photo.data)

            property_info = Property(title, num_bedrooms, num_bathrooms,
                                     location, price, property_type,
                                     description, photo)
            db.session.add(property_info)
            db.session.commit()
            flash('Property Added', 'success')
            return redirect(url_for('properties'))
    else:
        flash_errors(pf)
    return render_template('propertyADD.html', form=pf)
Beispiel #26
0
def property():
    form = PropertyForm()

    # Validate profile info on submit
    if request.method == 'POST':

        # Get image data and save to upload folder
        image = request.files['photo']
        filename = secure_filename(image.filename)
        image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        # Get the rest of the profile data
        Title = form.title.data
        details = form.details.data
        spaces = form.spaces.data
        bathroom = form.bathroom.data
        cost = form.cost.data
        located = form.located.data
        prop_type = form.prop_type.data

        # Save data to database
        newProperty = Property(Title=Title,
                               details=details,
                               spaces=spaces,
                               bathroom=bathroom,
                               cost=cost,
                               located=located,
                               ppty=prop_type,
                               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)
Beispiel #27
0
def property():
    myform = PropertyForm()

    if request.method == 'POST':
        if myform.validate_on_submit():
            title = myform.title.data
            bedrooms = myform.bedrooms.data
            bathrooms = myform.bathrooms.data
            location = myform.location.data
            price = myform.price.data
            prop_type = myform.prop_type.data
            description = myform.description.data
            image = myform.imageFile.data

            filename = secure_filename(image.filename)
            image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            property = UserProperty(title, bedrooms, bathrooms, location,
                                    price, prop_type, description, filename)
            db.session.add(property)
            db.session.commit()

            flash('You have successfully uploaded a property')
            return redirect(url_for('properties'))
    return render_template('property.html', form=myform)
Beispiel #28
0
def property():
    form = PropertyForm(request.form)
    if request.method == 'POST' and form.validate_on_submit():
        return 'We confirm your registration!'
    return render_template('property.html', form=form)
Beispiel #29
0
def upload():
    form1 = UploadForm1()
    form3 = UploadForm3()
    form2 = PropertyForm()
    if form1.category.data == 'Property':
        form2 = PropertyForm()
    elif form1.category.data == 'Fashion':
        form2 = FashionForm()
    elif form1.category.data == 'Electronics':
        form2 = ElectronicsForm()
    elif form1.category.data == 'Living':
        form2 = LivingForm()
    elif form1.category.data == 'Services':
        form2 = ServicesForm()
    else:
        form2 = EducationForm()

    if form1.submit_1.data and form1.validate() and not form2.submit_2.data:
        return render_template('upload.html',
                               title='Upload',
                               form=form2,
                               step=2)
    if form2.submit_2.data and not form2.validate():
        return render_template('upload.html',
                               title='Upload',
                               form=form2,
                               step=2)
    if form2.submit_2.data and form2.validate(
    ) and not form3.submit_final.data:
        return render_template('upload.html',
                               title='Upload',
                               form=form3,
                               step=3)
    if form3.submit_final.data and not form3.validate():
        return render_template('upload.html',
                               title='Upload',
                               form=form3,
                               step=3)

    if form3.submit_final.data and form3.validate():
        user_folder = os.path.join(MEDIA_ROOT, str(current_user.username))
        if not os.path.isdir(user_folder):
            os.mkdir(user_folder)
        current_time = math.floor(time.time())
        product_folder = os.path.join(user_folder, str(current_time))
        os.mkdir(product_folder)

        p = Product(title=form3.title.data, description=form3.description.data,\
        price=form3.price.data, author=current_user, timestamp=current_time,\
        condition=form3.condition.data,category=form3.category.data,subcategory=form3.subcategory.data)
        db.session.add(p)
        db.session.commit()

        for f in request.files.getlist('photo'):
            filename = secure_filename(f.filename)
            destination = os.path.join(product_folder, filename)
            f.save(destination)

            link = os.sep + os.path.relpath(destination, APP_ROOT)

            product = Product.query.filter_by(author=current_user,
                                              title=form3.title.data).first()
            i = Image(link=link, user_id=product.id)
            db.session.add(i)
            db.session.commit()
        return redirect(url_for('user', username=current_user.username))
    return render_template('upload.html', form=form1, step=1)