示例#1
0
def seed_org(unused_request, i):
  """Returns the properties for a new org entity.
  """

  _, current_user = ensureUser()
  gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')

  if not gsoc2009:
    raise Error('Run seed_db first')

  properties = {
      'key_name': 'google/gsoc2009/org_%d' % i,
      'link_id': 'org_%d' % i,
      'name': 'Organization %d' % i,
      'short_name': 'Org %d' % i,
      'founder': current_user,
      'scope_path': 'google/gsoc2009',
      'scope': gsoc2009,
      'status': 'active',
      'email': '*****@*****.**' % i,
      'home_page': 'http://code.google.com/p/soc',
      'description': 'Melange, share the love!',
      'license_name': 'Apache License',
      'contact_street': 'Some Street',
      'contact_city': 'Some City',
      'contact_country': 'United States',
      'contact_postalcode': '12345',
      'phone': '1-555-BANANA',
      'ideas': 'http://code.google.com/p/soc/issues',
      }

  return properties
示例#2
0
def seed_org(unused_request, i):
    """Returns the properties for a new org entity.
  """

    _, current_user = ensureUser()
    gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')

    if not gsoc2009:
        raise Error('Run seed_db first')

    properties = {
        'key_name': 'google/gsoc2009/org_%d' % i,
        'link_id': 'org_%d' % i,
        'name': 'Organization %d' % i,
        'short_name': 'Org %d' % i,
        'founder': current_user,
        'scope_path': 'google/gsoc2009',
        'scope': gsoc2009,
        'status': 'active',
        'email': '*****@*****.**' % i,
        'home_page': 'http://code.google.com/p/soc',
        'description': 'Melange, share the love!',
        'license_name': 'Apache License',
        'contact_street': 'Some Street',
        'contact_city': 'Some City',
        'contact_country': 'United States',
        'contact_postalcode': '12345',
        'phone': '1-555-BANANA',
        'ideas': 'http://code.google.com/p/soc/issues',
    }

    return properties
示例#3
0
    def commonSeedArgs(self, request):
        _, current_user = ensureUser()
        gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')

        if not gsoc2009:
            raise Error('Run seed_db first')

        return dict(current_user=current_user, gsoc2009=gsoc2009)
示例#4
0
  def _getNumberPerProgramRows(self, key_name, sources):
    source = sources[key_name]

    rows = []
    for program, number in source.iteritems():
      program = GSoCProgram.get_by_key_name(program)
      rows.append([program.name, int(number)])

    return rows
示例#5
0
  def commonSeedArgs(self, request):
    _, current_user = ensureUser()
    gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')

    if not gsoc2009:
      raise Error('Run seed_db first')

    return dict(current_user=current_user,
                gsoc2009=gsoc2009)
示例#6
0
def assignSlots(request, *args, **kwargs):
  """Sets the slots attribute for each organization entity

  POST Args:
    slots: an org_key:num_slots JSON dictionary
  """

  # Setup an artifical request deadline
  timelimit = int(request.REQUEST.get("timelimit", 20000))
  timekeeper = Timekeeper(timelimit)

  program_key = request.REQUEST.get("programkey")
  last_key = request.REQUEST.get("lastkey", "")
  program = GSoCProgram.get_by_key_name(program_key)

  # Copy for modification below
  params = request.POST.copy()
  params["timelimit"] = timelimit

  # Parse the JSON org:slots dictionary
  slots = simplejson.loads(program.slots_allocation)
  org_keys = [i for i in sorted(slots.keys()) if i > last_key]
  logging.info(org_keys)

  # Assign slots for each organization
  try:
    for clock, org_key in timekeeper.iterate(org_keys):
      logging.info("%s %s %s", request.path, clock, org_key)

      org_slots = slots[org_key]
      # Get the organization entity
      org_key = '/'.join([program_key, org_key])
      org = GSoCOrganization.get_by_key_name(org_key)

      if not org:
        logging.error("no such org '%s'/'%s'" % (program_key, org_key))
        continue

      # Count proposals and mentors
      org.slots = int(org_slots['slots'])
      org.nr_applications, org.nr_mentors = countProposals(org)

      # Update the organization entity
      org.put()

      # Mark the organization as done
      last_key = org_key

  # Requeue this task for continuation
  except DeadlineExceededError:
    params["lastkey"] = last_key
    taskqueue.add(url=request.path, params=params)

  # Exit this task successfully
  return responses.terminateTask()
