def resource(request): """ View to enter resource details into the crisis communicator. This help the response personal \ to find out the location or direct the refugees as per the updates. """ if request.method == 'POST': resource_form = ResourceForm(request.POST) comment_form = CommentForm(request.POST) valid_resource_form = resource_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_resource_form and valid_comment_form: if request.POST['quantity'] != '' and request.POST[ 'req_quantity'] != '': quantity = int(request.POST['quantity']) req_quantity = int(request.POST['req_quantity']) else: quantity = 0 req_quantity = 0 comment_form_data = comment_form.save(commit=False) _comment_id = randint(1, 10000) 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() resource_form_data = resource_form.save(commit=False) supply_obj = get_object_or_404( Supply, pk=update_supply(quantity, str(request.POST['measurement']))) required_supply_obj = get_object_or_404( Supply, pk=update_supply(req_quantity, str(request.POST['req_measurement']))) resource_form_data.supply = supply_obj resource_form_data.supply_requirement = required_supply_obj resource_form_data.gid = generate_gid() resource_form_data.comment = get_object_or_404( Comment, comment_id=_comment_id) resource_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('resource/resource.html', {'comment_form':comment_form,\ 'resource_form':resource_form}, 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('resource/resource.html', {'comment_form':CommentForm(),\ 'resource_form':ResourceForm(initial)}, RequestContext(request))
def resource(request): """ View to enter resource details into the crisis communicator. This help the response personal \ to find out the location or direct the refugees as per the updates. """ if request.method == 'POST': resource_form = ResourceForm(request.POST) comment_form = CommentForm(request.POST) valid_resource_form = resource_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_resource_form and valid_comment_form: if request.POST['quantity'] != '' and request.POST['req_quantity'] != '': quantity = int(request.POST['quantity']) req_quantity = int(request.POST['req_quantity']) else: quantity = 0 req_quantity = 0 comment_form_data = comment_form.save(commit=False) _comment_id = randint(1,10000) 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() resource_form_data = resource_form.save(commit=False) supply_obj = get_object_or_404(Supply, pk=update_supply(quantity, str(request.POST['measurement']))) required_supply_obj = get_object_or_404(Supply, pk=update_supply(req_quantity, str(request.POST['req_measurement']))) resource_form_data.supply = supply_obj resource_form_data.supply_requirement = required_supply_obj resource_form_data.gid = generate_gid() resource_form_data.comment = get_object_or_404(Comment, comment_id=_comment_id) resource_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('resource/resource.html', {'comment_form':comment_form,\ 'resource_form':resource_form}, 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('resource/resource.html', {'comment_form':CommentForm(),\ 'resource_form':ResourceForm(initial)}, RequestContext(request))
def postComment(request): form = CommentForm(request.POST) if form.is_valid(): comment = form.cleaned_data['comment'] post_id = form.cleaned_data['post'] dt = datetime.now() CommentModel(comment=comment, username=request.session['username'], post=post_id, datetime=dt).save() return render( request, "wall.html", {"posts": getAllPostsByUser(request.session['username'])})
def crime(request): """ View to report crime in a disaster area. """ if request.method == "POST": crime_form = CrimeForm(request.POST) comment_form = CommentForm(request.POST) valid_crime_form = crime_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_comment_form and valid_crime_form: comment_form_data = comment_form.save(commit=False) _comment_id = randint(1, 1000) # should we replace with some other assignment 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() crime_form_data = crime_form.save(commit=False) crime_form_data.gid = generate_gid() crime_form_data.comment = get_object_or_404(Comment, comment_id=_comment_id) crime_form_data.save() return HttpResponseRedirect("/crisis/") else: return render_to_response( "assessment/crime.html", {"crime_form": crime_form, "comment_form": comment_form}, 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/crime.html", {"crime_form": CrimeForm(initial), "comment_form": CommentForm()}, 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), )
def emergency(request): """ View to report emergency situtation that occurs during a disaster. """ if request.method == "POST": emergency_form = EmergencyForm(request.POST) comment_form = CommentForm(request.POST) valid_emergency_form = emergency_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_emergency_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() emergency_form_data = emergency_form.save(commit=False) emergency_form_data.gid = generate_gid() emergency_form_data.comment = get_object_or_404(Comment, comment_id=_comment_id) emergency_form_data.save() return HttpResponseRedirect("/crisis/") else: return render_to_response( "assessment/emergency.html", {"emergency_form": emergency_form, "comment_form": comment_form}, 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/emergency.html", {"emergency_form": EmergencyForm(initial), "comment_form": CommentForm()}, RequestContext(request), )
def crime(request): """ View to report crime in a disaster area. """ if request.method == 'POST': crime_form = CrimeForm(request.POST) comment_form = CommentForm(request.POST) valid_crime_form = crime_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_comment_form and valid_crime_form: comment_form_data = comment_form.save(commit=False) _comment_id = randint( 1, 1000) # should we replace with some other assignment 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() crime_form_data = crime_form.save(commit=False) crime_form_data.gid = generate_gid() crime_form_data.comment = get_object_or_404(Comment, comment_id=_comment_id) crime_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('assessment/crime.html', {'crime_form':crime_form,\ 'comment_form':comment_form},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/crime.html', {'crime_form':CrimeForm(initial),\ 'comment_form':CommentForm()},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))
def emergency(request): """ View to report emergency situtation that occurs during a disaster. """ if request.method == 'POST': emergency_form = EmergencyForm(request.POST) comment_form = CommentForm(request.POST) valid_emergency_form = emergency_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_emergency_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() emergency_form_data = emergency_form.save(commit=False) emergency_form_data.gid = generate_gid() emergency_form_data.comment = get_object_or_404( Comment, comment_id=_comment_id) emergency_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('assessment/emergency.html',{'emergency_form':emergency_form,\ 'comment_form':comment_form}, 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/emergency.html', {'emergency_form':EmergencyForm(initial),\ 'comment_form':CommentForm()}, RequestContext(request))
def emergency(request): """ View to report emergency situtation that occurs during a disaster. """ if request.method == 'POST': emergency_form = EmergencyForm(request.POST) comment_form = CommentForm(request.POST) valid_emergency_form = emergency_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_emergency_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() emergency_form_data = emergency_form.save(commit=False) emergency_form_data.gid = generate_gid() emergency_form_data.comment = get_object_or_404(Comment, comment_id=_comment_id) emergency_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('assessment/emergency.html',{'emergency_form':emergency_form,\ 'comment_form':comment_form}, 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/emergency.html', {'emergency_form':EmergencyForm(initial),\ 'comment_form':CommentForm()}, RequestContext(request))
def missing(request): """ The view is to file missing person, in the diseaster area. """ if request.method == 'POST': person_form = PersonForm(request.POST) missing_form = MissingForm(request.POST) comment_form = CommentForm(request.POST) valid_person_form = person_form.is_valid() valid_missing_form = missing_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_person_form and valid_missing_form and valid_comment_form: person_form_data = person_form.save() missing_form_data = missing_form.save(commit=False) missing_form_data.gid = generate_gid() missing_form_data.person_id = get_object_or_404(Person, person_id= \ person_form_data.person_id) 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() missing_form_data.comment = get_object_or_404( Comment, comment_id=_comment_id) missing_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('person/missing.html', {'person_form': person_form,\ 'missing_form':missing_form, 'comment_form':\ comment_form, 'error':person_form, 'error1':missing_form, 'error2':comment_form},RequestContext(request)) else: return render_to_response('person/missing.html', {'person_form': PersonForm(),\ 'missing_form':MissingForm(), 'comment_form': \ CommentForm()}, RequestContext(request))
def missing(request): """ The view is to file missing person, in the diseaster area. """ if request.method == 'POST': person_form = PersonForm(request.POST) missing_form = MissingForm(request.POST) comment_form = CommentForm(request.POST) valid_person_form = person_form.is_valid() valid_missing_form = missing_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_person_form and valid_missing_form and valid_comment_form: person_form_data = person_form.save() missing_form_data = missing_form.save(commit=False) missing_form_data.gid = generate_gid() missing_form_data.person_id = get_object_or_404(Person, person_id= \ person_form_data.person_id) 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() missing_form_data.comment = get_object_or_404(Comment, comment_id=_comment_id) missing_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('person/missing.html', {'person_form': person_form,\ 'missing_form':missing_form, 'comment_form':\ comment_form, 'error':person_form, 'error1':missing_form, 'error2':comment_form},RequestContext(request)) else: return render_to_response('person/missing.html', {'person_form': PersonForm(),\ 'missing_form':MissingForm(), 'comment_form': \ CommentForm()}, RequestContext(request))