<commit_before># Copyright 2013 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.

"""MapReduce to finalize and apply program administrators' decisions on
what organizations are accepted into program."""

from google.appengine.ext import db
from google.appengine.ext import ndb

from mapreduce import context as mapreduce_context

from melange.logic import organization as org_logic
from melange.models import organization as org_model

from soc.logic import site as site_logic


def process(org_key):
  """Processes a single organization.

  Organization status is updated to ACCEPTED or REJECTED if the current
  status has been set to PRE_ACCEPTED or PRE_REJECTED, respectively,
  by program administrators.

  Args:
    org_key: Organization key.
  """
  context = mapreduce_context.get()
  program_key = db.Key(context.mapreduce_spec.mapper.params['program_key'])

  program = db.get(program_key)
  organization = ndb.Key.from_old_key(org_key).get()

  # TODO(daniel): add email recipients, i.e. organization admins
  site = site_logic.singleton()

  @ndb.transactional
  def updateOrganizationStatus():
    """Transactionally updates organization status."""
    # only organizations defined for the specified program should be processed
    if organization.program.to_old_key() == program_key:
      if organization.status == org_model.Status.PRE_ACCEPTED:
        org_logic.setStatus(
            organization, program, site, org_model.Status.ACCEPTED)
      elif organization.status == org_model.Status.PRE_REJECTED:
        org_logic.setStatus(
            organization, program, site, org_model.Status.REJECTED)

  updateOrganizationStatus()<commit_msg>Fetch the list of org admins to whom the org acceptance/rejection emails should be sent.<commit_after># Copyright 2013 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.

"""MapReduce to finalize and apply program administrators' decisions on
what organizations are accepted into program."""

from google.appengine.ext import db
from google.appengine.ext import ndb

from mapreduce import context as mapreduce_context

from melange.logic import organization as org_logic
from melange.logic import profile as profile_logic
from melange.models import organization as org_model

from soc.logic import site as site_logic


def process(org_key):
  """Processes a single organization.

  Organization status is updated to ACCEPTED or REJECTED if the current
  status has been set to PRE_ACCEPTED or PRE_REJECTED, respectively,
  by program administrators.

  Args:
    org_key: Organization key.
  """
  context = mapreduce_context.get()
  program_key = db.Key(context.mapreduce_spec.mapper.params['program_key'])

  program = db.get(program_key)
  organization = ndb.Key.from_old_key(org_key).get()

  # TODO(daniel): add email recipients, i.e. organization admins
  site = site_logic.singleton()

  admins = profile_logic.getOrgAdmins(organization.key)
  recipients = [a.contact.email for a in admins]

  @ndb.transactional
  def updateOrganizationStatus():
    """Transactionally updates organization status."""
    # only organizations defined for the specified program should be processed
    if organization.program.to_old_key() == program_key:
      if organization.status == org_model.Status.PRE_ACCEPTED:
        org_logic.setStatus(
            organization, program, site, org_model.Status.ACCEPTED)
      elif organization.status == org_model.Status.PRE_REJECTED:
        org_logic.setStatus(
            organization, program, site, org_model.Status.REJECTED)

  updateOrganizationStatus()
{'fraction_non_alphanumeric': 0.07258064516129033, 'fraction_numerical': 0.0034873583260680036, 'mean_word_length': 4.379835873388042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6982979', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1220, 'n_words': 463}