示例#7
0
 def _getDataTableDescriptions(self, key_name, sources):
   if key_name in ['profiles', 'students', 'mentors', 'admins',
                   'students_with_proposals', 'students_with_projects']:
     return _NUMBER_PER_PROGRAM_DESCRIPTION
   if key_name in ['students_per_country', 'mentors_per_country']:
     columns = []
     columns.append(('country', 'string', 'Country'))
     source = sources[key_name]
     programs = GSoCProgram.get_by_key_name(source.keys())
     for program in programs:
       columns.append((program.key().name(), 'number', program.name))
     return columns
   if key_name in ['proposals_per_student']:
     columns = []
     columns.append(('proposals', 'number', 'Proposals'))
     source = sources[key_name]
     programs = GSoCProgram.get_by_key_name(source.keys())     
     for program in programs:
       columns.append((program.key().name(), 'number', program.name))
     return columns
示例#8
0
    def commonSeedArgs(self, request):
        _, current_user = ensureUser()
        gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')

        if not gsoc2009:
            raise Error('Run seed_db first')

        status = request.GET.get('status', 'pre-accepted')

        return dict(current_user=current_user,
                    gsoc2009=gsoc2009,
                    status=status)
示例#9
0
  def convertProposals(self, request, *args, **kwargs):
    """Start tasks to convert proposals for all organizations.

    POST Args:
      program_key: the key of the program whose proposals should be converted
      org_cursor: the cursor indicating at which org we currently are
    """
    params = dicts.merge(request.POST, request.GET)

    if 'program_key' not in params:
      logging.error("missing program_key in params: '%s'", params)
      return responses.terminateTask()

    program = GSoCProgram.get_by_key_name(params['program_key'])

    if not program:
      logging.error("invalid program_key in params: '%s'", params)
      return responses.terminateTask()

    query = soc_org_model.SOCOrganization.query(
        soc_org_model.SOCOrganization.program ==
            ndb.Key.from_old_key(program.key()),
        soc_org_model.SOCOrganization.status == org_model.Status.ACCEPTED)

    org_cursor = params.get('org_cursor')
    start_cursor = (
        datastore_query.Cursor(urlsafe=urllib.unquote_plus(org_cursor))
        if org_cursor else None)

    # Add a task for a single organization
    organizations, next_cursor, _ = query.fetch_page(
        1, start_cursor=start_cursor)

    if organizations:
      organization = organizations[0]
      logging.info(
          'Enqueing task to accept proposals for %s.', organization.name)
      # Compounded accept/reject taskflow
      taskqueue.add(
        url='/tasks/gsoc/accept_proposals/accept',
        params={
          'org_key': organization.key.id(),
        })

      # Enqueue a new task to do the next organization
      params['org_cursor'] = next_cursor.urlsafe()
      taskqueue.add(url=request.path, params=params)

    # Exit this task successfully
    return responses.terminateTask()
示例#10
0
  def status(self, request, *args, **kwargs):
    """Update the status of proposals conversion.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to update the
                   conversion status
    Args:
      request: Django Request object
    """
    params = request.POST

    # retrieve the program_key from POST data
    program_key = params.get('program_key')

    if not program_key:
      # invalid task data, log and return OK
      return error_handler.logErrorAndReturnOK(
          '"Missing program_key in params: "%s"' % params)

    # get the program for the given keyname
    program_entity = GSoCProgram.get_by_key_name(program_key)

    if not program_entity:
      # invalid program specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid program key specified: "%s"' % program_key)

    # obtain the accept proposals status
    aps_entity = conversion_logic.getOrCreateStatusForProgram(program_entity)

    # update the accept proposals status
    aps_entity.status = 'proceeded'

    # if the first proposal set the started_on
    converted_projects = aps_entity.nr_converted_projects + 1
    if converted_projects == 1:
      aps_entity.started_on = datetime.datetime.now()

    # tracks the number of converted projects so far
    aps_entity.nr_converted_projects = converted_projects

    db.put(aps_entity)

    # return OK
    return http.HttpResponse()
