<commit_before># Copyright 2011 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module containing the views for GCI accepted orgs."""

from django.conf.urls.defaults import url as django_url

from soc.logic.exceptions import AccessViolation
from soc.views.helper import lists
from soc.views.helper import url as url_helper
from soc.views.helper import url_patterns

from soc.modules.gci.logic import profile as profile_logic
from soc.modules.gci.models.organization import GCIOrganization
from soc.modules.gci.templates.org_list import OrgList
from soc.modules.gci.views.base import GCIRequestHandler
from soc.modules.gci.views.helper.url_patterns import url
from soc.modules.gci.views.helper import url_names


class AcceptedOrgsList(OrgList):
  """Template for list of accepted organizations.
  """

  def _getDescription(self):
    return 'List of organizations accepted into %s' % (
        self.data.program.name)

  def _getListConfig(self):
    # TODO(nathaniel): squeeze this back into a lambda expression in
    # the call to setRowAction below.
    def RowAction(e, *args):
      # TODO(nathaniel): make this .organization call unnecessary.
      self.data.redirect.organization(organization=e)

      return self.data.redirect.urlOf(url_names.GCI_ORG_HOME)

    list_config = lists.ListConfiguration()
    list_config.addPlainTextColumn('name', 'Name',
        lambda e, *args: e.name.strip())
    list_config.addSimpleColumn('link_id', 'Organization ID', hidden=True)
    list_config.setRowAction(RowAction)
    list_config.addPlainTextColumn(
        'ideas', 'Ideas',
        (lambda e, *args: url_helper.urlize(e.ideas, name="[ideas page]")),
        hidden=True)
    list_config.setDefaultPagination(False)
    list_config.setDefaultSort('name')
    return list_config

  def _getQuery(self):
    query = GCIOrganization.all()
    query.filter('scope', self.data.program)
    query.filter('status IN', ['new', 'active'])
    return query


class AcceptedOrgsPage(GCIRequestHandler):
  """View for the accepted organizations page."""

  def templatePath(self):
    return 'v2/modules/gci/accepted_orgs/base.html'

  def djangoURLPatterns(self):
    return [
        url(r'accepted_orgs/%s$' % url_patterns.PROGRAM, self,
            name='gci_accepted_orgs'),
    ]

  def checkAccess(self, data, check, mutator):
    check.acceptedOrgsAnnounced()

  def jsonContext(self, data, check, mutator):
    list_content = AcceptedOrgsList(data).getListData()
    if list_content:
      return list_content.content()
    else:
      raise AccessViolation('You do not have access to this data')

  def context(self, data, check, mutator):
    return {
        'page_name': "Accepted organizations for %s" % data.program.name,
        'accepted_orgs_list': AcceptedOrgsList(data),
        #'program_select': ProgramSelect(data, 'gci_accepted_orgs'),
    }


class AcceptedOrgsAdminList(OrgList):
  """Template for list of accepted organizations for admins."""

  def _getDescription(self):
    return 'List of organizations accepted into %s' % (
        self.data.program.name)

  def _getListConfig(self):
    # TODO(nathaniel): squeeze this back into a lambda expression in the
    # call to setRowAction below.
    def RowAction(e, *args):
      # TODO(nathaniel): make this .organization call unnecessary.
      self.data.redirect.organization(organization=e)

      return self.data.redirect.urlOf(url_names.GCI_ORG_HOME)

    list_config = lists.ListConfiguration()
    list_config.addPlainTextColumn('name', 'Name',
        lambda e, *args: e.name.strip())
    list_config.addSimpleColumn('link_id', 'Organization ID', hidden=True)
    list_config.setRowAction(RowAction)
    list_config.setDefaultPagination(False)
    list_config.setDefaultSort('name')
    list_config.addPlainTextColumn(
      'org_admins', 'Org Admins',
      lambda e, org_admins, *args: ", ".join(
          ["%s <%s>" % (o.name(), o.email) for o in org_admins[e.key()]]),
      hidden=True)
    return list_config

  def _getPrefetcher(self):
    def prefetcher(entities):
      prefetched_dict = {}
      for ent in entities:
        prefetched_dict[ent.key()] = profile_logic.orgAdminsForOrg(ent)

      return [prefetched_dict], {}
    return prefetcher

  def _getQuery(self):
    query = GCIOrganization.all()
    query.filter('scope', self.data.program)
    query.filter('status IN', ['new', 'active'])
    return query


class AcceptedOrgsAdminPage(GCIRequestHandler):
  """View for the accepted organizations page for admin with additional info.
  """

  def templatePath(self):<commit_msg>Inlined prefetcher function replaced by a designated class for list of accepted orgs.<commit_after># Copyright 2011 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module containing the views for GCI accepted orgs."""

from django.conf.urls.defaults import url as django_url

from soc.logic.exceptions import AccessViolation
from soc.views.helper import lists
from soc.views.helper import url as url_helper
from soc.views.helper import url_patterns

