<commit_before>from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils import simplejson
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, HttpResponseBadRequest
from django.contrib.auth.models import User
from django.views.generic import View, ListView, DetailView, CreateView, UpdateView, TemplateView, DeleteView
from django.shortcuts import get_object_or_404
from django.db.models import Q

from cms.models import Member, News, Page, Project, ProjectMember, BlogPost, Tag, Sponsor
from cms.forms import MemberForm, ProjectForm, BlogForm, MemberAdminForm, ProjectAdminForm, PageForm, SponsorForm

from cms import signals
from cms import permissions

import re
import time

class JSONResponseMixin(object):
    def get_json_response(self, json, **kwargs):
        return HttpResponse(json, content_type='application/json', **kwargs)

    def convert_to_json(self, context):
        return simplejson.dumps(context)

    def render_to_response(self, context):
        return self.get_json_response(self.convert_to_json(context))

class HomepageView(TemplateView):
    template_name = 'home.html'

    def get_context_data(self, **kwargs):
        context = super(HomepageView, self).get_context_data(**kwargs)
        context['blog_posts'] = BlogPost.objects.all().order_by('-date')[:5]
        context['SPONSOR_LOGO_URL'] = settings.SPONSOR_LOGO_URL
        context['sponsors'] = Sponsor.objects.all().order_by('name')
        if len(context['sponsors']) > 0:
            # This generates the percentage of the width a single sponsor image should
            # take up based on the number of sponsors. The .95 is required so as to
            # preserve the single line of images.
            context['sponsor_image_width'] = (100 / len(context['sponsors'])) * .95
        context['front_pages'] = Page.objects.filter(pub_front_page=True).order_by('weight')

        return context

class ProfileView(DetailView):
    model = Member
    template_name = 'members/profile.html'
    context_object_name = 'member'

    def get_context_data(self, **kwargs):
        context = super(ProfileView, self).get_context_data(**kwargs)

       # NOTE: "year" is a field lookup type so must use "year__exact" instead
        project_members = ProjectMember.objects.filter(member__pk=self.kwargs.get('pk', None)).order_by('-project__year')
        context['project_groups'] = [ {'year': x, 'project_members': project_members.filter(project__year__exact=x).order_by('project__title') } for x in project_members.values_list('project__year', flat=True).distinct() ]

        context['recent_blogs'] = BlogPost.objects.filter(author__pk=self.kwargs.get('pk', None)).order_by('-date')[:3]

        return context

class EditProfileView(UpdateView):
    model = Member
    form_class = MemberForm
    template_name = 'members/edit_profile.html'

    def dispatch(self, request, *args, **kwargs):
        member = get_object_or_404(Member, pk=kwargs.get('pk', None))

        if permissions.can_user_edit_member(request.user, member):
            return super(EditProfileView, self).dispatch(request, *args, **kwargs)
        else:
            return HttpResponseForbidden('You do not have permission to edit this profile.')

    def post(self, request, *args, **kwargs):
        form = MemberForm(request.POST)

        if form.is_valid():
            member = get_object_or_404(Member, pk=self.kwargs.get('pk', None))

            if member.status is None or member.status == Member.STATUS_EMPTY:
                member.status = Member.STATUS_ACTIVE
                member.save()

        return super(EditProfileView, self).post(request, *args, **kwargs)

    def get_success_url(self):
        return reverse('cms:members_url')


class MembersView(ListView):
    model = Member
    template_name = 'members/members.html'
    context_object_name = 'members'

    def get_context_data(self, **kwargs):
        context = super(MembersView, self).get_context_data(**kwargs)

        # NOTE: "year" is a field lookup type so must use "year__exact" instead
        project_members = ProjectMember.objects.filter(project__year__exact=self.kwargs.get('year', settings.CURRENT_YEAR))
        member_query = Q(pk__in=project_members.values_list('member'))

        # active members are shown unconditinoally for current year
        if int(self.kwargs.get('year', settings.CURRENT_YEAR)) == settings.CURRENT_YEAR:
            active_query = Q(status=Member.STATUS_ACTIVE)
        else:
            active_query = Q()

        context['members'] = Member.objects.filter(member_query | active_query).order_by('user__first_name', 'user__last_name').distinct()

        if permissions.is_user_slc_leader(self.request.user):
            context['archived_members'] = Member.objects.filter(status=Member.STATUS_ARCHIVED).order_by('user__first_name', 'user__last_name')

        context['project_member_groups'] = [{'group': x[1], 'members': context['members'].filter(group=x[0])} for x in Member.GROUP_CHOICES]
        context['project_member_groups'] += [{'group': 'Volunteer', 'project_members': project_members.filter(member=None).order_by('volunteer_name')}]

        context['current_year'] = settings.CURRENT_YEAR
        context['year'] = self.kwargs.get('year', settings.CURRENT_YEAR)
        next_year = int(context['year']) + 1
        context['year2'] = next_year
        prev_year = int(context['year']) - 1
