Ejemplo n.º 1
0
def process_batches():
    rows = BatchCSV.select()
    for row in rows:
        csv_file = os.path.join("./files/csv", row.Filename)
        with open(csv_file, 'rb') as fl:
            next(fl)
            rd = csv.reader(fl, delimiter='|', quotechar=' ')
            for r in rd:
                title= r[0]
                description = r[1]
                sourcing_fee = r[2]
                roi = r[3]
                address_1 = r[4]
                address_2 = r[5]
                county = r[6]
                city = r[7]
                postcode=r[8]
                dealtype=r[9]
                show_address =r[10]

                dealtypes = DealType.select(DealType.deal_type)
                types= [c.deal_type for c in dealtypes]
                errors = []
                if (title == ""):
                    errors.append("Title cannot be empty")
                if (description == ""):
                    errors.append("Description cannot be empty")
                if show_address.lower() == "true" or show_address.lower()=="1":
                    show_address=True
                else:
                    show_address=False
                dtype = None
                if (dealtype not in types):
                    errors.append("Deal type not found ["+dealtype+"]")
                else:
                    dtype = DealType.select().where(DealType.deal_type==dealtype)[0]
                if (city == ""):
                    errors.append("City cannot be empty")
                if (county == ""):
                    errors.append("County cannot be empty")

                BatchCSVData.create(Title=title,
                                    Description = description,
                                    Sourcing_Fee = sourcing_fee,
                                    ROI = roi,
                                    Address_Line_1 = address_1,
                                    Address_Line_2 = address_2,
                                    County = county,
                                    City = city,
                                    PostCode = postcode,
                                    DealType = dealtype,
                                    DealTypeObj = dtype.uuid,
                                    Batch = row,
                                    Is_Error = False if len(errors) == 0 else True,
                                    Errors = ", ".join(errors),
                                    Show_Address = bool(show_address),
                                    uuid = uuid.uuid4())
Ejemplo n.º 2
0
    def __init__(self,request, endpoint_name,caption):
        CustomFormBase.__init__(self, request=request, endpoint_name=endpoint_name, caption=caption)
        bedroom_list = Bedrooms.select()
        deal_type_list = DealType.select()

        self.header1 = FormHeader(label='Property Details', order=0.2)
        self.title = FormCharField(id="title", label="Title", map_to_column="title", order=1, validations=[NotEmpty_Validation])
        self.description = FormCharField(id="description", label="Description", map_to_column="description", order=2, show_in_list=False, validations=[NotEmpty_Validation])
        self.deal_type = FormDropdownField(id="deal_type", label="Type of Deal", map_to_column="deal_type", order=2.3,  data=deal_type_list, id_field="uuid", value_field="deal_type", validations=[NotEmpty_Validation])
        self.seperator = FormSeperator(order=2.1)

        self.header1 = FormHeader(label='Address', order=2.2)
        self.address_line_1 = FormCharField(id="address_line_1", label="Address 1", map_to_column="address_line_1", order=3, show_in_list=False)
        self.address_line_2 = FormCharField(id="address_line_2", label="Address 2", map_to_column="address_line_2", order=4, show_in_list=False)
        self.county = FormCharField(id="county", label="County", map_to_column="county", order=5, show_in_list=False, validations=[NotEmpty_Validation])
        self.city = FormCharField(id="city", label="City", map_to_column="city", order=6, show_in_list=True, validations=[NotEmpty_Validation])
        self.postcode = FormCharField(id="postcode", label="Postcode", map_to_column="postcode", order=7, show_in_list=False)
        self.show_address = FormCheckboxField(id="show_address", label="Show Address", map_to_column="show_address", order=8, show_in_list=False)
        self.bedrooms = FormDropdownField(id="bedrooms", label="Number of Bedrooms", map_to_column="bedrooms", order=9, show_in_list=False, data=bedroom_list, id_field="uuid", value_field="description", validations=[NotEmpty_Validation])

        self.header2 = FormHeader(label='Investor Details', order=9.1)
        self.sourcing_fee = FormCharField(id="sourcing_fee", label="Sourcing Fee", map_to_column="sourcing_fee", order=10, show_in_list=False)
        self.roi = FormCharField(id="roi", label="ROI", map_to_column="roi", order=11, show_in_list=False, validations=[IsPercentage_Validation])
        self.document = FormUploadField(id="document", label="Document", map_to_column="document", request=self.request, order=12, show_in_list=False, save_to_directory="./files/document")
        self.photos = FormUploadField(id="photos", label="Photos", order=13, show_in_list=False, request=self.request, allow_multiple=True, save_to_directory="./files/dealphotos")