from soc.modules.gci.logic import profile as profile_logic
from soc.modules.gci.models.organization import GCIOrganization
from soc.modules.gci.templates.org_list import OrgList
from soc.modules.gci.views.base import GCIRequestHandler
from soc.modules.gci.views.helper.url_patterns import url
from soc.modules.gci.views.helper import url_names


class AcceptedOrgsList(OrgList):
  """Template for list of accepted organizations.
  """

  def _getDescription(self):
    return 'List of organizations accepted into %s' % (
        self.data.program.name)

  def _getListConfig(self):
    # TODO(nathaniel): squeeze this back into a lambda expression in
    # the call to setRowAction below.
    def RowAction(e, *args):
      # TODO(nathaniel): make this .organization call unnecessary.
      self.data.redirect.organization(organization=e)

      return self.data.redirect.urlOf(url_names.GCI_ORG_HOME)

    list_config = lists.ListConfiguration()
    list_config.addPlainTextColumn('name', 'Name',
        lambda e, *args: e.name.strip())
    list_config.addSimpleColumn('link_id', 'Organization ID', hidden=True)
    list_config.setRowAction(RowAction)
    list_config.addPlainTextColumn(
        'ideas', 'Ideas',
        (lambda e, *args: url_helper.urlize(e.ideas, name="[ideas page]")),
        hidden=True)
    list_config.setDefaultPagination(False)
    list_config.setDefaultSort('name')
    return list_config

  def _getQuery(self):
    query = GCIOrganization.all()
    query.filter('scope', self.data.program)
    query.filter('status IN', ['new', 'active'])
    return query


class AcceptedOrgsPage(GCIRequestHandler):
  """View for the accepted organizations page."""

  def templatePath(self):
    return 'v2/modules/gci/accepted_orgs/base.html'

  def djangoURLPatterns(self):
    return [
        url(r'accepted_orgs/%s$' % url_patterns.PROGRAM, self,
            name='gci_accepted_orgs'),
    ]

  def checkAccess(self, data, check, mutator):
    check.acceptedOrgsAnnounced()

  def jsonContext(self, data, check, mutator):
    list_content = AcceptedOrgsList(data).getListData()
    if list_content:
      return list_content.content()
    else:
      raise AccessViolation('You do not have access to this data')

  def context(self, data, check, mutator):
    return {
        'page_name': "Accepted organizations for %s" % data.program.name,
        'accepted_orgs_list': AcceptedOrgsList(data),
        #'program_select': ProgramSelect(data, 'gci_accepted_orgs'),
    }


class AcceptedOrgsAdminList(OrgList):
  """Template for list of accepted organizations for admins."""

  class ListPrefetcher(lists.Prefetcher):
    """Prefetcher used for this list.

    See lists.Prefetcher for specification.
    """

    def prefetch(self, entities):
      """See lists.Prefetcher.prefetch for specification."""
      prefetched_dict = {}
      for ent in entities:
        prefetched_dict[ent.key()] = profile_logic.orgAdminsForOrg(ent)

      return [prefetched_dict], {}


  def _getDescription(self):
    return 'List of organizations accepted into %s' % (
        self.data.program.name)

  def _getListConfig(self):
    # TODO(nathaniel): squeeze this back into a lambda expression in the
    # call to setRowAction below.
    def RowAction(e, *args):
      # TODO(nathaniel): make this .organization call unnecessary.
      self.data.redirect.organization(organization=e)

      return self.data.redirect.urlOf(url_names.GCI_ORG_HOME)

    list_config = lists.ListConfiguration()
    list_config.addPlainTextColumn('name', 'Name',
        lambda e, *args: e.name.strip())
    list_config.addSimpleColumn('link_id', 'Organization ID', hidden=True)
    list_config.setRowAction(RowAction)
    list_config.setDefaultPagination(False)
    list_config.setDefaultSort('name')
    list_config.addPlainTextColumn(
      'org_admins', 'Org Admins',
      lambda e, org_admins, *args: ", ".join(
          ["%s <%s>" % (o.name(), o.email) for o in org_admins[e.key()]]),
      hidden=True)
    return list_config

  def _getPrefetcher(self):
    prefetcher = AcceptedOrgsAdminList.ListPrefetcher()
    # TODO(daniel): return prefetcher object rather than a function
    return prefetcher.prefetch

  def _getQuery(self):
    query = GCIOrganization.all()
    query.filter('scope', self.data.program)
    query.filter('status IN', ['new', 'active'])
    return query


class AcceptedOrgsAdminPage(GCIRequestHandler):
  """View for the accepted organizations page for admin with additional info.
  """

  def templatePath(self):
{'fraction_non_alphanumeric': 0.10446495855312736, 'fraction_numerical': 0.0016955538809344385, 'mean_word_length': 3.970505617977528, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1776843', 'n_tokens_mistral': 3262, 'n_tokens_neox': 3168, 'n_words': 867}