<commit_before>from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import get_object_or_404, render_to_response

from django.contrib.auth.decorators import login_required

from aiteo.forms import AskQuestionForm, AddResponseForm
from aiteo.groups import group_and_bridge, group_context
from aiteo.models import Question



@login_required # @@@
def question_list(request, **kwargs):
    
    group, bridge = group_and_bridge(kwargs)
    
    questions = Question.objects.all().order_by("-score", "created", "id")
    
    if group:
        questions = group.content_objects(questions)
    
    ctx = group_context(group, bridge)
    ctx.update({
        "group": group,
        "questions": questions,
    })
    
    return render_to_response("aiteo/question_list.html",
        context_instance = RequestContext(request, ctx)
    )


@login_required
def question_create(request, **kwargs):
    
    group, bridge = group_and_bridge(kwargs)
    
    if request.method == "POST":
        form = AskQuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.user = request.user
            question.save()
            return HttpResponseRedirect(question.get_absolute_url())
    else:
        form = AskQuestionForm()
    
    ctx = group_context(group, bridge)
    ctx.update({
        "group": group,
        "form": form,
    })
    
    return render_to_response("aiteo/question_create.html",
        context_instance = RequestContext(request, ctx)
    )


@login_required # @@@
def question_detail(request, question_id, **kwargs):
    
    group, bridge = group_and_bridge(kwargs)
    
    questions = Question.objects.all()
    
    if group:
        questions = group.content_objects(questions)
    
    question = get_object_or_404(questions, pk=question_id)
    responses = question.responses.order_by("-score", "created", "id")
    
    if question.user == request.user:
        is_me = True
    else:
        is_me = False
    <commit_msg>when no group is present only get non-grouped objects<commit_after>from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import get_object_or_404, render_to_response

from django.contrib.auth.decorators import login_required

from aiteo.forms import AskQuestionForm, AddResponseForm
from aiteo.groups import group_and_bridge, group_context
from aiteo.models import Question



@login_required # @@@
def question_list(request, **kwargs):
    
    group, bridge = group_and_bridge(kwargs)
    
    questions = Question.objects.all().order_by("-score", "created", "id")
    
    if group:
        questions = group.content_objects(questions)
    else:
        questions = questions.filter(group_content_type=None)
    
    ctx = group_context(group, bridge)
    ctx.update({
        "group": group,
        "questions": questions,
    })
    
    return render_to_response("aiteo/question_list.html",
        context_instance = RequestContext(request, ctx)
    )


@login_required
def question_create(request, **kwargs):
    
    group, bridge = group_and_bridge(kwargs)
    
    if request.method == "POST":
        form = AskQuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.user = request.user
            question.save()
            return HttpResponseRedirect(question.get_absolute_url())
    else:
        form = AskQuestionForm()
    
    ctx = group_context(group, bridge)
    ctx.update({
        "group": group,
        "form": form,
    })
    
    return render_to_response("aiteo/question_create.html",
        context_instance = RequestContext(request, ctx)
    )


@login_required # @@@
def question_detail(request, question_id, **kwargs):
    
    group, bridge = group_and_bridge(kwargs)
    
    questions = Question.objects.all()
    
    if group:
        questions = group.content_objects(questions)
    else:
        questions = questions.filter(group_content_type=None)
    
    question = get_object_or_404(questions, pk=question_id)
    responses = question.responses.order_by("-score", "created", "id")
    
    if question.user == request.user:
        is_me = True
    else:
        is_me = False
    
{'fraction_non_alphanumeric': 0.09812442817932296, 'fraction_numerical': 0.004117108874656907, 'mean_word_length': 3.0415896487985212, 'pattern_counts': {'":': 10, '<': 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': '175690', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1261, 'n_words': 268}