<commit_before>from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
from django.forms.models import modelformset_factory,modelform_factory
from django.http import HttpResponse
from django.shortcuts import render,redirect,get_object_or_404
from django.template import RequestContext, loader
from django.utils import timezone

from django_ajax.decorators import ajax

from fora.models import Forum,ForumThread,ForumMessage,MessagePoint,get_user_points
from member_resources.views import get_permissions as get_member_permissions
from mig_main.utility import get_previous_page, get_message_dict, Permissions

# Create your views here.


def get_permissions(user):
    permission_dict=get_member_permissions(user)
    is_member=False
    if hasattr(user,'userprofile') and user.userprofile.is_member:
        is_member=True
    permission_dict.update({'can_create_thread':Permissions.can_create_thread(user),
                            'can_create_forum':Permissions.can_create_forum(user),
                            'can_comment':hasattr(user,'userprofile') and user.userprofile.is_member(),
                            'can_moderate':Permissions.can_create_forum(user),
                            'can_downvote':get_user_points(user.userprofile.memberprofile)>0 if is_member else False})
    
    return permission_dict
def get_common_context(request):
    links=[]
    links.append({'name':'Submit Affirmation','link':reverse('member_resources:submit_praise')})
    context_dict=get_message_dict(request)
    context_dict.update({
        'subnav':'playground',
        'links':links,
        'profile':request.user.userprofile.memberprofile if (hasattr(request.user, 'userprofile') and request.user.userprofile.is_member()) else None,
        })
    return context_dict

def index(request):
    return view_thread(request,None)
    
def view_thread(request,thread_id):
    request.session['current_page']=request.path
    template = loader.get_template('fora/fora.html')
    fora = Forum.objects.all()
    if thread_id:
        active_thread=get_object_or_404(ForumThread,id=thread_id)
    else:
        threads=ForumThread.objects.filter(hidden=False).order_by('time_created')
        if threads.exists():
            active_thread=threads[0]
        else:
            active_thread=None
    reply_form = modelform_factory(ForumMessage,exclude=('forum_thread','in_reply_to','creator','time_created','last_modified','score','hidden'))
    context_dict = {
            'fora':fora,
            'active_thread':active_thread,
            'form':reply_form(),<commit_msg>Fix thread ordering<commit_after>from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
from django.forms.models import modelformset_factory,modelform_factory
from django.http import HttpResponse
from django.shortcuts import render,redirect,get_object_or_404
from django.template import RequestContext, loader
from django.utils import timezone

from django_ajax.decorators import ajax

from fora.models import Forum,ForumThread,ForumMessage,MessagePoint,get_user_points
from member_resources.views import get_permissions as get_member_permissions
from mig_main.utility import get_previous_page, get_message_dict, Permissions

# Create your views here.


def get_permissions(user):
    permission_dict=get_member_permissions(user)
    is_member=False
    if hasattr(user,'userprofile') and user.userprofile.is_member:
        is_member=True
    permission_dict.update({'can_create_thread':Permissions.can_create_thread(user),
                            'can_create_forum':Permissions.can_create_forum(user),
                            'can_comment':hasattr(user,'userprofile') and user.userprofile.is_member(),
                            'can_moderate':Permissions.can_create_forum(user),
                            'can_downvote':get_user_points(user.userprofile.memberprofile)>0 if is_member else False})
    
    return permission_dict
def get_common_context(request):
    links=[]
    links.append({'name':'Submit Affirmation','link':reverse('member_resources:submit_praise')})
    context_dict=get_message_dict(request)
    context_dict.update({
        'subnav':'playground',
        'links':links,
        'profile':request.user.userprofile.memberprofile if (hasattr(request.user, 'userprofile') and request.user.userprofile.is_member()) else None,
        })
    return context_dict

def index(request):
    return view_thread(request,None)
    
def view_thread(request,thread_id):
    request.session['current_page']=request.path
    template = loader.get_template('fora/fora.html')
    fora = Forum.objects.all()
    if thread_id:
        active_thread=get_object_or_404(ForumThread,id=thread_id)
    else:
        threads=ForumThread.objects.filter(hidden=False).order_by('-time_created')
        if threads.exists():
            active_thread=threads[0]
        else:
            active_thread=None
    reply_form = modelform_factory(ForumMessage,exclude=('forum_thread','in_reply_to','creator','time_created','last_modified','score','hidden'))
    context_dict = {
            'fora':fora,
            'active_thread':active_thread,
            'form':reply_form(),
{'fraction_non_alphanumeric': 0.09753769803397595, 'fraction_numerical': 0.003054017942355411, 'mean_word_length': 4.177865612648222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '860261', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1491, 'n_words': 243}