# Path: signup/models.py
# def create_signup( email, questions ):
# def update_signup( email, questions ):
# def create_or_update_signup( email, questions ):
# def delete_signup( email, sequence ):
# def _signup2json( signup_db ):
# def get_signup( email, sequence ):
# def get_all_user_signups( email ):
# def get_signup_by_invite_code( invite_code ):
# def get_signups( sequence ):
# def get_signups_for_archiving( sequence ):
# def get_new_signups( ):
# def handle_new_signups( ):
# def add_user_to_global_list( email, sequence ):


from django import http
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.views.decorators.http import require_http_methods
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from django.core.serializers.json import DjangoJSONEncoder
from forms import SignupForm
from signup import models as signup_model
import json


@csrf_exempt
def signup_ajax( request ):
    form = SignupForm(request.POST)

    if not form.is_valid():
        return http.HttpResponse(400)

    email = form.cleaned_data['email']
    signup_questions = request.POST.dict()
    del signup_questions['email']

    signup_model.create_or_update_signup(email, signup_questions )
    response = http.HttpResponse(200)
    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
    response['Access-Control-Allow-Headers'] =  '*'
    response['Access-Control-Max-Age'] = '1728000'
    return response


def signup_success( request ):
    return render_to_response('signup/success.html', {}, context_instance=RequestContext(request))


def count(request, sequence):
    sequence = int(sequence)

    context = {

# Path: signup/models.py
# def create_signup( email, questions ):
# def update_signup( email, questions ):
# def create_or_update_signup( email, questions ):
# def delete_signup( email, sequence ):
# def _signup2json( signup_db ):
# def get_signup( email, sequence ):
# def get_all_user_signups( email ):
# def get_signup_by_invite_code( invite_code ):
# def get_signups( sequence ):
# def get_signups_for_archiving( sequence ):
# def get_new_signups( ):
# def handle_new_signups( ):
# def add_user_to_global_list( email, sequence ):


# Path: signup/views.py
from django import http
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.views.decorators.http import require_http_methods
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from django.core.serializers.json import DjangoJSONEncoder
from forms import SignupForm
from signup import models as signup_model
import json



@csrf_exempt
def signup_ajax( request ):
    form = SignupForm(request.POST)

    if not form.is_valid():
        return http.HttpResponse(400)

    email = form.cleaned_data['email']
    signup_questions = request.POST.dict()
    del signup_questions['email']

    signup_model.create_or_update_signup(email, signup_questions )
    response = http.HttpResponse(200)
    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Allow-Methods'] = 'POST, OPTIONS'
    response['Access-Control-Allow-Headers'] =  '*'
    response['Access-Control-Max-Age'] = '1728000'
    return response


def signup_success( request ):
    return render_to_response('signup/success.html', {}, context_instance=RequestContext(request))


def count(request, sequence):
    sequence = int(sequence)

    context = {

        'signup_count': str(len(signup_model.get_signups(sequence))),