# Create your views here.
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
import json
from django.core.serializers.json import DjangoJSONEncoder

from forms import SignupForm
from signup import models as signup_model

@require_http_methods(['POST'])
def signup( request, iframe=False ):

    form = SignupForm(request.POST)

    if not form.is_valid():
        return render_to_response('signup/error.html', {'form': form}, context_instance=RequestContext(request))

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

    signup_model.create_or_update_signup(email, signup_questions )
    
    if request.is_ajax():
        response = http.HttpResponse(code=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
    elif iframe:
        return http.HttpResponseRedirect(reverse('signup_success_iframe'))
    return http.HttpResponseRedirect(reverse('signup_success'))


def allow_cors( method ):
    def call_method( *args, **kwargs):
        request = args[0]
        if request.method == 'OPTIONS':
            return http.HttpResponse(200);
        response = method(*args, **kwargs)
        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
    return call_method


@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))),
        'sequence': sequence
    }

    return render_to_response(
        'signup/count.html',
        context,
        context_instance=RequestContext(request)
    )


@login_required
def export(request, sequence):
    sequence = int(sequence)
    signups = signup_model.get_signups(sequence)
    return http.HttpResponse(json.dumps(signups, cls=DjangoJSONEncoder), content_type='application/json')

@@ -985,983 +985,154 @@
  if 
-request.is_ajax():%0A        response = http.HttpResponse(code=200)%0A        response%5B'Access-Control-Allow-Origin'%5D = '*'%0A        response%5B'Access-Control-Allow-Methods'%5D = 'POST, OPTIONS'%0A        response%5B'Access-Control-Allow-Headers'%5D =  '*'%0A        response%5B'Access-Control-Max-Age'%5D = '1728000'%0A        return response%0A    elif iframe:%0A        return http.HttpResponseRedirect(reverse('signup_success_iframe'))%0A    return http.HttpResponseRedirect(reverse('signup_success'))%0A%0A%0Adef allow_cors( method ):%0A    def call_method( *args, **kwargs):%0A        request = args%5B0%5D%0A        if request.method == 'OPTIONS':%0A            return http.HttpResponse(200);%0A        response = method(*args, **kwargs)%0A        response%5B'Access-Control-Allow-Origin'%5D = '*'%0A        response%5B'Access-Control-Allow-Methods'%5D = 'POST, OPTIONS'%0A        response%5B'Access-Control-Allow-Headers'%5D =  '*'%0A        response%5B'Access-Control-Max-Age'%5D = '1728000'%0A        return response%0A    return call_method
+iframe:%0A        return http.HttpResponseRedirect(reverse('signup_success_iframe'))%0A    return http.HttpResponseRedirect(reverse('signup_success'))
 %0A%0A%0A@

Remove unused code