Ejemplo n.º 1
0
def search():
    form = SearchForm()
    results = []
    if form.validate_on_submit():
        query = Deal.query.join(Property).join(Address)
        if form.line_1.data:
            query = query.filter(
                Address.line_1.like('%' + form.line_1.data + '%'))
        if form.city.data:
            query = query.filter(Address.city.like('%' + form.city.data + '%'))
        if form.state_province.data:
            query = query.filter(
                Address.state_province.like('%' + form.state_province.data +
                                            '%'))
        if form.postal_code.data:
            query = query.filter(
                Address.postal_code.like('%' + form.postal_code.data + '%'))
        results = query.all()
        if len(results) == 0:
            flash('No results found.', 'info')
    else:
        flashFormErrors(form)

    return render_template('deals/search.html',
                           title='Search',
                           results=results,
                           form=form)
Ejemplo n.º 2
0
def email(deal_id):
    deal = Deal.query.get_or_404(deal_id)
    form = MarketDealForm()
    if form.validate_on_submit():
        flash(form.body.data, 'info')
    elif len(form.errors):
        flashFormErrors(form)
    return render_template('deals/email.html',
                           title='Email',
                           deal=deal,
                           form=form)
Ejemplo n.º 3
0
def view(deal_id):
    deal = Deal.query.get_or_404(deal_id)
    form = DealForm(obj=deal)
    if form.validate_on_submit():
        form.populate_obj(deal)
        db.session.add(deal)
        db.session.commit()
        flash('Your updates have been saved.', 'info')
    elif len(form.errors):
        flashFormErrors(form)
    return render_template('deals/view.html',
                           title='View',
                           deal=deal,
                           form=form)
Ejemplo n.º 4
0
def add_criteria(contact_id):
    form = InvestmentCriteriaForm()
    if form.validate_on_submit():
        contact = Contact.query.get(contact_id)
        criteria = InvestmentCriteria()
        form.populate_obj(obj=criteria)
        contact.investment_criteria.append(criteria)
        db.session.add(contact)
        db.session.commit()
        return redirect(url_for('crm.criteria', contact_id=contact.id))
    elif len(form.errors):
        flashFormErrors(form)
    return render_template('crm/modify_criteria.html',
                           title='Criteria',
                           form=form)
Ejemplo n.º 5
0
def edit(deal_id):
    deal = Deal.query.get_or_404(deal_id)
    form = DealForm(obj=deal)
    if form.validate_on_submit():
        form.populate_obj(deal)
        deal.property.address.geocode()
        db.session.add(deal)
        db.session.commit()
        return redirect(url_for('deals.index'))
    elif len(form.errors):
        flashFormErrors(form)
    return render_template('deals/deal_form.html',
                           title='Edit',
                           form=form,
                           deal=deal)
Ejemplo n.º 6
0
def create():
    form = DealForm()
    if form.validate_on_submit():
        deal = Deal()
        deal.property = Property()
        deal.property.address = Address()
        form.populate_obj(deal)
        deal.property.address.geocode()
        current_user.deals.append(deal)
        db.session.add(current_user)
        db.session.commit()
        return redirect(url_for('deals.index'))
    elif len(form.errors):
        flashFormErrors(form)
    return render_template('deals/deal_form.html', title='Create', form=form)
Ejemplo n.º 7
0
def create():
    form = ContactForm()
    if form.validate_on_submit():
        contact = Contact()
        criteria = []
        for form_criteria in form.investment_criteria:
            if form_criteria.enabled.data:
                criteria.append(form_criteria)
        form.investment_criteria = criteria
        contact.investment_criteria = []
        form.populate_obj(obj=contact)
        current_user.contacts.append(contact)
        db.session.add(current_user)
        db.session.commit()
        return redirect(url_for('crm.view', contact_id=contact.id))
    elif len(form.errors):
        flashFormErrors(form)
    return render_template('crm/create.html', title='Dashboard', form=form)
Ejemplo n.º 8
0
def search():
    form = SearchForm()
    results = []
    if form.validate_on_submit():
        query = Contact.query.filter_by(user_id=current_user.id)
        if form.first_name.data:
            query = query.filter(
                Contact.first_name.like('%' + form.first_name.data + '%'))
        if form.last_name.data:
            query = query.filter(
                Contact.last_name.like('%' + form.last_name.data + '%'))
        results = query.all()
        if len(results) == 0:
            flash('No results found.', 'info')
    else:
        flashFormErrors(form)

    return render_template('crm/search.html',
                           title='Search',
                           form=form,
                           results=results)