def road_assessment_update(request, latitude, longitude):
    road_details = get_object_or_404(RoadAssessment, latitude=latitude, longitude=longitude)
    init_road = {
        "latitude": road_details.latitude,
        "longitude": road_details.longitude,
        "assessment": road_details.assessment,
    }
    if request.method == "POST":
        road_update_form = RoadAssessmentForm(request.POST)
        valid_road_update_form = road_update_form.is_valid()

        if valid_road_update_form:
            road_form_details = road_update_form.save(commit=False)
            update_r = RoadAssessment.objects.get(latitude=latitude, longitude=longitude)
            update_r.latitude = road_form_details.latitude
            update_r.longitude = road_form_details.longitude
            update_r.assessment = road_form_details.assessment

            update_r.save()
            return HttpResponseRedirect("/crisis/")
        else:
            return render_to_response(
                "assessment/road_update.html", {"road_form": RoadAssessmentForm(init_road)}, RequestContext(request)
            )

    else:
        return render_to_response(
            "assessment/road_update.html", {"road_form": RoadAssessmentForm(init_road)}, RequestContext(request)
        )
def road_assessment(request):

    """
    View to read the condition of a road or path in a disaster zone.

    """

    if request.method == "POST":
        road_form = RoadAssessmentForm(request.POST)
        comment_form = CommentForm(request.POST)
        valid_road_form = road_form.is_valid()
        valid_comment_form = comment_form.is_valid()

        if valid_road_form and valid_comment_form:
            comment_form_data = comment_form.save(commit=False)
            _comment_id = randint(1, 1000)
            comment_form_data.comment_id = _comment_id
            comment_form_data.user_id = get_object_or_404(User, user_id=request.session["user_id"])
            comment_form_data.save()
            road_form_data = road_form.save(commit=False)
            road_form_data.gid = generate_gid()
            road_form_data.comment = get_object_or_404(Comment, comment_id=_comment_id)
            road_form_data.save()
            return HttpResponseRedirect("/crisis/")
        else:
            return render_to_response(
                "assessment/road.html",
                {"road_form": RoadAssessmentForm(), "comment_form": CommentForm()},
                RequestContext(request),
            )
    else:
        initial = {}
        if request.GET.get("q") is not None:
            lnglat = request.GET.get("q").split(",")
            initial = {"latitude": float(lnglat[0]), "longitude": float(lnglat[1])}

        return render_to_response(
            "assessment/road.html",
            {"road_form": RoadAssessmentForm(initial), "comment_form": CommentForm()},
            RequestContext(request),
        )
예제 #3
0
def road_assessment_update(request, latitude, longitude):
    road_details = get_object_or_404(RoadAssessment,
                                     latitude=latitude,
                                     longitude=longitude)
    init_road = { 'latitude' : road_details.latitude , 'longitude' : road_details.longitude, \
            'assessment' : road_details.assessment }
    if request.method == 'POST':
        road_update_form = RoadAssessmentForm(request.POST)
        valid_road_update_form = road_update_form.is_valid()

        if valid_road_update_form:
            road_form_details = road_update_form.save(commit=False)
            update_r = RoadAssessment.objects.get(latitude=latitude,
                                                  longitude=longitude)
            update_r.latitude = road_form_details.latitude
            update_r.longitude = road_form_details.longitude
            update_r.assessment = road_form_details.assessment

            update_r.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response('assessment/road_update.html', { 'road_form' : RoadAssessmentForm(init_road)}\
                    , RequestContext(request))

    else:
        return render_to_response('assessment/road_update.html', { 'road_form' : RoadAssessmentForm(init_road)}\
                , RequestContext(request))
예제 #4
0
def road_assessment_update(request, latitude, longitude):
    road_details = get_object_or_404(RoadAssessment, latitude = latitude ,longitude = longitude)
    init_road = { 'latitude' : road_details.latitude , 'longitude' : road_details.longitude, \
            'assessment' : road_details.assessment }
    if request.method == 'POST':
        road_update_form =  RoadAssessmentForm(request.POST)
        valid_road_update_form = road_update_form.is_valid()

        if valid_road_update_form:
            road_form_details = road_update_form.save(commit = False)
            update_r = RoadAssessment.objects.get(latitude = latitude, longitude = longitude)
            update_r.latitude = road_form_details.latitude
            update_r.longitude = road_form_details.longitude
            update_r.assessment = road_form_details.assessment

            update_r.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response('assessment/road_update.html', { 'road_form' : RoadAssessmentForm(init_road)}\
                    , RequestContext(request))

    else:
        return render_to_response('assessment/road_update.html', { 'road_form' : RoadAssessmentForm(init_road)}\
                , RequestContext(request))
예제 #5
0
def road_assessment(request):
    """
    View to read the condition of a road or path in a disaster zone.

    """

    if request.method == 'POST':
        road_form = RoadAssessmentForm(request.POST)
        comment_form = CommentForm(request.POST)
        valid_road_form = road_form.is_valid()
        valid_comment_form = comment_form.is_valid()

        if valid_road_form and valid_comment_form:
            comment_form_data = comment_form.save(commit=False)
            _comment_id = randint(1, 1000)
            comment_form_data.comment_id = _comment_id
            comment_form_data.user_id = get_object_or_404(
                User, user_id=request.session['user_id'])
            comment_form_data.save()
            road_form_data = road_form.save(commit=False)
            road_form_data.gid = generate_gid()
            road_form_data.comment = get_object_or_404(Comment,
                                                       comment_id=_comment_id)
            road_form_data.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response('assessment/road.html', {'road_form':RoadAssessmentForm(), \
                    'comment_form':CommentForm()},RequestContext(request))
    else:
        initial = {}
        if request.GET.get('q') is not None:
            lnglat = request.GET.get('q').split(",")
            initial = {
                'latitude': float(lnglat[0]),
                'longitude': float(lnglat[1]),
            }

        return render_to_response('assessment/road.html', {'road_form':RoadAssessmentForm(initial), \
                'comment_form':CommentForm()}, RequestContext(request))