# Path: post/models.py
# POST_CATEGORIES = {
# 	1: "Crop Disease/Problems",
# 	2: "Climate Related",
# 	3: "Others",
# }
# 
# Path: User/models.py
# def check_if_auth_user(request):
# 	if (request.session is not None) and request.session.has_key("user_mail_id"):
# 		return request.session["user_mail_id"]
# 	else:
# 		return None


from django.shortcuts import render, get_object_or_404, redirect
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.db.models import Count
from django.db import connection, transaction
from post.models import POST_CATEGORIES
from User.models import check_if_auth_user
from collections import namedtuple

	3 : """
		SELECT name as CropName, family as Family FROM crop_crop 
		WHERE `crop_crop`.'name' LIKE %s or 
		`crop_crop`.'family' LIKE %s or `crop_crop`.'crop_id' = %s""",

	4 : """
		SELECT name as Name, user_id as Email FROM User_farmer 
		WHERE `User_farmer`.'location_id' = %s""",

	5 : """
		SELECT `crop_crop`.name as CropName, `crop_crop`.family as Family,
				`User_farmer`.name as FarmerName, `User_farmer`.'user_id' as Email, 
				`crop_disease`.name as Disease, `crop_disease`.category as Category
		FROM crop_crop 
		INNER JOIN `crop_cropfarmer` ON `crop_cropfarmer`.'crop_id' = `crop_crop`.'crop_id'
		INNER JOIN `User_farmer` ON `User_farmer`.'auto_id' = `crop_cropfarmer`.'farmer_id'
		INNER JOIN `crop_disease` ON `crop_disease`.'dis_id' = `crop_cropfarmer`.'disease_id'
		""",

	6 : """
		SELECT `crop_fertilizer`.'name' as Fertilizer, `crop_nutrient`.'name' as Nutrient, `crop_nutrient`.'nut_type' as NutrientType 
		FROM crop_fertiprovide
		INNER JOIN crop_nutrient ON `crop_fertiprovide`.nutrient_id = `crop_nutrient`.'nut_id'
		INNER JOIN crop_fertilizer ON `crop_fertiprovide`.ferti_id = `crop_fertilizer`.'ferti_id'
		ORDER BY Fertilizer""",
}

# Create your views here.
def index_page(request):	

# Path: post/models.py
# POST_CATEGORIES = {
# 	1: "Crop Disease/Problems",
# 	2: "Climate Related",
# 	3: "Others",
# }
# 
# Path: User/models.py
# def check_if_auth_user(request):
# 	if (request.session is not None) and request.session.has_key("user_mail_id"):
# 		return request.session["user_mail_id"]
# 	else:
# 		return None


# Path: home/views.py
from django.shortcuts import render, get_object_or_404, redirect
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.db.models import Count
from django.db import connection, transaction
from post.models import POST_CATEGORIES
from User.models import check_if_auth_user
from collections import namedtuple


	3 : """
		SELECT name as CropName, family as Family FROM crop_crop 
		WHERE `crop_crop`.'name' LIKE %s or 
		`crop_crop`.'family' LIKE %s or `crop_crop`.'crop_id' = %s""",

	4 : """
		SELECT name as Name, user_id as Email FROM User_farmer 
		WHERE `User_farmer`.'location_id' = %s""",

	5 : """
		SELECT `crop_crop`.name as CropName, `crop_crop`.family as Family,
				`User_farmer`.name as FarmerName, `User_farmer`.'user_id' as Email, 
				`crop_disease`.name as Disease, `crop_disease`.category as Category
		FROM crop_crop 
		INNER JOIN `crop_cropfarmer` ON `crop_cropfarmer`.'crop_id' = `crop_crop`.'crop_id'
		INNER JOIN `User_farmer` ON `User_farmer`.'auto_id' = `crop_cropfarmer`.'farmer_id'
		INNER JOIN `crop_disease` ON `crop_disease`.'dis_id' = `crop_cropfarmer`.'disease_id'
		""",

	6 : """
		SELECT `crop_fertilizer`.'name' as Fertilizer, `crop_nutrient`.'name' as Nutrient, `crop_nutrient`.'nut_type' as NutrientType 
		FROM crop_fertiprovide
		INNER JOIN crop_nutrient ON `crop_fertiprovide`.nutrient_id = `crop_nutrient`.'nut_id'
		INNER JOIN crop_fertilizer ON `crop_fertiprovide`.ferti_id = `crop_fertilizer`.'ferti_id'
		ORDER BY Fertilizer""",
}

# Create your views here.
def index_page(request):	

	check = check_if_auth_user(request)