Example #1
0
def create_search_profile(request):
    if request.method == "POST":
        user_form = UserRegForm(request.POST)
        form = SearchRegForm(request.POST, request.FILES)
        if form.is_valid() and user_form.is_valid():
            # upload photo
            file = request.FILES["file"]
            store_in_s3(file)
            p = PhotoUrl(url="http://roommater.s3.amazonaws.com/" + str(file))
            p.save()
            user = User.objects.create_user(request.POST["username"], request.POST["email"], request.POST["password"])
            newprofile = UserProfile(pic=p.url, user=user, name=request.POST["name"], about=request.POST["about"])
            newprofile.save()
            username = request.POST["username"]
            password = request.POST["password"]
            user = authenticate(username=username, password=password)
            login(request, user)
            if request.REQUEST.get("next" "") != None:
                redirect_to = request.REQUEST.get("next" "")
            else:
                redirect_to = "/dash/"
            return redirect(redirect_to)
    else:
        user_form = UserRegForm()
        form = SearchRegForm()
    return render_to_response(
        "registration/login.html", {"form": form, "user_form": user_form}, context_instance=RequestContext(request)
    )
Example #2
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/")