#!/usr/bin/env python

from django.shortcuts import render_to_response
from django.template.context import RequestContext
from ianonavy.core.forms import ContactForm


def index(request):
    return render_to_response('index.html',
                              context_instance=RequestContext(request))


def contact(request):
    if request.method == 'POST':
        contact_form = ContactForm(request=request, data=request.POST)
        if contact_form.is_valid():
            contact_form.save()
            return render_to_response('contact.html',
                                      dictionary={'contact_form': contact_form,
                                                  'success': True},
                                      context_instance=RequestContext(request))
        else:
            return render_to_response('contact.html',
                                      dictionary={'contact_form': contact_form},
                                      context_instance=RequestContext(request))
    else:
        contact_form = ContactForm(request=request)
        return render_to_response('contact.html',
                                  dictionary={'contact_form': contact_form},
                                  context_instance=RequestContext(request))