Ejemplo n.º 3
0
 def update_deal():
     deal = Deal.get_by_id(request.form["id"])
     deal.title = request.form['title']
     deal.description = request.form["description"]
     deal.sourcing_fee = float(request.form["sourcing_fee"])
     deal.roi = float(request.form["roi"])
     deal.county = request.form['county']
     deal.city = request.form['city']
     deal.address_line_1 = request.form['address_line_1']
     deal.address_line_2 = request.form['address_line_2']
     deal.postcode = request.form['postcode']
     deal.show_address_details = bool(request.form['show_address_details'])
     if request.form["deal_type"] is not None and request.form["deal_type"] != "":
         deal.deal_type = DealType.get_by_id(request.form["deal_type"])
     deal.save()
     return redirect("/find_deal")
Ejemplo n.º 4
0
    def find_deal():
        deal_type_id = request.args.get("deal_type_id")
        filter_city = request.args.get("city")
        filter_county = request.args.get("county")
        filter_bedrooms = request.args.get("bedrooms")

        pagenr =0 if request.args.get("page") is None else  int(request.args.get("page"))
        pagesize = 100 if request.args.get("pagesize") is None else int(request.args.get("pagesize"))
        rows = Deal.filter(deal_type_id=deal_type_id, filter_city=filter_city, filter_county=filter_county)
        data = rows.paginate(pagenr, pagesize)
        deal_types = DealType.select()
        return render_template("find_deal.html",
                               data=data,
                               deal_types=deal_types,
                               cities=Deal.available_cities(),
                               counties=Deal.available_counties(),
                               records=rows.count(),
                               pagesize=pagesize,
                               bedrooms=Bedrooms.select())
Ejemplo n.º 5
0
def load_successfull_entries():
    rows = BatchCSVData.select().where(BatchCSVData.Is_Error==False, BatchCSVData.Processed == False)
    for row in rows:
        dt = DealType.get(DealType.uuid == row.DealTypeObj_id)
        dl1 = Deal.create(description=row.Description,
                          title=row.Title,
                          created=datetime.datetime.now(),
                          created_by=row.Batch.Uploaded_By,
                          deal_type=dt,
                          sourcing_fee=row.Sourcing_Fee,
                          roi=row.ROI,
                          document=None,
                          uuid=uuid.uuid4(),
                          county=row.County,
                          city=row.City,
                          address_line_1=row.Address_1,
                          address_line_2=row.Address_2,
                          postcode=row.Postcode,
                         show_address=row.Show_Address)
        row.Processed = True;
        row.Date_Processed = datetime.datetime.now()
        row.save()
Ejemplo n.º 6
0
 def on_insert(self):
     self.get_field_values_from_request()
     DealType.create(deal_type=self.deal_type.value)
Ejemplo n.º 7
0
 def on_delete(self, id):
     query = DealType.delete().where(DealType.uuid == str(id))
     query.execute()
Ejemplo n.º 8
0
 def on_edit(self, id):
     dt = DealType.get(DealType.uuid == str(id))
     return dt
Ejemplo n.º 9
0
 def on_save(self, id):
     dt = DealType.get(DealType.uuid == str(id))
     dt.deal_type = self.deal_type.value
     dt.save()
Ejemplo n.º 10
0
 def on_get_list(self):
     dt = DealType.select()
     return dt
Ejemplo n.º 11
0
 def edit_deal(id):
     return render_template("edit_deal.html",
                            data=Deal.get_by_uuid(id),
                            deal_types=DealType.get_all())
