| # Copyright 2014 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 find profiles with duplicate proposals and set that information |
| for the specified program. |
| """ |
| |
| from google.appengine.ext import db |
| from google.appengine.ext import ndb |
| |
| from mapreduce import context as mr_context |
| |
| from melange.models import profile as profile_model |
| |
| from summerofcode.logic import profile as profile_logic |
| |
| # This MapReduce requires this model to have been imported. |
| # pylint: disable=unused-import |
| from summerofcode.models import organization as org_model |
| # pylint: enable=unused-import |
| |
| |
| ENTITY_KIND_ID_PARAM = 'entity_kind' |
| PROGRAM_KEY_URLSAFE_PARAM = 'program_key_id' |
| |
| def process(profile_key): |
| """Processes a single profile by finding out if it has duplicate proposals. |
| |
| Args: |
| profile_key: ndb.Key of the profile. |
| """ |
| profile_key = ndb.Key.from_old_key(profile_key) |
| |
| context = mr_context.get() |
| params = context.mapreduce_spec.mapper.params |
| |
| # requested program for which the duplicates are being found |
| program_key_urlsafe = params[PROGRAM_KEY_URLSAFE_PARAM] |
| |
| # actual program to which the profile corresponds |
| actual_program_key = db.Key(program_key_urlsafe) |
| |
| requested_program_key = db.Key.from_path( |
| 'GSoCProgram', '/'.join([ |
| profile_model.getSponsorId(profile_key), |
| profile_model.getProgramId(profile_key)])) |
| |
| if actual_program_key == requested_program_key: |
| profile_logic.setToBeAcceptedProposals(profile_key) |