<commit_msg>Only show active project participating members on members index page<commit_after>from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils import simplejson
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, HttpResponseBadRequest
from django.contrib.auth.models import User
from django.views.generic import View, ListView, DetailView, CreateView, UpdateView, TemplateView, DeleteView
from django.shortcuts import get_object_or_404
from django.db.models import Q

from cms.models import Member, News, Page, Project, ProjectMember, BlogPost, Tag, Sponsor
from cms.forms import MemberForm, ProjectForm, BlogForm, MemberAdminForm, ProjectAdminForm, PageForm, SponsorForm

from cms import signals
from cms import permissions

import re
import time

class JSONResponseMixin(object):
    def get_json_response(self, json, **kwargs):
        return HttpResponse(json, content_type='application/json', **kwargs)

    def convert_to_json(self, context):
        return simplejson.dumps(context)

    def render_to_response(self, context):
        return self.get_json_response(self.convert_to_json(context))

class HomepageView(TemplateView):
    template_name = 'home.html'

    def get_context_data(self, **kwargs):
        context = super(HomepageView, self).get_context_data(**kwargs)
        context['blog_posts'] = BlogPost.objects.all().order_by('-date')[:5]
        context['SPONSOR_LOGO_URL'] = settings.SPONSOR_LOGO_URL
        context['sponsors'] = Sponsor.objects.all().order_by('name')
        if len(context['sponsors']) > 0:
            # This generates the percentage of the width a single sponsor image should
            # take up based on the number of sponsors. The .95 is required so as to
            # preserve the single line of images.
            context['sponsor_image_width'] = (100 / len(context['sponsors'])) * .95
        context['front_pages'] = Page.objects.filter(pub_front_page=True).order_by('weight')

        return context

class ProfileView(DetailView):
    model = Member
    template_name = 'members/profile.html'
    context_object_name = 'member'

    def get_context_data(self, **kwargs):
        context = super(ProfileView, self).get_context_data(**kwargs)

       # NOTE: "year" is a field lookup type so must use "year__exact" instead
        project_members = ProjectMember.objects.filter(member__pk=self.kwargs.get('pk', None)).order_by('-project__year')
        context['project_groups'] = [ {'year': x, 'project_members': project_members.filter(project__year__exact=x).order_by('project__title') } for x in project_members.values_list('project__year', flat=True).distinct() ]

        context['recent_blogs'] = BlogPost.objects.filter(author__pk=self.kwargs.get('pk', None)).order_by('-date')[:3]

        return context

class EditProfileView(UpdateView):
    model = Member
    form_class = MemberForm
    template_name = 'members/edit_profile.html'

    def dispatch(self, request, *args, **kwargs):
        member = get_object_or_404(Member, pk=kwargs.get('pk', None))

        if permissions.can_user_edit_member(request.user, member):
            return super(EditProfileView, self).dispatch(request, *args, **kwargs)
        else:
            return HttpResponseForbidden('You do not have permission to edit this profile.')

    def post(self, request, *args, **kwargs):
        form = MemberForm(request.POST)

        if form.is_valid():
            member = get_object_or_404(Member, pk=self.kwargs.get('pk', None))

            if member.status is None or member.status == Member.STATUS_EMPTY:
                member.status = Member.STATUS_ACTIVE
                member.save()

        return super(EditProfileView, self).post(request, *args, **kwargs)

    def get_success_url(self):
        return reverse('cms:members_url')


class MembersView(ListView):
    model = Member
    template_name = 'members/members.html'
    context_object_name = 'members'

    def get_context_data(self, **kwargs):
        context = super(MembersView, self).get_context_data(**kwargs)

        # NOTE: "year" is a field lookup type so must use "year__exact" instead
        project_members = ProjectMember.objects.filter(project__year__exact=self.kwargs.get('year', settings.CURRENT_YEAR))
        member_query = Q(pk__in=project_members.values_list('member'))
        context['members'] = Member.objects.filter(member_query).order_by('user__first_name', 'user__last_name').distinct()

        if permissions.is_user_slc_leader(self.request.user):
            context['archived_members'] = Member.objects.filter(status=Member.STATUS_ARCHIVED).order_by('user__first_name', 'user__last_name')

        context['project_member_groups'] = [{'group': x[1], 'members': context['members'].filter(group=x[0])} for x in Member.GROUP_CHOICES]
        context['project_member_groups'] += [{'group': 'Volunteer', 'project_members': project_members.filter(member=None).order_by('volunteer_name')}]

        context['current_year'] = settings.CURRENT_YEAR
        context['year'] = self.kwargs.get('year', settings.CURRENT_YEAR)
        next_year = int(context['year']) + 1
        context['year2'] = next_year
        prev_year = int(context['year']) - 1

{'fraction_non_alphanumeric': 0.11532724221517807, 'fraction_numerical': 0.004475107216110386, 'mean_word_length': 4.055136663524976, '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': '6044715', 'n_tokens_mistral': 3153, 'n_tokens_neox': 3047, 'n_words': 691}