Ejemplo n.º 12
0
def setup_test_data():
    dt1 = DealType.create(deal_type="HMO")
    dt2 = DealType.create(deal_type="Land Development")
    dt3 = DealType.create(deal_type="R2R - HMO")
    dt4 = DealType.create(deal_type="R2R - SA")
    dt5 = DealType.create(deal_type="Buy to let")
    dt6 = DealType.create(deal_type="Commercial to Residentual")
    dt7 = DealType.create(deal_type="Lease Option")
    dt8 = DealType.create(deal_type="Other")
    dt9 = DealType.create(deal_type="Apartment Block")

    faq1 = FAQ.create(question="Question A", answer="Answer AA" )
    faq2 = FAQ.create(question="Question B", answer="Answer BB" )
    faq3 = FAQ.create(question="Question C", answer="Answer CC" )


    bedroom_not_applicable = Bedrooms.create(description="Not Applicable" )
    bedroomstudio = Bedrooms.create(description="Studio" )
    bedroom1 = Bedrooms.create(description="1 Bed" )
    bedroom2 = Bedrooms.create(description="2 Bed" )
    bedroom3 = Bedrooms.create(description="3 Bed" )
    bedroom4 = Bedrooms.create(description="4 Bed" )
    bedroom5 = Bedrooms.create(description="5 Bed" )
    bedroom6 = Bedrooms.create(description="6 Bed" )
    bedroom7 = Bedrooms.create(description="7 Bed" )
    bedroom8 = Bedrooms.create(description="8 Bed" )
    bedrooom_other = Bedrooms.create(description="More than 8" )

    desc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sed metus bibendum enim semper tempor vitae et neque. Integer lobortis lacus tortor. Fusce finibus hendrerit nunc sed vehicula. Sed dapibus lectus nec imperdiet faucibus. Mauris aliquet arcu nec quam aliquam, quis pharetra ipsum dapibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam imperdiet ornare purus, vitae suscipit risus cursus ac. Etiam scelerisque imperdiet nibh, non condimentum nisl aliquam non. Donec quis nunc in diam convallis vulputate sed in purus. Aliquam venenatis ultrices imperdiet. Suspendisse consectetur leo id nisl consequat, in vestibulum tortor vehicula. Vestibulum eget elit condimentum, bibendum sem luctus, venenatis mi. Nam pellentesque molestie urna ut congue."

    inv1 = User.create(name="Richard", surname="Smit", telephone="07540388001", email="*****@*****.**" ,
                       password="******", activated=True, is_admin=True, disabled=False)
    inv2 = User.create(name="John", surname="Haagensen", telephone="07540388001", email="*****@*****.**" ,
                       password="******", activated=True, disabled=True)

    dl1 = Deal.create(description=desc, title='Cheap SA', created=datetime.datetime(2018, 6, 13, 00, 00),
                      created_by=inv1, deal_type=dt1, sourcing_fee=2000, roi=10,
                      document="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg" , county="Surrey", city="Shepperton",
                      address_line_1="304 Laleham Road", address_line_2="laleham road", postcode='tw17 0jq',
                      comparables = "xxxx",
                      key_features = "Feature 1, Feature 2, Feature 3",
                      show_address=True)
    dl2 = Deal.create(description=desc, title='2 Year D2V', created=datetime.datetime.now(),
                      created_by=inv1, deal_type=dt2 , county="Berkshire", city="Reading")
    dl3 = Deal.create(description=desc, title='HMO D2V', created=datetime.datetime.now(),
                      created_by=inv2, deal_type=dt2 , county="Berkshire", city="London")

    dq1 = DealQuestion.create(question="Is this D2V?", deal=dl1.uuid , asked_by=inv1.uuid)
    dqa1 = DealQuestionAnswer.create(answer="Yes it is", deal_question=dq1.uuid , answered_by=inv2.uuid)

    dq2 = DealQuestion.create(question="Can we view the property?", deal=dl1.uuid , asked_by=inv1.uuid)
    dqa2 = DealQuestionAnswer.create(answer="No", deal_question=dq2.uuid , answered_by=inv2.uuid)

    msg = Message.create(message_from=inv2, message_to=inv1, message="hello there" )

    df = DealPhoto.create(filename="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg", deal=dl1.uuid )
    df2 = DealPhoto.create(filename="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg", deal=dl1.uuid )
    df3 = DealPhoto.create(filename="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg", deal=dl1.uuid )
    df4 = DealPhoto.create(filename="026d9108-6ec1-48b5-b7a4-ae02e2ff92e2.jpg", deal=dl1.uuid )

    fav = Favourites.create(deal=dl1.uuid , user=inv1.uuid)
    rev1 = Reviews.create(stars=3,
                          comment="test" ,
                          user=inv1.uuid)
    rev2 = Reviews.create(stars=5,
                          comment="test",
                          user=inv1.uuid)

    batch = BatchCSV.create(Filename="96249887-e751-4a1f-9b3d-05d5a24ecc46.csv" , Uploaded_By=inv1)