示例#11
0
def seed_survey(request, i):
  """Returns the properties for a new survey.
  """

  _, current_user = ensureUser()
  gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')

  if not gsoc2009:
    raise Error('Run seed_db first')
  link_id = 'survey_%d' % i
  fields = {'SelectionQ': [u'SelectionQ Option 2 for %s' % link_id,
                           u'SelectionQ Option 1 for %s'  % link_id
                           ],
            'PickMultipleQ': ['PickMultipleQ Checkbox 1 for %s' % link_id,
                              'PickMultipleQ Checkbox 2 for %s' % link_id,
                              ],
            'LongQ': 'LongQ Custom Prompt for %s' % link_id,
            'ShortQ': 'ShortQ Custom Prompt for %s' % link_id,
            }
  schema = {u'PickMultipleQ': {'index': 5, 'type': 'pick_multi',
                               'render': 'multi_checkbox'},
            u'LongQ': {'index': 2, 'type': 'long_answer'},
            u'ShortQ': {'index': 3, 'type': 'short_answer'},
            u'SelectionQ': {'index': 4, 'type': 'selection',
                            'render': 'single_select'}
            }
  properties = {
      'key_name': 'program/google/gsoc2009/%s' % link_id,
      'link_id': link_id,
      'scope_path': 'google/gsoc2009',
      'scope': None,
      'prefix': 'program',
      'author': current_user,
      'title': 'My Survey %d' % i,
      'short_name': 'Survey %d' % i,
      'modified_by': current_user,
      'is_featured': True,
      'fields': fields,
      'schema': schema,
      'deadline': DEADLINE,
      'taking_access': 'everyone',
      }
  return properties
示例#12
0
def seed_student(request, i):
    """Returns the properties for a new student entity.
  """

    gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')
    user = User.get_by_key_name('user_%d' % i)

    if not gsoc2009:
        raise Error('Run seed_db first')

    if not user:
        raise Error('Run seed_many for at least %d users first.' % i)

    properties = {
        'key_name': 'google/gsoc2009/student_%d' % i,
        'link_id': 'student_%d' % i,
        'scope_path': 'google/gsoc2009',
        'scope': gsoc2009,
        'user': user,
        'given_name': 'Student %d' % i,
        'surname': 'Last Name',
        'name_on_documents': 'Test Example',
        'email': '*****@*****.**',
        'res_street': 'Some Street',
        'res_city': 'Some City',
        'res_state': 'Some State',
        'res_country': 'United States',
        'res_postalcode': '12345',
        'phone': '1-555-BANANA',
        'birth_date': db.DateProperty.now(),
        'agreed_to_tos': True,
        'school_name': 'School %d' % i,
        'school_country': 'United States',
        'major': 'Computer Science',
        'degree': 'Undergraduate',
        'expected_graduation': 2012,
        'program_knowledge': 'Knowledge %d' % i,
        'school': None,
        'can_we_contact_you': True,
    }

    return properties
示例#13
0
def seed_student(request, i):
  """Returns the properties for a new student entity.
  """

  gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')
  user = User.get_by_key_name('user_%d' % i)

  if not gsoc2009:
    raise Error('Run seed_db first')

  if not user:
    raise Error('Run seed_many for at least %d users first.' % i)

  properties = {
      'key_name':'google/gsoc2009/student_%d' % i,
      'link_id': 'student_%d' % i,
      'scope_path': 'google/gsoc2009',
      'scope': gsoc2009,
      'user' : user,
      'given_name': 'Student %d' % i,
      'surname': 'Last Name',
      'name_on_documents': 'Test Example',
      'email': '*****@*****.**',
      'res_street': 'Some Street',
      'res_city': 'Some City',
      'res_state': 'Some State',
      'res_country': 'United States',
      'res_postalcode': '12345',
      'phone': '1-555-BANANA',
      'birth_date': db.DateProperty.now(),
      'agreed_to_tos': True,
      'school_name': 'School %d' % i,
      'school_country': 'United States',
      'major': 'Computer Science',
      'degree': 'Undergraduate',
      'expected_graduation': 2012,
      'program_knowledge': 'Knowledge %d' % i,
      'school': None,
      'can_we_contact_you': True,
  }

  return properties
示例#14
0
def seed_org_app(request, i):
    """Returns the properties for a new org proposal,
  """

    _, current_user = ensureUser()
    status = request.GET.get('status', 'pre-accepted')
    gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')

    if not gsoc2009:
        raise Error('Run seed_db first')

    properties = {
        'key_name': 'google/gsoc2009/org_%d' % i,
        'link_id': 'org_%d' % i,
        'name': 'Org App %d' % i,
        'scope_path': 'google/gsoc2009',
        'scope': gsoc2009,
        'status': status,
        'applicant': current_user,
        'home_page': 'http://www.google.com',
        'email': '*****@*****.**',
        'irc_channel': '#care',
        'pub_mailing_list': 'http://groups.google.com',
        'dev_mailing_list': 'http://groups.google.com',
        'description': 'This is an awesome org!',
        'why_applying': 'Because we can',
        'member_criteria': 'They need to be awesome',
        'license_name': 'Apache License, 2.0',
        'ideas': 'http://code.google.com/p/soc/issues',
        'contrib_disappears': 'We use google to find them',
        'member_disappears': 'See above',
        'encourage_contribs': 'We offer them cookies.',
        'continued_contribs': 'We promise them a cake.',
        'agreed_to_admin_agreement': True,
    }

    return properties
