Example #1
0
def Generate(request, id):
    user = UserInformation.objects.get(id=id)
    template = get_template('pdf_template.html')
    context = {
        'FirstName': user.first_name,
        'LastName': user.last_name,
        'EmailID': user.email,
        'PhoneNumber': user.phone_number,
        'Location': user.location_name,
        'Latitude': user.latitude,
        'Longitude': user.longitude,
        'DamageReported': user.damage_reported,
        'Description': user.description,
        'DroughtCondition': user.drought_condition,
        'FloodCondition': user.flood_condition,
        'CountBasinofwithdrawal': user.county_basin_withdrawal,
        'Surfacewaterwithdrawalvolume': user.surface_water_withdrawal_volume,
        'Groundwaterwithdrawalvolume': user.ground_water_withdrawal_volume,
        'Groundwaterlevel': user.ground_water_level,
        'Reportedusebysector': user.reported_use_by_sector,
        'Numberofintakes': user.number_of_intakes,
        'Surfacewaterwithdrawal': user.surface_water_withdrawal,
        'Groundwaterwithdrawal': user.ground_water_withdrawal,
        'Typeofcrop': user.type_of_crop,
        'Totalacersirrigated': user.total_acers_irrigated,
        'Totalacerspercropirrigated': user.total_acers_per_crop_irrigated,
        'Irrigationtype': user.irrigation_type,
        'Powerrequirementsandoperatingpressurerange': user.power_requirements,
        'Irrigationscheduleinformation': user.irrigation_schedule_info,
    }
    html = template.render(context)
    pdf = render_to_pdf('pdf_template.html', context)
    if pdf:
        response = HttpResponse(pdf, content_type='application/pdf')
        filename = "User_%s.pdf" % ("details")
        content = "inline; filename='%s'" % (filename)
        download = request.GET.get("download")
        if download:
            content = "attachment; filename='%s'" % (filename)
        response['Content-Disposition'] = content
        return response
    return HttpResponse("Not found")
Example #2
0
def add_user_form_submission(request):
    print("The form is submitted")
    first_name = request.POST["first_name"]
    last_name = request.POST["last_name"]
    email = request.POST["email"]
    phone_number = request.POST["phone_number"]
    location_name = request.POST["location_name"]
    latitude = request.POST["latitude"]
    longitude = request.POST["longitude"]
    damage_reported = request.POST["damage_reported"]
    description = request.POST["description"]
    drought_condition = request.POST["drought_condition"]
    flood_condition = request.POST["flood_condition"]
    county_basin_withdrawal = request.POST["county_basin_withdrawal"]
    surface_water_withdrawal_volume = request.POST[
        "surface_water_withdrawal_volume"]
    ground_water_withdrawal_volume = request.POST[
        "ground_water_withdrawal_volume"]
    ground_water_level = request.POST["ground_water_level"]
    reported_use_by_sector = request.POST["reported_use_by_sector"]
    number_of_intakes = request.POST["number_of_intakes"]
    surface_water_withdrawal = request.POST["surface_water_withdrawal"]
    ground_water_withdrawal = request.POST["ground_water_withdrawal"]
    type_of_crop = request.POST["type_of_crop"]
    total_acers_irrigated = request.POST["total_acers_irrigated"]
    total_acers_per_crop_irrigated = request.POST[
        "total_acers_per_crop_irrigated"]
    irrigation_type = request.POST["irrigation_type"]
    power_requirements = request.POST["power_requirements"]
    irrigation_schedule_info = request.POST["irrigation_schedule_info"]

    user_info = UserInformation(
        first_name=first_name,
        last_name=last_name,
        email=email,
        phone_number=phone_number,
        location_name=location_name,
        latitude=latitude,
        longitude=longitude,
        damage_reported=damage_reported,
        description=description,
        drought_condition=drought_condition,
        flood_condition=flood_condition,
        county_basin_withdrawal=county_basin_withdrawal,
        surface_water_withdrawal_volume=surface_water_withdrawal_volume,
        ground_water_withdrawal_volume=ground_water_withdrawal_volume,
        ground_water_level=ground_water_level,
        reported_use_by_sector=reported_use_by_sector,
        number_of_intakes=number_of_intakes,
        surface_water_withdrawal=surface_water_withdrawal,
        ground_water_withdrawal=ground_water_withdrawal,
        type_of_crop=type_of_crop,
        total_acers_irrigated=total_acers_irrigated,
        total_acers_per_crop_irrigated=total_acers_per_crop_irrigated,
        irrigation_type=irrigation_type,
        power_requirements=power_requirements,
        irrigation_schedule_info=irrigation_schedule_info)
    user_info.save()
    template = get_template('pdf_template.html')
    context = {
        'FirstName': first_name,
        'LastName': last_name,
        'EmailID': email,
        'PhoneNumber': phone_number,
        'Location': location_name,
        'Latitude': latitude,
        'Longitude': longitude,
        'DamageReported': damage_reported,
        'Description': description,
        'DroughtCondition': drought_condition,
        'FloodCondition': flood_condition,
        'CountBasinofwithdrawal': county_basin_withdrawal,
        'Surfacewaterwithdrawalvolume': surface_water_withdrawal_volume,
        'Groundwaterwithdrawalvolume': ground_water_withdrawal_volume,
        'Groundwaterlevel': ground_water_level,
        'Reportedusebysector': reported_use_by_sector,
        'Numberofintakes': number_of_intakes,
        'Surfacewaterwithdrawal': surface_water_withdrawal,
        'Groundwaterwithdrawal': ground_water_withdrawal,
        'Typeofcrop': type_of_crop,
        'Totalacersirrigated': total_acers_irrigated,
        'Totalacerspercropirrigated': total_acers_per_crop_irrigated,
        'Irrigationtype': irrigation_type,
        'Powerrequirementsandoperatingpressurerange': power_requirements,
        'Irrigationscheduleinformation': irrigation_schedule_info,
    }
    html = template.render(context)
    pdf = render_to_pdf('pdf_template.html', context)
    if pdf:
        response = HttpResponse(pdf, content_type='application/pdf')
        filename = "User_%s.pdf" % ("Details")
        content = "inline; filename='%s'" % (filename)
        download = request.GET.get("download")
        if download:
            content = "attachment; filename='%s'" % (filename)
        response['Content-Disposition'] = content
        return response
    return render(request, "add_user.html")