| # Copyright 2015 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 job that sends reminders for organizations which do not have |
| a backup administrator. |
| """ |
| |
| from melange.appengine import django_setup |
| django_setup.setup_environment() |
| |
| from google.appengine.ext import db |
| from google.appengine.ext import ndb |
| |
| from mapreduce import context as mapreduce_context |
| from mapreduce import operation |
| |
| from codein.views.helper import urls as ci_urls |
| |
| from melange.logic import organization as org_logic |
| from melange.logic import profile as profile_logic |
| from melange.request import links |
| |
| from summerofcode.views.helper import urls as soc_urls |
| |
| # pylint: disable=unused-import |
| from soc.modules.gci.models.program import GCIProgram |
| from soc.modules.gci.models.timeline import GCITimeline |
| from soc.modules.gsoc.models.program import GSoCProgram |
| from soc.modules.gsoc.models.timeline import GSoCTimeline |
| # pylint: enable=unused-import |
| |
| |
| def process(org_key): |
| """Sends reminders to organization administrators if their applications |
| have not been completed. |
| |
| Args: |
| org_key: ndb.Key of organization key. |
| """ |
| context = mapreduce_context.get() |
| program_key = db.Key(context.mapreduce_spec.mapper.params['program_key']) |
| dry_run = ( |
| False if context.mapreduce_spec.mapper.params.get('dry_run') == 'False' |
| else True) |
| |
| org_key = ndb.Key.from_old_key(org_key) |
| organization = org_key.get() |
| |
| # do not do anything for organizations participating in another program |
| if organization.program.to_old_key() != program_key: |
| return |
| |
| # check how many administrators the organization has so far |
| org_admins = profile_logic.getOrgAdmins(organization) |
| |
| if program_key.kind() == 'GSoCProgram': |
| url_names = soc_urls.UrlNames |
| elif program_key.kind() == 'GCIProgram': |
| url_names = ci_urls.UrlNames |
| else: |
| raise ValueError('Invalid program type %s' % program_key.kind()) |
| |
| program = db.get(program_key) |
| |
| is_dispatched = org_logic.maybeDispatchApplicationProcessUnfinishedReminder( |
| org_key, program, program.timeline, url_names, links.ABSOLUTE_LINKER, |
| dry_run=dry_run) |
| |
| if is_dispatched: |
| yield operation.counters.Increment('reminder sent') |
| else: |
| yield operation.counters.Increment('reminder not sent') |