示例#15
0
def assignProgramSlots(request, *args, **kwargs):
  """Assign slots for organizations within a program

  Gets the slot assignment data as a JSON string from the program
  and enqueues a task to process the slot assignments

  POST Args:
    programkey: the key of the program to operate upon
  """

  program = None
  params = request.REQUEST

  # Query the program entity
  try:
    program = GSoCProgram.get_by_key_name(params["programkey"])
  except KeyError:
    logging.error("programkey not in params")
    return responses.terminateTask()

  if not program:
    logging.error("no such program '%s'" % params["programkey"])
    return responses.terminateTask()

  if not program.slots_allocation:
    logging.error("empty slots_allocation")
    return responses.terminateTask()

  # Enqueue a task to assign the slots
  taskqueue.add(
    url = "/gsoc/tasks/assignslots/assign",
    params = {
        'programkey': params["programkey"],
    })

  # Return successful
  return responses.terminateTask()
示例#16
0
 def getGSoC2012Profile(link_id):
   program = GSoCProgram.get_by_key_name('google/gsoc2012')
   return GSoCProfile.all().filter('scope', program).filter('link_id', link_id).get()
示例#17
0
  def start(self, request, *args, **kwargs):
    """Starts the task to find all duplicate proposals which are about to be
    accepted for a single GSoCProgram.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to find the
                   duplicate proposals
      repeat: Specifies if a new task that must be performed again an hour
              later, with the same POST data

    Args:
      request: Django Request object
    """

    from soc.logic.helper import timeline as timeline_helper

    post_dict = request.POST

    # retrieve the program_key and repeat option from POST data
    program_key = post_dict.get('program_key')
    repeat = post_dict.get('repeat')

    if not (program_key and repeat):
      # invalid task data, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid task data: %s' % post_dict)

    # get the program for the given keyname
    program_entity = GSoCProgram.get_by_key_name(program_key)

    if not program_entity:
      # invalid program specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid program specified: %s' % program_key)

    # obtain the proposal duplicate status
    pds_entity = duplicates_logic.getOrCreateStatusForProgram(program_entity)

    if pds_entity.status == 'idle':
      # delete all old duplicates
      duplicates_logic.deleteAllForProgram(program_entity)

      # pass these data along params as POST to the new task
      task_params = {'program_key': program_key}
      task_url = '/tasks/gsoc/proposal_duplicates/calculate'

      new_task = taskqueue.Task(params=task_params, url=task_url)

      def txn():
        # add a new task that performs duplicate calculation per
        # organization
        new_task.add(transactional=True)

        # update the status of the PDS entity to processing
        pds_entity.status = 'processing'
        pds_entity.put()

      db.RunInTransaction(txn)

    # Add a new clone of this task that must be performed an hour later because
    # the current task is part of the task that repeatedly runs but repeat
    # it before accepted students are announced only.
    if repeat == 'yes' and timeline_helper.isBeforeEvent(
        program_entity.timeline, 'accepted_students_announced_deadline'):
      # pass along these params as POST to the new task
      task_params = {'program_key': program_key,
                     'repeat': 'yes'}
      task_url = '/tasks/gsoc/proposal_duplicates/start'

      new_task = taskqueue.Task(params=task_params, url=task_url,
                                countdown=3600)
      new_task.add()

    # return OK
    return http.HttpResponse()
