<commit_before>from django.shortcuts import render
from .models import Nomination, NominationInstance, UserProfile
from django.contrib.auth.decorators import login_required, permission_required
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse, reverse_lazy
from django.core.exceptions import ObjectDoesNotExist
from .forms import NominationForm
from forms.models import Questionnaire


def index(request):
    nominations = Nomination.objects.all()
    all_nominations = nominations[::-1]

    return render(request, 'index.html', context={'all_nominations': all_nominations})


@login_required
def nomi_apply(request, pk):
    nomination = Nomination.objects.get(pk=pk)
    ct = NominationInstance.objects.filter(nomination=nomination).filter(user=request.user).count()

    if not request.user.is_superuser:
        if not ct:
             ins = NominationInstance.objects.create(user=request.user, nomination=nomination)
             info = "Your application has been recorded"
             return render(request, 'nomi_done.html', context={'info': info})
        else:
            info = "You have applied for it already."

    else:
        info = "The nomination for your post has been created and is awaiting responses"
        return render(request, 'nomi_done.html', context={'info': info})

    return render(request, 'nomi_done.html', context={'info': info})


def result(request, pk):
    nomination = Nomination.objects.get(pk=pk)
    users = NominationInstance.objects.filter(nomination=nomination).filter(status__exact='a')

    return render(request, 'result.html', context={'users': users})


@permission_required('nomi.admin')
def application_result(request, pk):
    nomination = Nomination.objects.filter(pk=pk)
    applicants = NominationInstance.objects.filter(nomination=nomination)

    return render(request, 'applicants.html', context={'applicants': applicants})


@login_required
@permission_required('nomi.admin')
def accept_nomination(request, pk):
    application = NominationInstance.objects.get(pk=pk)
    id_accept = application.nomination.pk
    application.status = 'a'
    application.save()

    return HttpResponseRedirect(reverse('applicants', kwargs={'pk': id_accept}))


@login_required
@permission_required('nomi.admin')
def reject_nomination(request, pk):
    application = NominationInstance.objects.get(pk=pk)
    id_reject = application.nomination.pk
    application.status = 'r'
    application.save()

    return HttpResponseRedirect(reverse('applicants', kwargs={'pk': id_reject}))


@login_required
def profile_view(request):
    pk = request.user.pk

    try:
        user_profile = UserProfile.objects.get(user__id=pk)
        return render(request, 'profile.html', context={'user_profile': user_profile})
    except ObjectDoesNotExist:
        return HttpResponseRedirect('create')


class UserProfileCreate(CreateView):
    model = UserProfile
    fields = '__all__'
    success_url = reverse_lazy('index')


class UserProfileUpdate(UpdateView):
    model = UserProfile
    fields = '__all__'
    success_url = reverse_lazy('index')


def nomination_create(request):

    if request.method == 'POST':
        title_form = NominationForm(request.POST)
        if title_form.is_valid():

            questionnaire = Questionnaire.objects.create(name=title_form.cleaned_data['title'],
                                                         description=title_form.cleaned_data['description'])
            nomination = Nomination.objects.create(name=title_form.cleaned_data['title'],
                                                 description=title_form.cleaned_data['description'],
                                                 nomi_form=questionnaire)
            pk=questionnaire.pk
            return HttpResponseRedirect(reverse('forms:show_form', kwargs={'pk': pk}))

    else:
        title_form=NominationForm()

    return render(request, 'nomi/nomination_form.html', context={'form': title_form})


class NominationUpdate(UpdateView):
    model = Nomination
    fields = ['name', 'description']
    success_url = reverse_lazy('index')


class NominationDelete(DeleteView):
    model = Nomination
    success_url = reverse_lazy('index')

<commit_msg>make views to show and create post<commit_after>from django.shortcuts import render
from .models import Nomination, NominationInstance, UserProfile,Post
from django.contrib.auth.decorators import login_required, permission_required
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse, reverse_lazy
from django.core.exceptions import ObjectDoesNotExist
from .forms import NominationForm,PostForm
from forms.models import Questionnaire

@login_required
def index(request):
    nominations = Nomination.objects.all()
    all_nominations = nominations[::-1]
    posts=Post.objects.filter(post_holders=request.user)
    return render(request, 'index.html', context={'all_nominations': all_nominations,'posts':posts})

