<commit_before>from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden
import json
from django.core import serializers
from fest.models import *
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.forms import AuthenticationForm
from django.template.response import TemplateResponse
from django.contrib.auth import login
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Avg

def can_rate(user):
    if not hasattr(user, 'student'):
        return user.groups.filter(name='Jourie').count() == 1
    return True

def is_admin(user):
    return user.groups.filter(name='Admin').count() == 1

@login_required
@user_passes_test(can_rate, login_url='/')
def score(request):
    items = []
    for item in Item.objects.all():
        studentlist = {'item': item, 'scores':[] }
        for student in Student.objects.filter(items__in=Item.objects.filter(pk=item.id)):
            try:
                score = Score.objects.get(scored_by=request.user, item=item,
                    student=student).mark
            except ObjectDoesNotExist:
                score = 0
            studentlist['scores'].append({'student': student, 'score': score})
        items.append(studentlist)

    if request.user.groups.filter(name__icontains='Jourie').exists():
        return render_to_response('itemlist_jourie.html', { 'user': request.user, 'items': items})
    elif hasattr(request.user, 'student'):
        return render_to_response('itemlist.html', { 'user': request.user, 'items': items})

@csrf_exempt<commit_msg>ref #1. showing only allocated items to Jourie members<commit_after>from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden
import json
from django.core import serializers
from fest.models import *
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.forms import AuthenticationForm
from django.template.response import TemplateResponse
from django.contrib.auth import login
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Avg

def can_rate(user):
    if not hasattr(user, 'student'):
        return user.groups.filter(name='Jourie').count() == 1
    return True

def is_admin(user):
    return user.groups.filter(name='Admin').count() == 1

@login_required
@user_passes_test(can_rate, login_url='/')
def score(request):
    items = []
    if request.user.groups.filter(name__icontains='Jourie').exists():
        item_list = request.user.jourie.items.all()
    else:
        item_list = Item.objects.all()
    for item in item_list:
        studentlist = {'item': item, 'scores':[] }
        for student in Student.objects.filter(items__in=Item.objects.filter(pk=item.id)):
            try:
                score = Score.objects.get(scored_by=request.user, item=item,
                    student=student).mark
            except ObjectDoesNotExist:
                score = 0
            studentlist['scores'].append({'student': student, 'score': score})
        items.append(studentlist)

    if request.user.groups.filter(name__icontains='Jourie').exists():
        return render_to_response('itemlist_jourie.html', { 'user': request.user, 'items': items})
    elif hasattr(request.user, 'student'):
        return render_to_response('itemlist.html', { 'user': request.user, 'items': items})

@csrf_exempt
{'fraction_non_alphanumeric': 0.11287236949986335, 'fraction_numerical': 0.0019130910084722602, 'mean_word_length': 3.952638700947226, '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': '2168652', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1053, 'n_words': 244}