示例#18
0
  def calculate(self, request, *args, **kwargs):
    """Calculates the duplicate proposals in a given program for
    a student on a per Organization basis.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to find the
                   duplicate proposals
      org_cursor: Specifies the organization datastore cursor from which to
                  start the processing of finding the duplicate proposals

    Args:
      request: Django Request object
    """
    post_dict = request.POST

    program_key = post_dict.get('program_key')
    if not program_key:
      # invalid task data, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid program key: %s' % post_dict)

    program_entity = GSoCProgram.get_by_key_name(program_key)
    if not program_entity:
      # invalid program specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid program specified: %s' % program_key)

    # get the organization and update the cursor if possible
    q = GSoCOrganization.all()
    q.filter('status', 'active')
    q.filter('scope', program_entity)
    q.filter('slots >', 0)

    # retrieve the org_cursor from POST data
    org_cursor = post_dict.get('org_cursor')

    if org_cursor:
      org_cursor = str(org_cursor)
      q.with_cursor(org_cursor)

    org_entity = q.get()
    # update the cursor
    org_cursor = q.cursor()

    if org_entity:
      # get all the proposals likely to be accepted in the program
      accepted_proposals = proposal_logic.getProposalsToBeAcceptedForOrg(org_entity)

      for ap in accepted_proposals:
        student_entity = ap.parent()

        q = GSoCProposalDuplicate.all()
        q.filter('student', student_entity)
        proposal_duplicate = q.get()

        if proposal_duplicate and ap.key() not in proposal_duplicate.duplicates:
          # non-counted (to-be) accepted proposal found
          proposal_duplicate.duplicates = proposal_duplicate.duplicates + \
                                          [ap.key()]
          proposal_duplicate.is_duplicate = \
              len(proposal_duplicate.duplicates) >= 2
          if org_entity.key() not in proposal_duplicate.orgs:
            proposal_duplicate.orgs = proposal_duplicate.orgs + [org_entity.key()]
        else:
          pd_fields  = {
              'program': program_entity,
              'student': student_entity,
              'orgs':[org_entity.key()],
              'duplicates': [ap.key()],
              'is_duplicate': False
              }
          proposal_duplicate = GSoCProposalDuplicate(**pd_fields)

        proposal_duplicate.put()

      # Adds a new task that performs duplicate calculation for
      # the next organization.
      task_params = {'program_key': program_key,
                     'org_cursor': unicode(org_cursor)}
      task_url = '/tasks/gsoc/proposal_duplicates/calculate'

      new_task = taskqueue.Task(params=task_params, url=task_url)
      new_task.add()
    else:
      # There aren't any more organizations to process. So delete
      # all the proposals for which there are not more than one
      # proposal for duplicates property.
      duplicates_logic.deleteAllForProgram(program_entity, non_dupes_only=True)

      # update the proposal duplicate status and its timestamp
      pds_entity = duplicates_logic.getOrCreateStatusForProgram(program_entity)
      pds_entity.status = 'idle'
      pds_entity.calculated_on = datetime.datetime.now()
      pds_entity.put()

    # return OK
    return http.HttpResponse()
示例#19
0
    def calculate(self, request, *args, **kwargs):
        """Calculates the duplicate proposals in a given program for
    a student on a per Organization basis.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to find the
                   duplicate proposals
      org_cursor: Specifies the organization datastore cursor from which to
                  start the processing of finding the duplicate proposals

    Args:
      request: Django Request object
    """
        post_dict = request.POST

        program_key = post_dict.get('program_key')
        if not program_key:
            # invalid task data, log and return OK
            return error_handler.logErrorAndReturnOK(
                'Invalid program key: %s' % post_dict)

        program_entity = GSoCProgram.get_by_key_name(program_key)
        if not program_entity:
            # invalid program specified, log and return OK
            return error_handler.logErrorAndReturnOK(
                'Invalid program specified: %s' % program_key)

        # get the organization and update the cursor if possible
        query = soc_org_model.SOCOrganization.query(
            soc_org_model.SOCOrganization.status == org_model.Status.ACCEPTED,
            soc_org_model.SOCOrganization.program == ndb.Key.from_old_key(
                program_entity.key()),
            soc_org_model.SOCOrganization.slot_allocation > 0)

        # retrieve the org_cursor from POST data
        org_cursor = post_dict.get('org_cursor')
        start_cursor = (datastore_query.Cursor(
            urlsafe=org_cursor) if org_cursor else None)

        organizations, next_cursor, _ = query.fetch_page(
            1, start_cursor=start_cursor)

        if organizations:
            organization = organizations[0]
            # get all the proposals likely to be accepted in the program
            accepted_proposals = (
                proposal_logic.getProposalsToBeAcceptedForOrg(organization))

            for accepted_proposal in accepted_proposals:
                q = GSoCProposalDuplicate.all()
                q.filter('student', accepted_proposal.parent_key())
                proposal_duplicate = q.get()

                if (proposal_duplicate and accepted_proposal.key()
                        not in proposal_duplicate.duplicates):
                    # non-counted (to-be) accepted proposal found
                    proposal_duplicate.duplicates = proposal_duplicate.duplicates + \
                                                    [accepted_proposal.key()]
                    proposal_duplicate.is_duplicate = \
                        len(proposal_duplicate.duplicates) >= 2
                    if organization.key.to_old_key(
                    ) not in proposal_duplicate.orgs:
                        proposal_duplicate.orgs = (
                            proposal_duplicate.orgs +
                            [organization.key.to_old_key()])
                else:
                    pd_fields = {
                        'program': program_entity,
                        'student': accepted_proposal.parent_key(),
                        'orgs': [organization.key.to_old_key()],
                        'duplicates': [accepted_proposal.key()],
                        'is_duplicate': False
                    }
                    proposal_duplicate = GSoCProposalDuplicate(**pd_fields)

                proposal_duplicate.put()

            # Adds a new task that performs duplicate calculation for
            # the next organization.
            task_params = {
                'program_key': program_key,
                'org_cursor': next_cursor.urlsafe()
            }
            task_url = '/tasks/gsoc/proposal_duplicates/calculate'

            new_task = taskqueue.Task(params=task_params, url=task_url)
            new_task.add()
        else:
            # There aren't any more organizations to process. So delete
            # all the proposals for which there are not more than one
            # proposal for duplicates property.
            duplicates_logic.deleteAllForProgram(program_entity,
                                                 non_dupes_only=True)

            # update the proposal duplicate status and its timestamp
            pds_entity = duplicates_logic.getOrCreateStatusForProgram(
                program_entity)
            pds_entity.status = 'idle'
            pds_entity.calculated_on = datetime.datetime.now()
            pds_entity.put()

        # return OK
        return http.HttpResponse()
