# Path: ifiltr_site/models.py
# class clickThrough(models.Model):
#   person = models.ForeignKey(Person)
#   item = models.URLField()
# 
# class Category(models.Model):
#   parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.SET_NULL)
#   name = models.CharField(max_length=50)
#   depth = models.IntegerField()


from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound, HttpResponseBadRequest
from django.shortcuts import render_to_response
from django.template import RequestContext
from ifiltr_site.models import clickThrough, Category
import time, json
  return render_to_response('ifiltr/contacts_partnerships.html', 
    {}, 
    context_instance=RequestContext(request))

def search(request):
  required = ['q']
  optional = ['brands', 'minPrice', 'maxPrice', 'startIndex', 'maxResults']
  for param in required:
    if param not in request.GET:
      return HttpResponseBadRequest(param + " was not found in request.")
  
  params = {}
  for param in optional:
    if param in request.GET:
      params[param] = request.GET[param]
  
  return render_to_response('ifiltr/results.html', 
      {'title':'Search Results',
       'pagename':'results'}, 
      context_instance=RequestContext(request))

def goToItem(request):
  thisClick = clickThrough(person=request.GET['person'], item=request.GET['url'])
  thisClick.save()
  return HttpResponseRedirect(thisClick.item)

def getCategories(request):
  if 'parent' not in request.GET:
    categories = Category.objects.filter(parent__exact = None)
  else:

# Path: ifiltr_site/models.py
# class clickThrough(models.Model):
#   person = models.ForeignKey(Person)
#   item = models.URLField()
# 
# class Category(models.Model):
#   parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.SET_NULL)
#   name = models.CharField(max_length=50)
#   depth = models.IntegerField()


# Path: ifiltr_site/views.py
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound, HttpResponseBadRequest
from django.shortcuts import render_to_response
from django.template import RequestContext
from ifiltr_site.models import clickThrough, Category
import time, json

  return render_to_response('ifiltr/contacts_partnerships.html', 
    {}, 
    context_instance=RequestContext(request))

def search(request):
  required = ['q']
  optional = ['brands', 'minPrice', 'maxPrice', 'startIndex', 'maxResults']
  for param in required:
    if param not in request.GET:
      return HttpResponseBadRequest(param + " was not found in request.")
  
  params = {}
  for param in optional:
    if param in request.GET:
      params[param] = request.GET[param]
  
  return render_to_response('ifiltr/results.html', 
      {'title':'Search Results',
       'pagename':'results'}, 
      context_instance=RequestContext(request))

def goToItem(request):
  thisClick = clickThrough(person=request.GET['person'], item=request.GET['url'])
  thisClick.save()
  return HttpResponseRedirect(thisClick.item)

def getCategories(request):
  if 'parent' not in request.GET:
    categories = Category.objects.filter(parent__exact = None)
  else:

    categories = Category.objects.filter(parent__name__exact = request.GET['parent'],