Beispiel #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))
Beispiel #2
0
def spotted_tree_list(request):
    trees = SpottedTree.objects.all()
    for tree in trees:
        tree.lat = geo_code(tree.address.address, tree.address.city, tree.address.state, tree.address.zip)[0]
        tree.lng = geo_code(tree.address.address, tree.address.city, tree.address.state, tree.address.zip)[1]
        tree.save()
    return render_to_response("spotted_trees.html", {'trees':trees}, context_instance=RequestContext(request))
Beispiel #3
0
def create_survey(request):
    standard_questions = Question.objects.filter(standard=True)
    if not request.method == "POST":
        form = ListRegForm()
        user_form = UserRegForm(request.POST)
        return render_to_response(
            "create_survey.html",
            {"form": form, "user_form": user_form, "standard": standard_questions},
            context_instance=RequestContext(request),
        )
    form = ListRegForm(request.POST, request.FILES)
    user_form = UserRegForm(request.POST)
    print "post"
    if not form.is_valid() or not user_form.is_valid():
        print "something not valid"
        return render_to_response(
            "create_survey.html",
            {"form": form, "user_form": user_form, "standard": standard_questions},
            context_instance=RequestContext(request),
        )
    try:
        file = request.FILES["file"]
        store_in_s3(file)
        p = PhotoUrl(url="http://roommater.s3.amazonaws.com/" + str(file))
        p.save()
        picture = p.url
    except:
        picture = ""
    # create a new user and profile
    user = User.objects.create_user(request.POST["username"], request.POST["email"], request.POST["password"])
    newprofile = UserProfile(pic=picture, user=user, name=request.POST["name"], about=request.POST["about"])
    newprofile.save()
    # log the new user in
    username = request.POST["username"]
    password = request.POST["password"]
    user = authenticate(username=username, password=password)
    login(request, user)
    # submit the survey they just made
    room = Room(
        price=request.POST["price"],
        address=request.POST["address"],
        city=request.POST["city"],
        state=request.POST["state"],
        zip=request.POST["zip"],
        about=request.POST["room_about"],
        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],
    )
    room.save()
    #    print geo_code(request.POST["address"], request.POST["city"])[0]
    submit_create_survey(request, room)
    return redirect("/dash/")
Beispiel #4
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))
Beispiel #5
0
def edit_survey(request, room):
    user_profile = request.user.get_profile()
    if request.method == "POST":
        form = EditRoomForm(request.POST)
        if form.is_valid():
            room = Room.objects.get(pk=room)
            room.price = form.cleaned_data["price"]
            room.address = form.cleaned_data["address"]
            room.city = form.cleaned_data["city"]
            room.state = form.cleaned_data["state"]
            room.zip = form.cleaned_data["zip"]
            room.about = form.cleaned_data["room_about"]
            room.lat = geo_code(room.address, room.city, room.state, room.zip)[0]
            room.lng = geo_code(room.address, room.city, room.state, room.zip)[1]
            room.save()
            return redirect("/dash/")
    else:
        form = EditRoomForm()
    return render_to_response(
        "edit_survey.html", {"user": user_profile, "form": form}, context_instance=RequestContext(request)
    )