@login_required
def post_view(request,pk):
    post=Post.objects.get(pk=pk)
    child_posts=Post.objects.filter(parent=post)

    return render(request, 'post.html', context={'post': post, 'child_posts': child_posts})





@login_required
def nomi_apply(request, pk):
    nomination = Nomination.objects.get(pk=pk)
    ct = NominationInstance.objects.filter(nomination=nomination).filter(user=request.user).count()

    if not request.user.is_superuser:
        if not ct:
             ins = NominationInstance.objects.create(user=request.user, nomination=nomination)
             info = "Your application has been recorded"
             return render(request, 'nomi_done.html', context={'info': info})
        else:
            info = "You have applied for it already."

    else:
        info = "The nomination for your post has been created and is awaiting responses"
        return render(request, 'nomi_done.html', context={'info': info})

    return render(request, 'nomi_done.html', context={'info': info})


def result(request, pk):
    nomination = Nomination.objects.get(pk=pk)
    users = NominationInstance.objects.filter(nomination=nomination).filter(status__exact='a')

    return render(request, 'result.html', context={'users': users})


@permission_required('nomi.admin')
def application_result(request, pk):
    nomination = Nomination.objects.filter(pk=pk)
    applicants = NominationInstance.objects.filter(nomination=nomination)

    return render(request, 'applicants.html', context={'applicants': applicants})


@login_required
@permission_required('nomi.admin')
def accept_nomination(request, pk):
    application = NominationInstance.objects.get(pk=pk)
    id_accept = application.nomination.pk
    application.status = 'a'
    application.save()

    return HttpResponseRedirect(reverse('applicants', kwargs={'pk': id_accept}))


@login_required
@permission_required('nomi.admin')
def reject_nomination(request, pk):
    application = NominationInstance.objects.get(pk=pk)
    id_reject = application.nomination.pk
    application.status = 'r'
    application.save()

    return HttpResponseRedirect(reverse('applicants', kwargs={'pk': id_reject}))


@login_required
def profile_view(request):
    pk = request.user.pk

    try:
        user_profile = UserProfile.objects.get(user__id=pk)
        return render(request, 'profile.html', context={'user_profile': user_profile})
    except ObjectDoesNotExist:
        return HttpResponseRedirect('create')


class UserProfileCreate(CreateView):
    model = UserProfile
    fields = '__all__'
    success_url = reverse_lazy('index')


class UserProfileUpdate(UpdateView):
    model = UserProfile
    fields = '__all__'
    success_url = reverse_lazy('index')


def nomination_create(request,pk):

    if request.method == 'POST':
        title_form = NominationForm(request.POST)
        if title_form.is_valid():
            post=Post.objects.get(pk=pk)

            questionnaire = Questionnaire.objects.create(name=title_form.cleaned_data['title'],
                                                         description=title_form.cleaned_data['description'])
            nomination = Nomination.objects.create(name=title_form.cleaned_data['title'],
                                                 description=title_form.cleaned_data['description'],
                                                 nomi_form=questionnaire)
            post.nomination=nomination
            post.save()
            pk=questionnaire.pk
            return HttpResponseRedirect(reverse('forms:show_form', kwargs={'pk': pk}))

    else:
        title_form=NominationForm()

    return render(request, 'nomi/nomination_form.html', context={'form': title_form})


class NominationUpdate(UpdateView):
    model = Nomination
    fields = ['name', 'description']
    success_url = reverse_lazy('index')


class NominationDelete(DeleteView):
    model = Nomination
    success_url = reverse_lazy('index')


def post_create(request,pk):
    if request.method == 'POST':
        parent=Post.objects.get(pk=pk)
        post_form = PostForm(request.POST)
        if post_form.is_valid():
            post=Post.objects.create(post_name=post_form.cleaned_data['post_title'],parent=parent)
            return HttpResponseRedirect(reverse('nomi_create',kwargs={'pk':pk}))

    else:
        post_form = PostForm()

    return render(request, 'nomi/post_form.html', context={'form': post_form})


{'fraction_non_alphanumeric': 0.10940099833610649, 'fraction_numerical': 0.00020798668885191348, 'mean_word_length': 3.8253888610135474, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '860734', 'n_tokens_mistral': 2702, 'n_tokens_neox': 2646, 'n_words': 538}