示例#20
0
    def start(self, request, *args, **kwargs):
        """Starts the task to find all duplicate proposals which are about to be
    accepted for a single GSoCProgram.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to find the
                   duplicate proposals
      repeat: Specifies if a new task that must be performed again an hour
              later, with the same POST data

    Args:
      request: Django Request object
    """

        from soc.logic.helper import timeline as timeline_helper

        post_dict = request.POST

        # retrieve the program_key and repeat option from POST data
        program_key = post_dict.get('program_key')
        repeat = post_dict.get('repeat')

        if not (program_key and repeat):
            # invalid task data, log and return OK
            return error_handler.logErrorAndReturnOK('Invalid task data: %s' %
                                                     post_dict)

        # get the program for the given keyname
        program_entity = GSoCProgram.get_by_key_name(program_key)

        if not program_entity:
            # invalid program specified, log and return OK
            return error_handler.logErrorAndReturnOK(
                'Invalid program specified: %s' % program_key)

        # obtain the proposal duplicate status
        pds_entity = duplicates_logic.getOrCreateStatusForProgram(
            program_entity)

        if pds_entity.status == 'idle':
            # delete all old duplicates
            duplicates_logic.deleteAllForProgram(program_entity)

            # pass these data along params as POST to the new task
            task_params = {'program_key': program_key}
            task_url = '/tasks/gsoc/proposal_duplicates/calculate'

            new_task = taskqueue.Task(params=task_params, url=task_url)

            def txn():
                # add a new task that performs duplicate calculation per
                # organization
                new_task.add(transactional=True)

                # update the status of the PDS entity to processing
                pds_entity.status = 'processing'
                pds_entity.put()

            db.RunInTransaction(txn)

        # Add a new clone of this task that must be performed an hour later because
        # the current task is part of the task that repeatedly runs but repeat
        # it before accepted students are announced only.
        if repeat == 'yes' and timeline_helper.isBeforeEvent(
                program_entity.timeline,
                'accepted_students_announced_deadline'):
            # pass along these params as POST to the new task
            task_params = {'program_key': program_key, 'repeat': 'yes'}
            task_url = '/tasks/gsoc/proposal_duplicates/start'

            new_task = taskqueue.Task(params=task_params,
                                      url=task_url,
                                      countdown=3600)
            new_task.add()

        # return OK
        return http.HttpResponse()
