# Path: ml/models.py
# class machine_learning_model(models.Model):
#     title = models.CharField(unique=True, max_length=100)
#     type = models.CharField(max_length=10,
#                             choices=(
#                                 ('logistic', 'logistic'), ('linear', 'linear'),
#                                 ('tree', 'tree')),
#                             default='None')
#     query = models.ForeignKey('website.Query')
#     target_column = models.CharField(max_length=100)
# 
#     class Meta:
#         unique_together = ['query', 'target_column', 'type']
# 
#     def __str__(self):
#         return '%s %s %s' % (self.title, self.type, self.target_column)
# 
#     # TODO make a validation method to validate columns existance


from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.contrib.admin.views.decorators import staff_member_required
from django.template import RequestContext
from django.contrib.auth.models import User
from django.db.models import Q
from itertools import chain
from ml.models import machine_learning_model
from date_time_encoder import DateTimeEncoder
import json
import time
import logging
import traceback
import favit.models
import query
import models
import sql_manager
    return HttpResponse(
        json.dumps(return_data, cls=DateTimeEncoder),
        content_type="application/json")


@login_required
def query_view(request, query_ids, type='query', **kwargs):
    query_id_array = query_ids.split(',')
    # TODO filter to make sure only this applies to queries which exist
    query_list = [m for m in models.Query.objects.filter(
        id__in=query_id_array)]
    # Get Favorites
    # TODO get rid of copy paste job here with queries
    user = User.objects.get(username=request.user)
    query_favorites = favit.models.Favorite.objects.for_user(
        user, model=models.Query)
    query_fav_dict = dict([(i.target_object_id, i) for i in query_favorites])

    replacement_dict = {}
    json_get = {}
    for q in query_list:
        if q.id in query_fav_dict:
            setattr(q, 'fav', True)
        else:
            setattr(q, 'fav', False)

        lq = query.LoadQuery(
            query_id=q.id,
            user=request.user,
            parameters=request.GET.dict())

# Path: ml/models.py
# class machine_learning_model(models.Model):
#     title = models.CharField(unique=True, max_length=100)
#     type = models.CharField(max_length=10,
#                             choices=(
#                                 ('logistic', 'logistic'), ('linear', 'linear'),
#                                 ('tree', 'tree')),
#                             default='None')
#     query = models.ForeignKey('website.Query')
#     target_column = models.CharField(max_length=100)
# 
#     class Meta:
#         unique_together = ['query', 'target_column', 'type']
# 
#     def __str__(self):
#         return '%s %s %s' % (self.title, self.type, self.target_column)
# 
#     # TODO make a validation method to validate columns existance


# Path: website/views.py
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.contrib.admin.views.decorators import staff_member_required
from django.template import RequestContext
from django.contrib.auth.models import User
from django.db.models import Q
from itertools import chain
from ml.models import machine_learning_model
from date_time_encoder import DateTimeEncoder
import json
import time
import logging
import traceback
import favit.models
import query
import models
import sql_manager

    return HttpResponse(
        json.dumps(return_data, cls=DateTimeEncoder),
        content_type="application/json")


@login_required
def query_view(request, query_ids, type='query', **kwargs):
    query_id_array = query_ids.split(',')
    # TODO filter to make sure only this applies to queries which exist
    query_list = [m for m in models.Query.objects.filter(
        id__in=query_id_array)]
    # Get Favorites
    # TODO get rid of copy paste job here with queries
    user = User.objects.get(username=request.user)
    query_favorites = favit.models.Favorite.objects.for_user(
        user, model=models.Query)
    query_fav_dict = dict([(i.target_object_id, i) for i in query_favorites])

    replacement_dict = {}
    json_get = {}
    for q in query_list:
        if q.id in query_fav_dict:
            setattr(q, 'fav', True)
        else:
            setattr(q, 'fav', False)

        lq = query.LoadQuery(
            query_id=q.id,
            user=request.user,
            parameters=request.GET.dict())

        ml = machine_learning_model.objects.filter(query=q.id)