<commit_before>from cog.forms import *
from cog.models import *
from django.contrib.auth.decorators import login_required, user_passes_test
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
import ast
from django.contrib.sites.models import Site  
from cog.models import PeerSite
from django.forms.models import modelformset_factory
from cog.views.utils import getUsersThatMatch, get_projects_by_name, paginate


def site_home(request):
    
    # redirect to HOME_PROJECT home
    return HttpResponseRedirect(reverse('project_home', args=[settings.HOME_PROJECT]))
        
    # redirect to 'cog' project hone page
    #return HttpResponseRedirect()
            
    # redirect to independent splash page
    #return render_to_response('cog/index.html', 
    #                          {'title':'Welcome to COG' }, 
    #                          context_instance=RequestContext(request))


# admin page for managing projects
@user_passes_test(lambda u: u.is_staff)
def admin_projects(request):
    """
    Lists local projects in a table with links to edit or delete
    """
    site = Site.objects.get_current()

    # optional active=True|False filter
    active = request.GET.get('active', None)
    if active != None:
        project_list = Project.objects.filter(site=Site.objects.get_current()).filter(active=ast.literal_eval(active))\
            .order_by('short_name')
    else:
        if request.method == 'GET':
            project_list = Project.objects.filter(site=Site.objects.get_current()).order_by('short_name')
        else:
            # list project by search criteria. Search function located in utils.py
            # get list of all projects
            project_list = get_projects_by_name(request.POST['match'])
            # filter projects to include local site only
            project_list = project_list.filter(site=Site.objects.get_current()).order_by('short_name')

    # retrieve top-level projects, ordered alphabetically by short name. Only list those on the current site.
    return render_to_response('cog/admin/admin_projects.html',
                              {'project_list': paginate(project_list, request),
                               'title': '%s Projects Administration' % site.name,
                               }, context_instance=RequestContext(request))


# admin page for listing all system users
@user_passes_test(lambda u: u.is_staff)
def admin_users(request):

    # get sort command if it exists
    sortby = request.GET.get('sortby', 'title')

    # load all users
    if request.method == 'GET':

        # display and sort based on lower case last name
        users = User.objects.all().extra(select={'last_name': 'lower(last_name)'})
        users = users.extra(select={'first_name': 'lower(first_name)'})

        if sortby == 'last_login':
            results = users.order_by('last_login')
        elif sortby == 'last_name':
            results = users.order_by('last_name')
        elif sortby == 'email':
            results = users.order_by('email')
        else:
            results = User.objects.all().order_by('last_name')  # default

    else:  # lookup specific user
        results = getUsersThatMatch(request.POST['match'])
<commit_msg>converting to lower case does not work on cu-dev, removing that for now<commit_after>from cog.forms import *
from cog.models import *
from django.contrib.auth.decorators import login_required, user_passes_test
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
import ast
from django.contrib.sites.models import Site  
from cog.models import PeerSite
from django.forms.models import modelformset_factory
from cog.views.utils import getUsersThatMatch, get_projects_by_name, paginate


def site_home(request):
    
    # redirect to HOME_PROJECT home
    return HttpResponseRedirect(reverse('project_home', args=[settings.HOME_PROJECT]))
        
    # redirect to 'cog' project hone page
    #return HttpResponseRedirect()
            
    # redirect to independent splash page
    #return render_to_response('cog/index.html', 
    #                          {'title':'Welcome to COG' }, 
    #                          context_instance=RequestContext(request))


# admin page for managing projects
@user_passes_test(lambda u: u.is_staff)
def admin_projects(request):
    """
    Lists local projects in a table with links to edit or delete
    """
    site = Site.objects.get_current()

    # optional active=True|False filter
    active = request.GET.get('active', None)
    if active != None:
        project_list = Project.objects.filter(site=Site.objects.get_current()).filter(active=ast.literal_eval(active))\
            .order_by('short_name')
    else:
        if request.method == 'GET':
            project_list = Project.objects.filter(site=Site.objects.get_current()).order_by('short_name')
        else:
            # list project by search criteria. Search function located in utils.py
            # get list of all projects
            project_list = get_projects_by_name(request.POST['match'])
            # filter projects to include local site only
            project_list = project_list.filter(site=Site.objects.get_current()).order_by('short_name')

    # retrieve top-level projects, ordered alphabetically by short name. Only list those on the current site.
    return render_to_response('cog/admin/admin_projects.html',
                              {'project_list': paginate(project_list, request),
                               'title': '%s Projects Administration' % site.name,
                               }, context_instance=RequestContext(request))


# admin page for listing all system users
@user_passes_test(lambda u: u.is_staff)
def admin_users(request):

    # get sort command if it exists
    sortby = request.GET.get('sortby', 'title')

    # load all users
    if request.method == 'GET':

        # display and sort based on lower case last name

        # TODO: This works locally but causes a YSD on cu-dev when passed to the order by
        # users = User.objects.all().extra(select={'last_name': 'lower(last_name)'})
        # users = users.extra(select={'first_name': 'lower(first_name)'})

        if sortby == 'last_login':
            results = User.objects.all().order_by('last_login')
        elif sortby == 'last_name':
            results = User.objects.all().order_by('last_name')
        elif sortby == 'email':
            results = User.objects.all().order_by('email')
        else:
            results = User.objects.all().order_by('last_name')  # default

    else:  # lookup specific user
        results = getUsersThatMatch(request.POST['match'])

{'fraction_non_alphanumeric': 0.09714203233256351, 'fraction_numerical': 0.0008660508083140878, 'mean_word_length': 2.9571673329525985, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2098027', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1855, 'n_words': 504}