示例#21
0
  def spawnRemindersForProjectSurvey(self, request, *args, **kwargs):
    """Spawns tasks for each GSoCProject in the given Program.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to loop over all
                   the GSoCProject entities
      survey_key: specifies the key name for the ProjectSurvey to send
                  reminders for
      survey_type: a string which is project or grading depending on
                   the type of Survey.
      cursor: optional query cursor to indicate how far along we are.

    Args:
      request: Django Request object
    """
    post_dict = request.POST

    # retrieve the program_key and survey_key from POST data
    program_key = post_dict.get('program_key')
    survey_key = post_dict.get('survey_key')
    survey_type = post_dict.get('survey_type')

    if not (program_key and survey_key and survey_type):
      # invalid task data, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid spawnRemindersForProjectSurvey data: %s' % post_dict)

    program_entity = GSoCProgram.get_by_key_name(program_key)

    if not program_entity:
      # invalid program specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid program specified: %s' % program_key)

    q = GSoCProject.all()
    q.filter('status', 'accepted')
    q.filter('program', program_entity)

    if 'cursor' in post_dict:
      q.with_cursor(post_dict['cursor'])

    projects = q.fetch(self.BATCH_SIZE)

    if not projects:
      # we are done, return OK
      return http.HttpResponse()

    for project in projects:
      task_params = {
          'survey_key': survey_key,
          'survey_type': survey_type,
          'project_key': str(project.key())
          }
      task_url = '/tasks/gsoc/surveys/send_reminder/send'

      new_task = taskqueue.Task(params=task_params, url=task_url)
      new_task.add('mail')

    # pass along these params as POST to the new task
    task_params = {
        'program_key': program_key,
        'survey_key': survey_key,
        'survey_type': survey_type,
        'cursor': q.cursor()
        }
    task_url = request.path
    new_task = taskqueue.Task(params=task_params, url=task_url)
    new_task.add()

    # return OK
    return http.HttpResponse()
示例#22
0
    def spawnRemindersForProjectSurvey(self, request, *args, **kwargs):
        """Spawns tasks for each GSoCProject in the given Program.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to loop over all
                   the GSoCProject entities
      survey_key: specifies the key name for the ProjectSurvey to send
                  reminders for
      survey_type: a string which is project or grading depending on
                   the type of Survey.
      cursor: optional query cursor to indicate how far along we are.

    Args:
      request: Django Request object
    """
        post_dict = request.POST

        # retrieve the program_key and survey_key from POST data
        program_key = post_dict.get('program_key')
        survey_key = post_dict.get('survey_key')
        survey_type = post_dict.get('survey_type')

        if not (program_key and survey_key and survey_type):
            # invalid task data, log and return OK
            return error_handler.logErrorAndReturnOK(
                'Invalid spawnRemindersForProjectSurvey data: %s' % post_dict)

        program_entity = GSoCProgram.get_by_key_name(program_key)

        if not program_entity:
            # invalid program specified, log and return OK
            return error_handler.logErrorAndReturnOK(
                'Invalid program specified: %s' % program_key)

        q = GSoCProject.all()
        q.filter('status', 'accepted')
        q.filter('program', program_entity)

        if 'cursor' in post_dict:
            q.with_cursor(post_dict['cursor'])

        projects = q.fetch(self.BATCH_SIZE)

        if not projects:
            # we are done, return OK
            return http.HttpResponse()

        for project in projects:
            task_params = {
                'survey_key': survey_key,
                'survey_type': survey_type,
                'project_key': str(project.key())
            }
            task_url = '/tasks/gsoc/surveys/send_reminder/send'

            new_task = taskqueue.Task(params=task_params, url=task_url)
            new_task.add('mail')

        # pass along these params as POST to the new task
        task_params = {
            'program_key': program_key,
            'survey_key': survey_key,
            'survey_type': survey_type,
            'cursor': q.cursor()
        }
        task_url = request.path
        new_task = taskqueue.Task(params=task_params, url=task_url)
        new_task.add()

        # return OK
        return http.HttpResponse()
