Esempio n. 1
0
def tree_by_owner(request):
    if request.method == 'POST':
        form = TreeByOwnerForm(request.POST)
        house_form = HouseForm(request.POST)
        if form.is_valid() and house_form.is_valid():
            type = form.cleaned_data['type']
            owner = house_form.cleaned_data['owner']
            owner_email = house_form.cleaned_data['owner_email']
            owner_phone = house_form.cleaned_data['owner_phone']
            yard_location = form.cleaned_data['yard_location']
            height = form.cleaned_data['height']
            age = form.cleaned_data['age']
            production = form.cleaned_data['production']
            sprayed = form.cleaned_data['sprayed']
            ripen_month = form.cleaned_data['ripen_month']
            reference = house_form.cleaned_data['reference']
            reference_email = house_form.cleaned_data['reference_email']
            comments = form.cleaned_data['comments']
            lat=geo_code(request.POST["address"], request.POST["city"], request.POST['state'], request.POST['zip'])[0]
            lng = geo_code(request.POST["address"], request.POST["city"], request.POST['state'], request.POST['zip'])[1]
            new_house = House(address=request.POST["address"], city=request.POST["city"], state=request.POST['state'], zip=request.POST['zip'], owner=owner, owner_email=owner_email, owner_phone=owner_phone, reference=reference, reference_email=reference_email, lat=lat,lng=lng)
            new_house.save()
            new_tree = Tree(type=type, house=new_house, yard_location=yard_location, height=height, age=age, production=production, sprayed=sprayed,ripen_month=ripen_month, comments=comments)
            new_tree.save()
            return redirect("/tree_list/")
    else:
        form = TreeByOwnerForm()
        house_form = HouseForm()
    return render_to_response("tree_by_owner.html", {'form':form, 'house_form':house_form}, context_instance=RequestContext(request))
Esempio n. 2
0
def index(page = 1):
    form = HouseForm()
    if form.validate_on_submit():
        language = guessLanguage(form.house.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        house = House(body = form.house.data,
            timestamp = datetime.utcnow(),
            author = g.user,
            language = language)
        db.session.add(house)
        db.session.commit()
        flash(gettext('Your house is now live!'))
        return redirect(url_for('index'))
    houses = g.user.followed_houses().paginate(page, POSTS_PER_PAGE, False)
    return render_template('index.html',
        title = 'Home',
        form = form,
        houses = houses)
Esempio n. 3
0
def house(request):
    if request.method == 'POST':
        form = HouseForm(request.POST)
        formset = TreeFormSet(request.POST, prefix='tree')
        if form.is_valid() and formset.is_valid():
            house = form.save()
            house.lat = geo_code(house.address, house.city, house.state, house.zip)[0]
            house.lng = geo_code(house.address, house.city, house.state, house.zip)[1]            
            house.save()
            for f in formset:
                try:
                    new_tree = Tree(type=f.cleaned_data['type'], yard_location =f.cleaned_data['yard_location'], height=f.cleaned_data['height'], age = f.cleaned_data['age'], house=house)
                    new_tree.save()
                except:
                    pass
            return redirect('/')
    else:
        form = HouseForm()
        formset = TreeFormSet(prefix='tree')
    return render_to_response("house.html", {'form':form, 'formset':formset}, context_instance=RequestContext(request))