<commit_before>from django.http import HttpResponse
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login  # Login module handles sessions
from django.views import generic
from django.views.generic import View
from .forms import UserForm


def index(request):
    return HttpResponse("Hello, world. You're at the SkalVi index.")


class UserFormView(View):
    form_class = UserForm  ## FormView blueprint
    template_name = "register.html"  # HTML file that form will appear in

    # display blank form
    def get(self, request):
        form = self.form_class(None)  # None represents context
        return render(request, self.template_name, {'form': form})

    # process form data
    def post(self, request):
        form = self.form_class(request.POST)

        if form.is_valid():
            # Take submitted data and save to database
            #
            user = form.save(commit=False)  # temporary saved, not saved in database

            # cleaned (normalized) data / formated properly
            email = form.cleaned_data['email']
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']



            user.set_password(password)
            user.save()  # saves users to the database


            # Returns User Object if credentials are correct
            user = authenticate(username=username, password=password)

            # Check that we got a user back
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return redirect('skalvi:index')

        # If not successfully logged in, returns to the same page.
        # Return to the login page
        return render(request, self.template_name, {'form' : form})












<commit_msg>added view to handle register form and use database api to register the user in database<commit_after>from django.http import HttpResponse
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login  # Login module handles sessions
from django.views import generic
from django.views.generic import View
from .forms import UserForm, UserProfileForm



def index(request):
    return HttpResponse("Hello, world. You're at the SkalVi index.")


class UserFormView(View):
    form_class = UserForm  # Form View blueprint
    profile_form_class = UserProfileForm
    template_name = "register.html"  # HTML file that form will appear in

    # display blank form
    def get(self, request):
        form = self.form_class(None)  # None represents context
        profile = self.profile_form_class(None)
        return render(request, self.template_name, {
            'form': form,
            'profile': profile

        })

    # process form data
    def post(self, request):
        form = self.form_class(request.POST)
        profile_form = self.profile_form_class(request.POST)

        print(form)
        print(profile_form)



        if form.is_valid():

            # Take submitted data and save to database
            user = form.save(commit=False)  # temporary saved, not saved in database
            profile = profile_form.save(commit=False)

            print(user)
            #print(profile)

            # cleaned (normalized) data / formated properly
            email = form.cleaned_data['email']
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']

            # Make som changes or something useful
            user.set_password(password)


            user.save()  # saves users to the database


            #Returns User Object if credentials are correct
            user = authenticate(username=username, password=password)

            # Check that we got a user back
            if user is not None:
                if user.is_active:
                    login(request, user)

                    return redirect('skalvi:index')

        # If not successfully logged in, returns to the same page.
        # Return to the login page
        print("NEEEI")
        return render(request, self.template_name,
            {
                'form' : form,
                'profile' : profile_form
            })













{'fraction_non_alphanumeric': 0.0750263435194942, 'fraction_numerical': 0.0, 'mean_word_length': 2.368346344925479, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2590017', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1172, 'n_words': 392}