示例#23
0
  def calculate(self, request, *args, **kwargs):
    """Calculates the duplicate proposals in a given program for
    a student on a per Organization basis.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to find the
                   duplicate proposals
      org_cursor: Specifies the organization datastore cursor from which to
                  start the processing of finding the duplicate proposals

    Args:
      request: Django Request object
    """
    post_dict = request.POST

    program_key = post_dict.get('program_key')
    if not program_key:
      # invalid task data, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid program key: %s' % post_dict)

    program_entity = GSoCProgram.get_by_key_name(program_key)
    if not program_entity:
      # invalid program specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid program specified: %s' % program_key)

    # get the organization and update the cursor if possible
    query = soc_org_model.SOCOrganization.query(
        soc_org_model.SOCOrganization.status == org_model.Status.ACCEPTED,
        soc_org_model.SOCOrganization.program ==
            ndb.Key.from_old_key(program_entity.key()),
        soc_org_model.SOCOrganization.slot_allocation > 0)

    # retrieve the org_cursor from POST data
    org_cursor = post_dict.get('org_cursor')
    start_cursor = (
        datastore_query.Cursor(urlsafe=org_cursor) if org_cursor else None)

    organizations, next_cursor, _ = query.fetch_page(
        1, start_cursor=start_cursor)

    if organizations:
      organization = organizations[0]
      # get all the proposals likely to be accepted in the program
      accepted_proposals = (
          proposal_logic.getProposalsToBeAcceptedForOrg(organization))

      for accepted_proposal in accepted_proposals:
        q = GSoCProposalDuplicate.all()
        q.filter('student', accepted_proposal.parent_key())
        proposal_duplicate = q.get()

        if (proposal_duplicate and
            accepted_proposal.key() not in proposal_duplicate.duplicates):
          # non-counted (to-be) accepted proposal found
          proposal_duplicate.duplicates = proposal_duplicate.duplicates + \
                                          [accepted_proposal.key()]
          proposal_duplicate.is_duplicate = \
              len(proposal_duplicate.duplicates) >= 2
          if organization.key.to_old_key() not in proposal_duplicate.orgs:
            proposal_duplicate.orgs = (
                proposal_duplicate.orgs + [organization.key.to_old_key()])
        else:
          pd_fields = {
              'program': program_entity,
              'student': accepted_proposal.parent_key(),
              'orgs':[organization.key.to_old_key()],
              'duplicates': [accepted_proposal.key()],
              'is_duplicate': False
              }
          proposal_duplicate = GSoCProposalDuplicate(**pd_fields)

        proposal_duplicate.put()

      # Adds a new task that performs duplicate calculation for
      # the next organization.
      task_params = {
          'program_key': program_key,
          'org_cursor': next_cursor.urlsafe()
          }
      task_url = '/tasks/gsoc/proposal_duplicates/calculate'

      new_task = taskqueue.Task(params=task_params, url=task_url)
      new_task.add()
    else:
      # There aren't any more organizations to process. So delete
      # all the proposals for which there are not more than one
      # proposal for duplicates property.
      duplicates_logic.deleteAllForProgram(program_entity, non_dupes_only=True)

      # update the proposal duplicate status and its timestamp
      pds_entity = duplicates_logic.getOrCreateStatusForProgram(program_entity)
      pds_entity.status = 'idle'
      pds_entity.calculated_on = datetime.datetime.now()
      pds_entity.put()

    # return OK
    return http.HttpResponse()
示例#24
0
文件: stats.py 项目: adviti/melange
 def getGSoC2011Profile(link_id):
   program = GSoCProgram.get_by_key_name('google/gsoc2011')
   return GSoCProfile.all().filter('scope', program).filter('link_id', link_id).get()
示例#25
0
def seed_survey(request, i):
    """Returns the properties for a new survey.
  """

    _, current_user = ensureUser()
    gsoc2009 = GSoCProgram.get_by_key_name('google/gsoc2009')

    if not gsoc2009:
        raise Error('Run seed_db first')
    link_id = 'survey_%d' % i
    fields = {
        'SelectionQ': [
            u'SelectionQ Option 2 for %s' % link_id,
            u'SelectionQ Option 1 for %s' % link_id
        ],
        'PickMultipleQ': [
            'PickMultipleQ Checkbox 1 for %s' % link_id,
            'PickMultipleQ Checkbox 2 for %s' % link_id,
        ],
        'LongQ':
        'LongQ Custom Prompt for %s' % link_id,
        'ShortQ':
        'ShortQ Custom Prompt for %s' % link_id,
    }
    schema = {
        u'PickMultipleQ': {
            'index': 5,
            'type': 'pick_multi',
            'render': 'multi_checkbox'
        },
        u'LongQ': {
            'index': 2,
            'type': 'long_answer'
        },
        u'ShortQ': {
            'index': 3,
            'type': 'short_answer'
        },
        u'SelectionQ': {
            'index': 4,
            'type': 'selection',
            'render': 'single_select'
        }
    }
    properties = {
        'key_name': 'program/google/gsoc2009/%s' % link_id,
        'link_id': link_id,
        'scope_path': 'google/gsoc2009',
        'scope': None,
        'prefix': 'program',
        'author': current_user,
        'title': 'My Survey %d' % i,
        'short_name': 'Survey %d' % i,
        'modified_by': current_user,
        'is_featured': True,
        'fields': fields,
        'schema': schema,
        'deadline': DEADLINE,
        'taking_access': 'everyone',
    }
    return properties