<commit_before>from django.shortcuts import render
from .models import Nomination, NominationInstance, UserProfile, Post, Club
from django.contrib.auth.decorators import login_required
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse, reverse_lazy
from django.core.exceptions import ObjectDoesNotExist
from .forms import NominationForm, PostForm, ConfirmApplication, ClubForm
from forms.models import Questionnaire
from .filters import UserProfileFilter
import json


@login_required
def index(request):
    nominations = Nomination.objects.filter(status='Nomination out')
    all_nominations = nominations[::-1]
    posts = Post.objects.filter(post_holders=request.user)
    clubs = Club.objects.filter(club_members=request.user)
    username = UserProfile.objects.get(user=request.user)

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


@login_required
def club_view(request, pk):
    club = Club.objects.get(pk=pk)
    child_clubs = Club.objects.filter(club_parent=club)
    posts = Post.objects.filter(post_holders=request.user)

    return render(request, 'club.html', context={'club': club, 'child_clubs': child_clubs, 'posts': posts})


@login_required
def post_view(request, pk):
    post = Post.objects.get(pk=pk)
    child_posts = Post.objects.filter(parent=post)
    child_posts_reverse = child_posts[::-1]
    post_approval = Post.objects.filter(post_approvals=post).filter(status='Post created')
    nomi_approval = Nomination.objects.filter(nomi_approvals=post).filter(status='Nomination created')

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


@login_required
def post_create(request, pk):
    if request.method == 'POST':
        parent = Post.objects.get(pk=pk)
        post_form = PostForm(request.POST)
        club = parent.club
        if post_form.is_valid():
            post = Post.objects.create(post_name=post_form.cleaned_data['post_title'], club=club, parent=parent)
            post_pk = post.pk

            return HttpResponseRedirect(reverse('nomi_create', kwargs={'pk': post_pk}))

    else:
        post_form = PostForm()

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


@login_required
def club_create(request, pk):
    if request.method == 'POST':
        parent = Club.objects.get(pk=pk)
        club_form = ClubForm(request.POST)

        if club_form.is_valid():
            club = Club.objects.create(club_name=club_form.cleaned_data['club_name'], club_parent=parent)
            club_pk = club.pk

            return HttpResponseRedirect(reverse('index'))

    else:
        club_form = ClubForm()

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


@login_required
def child_post_view(request, pk, view_pk):
    post = Post.objects.get(pk=pk)
    nominations = Nomination.objects.filter(nomi_post=post)

    if post.status == 'Post created':
        approved = 1
    else:
        approved = 0

    view_pk = view_pk
    view = Post.objects.get(pk=view_pk)

    if view.perms == 'normal':
        power_to_approve = 0
    else:<commit_msg>Minor changes in variable declaration<commit_after>from django.shortcuts import render
from .models import Nomination, NominationInstance, UserProfile, Post, Club
from django.contrib.auth.decorators import login_required
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse, reverse_lazy
from django.core.exceptions import ObjectDoesNotExist
from .forms import NominationForm, PostForm, ConfirmApplication, ClubForm
from forms.models import Questionnaire
from .filters import UserProfileFilter
import json


@login_required
def index(request):
    nominations = Nomination.objects.filter(status='Nomination out')
    all_nominations = nominations[::-1]
    posts = Post.objects.filter(post_holders=request.user)
    clubs = Club.objects.filter(club_members=request.user)
    username = UserProfile.objects.get(user=request.user)

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


@login_required
def club_view(request, pk):
    club = Club.objects.get(pk=pk)
    child_clubs = Club.objects.filter(club_parent=club)
    posts = Post.objects.filter(post_holders=request.user)

    return render(request, 'club.html', context={'club': club, 'child_clubs': child_clubs, 'posts': posts})


@login_required
def post_view(request, pk):
    post = Post.objects.get(pk=pk)
    child_posts = Post.objects.filter(parent=post)
    child_posts_reverse = child_posts[::-1]

    post_approvals = Post.objects.filter(post_approvals=post).filter(status='Post created')
    nomi_approvals = Nomination.objects.filter(nomi_approvals=post).filter(status='Nomination created')

    return render(request, 'post.html', context={'post': post, 'child_posts': child_posts_reverse,
                                                 'post_approval': post_approvals, 'nomi_approval': nomi_approvals})


@login_required
def club_create(request, pk):
    if request.method == 'POST':
        parent = Club.objects.get(pk=pk)
        club_form = ClubForm(request.POST)

        if club_form.is_valid():
            club = Club.objects.create(club_name=club_form.cleaned_data['club_name'], club_parent=parent)
            club_pk = club.pk

            return HttpResponseRedirect(reverse('index'))

    else:
        club_form = ClubForm()

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


@login_required
def post_create(request, pk):
    if request.method == 'POST':
        parent = Post.objects.get(pk=pk)
        post_form = PostForm(request.POST)
        club = parent.club
        if post_form.is_valid():
            post = Post.objects.create(post_name=post_form.cleaned_data['post_title'], club=club, parent=parent)
            post_pk = post.pk

            return HttpResponseRedirect(reverse('nomi_create', kwargs={'pk': post_pk}))

    else:
        post_form = PostForm()

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



@login_required
def child_post_view(request, pk, view_pk):
    post = Post.objects.get(pk=pk)
    nominations = Nomination.objects.filter(nomi_post=post)

    if post.status == 'Post created':
        approved = 1
    else:
        approved = 0

    view_pk = view_pk
    view = Post.objects.get(pk=view_pk)

    if view.perms == 'normal':
        power_to_approve = 0
    else:
{'fraction_non_alphanumeric': 0.11217902739922536, 'fraction_numerical': 0.0014345144168698895, 'mean_word_length': 3.7044534412955468, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1621764', 'n_tokens_mistral': 2098, 'n_tokens_neox': 2067, 'n_words': 426}