Source

Lightning Talks / lightning / common / views.py

Full commit
Kenneth Love d9dd2e5 































from django.contrib.auth import logout
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views.generic import TemplateView
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator

from common.forms import ProfileForm

def logout_view(request):
    logout(request)
    return HttpResponseRedirect(reverse('home'))

class CreateUpdateProfileView(TemplateView):
    template_name = 'common/profile_form.html'

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(CreateUpdateProfileView, self).dispatch(*args, **kwargs)

    def get(self, request):
        form = ProfileForm(instance=request.user)
        return self.render_to_response({'form': form})

    def post(self, request):
        form = ProfileForm(request.POST, instance=request.user)

        if form.is_valid():
            form.save()

            return HttpResponseRedirect(reverse('profile'))

        return self.render_to_response({'form': form})