def track(request): if is_loggedin(request): dynamodb = boto3.resource('dynamodb') table_order = dynamodb.Table('Order') table_crop = dynamodb.Table('cropinfo') table_user = dynamodb.Table('user') cur = request.session['email'] is_admin = False users = table_user.scan( FilterExpression=Attr('email').eq(cur) )['Items'] try: if users[0]['is_admin']: is_admin = True except: is_admin = False if not is_admin: order_items = table_order.scan( FilterExpression=Attr('email').eq(cur) )['Items'] else: order_items = table_order.scan( FilterExpression=Attr('is_purchased').eq(True) )['Items'] # print(order_items) crop_orders = [] crop_order_id = [] corps = table_crop.scan()['Items'] # print(corps[0]['cr']) for i in order_items: crops = table_crop.scan( FilterExpression=Attr('crop_id').eq(str(i['crop_id'])) )['Items'][0] # print(crops) if crops['crop_id'] not in crop_order_id: crop_order_id.append(crops['crop_id']) crop_orders.append(crops) # print(crop_orders) context = { 'orders':order_items, 'is_admin':is_admin, 'crop_orders':crop_orders } return render(request,'tracking/tracking.html',context) else: return redirect('registration:login_display')
def get_address(request): if is_loggedin(request): email = request.session['email'] dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('user') response = table.scan(FilterExpression=Attr('email').eq(email)) if (len(response['Items']) != 0): user = response['Items'][0] else: user = None address = user['address'] return render(request, 'geosearch/auto_complete.html', {'address': address}) else: return redirect('registration:login_display')
def gmaps(request): if is_loggedin(request): address = request.POST.get('address') geolocator = Nominatim(user_agent="farmup01") location = geolocator.geocode(address) print(location) center = (location.latitude, location.longitude) new_location = geolocator.reverse(str(location.latitude) + ',' + str(location.longitude), exactly_one=True) address = new_location.raw['address'] print(address) city = address.get('city', '') state = address.get('state', '') if not city: city = address.get('village', '') if not city: city = address.get('town', '') dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('LandInfo') response = table.scan(FilterExpression=Attr('city').eq(city)) if (len(response['Items']) > 0): locs = response['Items'] display_lands = [] for land in locs: position = (float(land['latitude']), float(land['longitude'])) dist = geodesic(center, position).kilometers lat = position[0] lng = position[1] display_lands.append({ 'lat': lat, 'lng': lng, 'dist': dist, 'land_id': land['land_id'] }) print(display_lands) return render( request, 'geosearch/g_search.html', { 'lat': center[0], 'lng': center[1], 'display_lands': json.dumps(display_lands) }) else: return redirect('registration:login_display')
def buyingpage(request): if not is_loggedin(request): return redirect('home') else: dynamodb = boto3.resource('dynamodb') crop_table = dynamodb.Table('cropinfo') order_table = dynamodb.Table('Order') responses = order_table.scan( FilterExpression=Attr('email').eq(request.session['email']) & Attr('is_purchased').eq(False)) order_ids_cr = [] order_ids_fr = [] for i in responses['Items']: if i['type'] == 'crops': order_ids_cr.append(str(i['crop_id'])) if i['type'] == 'fertilizer': order_ids_fr.append(str(i['crop_id'])) crop_table_elements = crop_table.scan()['Items'] crop_id = [] crop_name = [] crop_cost = [] crop_amount = [] crop_image_link = [] for i in range(len(crop_table_elements)): crop_id.append(crop_table_elements[i]['crop_id']) crop_name.append(crop_table_elements[i]['name']) crop_cost.append(crop_table_elements[i]['cost']) crop_amount.append(crop_table_elements[i]['stock']) crop_image_link.append(crop_table_elements[i]['image_link']) crop_info = zip(crop_id, crop_name, crop_cost, crop_amount, crop_image_link) context = {'crop_info': crop_info, 'order_ids': order_ids_cr} return render(request, 'shopping_cart/shop.html', context)
def dashboardfarmer(request): dynamodb = boto3.resource('dynamodb') #farmer_id="1e25388fde8290dc286a6164fa2d97e551b53498dcbf7bc378eb1f178" if is_loggedin(request): email = request.session['email'] table = dynamodb.Table('user') response = table.scan(FilterExpression=Attr('email').eq(email)) farmer_id = response['Items'][0]['farmer_id'] table = dynamodb.Table('FarmerInfo') response = table.scan(FilterExpression=Attr('farmer_id').eq(farmer_id)) #print(response) if response['Count'] == 1: land_id = response['Items'][0]['land_working'] lands_worked = response['Items'][0]['lands_worked'] #print(land_id) land_working = land_id table = dynamodb.Table('LandInfo') response = table.scan(FilterExpression=Attr('land_id').eq(land_id)) #print(response) if land_id != "" and lands_worked == {0}: lid = response['Items'][0]['land_id'] #print(lid) toc = response['Items'][0]['type_of_crop'] wd = response['Items'][0]['wages_description'] lpc = response['Items'][0]['land_pin_code'] la = response['Items'][0]['land_area'] tos = response['Items'][0]['type_of_soil'] lat = response['Items'][0]['latitude'] logt = response['Items'][0]['longitude'] city = response['Items'][0]['city'] state = response['Items'][0]['state'] d = { 'lid': lid, 'toc': toc, 'wd': wd, 'lpc': lpc, 'la': la, 'tos': tos, 'lat': lat, 'lgt': logt, 'city': city, 'state': state } #print(lands_worked) return render(request, 'farmerandlandlord/dashboardfarmer.html', { 'd': d, 'lwg': land_working }) if lands_worked != {0} and land_id == "": t = {} c = 0 for k in lands_worked: new2 = table.scan( FilterExpression=Attr('land_id').eq(str(k))) #print(new2) if new2['Count'] == 1: c += 1 lid = new2['Items'][0]['land_id'] toc = new2['Items'][0]['type_of_crop'] wd = new2['Items'][0]['wages_description'] lpc = new2['Items'][0]['land_pin_code'] la = new2['Items'][0]['land_area'] tos = new2['Items'][0]['type_of_soil'] t[k] = { 'lid': lid, 'toc': toc, 'wd': wd, 'lpc': lpc, 'la': la, 'tos': tos } print(t) return render(request, 'farmerandlandlord/dashboardfarmer.html', { 't': t, 'lwg': land_working, 'c': c }) #print(d) if lands_worked != {0} and land_id != "": lid = response['Items'][0]['land_id'] #print(lid) toc = response['Items'][0]['type_of_crop'] wd = response['Items'][0]['wages_description'] lpc = response['Items'][0]['land_pin_code'] la = response['Items'][0]['land_area'] tos = response['Items'][0]['type_of_soil'] lat = response['Items'][0]['latitude'] logt = response['Items'][0]['longitude'] city = response['Items'][0]['city'] state = response['Items'][0]['state'] d = { 'lid': lid, 'toc': toc, 'wd': wd, 'lpc': lpc, 'la': la, 'tos': tos, 'lat': lat, 'lgt': logt, 'city': city, 'state': state } t = {} for k in lands_worked: new2 = table.scan( FilterExpression=Attr('land_id').eq(str(k))) #print(new2) if new2['Count'] == 1: lid = new2['Items'][0]['land_id'] toc = new2['Items'][0]['type_of_crop'] wd = new2['Items'][0]['wages_description'] lpc = new2['Items'][0]['land_pin_code'] la = new2['Items'][0]['land_area'] tos = new2['Items'][0]['type_of_soil'] t[k] = { 'lid': lid, 'toc': toc, 'wd': wd, 'lpc': lpc, 'la': la, 'tos': tos } print(t) return render(request, 'farmerandlandlord/dashboardfarmer.html', { 'd': d, 't': t, 'lwg': land_working, 'c': c }) else: return render(request, 'farmerandlandlord/dashboardfarmer.html') else: return redirect('registration:login_display')
def dashboardlandlord(request): dynamodb = boto3.resource('dynamodb') if is_loggedin(request): email = request.session['email'] table = dynamodb.Table('user') response = table.scan(FilterExpression=Attr('email').eq(email)) land_lord_id = response['Items'][0]['land_lord_id'] table = dynamodb.Table('Landlord') #land_lord_id="2e25388fde8290dc286a6164fa2d97e551b53498dcbf7bc378eb1f1780" #pincode=522006 response = table.scan( FilterExpression=Attr('land_lord_id').eq(land_lord_id)) if response['Count'] == 1: lands_owned = response['Items'][0]['lands_owned'] d = {} table = dynamodb.Table('LandInfo') c = 0 lcrop = [] f = 0 for k in lands_owned: new2 = table.scan(FilterExpression=Attr('land_id').eq(str(k))) #print(new2) if new2['Count'] == 1: c += 1 lid = new2['Items'][0]['land_id'] toc = new2['Items'][0]['type_of_crop'] if toc not in lcrop: lcrop.append(toc) wd = new2['Items'][0]['wages_description'] lpc = new2['Items'][0]['land_pin_code'] la = new2['Items'][0]['land_area'] tos = new2['Items'][0]['type_of_soil'] fw = new2['Items'][0]['farmers_working'] city = new2['Items'][0]['city'] state = new2['Items'][0]['state'] img_url = new2['Items'][0]['img_url'] for x in fw: if x != 0: f += 1 d[k] = { 'lid': lid, 'toc': toc, 'wd': wd, 'lpc': lpc, 'la': la, 'tos': tos, 'city': city, 'state': state, 'image': img_url } #print(c,len(l),f) table = dynamodb.Table('FarmerRequest') response = table.scan() if response['Count'] > 0: l = [] for i in range(response['Count']): l.append(response['Items'][i]['land_id']) table = dynamodb.Table('Landlord') response2 = table.scan( FilterExpression=Attr('land_lord_id').eq(land_lord_id)) r = 0 for i in response2['Items'][0]['lands_owned']: if str(i) in l: r += 1 print(r, l) return render(request, 'farmerandlandlord/dashboardlandlord.html', { 'd': d, 'c': c, 't': len(lcrop), 'f': f, 'r': r }) else: return render(request, 'farmerandlandlord/dashboardlandlord.html') else: return redirect('registration:login_display')