Esempio n. 1
0
def runProgramConversionUpdate(request, entities, context, *args, **kwargs):
  """AppEngine Task that converts Programs into GSoCPrograms.

  Args:
    request: Django Request object
    entities: list of Program entities to convert
    context: the context of this task
  """

  from soc.modules.gsoc.models.program import GSoCProgram

  # get all the properties that are part of each Programs
  program_model = program_logic.getModel()
  program_properties = program_model.properties().keys()

  # use this to store all the new GSoCPrograms
  gsoc_programs = []

  for entity in entities:
    gsoc_properties = {}

    for program_property in program_properties:
      # copy over all the information from the program entity
      gsoc_properties[program_property] = getattr(entity, program_property)

    # create the new GSoCProgram entity and prepare it to be stored
    gsoc_program_entity = GSoCProgram(key_name=entity.key().name(),
                                      **gsoc_properties)
    gsoc_programs.append(gsoc_program_entity)

  # store all the new GSoCPrograms
  db.put(gsoc_programs)

  # task completed, return
  return
Esempio n. 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
Esempio n. 3
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
Esempio n. 4
0
  def programs(self):
    """Memoizes and returns a list of all programs.
    """
    from soc.modules.gsoc.models.program import GSoCProgram
    if not self._programs:
      self._programs = list(GSoCProgram.all())

    return self._programs
Esempio n. 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)
Esempio n. 6
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)
Esempio n. 7
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
Esempio n. 8
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()
Esempio n. 9
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
Esempio n. 10
0
  def registerWithProgramMap(self):
    """Called by the server when program_map entries should be registered.
    """

    self.core.requireUniqueService('registerWithProgramMap')

    from soc.modules.gsoc.models.program import GSoCProgram
    program_entities = GSoCProgram.all().fetch(1000)
    map = ('GSoC Programs', [
        (str(e.key()), e.name) for e in program_entities])

    self.core.registerProgramEntry(map)
Esempio n. 11
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)
Esempio n. 12
0
def clear(*args, **kwargs):
    """Removes all entities from the datastore.
  """

    # there no explicit ranker model anywhere, so make one for
    # our own convenience to delete all rankers
    class ranker(db.Model):
        """ranker model used with ranklist module.
    """
        pass

    # TODO(dbentley): If there are more than 1000 instances of any model,
    # this method will not clear all instances.  Instead, it should continually
    # call .all(), delete all those, and loop until .all() is empty.
    entities = itertools.chain(*[
        Notification.all(),
        GSoCMentor.all(),
        GHOPMentor.all(),
        GSoCStudent.all(),
        GHOPStudent.all(),
        Survey.all(),
        SurveyContent.all(),
        SurveyRecord.all(),
        GSoCOrgAdmin.all(),
        GHOPOrgAdmin.all(),
        ranker.all(),
        RankerRoot.all(),
        StudentProposal.all(),
        GSoCOrganization.all(),
        GHOPOrganization.all(),
        OrgApplication.all(),
        GSoCTimeline.all(),
        GHOPTimeline.all(),
        GSoCProgram.all(),
        GHOPProgram.all(),
        Host.all(),
        Sponsor.all(),
        User.all(),
        Site.all(),
        Document.all(),
    ])

    try:
        for entity in entities:
            entity.delete()
    except db.Timeout:
        return http.HttpResponseRedirect('#')
    # pylint: disable-msg=E1101
    memcache.flush_all()

    return http.HttpResponse('Done')
Esempio n. 13
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()
Esempio n. 14
0
def clear(*args, **kwargs):
  """Removes all entities from the datastore.
  """

  # there no explicit ranker model anywhere, so make one for
  # our own convenience to delete all rankers
  class ranker(db.Model):
    """ranker model used with ranklist module.
    """
    pass

  # TODO(dbentley): If there are more than 1000 instances of any model,
  # this method will not clear all instances.  Instead, it should continually
  # call .all(), delete all those, and loop until .all() is empty.
  entities = itertools.chain(*[
      Notification.all(),
      GSoCMentor.all(),
      GCIMentor.all(),
      GSoCStudent.all(),
      GCIStudent.all(),
      Survey.all(),
      SurveyContent.all(),
      SurveyRecord.all(),
      GSoCOrgAdmin.all(),
      GCIOrgAdmin.all(),
      ranker.all(),
      RankerRoot.all(),
      StudentProposal.all(),
      GSoCOrganization.all(),
      GCIOrganization.all(),
      GSoCTimeline.all(),
      GCITimeline.all(),
      GSoCProgram.all(),
      GCIProgram.all(),
      Host.all(),
      Sponsor.all(),
      User.all(),
      Site.all(),
      Document.all(),
      ])

  try:
    for entity in entities:
      entity.delete()
  except db.Timeout:
    return http.HttpResponseRedirect('#')
  # pylint: disable=E1101
  memcache.flush_all()

  return http.HttpResponse('Done')
Esempio n. 15
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()
Esempio n. 16
0
def clear(*args, **kwargs):
  """Removes all entities from the datastore.
  """

  # TODO(dbentley): If there are more than 1000 instances of any model,
  # this method will not clear all instances.  Instead, it should continually
  # call .all(), delete all those, and loop until .all() is empty.
  entities = itertools.chain(*[
      Survey.all(),
      SurveyRecord.all(),
      GCIOrganization.all(),
      GSoCTimeline.all(),
      GCITimeline.all(),
      GSoCProgram.all(),
      GSoCProject.all(),
      GSoCProposal.all(),
      GCIProgram.all(),
      GCIScore.all(),
      GSoCStudentInfo.all(),
      GCIStudentInfo.all(),
      GCITask.all(),
      Sponsor.all(),
      Site.all(),
      Document.all(),
      # The below models are all subclasses of ndb.Model and therefore must
      # use .query() to return all instances instead of .all().
      soc_org_model.SOCOrganization.query(),
      profile_model.Profile.query(),
      soc_profile.SOCStudentData.query(),
      user.User.query(),
      address.Address.query(),
      contact.Contact.query()
      ])

  try:
    for entity in entities:
      if isinstance(entity, ndb.Model):
        entity.key.delete()
      else:
        entity.delete()
  except db.Timeout:
    return http.HttpResponseRedirect('#')
  memcache.flush_all()

  return http.HttpResponse('Done')
Esempio n. 17
0
def clear(*args, **kwargs):
    """Removes all entities from the datastore.
  """

    # TODO(dbentley): If there are more than 1000 instances of any model,
    # this method will not clear all instances.  Instead, it should continually
    # call .all(), delete all those, and loop until .all() is empty.
    entities = itertools.chain(*[
        Survey.all(),
        SurveyRecord.all(),
        GCIOrganization.all(),
        GSoCTimeline.all(),
        GCITimeline.all(),
        GSoCProgram.all(),
        GSoCProject.all(),
        GSoCProposal.all(),
        GCIProgram.all(),
        GCIScore.all(),
        GSoCStudentInfo.all(),
        GCIStudentInfo.all(),
        GCITask.all(),
        Sponsor.all(),
        Site.all(),
        Document.all(),
        # The below models are all subclasses of ndb.Model and therefore must
        # use .query() to return all instances instead of .all().
        soc_org_model.SOCOrganization.query(),
        profile_model.Profile.query(),
        soc_profile.SOCStudentData.query(),
        user.User.query(),
        address.Address.query(),
        contact.Contact.query()
    ])

    try:
        for entity in entities:
            if isinstance(entity, ndb.Model):
                entity.key.delete()
            else:
                entity.delete()
    except db.Timeout:
        return http.HttpResponseRedirect('#')
    memcache.flush_all()

    return http.HttpResponse('Done')
Esempio n. 18
0
def convertUser(user_key):
    """Converts the specified user by creating a new user entity that inherits
  from the newly added NewUser model.

  Args:
    user_key: User key.
  """
    user = User.get(user_key)

    entity_id = user.key().name()
    account_id = user.user_id or 'unset'

    if user.status == 'valid':
        status = user_model.Status.ACTIVE
    elif user.status == 'invalid':
        status = user_model.Status.BANNED
    else:
        operation.counters.Increment('Bad status')
        logging.warning('Invalid status %s for user %s', user.status,
                        user.key().name())
        return

    host_for = []
    for sponsor_key in user.host_for:
        host_for.extend(
            map(
                ndb.Key.from_old_key,
                GSoCProgram.all(keys_only=True).filter(
                    'sponsor', sponsor_key).fetch(1000)))
        host_for.extend(
            map(
                ndb.Key.from_old_key,
                GCIProgram.all(keys_only=True).filter(
                    'sponsor', sponsor_key).fetch(1000)))

    account = user.account

    new_user = NewUser(id=entity_id,
                       account_id=account_id,
                       status=status,
                       host_for=host_for,
                       account=account)
    _createUserTxn(new_user)
Esempio n. 19
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
Esempio n. 20
0
def clear(*args, **kwargs):
  """Removes all entities from the datastore.
  """

  # TODO(dbentley): If there are more than 1000 instances of any model,
  # this method will not clear all instances.  Instead, it should continually
  # call .all(), delete all those, and loop until .all() is empty.
  entities = itertools.chain(*[
      Notification.all(),
      GCIStudent.all(),
      Survey.all(),
      SurveyRecord.all(),
      StudentProposal.all(),
      GSoCOrganization.all(),
      GCIOrganization.all(),
      GSoCTimeline.all(),
      GCITimeline.all(),
      GSoCProgram.all(),
      GSoCProfile.all(),
      GCIProfile.all(),
      GSoCProposal.all(),
      GCIProgram.all(),
      GCIScore.all(),
      GSoCStudentInfo.all(),
      GCIStudentInfo.all(),
      GCITask.all(),
      Host.all(),
      Sponsor.all(),
      User.all(),
      Site.all(),
      Document.all(),
      ])

  try:
    for entity in entities:
      entity.delete()
  except db.Timeout:
    return http.HttpResponseRedirect('#')
  # pylint: disable=E1101
  memcache.flush_all()

  return http.HttpResponse('Done')
Esempio n. 21
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
Esempio n. 22
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
Esempio n. 23
0
def convertUser(user_key):
  """Converts the specified user by creating a new user entity that inherits
  from the newly added NewUser model.

  Args:
    user_key: User key.
  """
  user = User.get(user_key)

  entity_id = user.key().name()
  account_id = user.user_id or 'unset'

  if user.status == 'valid':
    status = user_model.Status.ACTIVE
  elif user.status == 'invalid':
    status = user_model.Status.BANNED
  else:
    operation.counters.Increment('Bad status')
    logging.warning(
        'Invalid status %s for user %s', user.status, user.key().name())
    return

  host_for = []
  for sponsor_key in user.host_for:
    host_for.extend(map(
        ndb.Key.from_old_key,
        GSoCProgram.all(keys_only=True)
            .filter('sponsor', sponsor_key).fetch(1000)))
    host_for.extend(map(
        ndb.Key.from_old_key,
        GCIProgram.all(keys_only=True)
            .filter('sponsor', sponsor_key).fetch(1000)))

  account = user.account

  new_user = NewUser(
      id=entity_id, account_id=account_id, status=status, host_for=host_for,
      account=account)
  _createUserTxn(new_user)
Esempio n. 24
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()
Esempio n. 25
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
Esempio n. 26
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()
Esempio n. 27
0
 def setUp(self):
     """Set up required for the task tests.
 """
     # Setup TaskQueueTestCase and MailTestCase first
     super(AcceptProposalsTest, self).setUp()
     # Create a user for the founder of sponsor
     email = "*****@*****.**"
     account = users.User(email=email)
     link_id = 'a_sponsor_user'
     name = 'A Sponsor User'
     sponsor_user_properties = {
         'account': account,
         'link_id': link_id,
         'name': name,
     }
     sponsor_user = user_logic.updateOrCreateFromFields(
         sponsor_user_properties)
     # Create a sponsor
     link_id = 'a_sponsor'
     name = link_id
     founder = 'a_founder'
     phone = '01234567'
     contact_postalcode = 'A postalcode'
     description = 'A description'
     contact_country = 'United States'
     short_name = 'AS'
     contact_city = 'A city'
     home_page = 'http://www.asponsor.com'
     email = '*****@*****.**'
     sponsor_properties = {
         'link_id': link_id,
         'name': name,
         'short_name': short_name,
         'founder': sponsor_user,
         'phone': phone,
         'description': description,
         'contact_country': contact_country,
         'contact_city': 'A City',
         'contact_street': 'A Street',
         'contact_postalcode': contact_postalcode,
         'home_page': home_page,
         'email': email,
         'status': 'active',
     }
     sponsor = sponsor_logic.updateOrCreateFromFields(sponsor_properties)
     # Create a timeline for a program
     timeline_properties = {
         'link_id': 'a_program',
         'scope_path': 'a_sponsor',
         'scope': sponsor,
         'accepted_students_announced_deadline': datetime.datetime.now() \
             + datetime.timedelta(10)
           }
     timeline = gsoc_timeline_logic.updateOrCreateFromFields(
         timeline_properties)
     # Create a program for a_sponsor
     program_properties = {
         'key_name': 'a_sponsor/a_program',
         'link_id': 'a_program',
         'scope': sponsor,
         'scope_path': 'a_sponsor',
         'name': 'A Program 2010',
         'short_name': 'AP2010',
         'group_label': 'AP',
         'description': 'This is the program for AP2010.',
         'apps_tasks_limit': 42,
         'slots': 42,
         'allocations_visible': True,
         'timeline': timeline,
         'status': 'visible',
     }
     # GSoC program logic does not work: error in updatePredefinedOrgTags
     from soc.modules.gsoc.models.program import GSoCProgram
     program = GSoCProgram(**program_properties)
     program.put()
     self.program = program
     # Create an organization for a_program
     organization_properties = {
         'link_id': 'an_org',
         'name': 'An Organization',
         'short_name': 'AO',
         'scope_path': 'a_sponsor/a_program',
         'scope': program,
         'founder': sponsor_user,
         'home_page': 'http://www.an_org.com',
         'phone': '1-555-2222',
         'description': 'An Organization',
         'license_name': 'Apache License',
         'ideas': 'http://www.an_org.com/ideas',
         'contact_country': contact_country,
         'contact_city': 'A City',
         'contact_street': 'A Street',
         'contact_postalcode': contact_postalcode,
         'home_page': home_page,
         'email': email,
         'slots': 1,
         'status': 'active',
     }
     organization = gsoc_organization_logic.updateOrCreateFromFields(
         organization_properties)
     self.organization = organization
     # Create another organization for a_program
     organization_properties.update({
         'link_id': 'another_org',
     })
     another_organization = gsoc_organization_logic.updateOrCreateFromFields(
         organization_properties)
     # Create an organization to serve as cursor sub for a_program, which should
     # come as the first result of query
     organization_properties.update({
         'link_id': 'aa_org',
     })
     stub_organization = gsoc_organization_logic.updateOrCreateFromFields(
         organization_properties)
     self.stub_organization = stub_organization
     # Create a user for all roles except sponsor
     email = "*****@*****.**"
     account = users.User(email=email)
     link_id = 'a_role_user'
     name = 'A Role User'
     properties = {
         'account': account,
         'link_id': link_id,
         'name': name,
     }
     key_name = user_logic.getKeyNameFromFields(properties)
     role_user = user_logic.updateOrCreateFromKeyName(properties, key_name)
     # Create a mentor for an_org
     mentor_properties = sponsor_properties.copy()
     mentor_properties.update({
         'link_id':
         'a_mentor',
         'scope_path':
         organization.scope_path + '/' + organization.link_id,
         'scope':
         organization,
         'program':
         program,
         'given_name':
         'A',
         'surname':
         'Mentor',
         'res_country':
         'United States',
         'res_city':
         'A City',
         'res_street':
         'A Street',
         'res_postalcode':
         '12345',
         'birth_date':
         db.DateProperty.now(),
         'user':
         role_user,
         'email':
         '*****@*****.**',
     })
     mentor = mentor_logic.updateOrCreateFromFields(mentor_properties)
     self.mentor = mentor
     # Create a student for a_program
     student_properties = mentor_properties.copy()
     student_properties.update({
         'link_id':
         'a_student',
         'scope_path':
         program.scope_path + '/' + program.link_id,
         'scope':
         program,
         'program':
         program,
         'given_name':
         'A',
         'surname':
         'Student',
         'major':
         'A Major',
         'name_on_documents':
         'A Name on Documents',
         'publish_location':
         True,
         'blog':
         'http://www.ablog.com/',
         'home_page':
         'http://www.ahomepage.com/',
         'email':
         '*****@*****.**',
         'photo_url':
         'http://www.astudent.com/aphoto.png',
         'expected_graduation':
         2011,
         'school_country':
         'United States',
         'school_name':
         'A School',
         'tshirt_size':
         'XS',
         'tshirt_style':
         'male',
         'degree':
         'Undergraduate',
         'phone':
         '1650253000',
         'can_we_contact_you':
         True,
         'program_knowledge':
         'I heard about this program through a friend.'
     })
     student = student_logic.updateOrCreateFromFields(student_properties)
     self.student = student
     # Create another student for a_program
     student_properties.update({
         'link_id': 'another_student',
         'email': '*****@*****.**',
     })
     another_student = student_logic.updateOrCreateFromFields(
         student_properties)
     self.another_student = another_student
     # Create a third student for a_program
     student_properties.update({
         'link_id': 'third_student',
         'email': '*****@*****.**',
     })
     third_student = student_logic.updateOrCreateFromFields(
         student_properties)
     self.third_student = third_student
     # Create a student proposal to an_org for a_student
     student_proposal_properties = {
         'link_id': 'a_proposal',
         'scope_path': student.scope_path + '/' + student.link_id,
         'scope': student,
         'title': 'A Proposal Title',
         'abstract': 'A Proposal Abstract',
         'content': 'A Proposal Content',
         'additional_info': 'http://www.a_proposal.com',
         'mentor': mentor,
         'status': 'pending',
         'org': organization,
         'program': program,
         'score': 90,
     }
     self.proposal = student_proposal_logic.updateOrCreateFromFields(
         student_proposal_properties)
     # Create another student proposal to an_org for another_student
     student_proposal_properties.update({
         'link_id':
         'another_proposal',
         'scope_path':
         another_student.scope_path + '/' + another_student.link_id,
         'scope':
         another_student,
         'score':
         100,
     })
     self.another_proposal = student_proposal_logic.updateOrCreateFromFields(
         student_proposal_properties)
     # Create a third student proposal to another_org for third_student
     student_proposal_properties.update({
         'link_id':
         'third_proposal',
         'scope_path':
         third_student.scope_path + '/' + third_student.link_id,
         'scope':
         third_student,
         'org':
         another_organization,
         'score':
         10,
     })
     student_proposal_logic.updateOrCreateFromFields(
         student_proposal_properties)
Esempio n. 28
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()
Esempio n. 29
0
def seed(request, *args, **kwargs):
  """Seeds the datastore with some default values.
  """

  site_properties = {
      'key_name': 'site',
      'latest_gsoc': 'numenta/son2014',
      # 'latest_gci': 'numenta/gci2013',
      }
  site = Site(**site_properties)
  site.put()

  account = accounts.getCurrentAccount()

  if not account:
    account = users.User(email='*****@*****.**')

  user_properties = {
      'id': 'matt',
      'account_id': account.user_id(),
      'account': account,
      }
  current_user = user.User(**user_properties)
  current_user.put()

  group_properties = {
       'key_name': 'numenta',
       'link_id': 'numenta',
       'name': 'Numenta Inc.',
       'short_name': 'Numenta',
       'home_page': 'http://numenta.org',
       'email': '*****@*****.**',
       'description': 'This is the profile for Numenta.',
       'contact_street': '811 Hamilton St',
       'contact_city': 'Redwood City, CA',
       'contact_country': 'United States',
       'contact_postalcode': '94063',
       'phone': '6503698282',
       'status': 'active',
       }
  numenta = Sponsor(**group_properties)
  numenta.put()

  now = datetime.datetime.now()
  # before = now - datetime.timedelta(365)
  # after = now + datetime.timedelta(365)
  # past_before = before - datetime.timedelta(2 * 365)
  # past_after = after - datetime.timedelta(2 * 365)

  # first_day = datetime.datetime(2014, 5, 1)
  # last_day = datetime.datetime(2014, 9, 1)
  # signup_deadline = first_day + datetime.timedelta(30)
  # signup_start = first_day
  # students_announced = signup_deadline + datetime.timedelta(15)
  program_start = datetime.datetime(2014, 3, 5)
  program_end = datetime.datetime(2014, 9, 1)

  timeline_properties = {
      'key_name': 'numenta/son2014',
      'link_id': 'son2014',
      'scope': numenta,

      'program_start': program_start,
      'program_end': program_end,

      'accepted_organization_announced_deadline': datetime.datetime(2014, 3, 1),
      'accepted_students_announced_deadline' : datetime.datetime(2014, 4, 15),

      'student_signup_start': datetime.datetime(2014, 3, 5),
      'student_signup_end': datetime.datetime(2014, 4, 1),

      'application_review_deadline': datetime.datetime(2014, 4, 10),

      'form_submission_start': datetime.datetime(2014, 3, 5),

      'student_application_matched_deadline': datetime.datetime(2014, 4, 12),

      'bonding_start': datetime.datetime(2014, 4, 15),
      'bonding_end': datetime.datetime(2014, 5, 1),

      'coding_start': datetime.datetime(2014, 5, 1),
      'coding_end': datetime.datetime(2014, 8, 1),

  }
  son2014_timeline = GSoCTimeline(**timeline_properties)
  son2014_timeline.put()

  program_properties = {
      'key_name': 'numenta/son2014',
      'link_id': 'son2014',
      'program_id': 'son2014',
      'sponsor': numenta,
      'scope': numenta,
      'name': 'Numenta Season of NuPIC 2014',
      'short_name': 'SoN 2014',
      'description': 'This is the program for SoN 2014.',
      'apps_tasks_limit': 42,
      'slots': 42,
      'timeline': son2014_timeline,
      'status': program_model.STATUS_VISIBLE,
      }
  son2014 = GSoCProgram(**program_properties)
  son2014.put()

  # timeline_properties.update({
  #     'key_name': 'numenta/gsoc2010',
  #     'link_id': 'gsoc2010',
  #     'program_start': past_before,
  #     'program_end': past_after,
  #     'accepted_organization_announced_deadline': past_before,
  #     'accepted_students_announced_deadline' : past_after,
  #     'student_signup_start': past_before,
  #     'student_signup_end': past_after,
  #     'application_review_deadline': past_after,
  #     'student_application_matched_deadline': past_after,
  #     'accepted_students_announced_deadline': past_after,
  #     'form_submission_start': past_before,
  # })
  # gsoc2010_timeline = GSoCTimeline(**timeline_properties)
  # gsoc2010_timeline.put()

  # program_properties.update({
  #     'key_name': 'numenta/gsoc2010',
  #     'link_id': 'gsoc2010',
  #     'program_id': 'gsoc2010',
  #     'name': 'Numenta Season of NuPIC 2010',
  #     'description': 'This is the program for GSoC 2010.',
  #     'short_name': 'GSoC 2010',
  #     'timeline': gsoc2010_timeline,
  # })
  # gsoc2010 = GSoCProgram(**program_properties)
  # gsoc2010.put()

  # TODO(drew): Replace son2014.prefix with whatever its replacement becomes
  # once prefix is removed from program and no longer used in the query for
  # OrgAppSurvey in soc.views.helper.RequestData._getProgramWideFields().
  org_app_survey_properties = {
    'key_name' : '%s/%s/orgapp' % (son2014.prefix, son2014.key().name()),
    'program' : son2014,
    'title' : 'Org App Survey',
    'content' : 'Here is some content.',
    'modified_by' : current_user.key.to_old_key(),
    'survey_start' : program_start,
    'survey_end' : program_end
  }
  org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

  org_app_survey_properties['key_name'] = ('%s/%s/orgapp' % (
      son2014.prefix, son2014.key().name()))
  org_app_survey_properties['program'] = son2014
  org_app_survey_properties['survey_start'] = program_start
  org_app_survey_properties['survey_end'] = program_end
  org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

  # timeline_properties = {
  #       'key_name': 'numenta/gci2013',
  #       'link_id': 'gci2013',
  #       'scope': numenta,
  #       'program_start': before,
  #       'program_end': after,
  #       'accepted_organization_announced_deadline': before,
  #       'student_signup_start': before,
  #       'student_signup_end': after,
  #       'tasks_publicly_visible': before,
  #       'task_claim_deadline': after,
  #       'stop_all_work_deadline': after,
  # }
  # gci2013_timeline = GCITimeline(**timeline_properties)
  # gci2013_timeline.put()

  # program_properties.update({
  #     'key_name': 'numenta/gci2013',
  #     'link_id': 'gci2013',
  #     'program_id': 'gci2013',
  #     'name': 'Numenta Code In Contest 2013',
  #     'short_name': 'GCI 2009',
  #     'description': 'This is the program for GCI 2013.',
  #     'timeline': gci2013_timeline,
  #     })
  # gci2013 = GCIProgram(**program_properties)
  # gci2013.put()

  # site.active_program = gci2013
  site.active_program = son2014
  site.put()

  current_user.host_for = [
      # ndb.Key.from_old_key(gsoc2010.key()),
      ndb.Key.from_old_key(son2014.key()),
      # ndb.Key.from_old_key(gci2013.key())
  ]
  current_user.put()

  # group_properties.update({
  #   'key_name': 'numenta/gci2013/melange',
  #   'link_id': 'melange',
  #   'name': 'Melange Development Team',
  #   'short_name': 'Melange',
  #   'scope': gci2013,
  #   'program': gci2013,
  #   'sponsor': numenta,
  #   'home_page': 'http://code.numenta.com/p/soc',
  #   'description': 'Melange, share the love!',
  #   'license_name': 'Apache License',
  #   'ideas': 'http://code.numenta.com/p/soc/issues',
  #   })
  # melange = GCIOrganization(**group_properties)
  # melange.put()

  group_properties.update({
    'scope': son2014,
    'program': son2014,
    })

  address_properties = address.Address(
      street='942 Brookgrove Ln',
      city='Cupertino, CA',
      country='United States',
      postal_code='95014')
  address_properties.put()

  contact_info = contact.Contact(email='*****@*****.**')
  contact_info.put()

  gsoc_delta = datetime.timedelta(days=(365 * 18))

  profile_properties = {
      'id': son2014.key().name() + '/' + current_user.key.id(),
      'parent': current_user.key,
      'public_name': 'Matt Taylor',
      'program': ndb.Key.from_old_key(son2014.key()),
      'first_name': 'Matthew',
      'last_name': 'Taylor',
      'contact' : contact_info,
      'residential_address' : address_properties,
      'shipping_address' : address_properties,
      'birth_date' : datetime.datetime(1978, 7, 11),
      'program_knowledge' : 'Creator',
      }
  profile = profile_model.Profile(**profile_properties)

  # ndb_orgs = []
  # for i in range(2):
  group_properties.update({
      'key_name': 'numenta/son2014/numenta_org',
      'link_id': 'numenta_org',
      'name': 'Numenta Inc.',
      'short_name': 'Numenta',
      'description': 'This is the organization for Numenta, Inc.',
      })

  org_properties = {
      'name': 'Numenta Inc.',
      'org_id': 'numenta_org',
      'program': ndb.Key.from_old_key(son2014.key()),
      'description': 'This is the organization for Numenta, Inc.',
      }
  org = soc_org_model.SOCOrganization(
      id='numenta/son2014/numenta_org', **org_properties)
  org.put()

  profile.admin_for.append(org.key)
  profile.mentor_for.append(org.key)
  profile.put()

  # profile_properties.update({
  #     'id': son2014.key().name() + '/' + current_user.key.id(),
  #     'parent': current_user.key,
  #     'program': ndb.Key.from_old_key(son2014.key()),
  #     'admin_for': [ndb.Key.from_old_key(son2014.key())],
  #     'mentor_for': [ndb.Key.from_old_key(son2014.key())],
  #     })
  # numenta_admin = profile_model.Profile(**profile_properties)
  # # TODO: add GCI orgs
  # numenta_admin.put()

  # task_properties = {
  #     'status': 'Open',
  #     'modified_by': numenta_admin.key.to_old_key(),
  #     'subscribers': [numenta_admin.key.to_old_key()],
  #     'title': 'Awesomeness (test task)',
  #     'created_by': numenta_admin.key.to_old_key(),
  #     'created_on': now,
  #     'program': son2014,
  #     'time_to_complete': 1337,
  #     'modified_on': now,
  #     'org': org.key,
  #     'description': '<p>AWESOME</p>',
  #     'difficulty_level': DifficultyLevel.MEDIUM,
  #     'types': ['Code']
  # }
  # gci_task = GCITask(**task_properties)
  # gci_task.put()

  user_properties = {
      'id': 'student',
      'account_id': '12345',
      'account': users.User(email='*****@*****.**'),
      }
  student_user = user.User(**user_properties)
  student_user.put()

  gci_delta = datetime.timedelta(days=(365 * 14))

  contact_properties = contact.Contact(
      email='*****@*****.**',
      web_page='http://www.homepage.com/',
      blog='http://www.blog.com/',
      phone='1650253000')
  contact_properties.put()

  graduation_year = datetime.date.today() + datetime.timedelta(days=365)

  student_data = soc_profile.SOCStudentData(
      education=education.Education(
          school_id="123",
          school_country="United States",
          expected_graduation=int(graduation_year.strftime('%Y')),
          major='Some Major',
          degree=education.Degree.UNDERGRADUATE)
      )
  student_data.put()

  student_id = 'student'
  student_properties = {
      'id': son2014.key().name() + "/" + student_id,
      'parent': student_user.key,
      'program': ndb.Key.from_old_key(son2014.key()),
      'public_name': 'Student',
      'first_name': 'Student',
      'last_name': 'Student',
      'contact' : contact_properties,
      'residential_address' : address_properties,
      'shipping_address' : address_properties,
      'birth_date': datetime.date.today() - gci_delta,
      'tee_size': profile_model.TeeSize.L,
      'tee_style': profile_model.TeeStyle.MALE,
      'gender' : profile_model.Gender.MALE,
      'program_knowledge': 'Friend referral.',
      'student_data' : student_data,
      }
  nupic_student = profile_model.Profile(**student_properties)
  nupic_student.put()

  student_id = 'student2'
  user_properties = {
      'id': student_id,
      'account_id': 'student2',
      'account': users.User(email='*****@*****.**'),
      }
  student_user2 = user.User(**user_properties)
  student_user2.put()

  student_properties.update({
      'id': son2014.key().name() + "/" + student_id,
      'parent': student_user2.key,
      'first_name' : 'Student 2',
      'last_name' : 'Example'
  })
  nupic_student2 = profile_model.Profile(**student_properties)
  nupic_student2.put()

  proposal_properties = {
      'parent': nupic_student.key.to_old_key(),
      'program': son2014,
      'title': 'test proposal',
      'abstract': 'test abstract',
      'content': 'test content',
      'mentor': profile.key.to_old_key(),
      'status': 'accepted',
      'has_mentor': True,
      'org': org.key.to_old_key(),
      'possible_mentors': [profile.key.to_old_key()]
      }
  nupic_proposal = GSoCProposal(**proposal_properties)
  nupic_proposal.put()

  project_properties = {
      'title': 'NuPIC test project 1',
      'abstract': 'test abstract',
      'status': 'accepted',
      'parent': nupic_student.key.to_old_key(),
      'mentors': [profile.key.to_old_key()],
      'program':  son2014,
      'org': org.key.to_old_key(),
      'proposal' : nupic_proposal.key(),
       }
  nupic_project = GSoCProject(**project_properties)
  nupic_project.put()
  org.slot_allocation = 1
  org.put()

  student_data.number_of_projects = 1
  student_data.number_of_proposals = 1
  student_data.project_for_orgs = [org.key]

  nupic_student.put()
  nupic_student2.put()

  project_properties.update({
      'student': nupic_student2,
      'title': 'NuPIC test project 2'
      })
  nupic_project2 = GSoCProject(**project_properties)
  nupic_project2.put()
  org.slot_allocation += 1
  org.put()

  # student_id = 'student'
  # student_properties.update({
  #     'id': son2014.key().name() + '/' + student_id,
  #     'parent': student_user.key,
  #     'program': ndb.Key.from_old_key(son2014.key()),
  # })
  # gci_student = profile_model.Profile(**student_properties)
  # gci_student.put()

  # score_properties = {
  #     'parent': gci_student.key.to_old_key(),
  #     'program': gci2013,
  #     'points': 5,
  #     'tasks': [gci_task.key()]
  #     }
  # score = GCIScore(**score_properties)
  # score.put()

  document_properties = {
      'key_name': 'site/site/home',
      'link_id': 'home',
      'scope': site,
      'prefix': 'site',
      'author': current_user.key.to_old_key(),
      'title': 'Home Page',
      'content': 'This is the Home Page',
      'modified_by': current_user.key.to_old_key(),
      }
  home_document = Document(**document_properties)
  home_document.put()

  document_properties = {
      'key_name': 'user/test/notes',
      'link_id': 'notes',
      'scope': current_user.key.to_old_key(),
      'prefix': 'user',
      'author': current_user.key.to_old_key(),
      'title': 'My Notes',
      'content': 'These are my notes',
      'modified_by': current_user.key.to_old_key(),
      }
  notes_document = Document(**document_properties)
  notes_document.put()

  site.home = home_document
  site.put()

  memcache.flush_all()

  return http.HttpResponse('Done')
 def setUp(self):
   """Set up required for the view tests.
   """
   # Setup TaskQueueTestCase and MailTestCase first
   super(ProposalDuplicatesTest, self).setUp()
   # Create a user for the founder of sponsor
   email = "*****@*****.**"
   account = users.User(email=email)
   link_id = 'a_sponsor_user'
   name = 'A Sponsor User'
   sponsor_user_properties = {
       'account': account,
       'link_id': link_id,
       'name': name,
       }
   sponsor_user = user_logic.updateOrCreateFromFields(sponsor_user_properties)
   # Create a sponsor
   link_id = 'a_sponsor'
   name = link_id
   founder = 'a_founder'
   phone = '01234567'
   contact_postalcode = 'A postalcode'
   description = 'A description'
   contact_country = 'United States'
   short_name = 'AS'
   contact_city = 'A city'
   home_page = 'http://www.asponsor.com'
   email = '*****@*****.**'
   sponsor_properties = {
       'link_id': link_id,
       'name': name,
       'short_name': short_name,
       'founder': sponsor_user,
       'phone': phone,
       'description': description,
       'contact_country': contact_country,
       'contact_city': 'A City',
       'contact_street': 'A Street',
       'contact_postalcode': contact_postalcode,
       'home_page': home_page,
       'email': email,
       'status': 'active',
       }
   sponsor = sponsor_logic.updateOrCreateFromFields(sponsor_properties)
   # Create a timeline for a program
   timeline_properties = {
       'link_id': 'a_program',
       'scope_path': 'a_sponsor',
       'scope': sponsor,
       'accepted_students_announced_deadline': datetime.datetime.now() \
           + datetime.timedelta(10)
         }
   timeline = gsoc_timeline_logic.updateOrCreateFromFields(timeline_properties)
   # Create a program for a_sponsor
   program_properties = {
       'key_name': 'a_sponsor/a_program',
       'link_id': 'a_program',
       'scope': sponsor,
       'scope_path': 'a_sponsor',
       'name': 'A Program 2010',
       'short_name': 'AP2010',
       'group_label': 'AP',
       'description': 'This is the program for AP2010.',
       'apps_tasks_limit': 42,
       'slots': 42,
       'allocations_visible': True,
       'timeline': timeline,
       'status': 'visible',
       }
   # GSoC program logic does not work: error in updatePredefinedOrgTags
   from soc.modules.gsoc.models.program import GSoCProgram
   program = GSoCProgram(**program_properties)
   program.put()
   self.program = program
   # Create an organization for a_program
   organization_properties = {
     'link_id': 'an_org',
     'name': 'An Organization',
     'short_name': 'AO',
     'scope_path': 'a_sponsor/a_program',
     'scope': program,
     'founder': sponsor_user,
     'home_page': 'http://www.an_org.com',
     'phone': '1-555-2222',
     'description': 'An Organization',
     'license_name': 'Apache License',
     'ideas': 'http://www.an_org.com/ideas',
     'contact_country': contact_country,
     'contact_city': 'A City',
     'contact_street': 'A Street',
     'contact_postalcode': contact_postalcode,
     'home_page': home_page,
     'email': email,
     'slots': 5,
     'status': 'active',
     }
   organization = gsoc_organization_logic.updateOrCreateFromFields(
       organization_properties)
   self.organization = organization
   # Create another organization
   organization_properties.update({
     'link_id': 'another_org',
     })
   another_organization =  gsoc_organization_logic.updateOrCreateFromFields(
       organization_properties)
   # Create an organization to serve as cursor sub for a_program, which should
   # come as the first result of query
   organization_properties.update({
     'link_id': 'aa_org',
     })
   stub_organization = gsoc_organization_logic.updateOrCreateFromFields(
       organization_properties)
   # Create a user for all roles except sponsor
   email = "*****@*****.**"
   account = users.User(email=email)
   link_id = 'a_role_user'
   name = 'A Role User'
   properties = {
       'account': account,
       'link_id': link_id,
       'name': name,
       }
   key_name = user_logic.getKeyNameFromFields(properties)
   role_user = user_logic.updateOrCreateFromKeyName(properties, key_name)
   # Create a mentor for an_org
   mentor_properties = sponsor_properties.copy()
   mentor_properties.update({
       'link_id': 'a_mentor',
       'scope_path': organization.scope_path + '/' + organization.link_id,
       'scope': organization,
       'program': program,
       'given_name': 'A',
       'surname': 'Mentor',
       'res_country': 'United States',
       'res_city': 'A City',
       'res_street': 'A Street',
       'res_postalcode': '12345',
       'birth_date': db.DateProperty.now(),
       'user': role_user,
       })
   mentor = mentor_logic.updateOrCreateFromFields(mentor_properties)
   self.mentor = mentor
   # Create a student for a_program
   student_properties = mentor_properties.copy()
   student_properties.update({
       'link_id': 'a_student',
       'scope_path': program.scope_path + '/' + program.link_id,
       'scope': program,
       'program': program,
       'given_name': 'A',
       'surname': 'Student',
       'major': 'A Major',
       'name_on_documents': 'A Name on Documents',
       'publish_location': True,
       'blog': 'http://www.ablog.com/',
       'home_page': 'http://www.ahomepage.com/',
       'photo_url': 'http://www.astudent.com/aphoto.png',
       'expected_graduation': 2011,
       'school_country': 'United States',
       'school_name': 'A School',
       'tshirt_size': 'XS',
       'tshirt_style': 'male',
       'degree': 'Undergraduate',
       'phone': '1650253000',
       'can_we_contact_you': True,
       'program_knowledge': 'I heard about this program through a friend.'
       })
   student = student_logic.updateOrCreateFromFields(student_properties)
   self.student = student
   # Create a student proposal to an_org for a_student
   student_proposal_properties = {
   'link_id': 'a_proposal',
   'scope_path': student.scope_path + '/' + student.link_id,
   'scope': student,
   'title': 'A Proposal Title',
   'abstract': 'A Proposal Abstract',
   'content': 'A Proposal Content',
   'additional_info': 'http://www.a_proposal.com',
   'mentor': mentor,
   'status': 'pending',
   'org': organization,
   'program': program,
   }
   self.student_proposal = student_proposal_logic.updateOrCreateFromFields(
       student_proposal_properties)
   # Create another student proposal to an_org for a_student
   student_proposal_properties.update({
   'link_id': 'another_proposal',
   })
   student_proposal_logic.updateOrCreateFromFields(student_proposal_properties)
   # Create the third student proposal to another_org for a_student
   student_proposal_properties.update({
   'link_id': 'third_proposal',
   'org': another_organization,
   })
   student_proposal_logic.updateOrCreateFromFields(student_proposal_properties)
Esempio n. 31
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()
Esempio n. 32
0
 def setUp(self):
   """Set up required for the view tests.
   """
   # Ensure that current user with developer privilege is created
   user_properties = {
       'account': users.get_current_user(),
       'link_id': 'current_user',
       'name': 'Current User',
       'is_developer': True,
       }
   user_logic.updateOrCreateFromFields(user_properties)
   # Create a user for the founder of sponsor
   email = "*****@*****.**"
   account = users.User(email=email)
   link_id = 'a_user'
   name = 'A User'
   sponsor_user_properties = {
       'account': account,
       'link_id': link_id,
       'name': name,
       }
   sponsor_user = user_logic.updateOrCreateFromFields(sponsor_user_properties)
   # Create sponsor
   link_id = 'a_sponsor'
   name = link_id
   founder = 'a_founder'
   phone = '01234567'
   contact_postalcode = 'A postalcode'
   description = 'A description'
   contact_country = 'United States'
   short_name = 'AS'
   contact_city = 'A city'
   home_page = 'http://www.asponsor.com'
   email = '*****@*****.**'
   sponsor_properties = {
       'link_id': link_id,
       'name': name,
       'short_name': short_name,
       'founder': sponsor_user,
       'phone': phone,
       'description': description,
       'contact_country': contact_country,
      'contact_city': 'A City',
      'contact_street': 'A Street',
       'contact_postalcode': contact_postalcode,
       'home_page': home_page,
       'email': email,
       'status': 'active',
       }
   sponsor = sponsor_logic.updateOrCreateFromFields(sponsor_properties)
   # Create a timeline for a program
   timeline_properties = {
       'link_id': 'a_program',
       'scope_path': 'a_sponsor',
       'scope': sponsor,
         }
   timeline = timeline_logic.updateOrCreateFromFields(timeline_properties)
   # Create a program for a_sponsor
   program_properties = {
       'link_id': 'a_program',
       'scope': sponsor,
       'scope_path': 'a_sponsor',
       'name': 'A Program 2010',
       'short_name': 'AP2010',
       'group_label': 'AP',
       'description': 'This is the program for AP2010.',
       'apps_tasks_limit': 42,
       'slots': 42,
       'allocations_visible': True,
       'timeline': timeline,
       'status': 'visible',
       }
   # GSoC program logic does not work: error in updatePredefinedOrgTags
   from soc.modules.gsoc.models.program import GSoCProgram
   program = GSoCProgram(**program_properties)
   program.put()
   # Create an organization for a_program
   organization_properties = {
     'link_id': 'an_org',
     'name': 'An Organization',
     'short_name': 'AO',
     'scope_path': 'a_sponsor/a_program',
     'scope': program,
     'founder': sponsor_user,
     'home_page': 'http://www.an_org.com',
     'phone': '1-555-2222',
     'description': 'An Organization',
     'license_name': 'Apache License',
     'ideas': 'http://www.an_org.com/ideas',
       'contact_country': contact_country,
      'contact_city': 'A City',
      'contact_street': 'A Street',
       'contact_postalcode': contact_postalcode,
       'home_page': home_page,
       'email': email,
       'status': 'active',
     }
   organization = gsoc_organization_logic.updateOrCreateFromFields(
       organization_properties)
   self.scope_path = organization.scope_path
   self.link_id = organization.link_id
Esempio n. 33
0
 def setUp(self):
     """Set up required for the view tests.
 """
     # Ensure that current user with developer privilege is created
     user_properties = {
         'account': users.get_current_user(),
         'link_id': 'current_user',
         'name': 'Current User',
         'is_developer': True,
     }
     user_logic.updateOrCreateFromFields(user_properties)
     # Create a user for the founder of sponsor
     email = "*****@*****.**"
     account = users.User(email=email)
     link_id = 'a_user'
     name = 'A User'
     sponsor_user_properties = {
         'account': account,
         'link_id': link_id,
         'name': name,
     }
     sponsor_user = user_logic.updateOrCreateFromFields(
         sponsor_user_properties)
     # Create sponsor
     link_id = 'a_sponsor'
     name = link_id
     founder = 'a_founder'
     phone = '01234567'
     contact_postalcode = 'A postalcode'
     description = 'A description'
     contact_country = 'United States'
     short_name = 'AS'
     contact_city = 'A city'
     home_page = 'http://www.asponsor.com'
     email = '*****@*****.**'
     sponsor_properties = {
         'link_id': link_id,
         'name': name,
         'short_name': short_name,
         'founder': sponsor_user,
         'phone': phone,
         'description': description,
         'contact_country': contact_country,
         'contact_city': 'A City',
         'contact_street': 'A Street',
         'contact_postalcode': contact_postalcode,
         'home_page': home_page,
         'email': email,
         'status': 'active',
     }
     sponsor = sponsor_logic.updateOrCreateFromFields(sponsor_properties)
     # Create a timeline for a program
     timeline_properties = {
         'link_id': 'a_program',
         'scope_path': 'a_sponsor',
         'scope': sponsor,
     }
     timeline = timeline_logic.updateOrCreateFromFields(timeline_properties)
     # Create a program for a_sponsor
     program_properties = {
         'link_id': 'a_program',
         'scope': sponsor,
         'scope_path': 'a_sponsor',
         'name': 'A Program 2010',
         'short_name': 'AP2010',
         'group_label': 'AP',
         'description': 'This is the program for AP2010.',
         'apps_tasks_limit': 42,
         'slots': 42,
         'allocations_visible': True,
         'timeline': timeline,
         'status': 'visible',
     }
     # GSoC program logic does not work: error in updatePredefinedOrgTags
     from soc.modules.gsoc.models.program import GSoCProgram
     program = GSoCProgram(**program_properties)
     program.put()
     # Create an organization for a_program
     organization_properties = {
         'link_id': 'an_org',
         'name': 'An Organization',
         'short_name': 'AO',
         'scope_path': 'a_sponsor/a_program',
         'scope': program,
         'founder': sponsor_user,
         'home_page': 'http://www.an_org.com',
         'phone': '1-555-2222',
         'description': 'An Organization',
         'license_name': 'Apache License',
         'ideas': 'http://www.an_org.com/ideas',
         'contact_country': contact_country,
         'contact_city': 'A City',
         'contact_street': 'A Street',
         'contact_postalcode': contact_postalcode,
         'home_page': home_page,
         'email': email,
         'status': 'active',
     }
     organization = gsoc_organization_logic.updateOrCreateFromFields(
         organization_properties)
     self.scope_path = organization.scope_path
     self.link_id = organization.link_id
Esempio n. 34
0
def seed(request, *args, **kwargs):
    """Seeds the datastore with some default values.
  """

    site_properties = {
        'key_name': 'site',
        'link_id': 'site',
    }

    site = Site(**site_properties)
    site.put()

    _, current_user = ensureUser()

    seeder = UserSeeder()
    for i in range(15):
        seeder.seed(i)

    group_properties = {
        'key_name': 'google',
        'link_id': 'google',
        'name': 'Google Inc.',
        'short_name': 'Google',
        'founder': current_user,
        'home_page': 'http://www.google.com',
        'email': '*****@*****.**',
        'description': 'This is the profile for Google.',
        'contact_street': 'Some Street',
        'contact_city': 'Some City',
        'contact_country': 'United States',
        'contact_postalcode': '12345',
        'phone': '1-555-BANANA',
        'status': 'active',
    }

    google = Sponsor(**group_properties)
    google.put()

    role_properties = {
        'key_name': 'google/test',
        'link_id': 'test',
        'scope': google,
        'scope_path': 'google',
        'user': current_user,
        'given_name': 'Test',
        'surname': 'Example',
        '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,
    }

    google_host = Host(**role_properties)
    google_host.put()

    timeline_properties = {
        'key_name': 'google/gsoc2009',
        'link_id': 'gsoc2009',
        'scope_path': 'google',
        'scope': google,
    }

    gsoc2009_timeline = GSoCTimeline(**timeline_properties)
    gsoc2009_timeline.put()

    program_properties = {
        'key_name': 'google/gsoc2009',
        'link_id': 'gsoc2009',
        'scope_path': 'google',
        'scope': google,
        'name': 'Google Summer of Code 2009',
        'short_name': 'GSoC 2009',
        'group_label': 'GSOC',
        'description': 'This is the program for GSoC 2009.',
        'apps_tasks_limit': 42,
        'slots': 42,
        'timeline': gsoc2009_timeline,
        'status': 'visible',
    }

    gsoc2009 = GSoCProgram(**program_properties)
    gsoc2009.put()

    # TODO: Use real GHOPProgram here
    timeline_properties = {
        'key_name': 'google/ghop2009',
        'link_id': 'ghop2009',
        'scope_path': 'google',
        'scope': google,
    }

    ghop2009_timeline = GHOPTimeline(**timeline_properties)
    ghop2009_timeline.put()

    program_properties.update({
        'key_name': 'google/ghop2009',
        'link_id': 'ghop2009',
        'name': 'Google Highly Open Participation Contest 2009',
        'short_name': 'GHOP 2009',
        'group_label': 'GHOP',
        'description': 'This is the program for GHOP 2009.',
        'timeline': ghop2009_timeline,
    })

    ghop2009 = GHOPProgram(**program_properties)
    ghop2009.put()

    org_app_properties = {
        'scope_path': 'google/gsoc2009',
        'scope': gsoc2009,
        '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',
        'status': 'pre-accepted',
        '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,
    }

    for i in range(10):
        org_app_properties['key_name'] = 'google/gsoc2009/org_%04d' % i
        org_app_properties['link_id'] = 'org_%04d' % i
        org_app_properties['name'] = 'Org App %04d' % i
        entity = OrgApplication(**org_app_properties)
        entity.put()

    org_app_properties['status'] = 'pre-rejected'

    for i in range(10, 20):
        org_app_properties['key_name'] = 'google/gsoc2009/loser_%d' % i
        org_app_properties['link_id'] = 'loser_%d' % i
        org_app_properties['name'] = 'Loser %d' % i
        entity = OrgApplication(**org_app_properties)
        entity.put()

    group_properties.update({
        'key_name': 'google/ghop2009/melange',
        'link_id': 'melange',
        'name': 'Melange Development Team',
        'short_name': 'Melange',
        'scope_path': 'google/ghop2009',
        'scope': ghop2009,
        'home_page': 'http://code.google.com/p/soc',
        'description': 'Melange, share the love!',
        'license_name': 'Apache License',
        'ideas': 'http://code.google.com/p/soc/issues',
    })

    melange = GHOPOrganization(**group_properties)
    melange.put()
    # create a new ranker
    ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, melange,
                             student_proposal.DEF_SCORE, 100)

    group_properties.update({
        'scope_path': 'google/gsoc2009',
        'scope': gsoc2009,
    })

    orgs = []
    for i in range(15):
        group_properties.update({
            'key_name': 'google/gsoc2009/org_%d' % i,
            'link_id': 'org_%d' % i,
            'name': 'Organization %d' % i,
            'short_name': 'Org %d' % i,
            'description': 'Organization %d!' % i,
        })

        entity = GSoCOrganization(**group_properties)
        orgs.append(entity)
        entity.put()
        # create a new ranker
        ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity,
                                 student_proposal.DEF_SCORE, 100)

        if i < 2:
            role_properties.update({
                'key_name': 'google/gsoc2009/org_%d/test' % i,
                'link_id': 'test',
                'scope_path': 'google/gsoc2009/org_%d' % i,
                'scope': entity,
                'program': gsoc2009,
            })

            # Admin for the first org
            if i == 0:
                org_1_admin = GSoCOrgAdmin(**role_properties)
                org_1_admin.put()

            # Only a mentor for the second org
            if i == 1:
                org_1_admin = GSoCOrgAdmin(**role_properties)
                org_1_admin.put()
                org_1_mentor = GSoCMentor(**role_properties)
                org_1_mentor.put()

    role_properties.update({
        'key_name': 'google/ghop2009/melange/test',
        'link_id': 'test',
        'scope_path': 'google/ghop2009/melange',
        'scope': melange,
        'program': ghop2009,
    })

    melange_admin = GHOPOrgAdmin(**role_properties)
    melange_admin.put()

    melange_mentor = GHOPMentor(**role_properties)
    melange_mentor.put()

    student_id = 'test'
    student_properties = {
        'key_name': gsoc2009.key().name() + "/" + student_id,
        'link_id': student_id,
        'scope_path': gsoc2009.key().name(),
        'scope': gsoc2009,
        'program': gsoc2009,
        'user': current_user,
        'given_name': 'test',
        'surname': 'test',
        'birth_date': db.DateProperty.now(),
        'email': '*****@*****.**',
        'im_handle': 'test_im_handle',
        'major': 'test major',
        'name_on_documents': 'test',
        'res_country': 'United States',
        'res_city': 'city',
        'res_street': 'test street',
        'res_postalcode': '12345',
        'publish_location': True,
        'blog': 'http://www.blog.com/',
        'home_page': 'http://www.homepage.com/',
        'photo_url': 'http://www.photosite.com/thumbnail.png',
        'ship_state': None,
        'expected_graduation': 2009,
        'school_country': 'United States',
        'school_name': 'Test School',
        'tshirt_size': 'XS',
        'tshirt_style': 'male',
        'degree': 'Undergraduate',
        'phone': '1650253000',
        'can_we_contact_you': True,
        'program_knowledge': 'I heard about this program through a friend.'
    }

    melange_student = GSoCStudent(**student_properties)
    melange_student.put()

    student_id = 'test2'
    student_properties.update({
        'key_name': gsoc2009.key().name() + "/" + student_id,
        'link_id': student_id,
        'user': current_user
    })

    melange_student2 = GSoCStudent(**student_properties)
    melange_student2.put()

    project_id = 'test_project'
    project_properties = {
        'key_name': gsoc2009.key().name() + "/org_1/" + project_id,
        'link_id': project_id,
        'scope_path': gsoc2009.key().name() + "/org_1",
        'scope': orgs[1].key(),
        'title': 'test project',
        'abstract': 'test abstract',
        'status': 'accepted',
        'student': melange_student,
        'mentor': org_1_mentor,
        'program': gsoc2009
    }

    melange_project = StudentProject(**project_properties)
    melange_project.put()

    project_id = 'test_project2'
    project_properties.update({
        'key_name': gsoc2009.key().name() + "/org_1/" + project_id,
        'link_id': project_id,
        'student': melange_student2,
        'title': 'test project2'
    })

    melange_project2 = StudentProject(**project_properties)
    melange_project2.put()

    document_properties = {
        'key_name': 'site/site/home',
        'link_id': 'home',
        'scope_path': 'site',
        'scope': site,
        'prefix': 'site',
        'author': current_user,
        'title': 'Home Page',
        'short_name': 'Home',
        'content': 'This is the Home Page',
        'modified_by': current_user,
    }

    home_document = Document(**document_properties)
    home_document.put()
    document_logic._onCreate(home_document)

    document_properties = {
        'key_name': 'user/test/notes',
        'link_id': 'notes',
        'scope_path': 'test',
        'scope': current_user,
        'prefix': 'user',
        'author': current_user,
        'title': 'My Notes',
        'short_name': 'Notes',
        'content': 'These are my notes',
        'modified_by': current_user,
    }

    notes_document = Document(**document_properties)
    notes_document.put()
    document_logic._onCreate(home_document)

    site.home = home_document
    site.put()
    # pylint: disable-msg=E1101
    memcache.flush_all()

    return http.HttpResponse('Done')
 def setUp(self):
   """Set up required for the view tests.
   """
   # Setup TaskQueueTestCase and MailTestCase first
   super(GradingSurveyGroupTasksTest, self).setUp()
   # Create a user for the founder of sponsor
   email = "*****@*****.**"
   account = users.User(email=email)
   link_id = 'a_sponsor_user'
   name = 'A Sponsor User'
   sponsor_user_properties = {
       'account': account,
       'link_id': link_id,
       'name': name,
       }
   sponsor_user = user_logic.updateOrCreateFromFields(sponsor_user_properties)
   # Create sponsor
   link_id = 'a_sponsor'
   name = 'A Sponsor'
   founder = 'a_founder'
   phone = '01234567'
   contact_postalcode = 'A postalcode'
   description = 'A description'
   contact_country = 'United States'
   short_name = 'AS'
   contact_city = 'A city'
   home_page = 'http://www.asponsor.com'
   email = '*****@*****.**'
   sponsor_properties = {
       'link_id': link_id,
       'name': name,
       'short_name': short_name,
       'founder': sponsor_user,
       'phone': phone,
       'description': description,
       'contact_country': contact_country,
      'contact_city': 'A City',
      'contact_street': 'A Street',
       'contact_postalcode': contact_postalcode,
       'home_page': home_page,
       'email': email,
       'status': 'active',
       }
   sponsor = sponsor_logic.updateOrCreateFromFields(sponsor_properties)
   # Create a timeline for a program
   timeline_properties = {
       'link_id': 'a_program',
       'scope_path': 'a_sponsor',
       'scope': sponsor,
         }
   timeline = timeline_logic.updateOrCreateFromFields(timeline_properties)
   # Create a program for a_sponsor
   program_properties = {
       'key_name': 'a_sponsor/a_program',
       'link_id': 'a_program',
       'scope': sponsor,
       'scope_path': 'a_sponsor',
       'name': 'A Program 2010',
       'short_name': 'AP2010',
       'group_label': 'AP',
       'description': 'This is the program for AP2010.',
       'apps_tasks_limit': 42,
       'slots': 42,
       'allocations_visible': True,
       'timeline': timeline,
       'status': 'visible',
       }
   # GSoC program logic does not work: error in updatePredefinedOrgTags
   from soc.modules.gsoc.models.program import GSoCProgram
   program = GSoCProgram(**program_properties)
   program.put()
   self.program = program
   # Create an organization for a_program
   organization_properties = {
     'link_id': 'an_org',
     'name': 'An Organization',
     'short_name': 'AO',
     'scope_path': 'a_sponsor/a_program',
     'scope': program,
     'founder': sponsor_user,
     'home_page': 'http://www.an_org.com',
     'phone': '1-555-2222',
     'description': 'An Organization',
     'license_name': 'Apache License',
     'ideas': 'http://www.an_org.com/ideas',
       'contact_country': contact_country,
      'contact_city': 'A City',
      'contact_street': 'A Street',
       'contact_postalcode': contact_postalcode,
       'home_page': home_page,
       'email': email,
       'status': 'active',
     }
   organization = gsoc_organization_logic.updateOrCreateFromFields(
       organization_properties)
   # Create a user for all roles except sponsor
   email = "*****@*****.**"
   account = users.User(email=email)
   link_id = 'a_role_user'
   name = 'A Role User'
   properties = {
       'account': account,
       'link_id': link_id,
       'name': name,
       }
   key_name = user_logic.getKeyNameFromFields(properties)
   role_user = user_logic.updateOrCreateFromKeyName(properties, key_name)
   # Create an admin for an_org
   gsoc_org_admin_properties = {
     'link_id': 'an_org_admin',
     'given_name': 'A',
     'surname': 'Orgadmin',
     'scope_path': organization.scope_path + '/' + organization.link_id,
     'scope': organization,
     'program': program,
     'phone': '1-555-2222',
     'email': '*****@*****.**',
     'res_country': 'United States',
     'res_city': 'A City',
     'res_street': 'A Street',
     'res_postalcode': '12345',
     'birth_date': db.DateProperty.now(),
     'user': role_user,
     }
   gsoc_org_admin_logic.updateOrCreateFromFields(gsoc_org_admin_properties)
   # Create a mentor for an_org
   mentor_properties = gsoc_org_admin_properties.copy()
   mentor_properties.update({
       'link_id': 'a_mentor',
       'given_name': 'A',
       'surname': 'Mentor',
     'email': '*****@*****.**',
       })
   mentor = mentor_logic.updateOrCreateFromFields(mentor_properties)
   self.mentor = mentor
   # Create students for a_program
   student_properties = gsoc_org_admin_properties.copy()
   student_properties.update({
       'scope_path': program.scope_path + '/' + program.link_id,
       'scope': program,
       'program': program,
       'given_name': 'A',
       'surname': 'Student',
       'major': 'A Major',
       'name_on_documents': 'A Name on Documents',
       'publish_location': True,
       'blog': 'http://www.ablog.com/',
       'home_page': 'http://www.ahomepage.com/',
       'photo_url': 'http://www.astudent.com/aphoto.png',
       'expected_graduation': 2011,
       'school_country': 'United States',
       'school_name': 'A School',
       'tshirt_size': 'XS',
       'tshirt_style': 'male',
       'degree': 'Undergraduate',
       'phone': '1650253000',
       'can_we_contact_you': True,
       'program_knowledge': 'I heard about this program through a friend.'
       })
   # Create projects for a_program, an_org and a_mentor
   project_properties = {
       'scope_path': organization.scope_path + '/' + organization.link_id,
       'scope': organization,
       'title': 'test project',
       'abstract': 'test abstract',
       'status': 'accepted',
       'mentor': mentor,
       'program': program,
        }
   #The string order of students' link_id is the same with that of students
   #in the array in order to make sure the last student is handled last
   size = DEF_BATCH_SIZE
   num_digits = 0
   while True:
     size /= 10
     num_digits += 1
     if size == 0:
       break
   students, projects = [], []
   for i in xrange(DEF_BATCH_SIZE+1):
     student_link_id = ('student%0'+str(num_digits)+'d') % i
     student_properties.update({
         'link_id': student_link_id,
         'email': student_link_id + '@email.com',
         })
     student = student_logic.updateOrCreateFromFields(student_properties)
     students.append(student)
     project_link_id = ('project%0'+str(num_digits)+'d') % i
     project_properties.update({
         'link_id': project_link_id,
         'student': student,
         })
     project = student_project_logic.updateOrCreateFromFields(
         project_properties)
     projects.append(project)
   self.students = students
   self.projects = projects
   # Create a project survey for a_program
   link_id = 'a_project_survey'
   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'}
             }
   survey_properties = {
       'link_id': link_id,
       'scope_path': program.scope_path + '/' + program.link_id,
       'scope': None,
       'prefix': 'program',
       'author': role_user,
       'title': 'A Project Survey',
       'short_name': 'APS',
       'modified_by': role_user,
       'is_featured': True,
       'fields': fields,
       'schema': schema,
       'deadline': datetime.datetime.now() + datetime.timedelta(10),
       'taking_access': 'student',
       }
   project_survey = project_survey_logic.updateOrCreateFromFields(
       survey_properties)
   self.project_survey = project_survey
   # Create a grading survey for a_program
   link_id = 'a_grading_survey'
   survey_properties.update({
       'link_id': link_id,
       'title': 'A Grading Survey',
       'short_name': 'AGS',
       'taking_access': 'mentor',
       })
   grading_survey = grading_survey_logic.updateOrCreateFromFields(
       survey_properties)
   self.grading_survey = grading_survey
   # Create a survey group for a_grading_survey and a_project_survey
   # of a_program
   survey_group_properties = {
       'link_id': link_id,
       'scope_path': program.scope_path + '/' + program.link_id,
       'scope': program,
       'name': 'A Survey Group',
       'grading_survey': grading_survey,
       'student_survey': project_survey,
       }
   survey_group = survey_group_logic.updateOrCreateFromFields(
       survey_group_properties)
   self.survey_group = survey_group
Esempio n. 36
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()
Esempio n. 37
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()
Esempio n. 38
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()
Esempio n. 39
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
Esempio n. 40
0
def seed(request, *args, **kwargs):
  """Seeds the datastore with some default values.
  """

  site_properties = {
      'key_name': 'site',
      'link_id': 'site',
      }

  site = Site(**site_properties)
  site.put()


  _, current_user = ensureUser()


  seeder = UserSeeder()
  for i in range(15):
    seeder.seed(i)

  group_properties = {
       'key_name': 'google',
       'link_id': 'google',
       'name': 'Google Inc.',
       'short_name': 'Google',
       'founder': current_user,
       'home_page': 'http://www.google.com',
       'email': '*****@*****.**',
       'description': 'This is the profile for Google.',
       'contact_street': 'Some Street',
       'contact_city': 'Some City',
       'contact_country': 'United States',
       'contact_postalcode': '12345',
       'phone': '1-555-BANANA',
       'status': 'active',
       }

  google = Sponsor(**group_properties)
  google.put()


  role_properties = {
      'key_name': 'google/test',
      'link_id': 'test',
      'scope': google,
      'scope_path': 'google',
      'user': current_user,
      'given_name': 'Test',
      'surname': 'Example',
      '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,
      }


  current_user.host_for = [google.key()]
  current_user.put()

  google_host = Host(**role_properties)
  google_host.put()

  from datetime import datetime
  from datetime import timedelta

  before = datetime.now() - timedelta(365)
  after = datetime.now() + timedelta(365)

  timeline_properties = {
      'key_name': 'google/gsoc2009',
      'link_id': 'gsoc2009',
      'scope_path': 'google',
      'scope': google,
      'program_start': before,
      'program_end': after,
      'accepted_organization_announced_deadline': after,
      'student_signup_start': before,
      'student_signup_end': after,
  }

  gsoc2009_timeline = GSoCTimeline(**timeline_properties)
  gsoc2009_timeline.put()


  program_properties = {
      'key_name': 'google/gsoc2009',
      'link_id': 'gsoc2009',
      'scope_path': 'google',
      'scope': google,
      'name': 'Google Summer of Code 2009',
      'short_name': 'GSoC 2009',
      'group_label': 'GSOC',
      'description': 'This is the program for GSoC 2009.',
      'apps_tasks_limit': 42,
      'slots': 42,
      'timeline': gsoc2009_timeline,
      'status': 'visible',
      }

  gsoc2009 = GSoCProgram(**program_properties)
  gsoc2009.put()

  site.active_program = gsoc2009
  site.put()

  # TODO: Use real GCIProgram here
  timeline_properties = {
        'key_name': 'google/gci2009',
        'link_id': 'gci2009',
        'scope_path': 'google',
        'scope': google,
  }

  gci2009_timeline = GCITimeline(**timeline_properties)
  #gci2009_timeline.put()


  program_properties.update({
      'key_name': 'google/gci2009',
      'link_id': 'gci2009',
      'name': 'Google Code In Contest 2009',
      'short_name': 'GCI 2009',
      'group_label': 'GCI',
      'description': 'This is the program for GCI 2009.',
      'timeline': gci2009_timeline,
      })

  gci2009 = GCIProgram(**program_properties)
  #gci2009.put()


  group_properties.update({
    'key_name': 'google/gci2009/melange',
    'link_id': 'melange',
    'name': 'Melange Development Team',
    'short_name': 'Melange',
    'scope_path': 'google/gci2009',
    'scope': gci2009,
    'home_page': 'http://code.google.com/p/soc',
    'description': 'Melange, share the love!',
    'license_name': 'Apache License',
    'ideas': 'http://code.google.com/p/soc/issues',
    })

  melange = GCIOrganization(**group_properties)
  #melange.put()
  # create a new ranker
  #ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, melange,
  #    student_proposal.DEF_SCORE, 100)


  group_properties.update({
    'scope_path': 'google/gsoc2009',
    'scope': gsoc2009,
    })

  role_properties.update({
      'key_name': 'google/gsoc2009/test',
      'link_id': 'test',
      'scope_path': 'google/gsoc2009',
      'scope': gsoc2009,
      'program': gsoc2009,
      'parent': current_user,
      })

  profile = GSoCProfile(**role_properties)
  role_properties.pop('parent')

  orgs = []
  for i in range(15):
    group_properties.update({
        'key_name': 'google/gsoc2009/org_%d' % i,
        'link_id': 'org_%d' % i,
        'name': 'Organization %d' % i,
        'short_name': 'Org %d' % i,
        'description': 'Organization %d!' % i,
        })

    entity = GSoCOrganization(**group_properties)
    orgs.append(entity)
    entity.put()
    # create a new ranker
    ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity,
        student_proposal.DEF_SCORE, 100)

    # Admin for the first org
    if i == 0:
      profile.org_admin_for.append(entity.key())
      profile.put()

    # Mentor and admin for the second org
    if i == 1:
      profile.org_admin_for.append(entity.key())
      profile.mentor_for.append(entity.key())
      profile.put()

  role_properties.update({
      'key_name': 'google/gci2009/melange/test',
      'link_id': 'test',
      'scope_path': 'google/gci2009/melange',
      'scope': melange,
      'program': gci2009,
      })

  melange_admin = GCIOrgAdmin(**role_properties)
  #melange_admin.put()

  melange_mentor = GCIMentor(**role_properties)
  #melange_mentor.put()

  student_id = 'test'
  student_properties = {
      'key_name': gsoc2009.key().name() + "/" + student_id,
      'link_id': student_id, 
      'scope_path': gsoc2009.key().name(),
      'scope': gsoc2009,
      'program': gsoc2009,
      'user': current_user,
      'given_name': 'test',
      'surname': 'test',
      'birth_date': db.DateProperty.now(),
      'email': '*****@*****.**',
      'im_handle': 'test_im_handle',
      'major': 'test major',
      'name_on_documents': 'test',
      'res_country': 'United States',
      'res_city': 'city',
      'res_street': 'test street',
      'res_postalcode': '12345',
      'publish_location': True,
      'blog': 'http://www.blog.com/',
      'home_page': 'http://www.homepage.com/',
      'photo_url': 'http://www.photosite.com/thumbnail.png',
      'ship_state': None,
      'expected_graduation': 2009,
      'school_country': 'United States',
      'school_name': 'Test School', 
      'tshirt_size': 'XS',
      'tshirt_style': 'male',
      'degree': 'Undergraduate',
      'phone': '1650253000',
      'can_we_contact_you': True, 
      'program_knowledge': 'I heard about this program through a friend.'
      }

  melange_student = GSoCStudent(**student_properties)
  melange_student.put()

  student_id = 'test2'
  student_properties.update({
      'key_name': gsoc2009.key().name() + "/" + student_id,
      'link_id': student_id,
      'user': current_user 
      })

  melange_student2 = GSoCStudent(**student_properties)
  melange_student2.put()
                                       
  project_id = 'test_project'
  project_properties = {
      'key_name':  gsoc2009.key().name() + "/org_1/" + project_id,
      'link_id': project_id, 
      'scope_path': gsoc2009.key().name() + "/org_1",
      'scope': orgs[1].key(),

      'title': 'test project',
      'abstract': 'test abstract',
      'status': 'accepted',
      'student': melange_student,
      'mentor': profile,
      'program':  gsoc2009
       }

  melange_project = StudentProject(**project_properties)
  melange_project.put()

  project_id = 'test_project2'
  project_properties.update({
      'key_name':  gsoc2009.key().name() + "/org_1/" + project_id,
      'link_id': project_id,
      'student': melange_student2,
      'title': 'test project2'
      })
      
  melange_project2 = StudentProject(**project_properties)
  melange_project2.put()
    
  document_properties = {
      'key_name': 'site/site/home',
      'link_id': 'home',
      'scope_path': 'site',
      'scope': site,
      'prefix': 'site',
      'author': current_user,
      'title': 'Home Page',
      'short_name': 'Home',
      'content': 'This is the Home Page',
      'modified_by': current_user,
      }

  home_document = Document(**document_properties)
  home_document.put()
  document_logic._onCreate(home_document) 


  document_properties = {
      'key_name': 'user/test/notes',
      'link_id': 'notes',
      'scope_path': 'test',
      'scope': current_user,
      'prefix': 'user',
      'author': current_user,
      'title': 'My Notes',
      'short_name': 'Notes',
      'content': 'These are my notes',
      'modified_by': current_user,
      }

  notes_document = Document(**document_properties)
  notes_document.put()
  document_logic._onCreate(home_document) 

  site.home = home_document
  site.put()
  # pylint: disable=E1101
  memcache.flush_all()

  return http.HttpResponse('Done')
Esempio n. 41
0
 def getGSoC2011Profile(link_id):
   program = GSoCProgram.get_by_key_name('google/gsoc2011')
   return GSoCProfile.all().filter('scope', program).filter('link_id', link_id).get()
Esempio n. 42
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()
Esempio n. 43
0
def seed(request, *args, **kwargs):
    """Seeds the datastore with some default values.
  """

    site_properties = {
        'key_name': 'site',
        'link_id': 'site',
    }

    site = Site(**site_properties)
    site.put()

    _, current_user = ensureUser()

    seeder = UserSeeder()
    for i in range(15):
        seeder.seed(i)

    group_properties = {
        'key_name': 'google',
        'link_id': 'google',
        'name': 'Google Inc.',
        'short_name': 'Google',
        'founder': current_user,
        'home_page': 'http://www.google.com',
        'email': '*****@*****.**',
        'description': 'This is the profile for Google.',
        'contact_street': 'Some Street',
        'contact_city': 'Some City',
        'contact_country': 'United States',
        'contact_postalcode': '12345',
        'phone': '1-555-BANANA',
        'status': 'active',
    }

    google = Sponsor(**group_properties)
    google.put()

    role_properties = {
        'key_name': 'google/test',
        'link_id': 'test',
        'scope': google,
        'scope_path': 'google',
        'user': current_user,
        'given_name': 'Test',
        'surname': 'Example',
        '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,
    }

    current_user.host_for = [google.key()]
    current_user.put()

    google_host = Host(**role_properties)
    google_host.put()

    from datetime import datetime
    from datetime import timedelta

    before = datetime.now() - timedelta(365)
    after = datetime.now() + timedelta(365)

    timeline_properties = {
        'key_name': 'google/gsoc2009',
        'link_id': 'gsoc2009',
        'scope_path': 'google',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': after,
        'student_signup_start': before,
        'student_signup_end': after,
    }

    gsoc2009_timeline = GSoCTimeline(**timeline_properties)
    gsoc2009_timeline.put()

    program_properties = {
        'key_name': 'google/gsoc2009',
        'link_id': 'gsoc2009',
        'scope_path': 'google',
        'scope': google,
        'name': 'Google Summer of Code 2009',
        'short_name': 'GSoC 2009',
        'group_label': 'GSOC',
        'description': 'This is the program for GSoC 2009.',
        'apps_tasks_limit': 42,
        'slots': 42,
        'timeline': gsoc2009_timeline,
        'status': 'visible',
    }

    gsoc2009 = GSoCProgram(**program_properties)
    gsoc2009.put()

    site.active_program = gsoc2009
    site.put()

    # TODO: Use real GCIProgram here
    timeline_properties = {
        'key_name': 'google/gci2009',
        'link_id': 'gci2009',
        'scope_path': 'google',
        'scope': google,
    }

    gci2009_timeline = GCITimeline(**timeline_properties)
    #gci2009_timeline.put()

    program_properties.update({
        'key_name': 'google/gci2009',
        'link_id': 'gci2009',
        'name': 'Google Code In Contest 2009',
        'short_name': 'GCI 2009',
        'group_label': 'GCI',
        'description': 'This is the program for GCI 2009.',
        'timeline': gci2009_timeline,
    })

    gci2009 = GCIProgram(**program_properties)
    #gci2009.put()

    group_properties.update({
        'key_name': 'google/gci2009/melange',
        'link_id': 'melange',
        'name': 'Melange Development Team',
        'short_name': 'Melange',
        'scope_path': 'google/gci2009',
        'scope': gci2009,
        'home_page': 'http://code.google.com/p/soc',
        'description': 'Melange, share the love!',
        'license_name': 'Apache License',
        'ideas': 'http://code.google.com/p/soc/issues',
    })

    melange = GCIOrganization(**group_properties)
    #melange.put()
    # create a new ranker
    #ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, melange,
    #    student_proposal.DEF_SCORE, 100)

    group_properties.update({
        'scope_path': 'google/gsoc2009',
        'scope': gsoc2009,
    })

    role_properties.update({
        'key_name': 'google/gsoc2009/test',
        'link_id': 'test',
        'scope_path': 'google/gsoc2009',
        'scope': gsoc2009,
        'program': gsoc2009,
        'parent': current_user,
    })

    profile = GSoCProfile(**role_properties)
    role_properties.pop('parent')

    orgs = []
    for i in range(15):
        group_properties.update({
            'key_name': 'google/gsoc2009/org_%d' % i,
            'link_id': 'org_%d' % i,
            'name': 'Organization %d' % i,
            'short_name': 'Org %d' % i,
            'description': 'Organization %d!' % i,
        })

        entity = GSoCOrganization(**group_properties)
        orgs.append(entity)
        entity.put()
        # create a new ranker
        ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity,
                                 student_proposal.DEF_SCORE, 100)

        # Admin for the first org
        if i == 0:
            profile.org_admin_for.append(entity.key())
            profile.put()

        # Mentor and admin for the second org
        if i == 1:
            profile.org_admin_for.append(entity.key())
            profile.mentor_for.append(entity.key())
            profile.put()

    role_properties.update({
        'key_name': 'google/gci2009/melange/test',
        'link_id': 'test',
        'scope_path': 'google/gci2009/melange',
        'scope': melange,
        'program': gci2009,
    })

    melange_admin = GCIOrgAdmin(**role_properties)
    #melange_admin.put()

    melange_mentor = GCIMentor(**role_properties)
    #melange_mentor.put()

    student_id = 'test'
    student_properties = {
        'key_name': gsoc2009.key().name() + "/" + student_id,
        'link_id': student_id,
        'scope_path': gsoc2009.key().name(),
        'scope': gsoc2009,
        'program': gsoc2009,
        'user': current_user,
        'given_name': 'test',
        'surname': 'test',
        'birth_date': db.DateProperty.now(),
        'email': '*****@*****.**',
        'im_handle': 'test_im_handle',
        'major': 'test major',
        'name_on_documents': 'test',
        'res_country': 'United States',
        'res_city': 'city',
        'res_street': 'test street',
        'res_postalcode': '12345',
        'publish_location': True,
        'blog': 'http://www.blog.com/',
        'home_page': 'http://www.homepage.com/',
        'photo_url': 'http://www.photosite.com/thumbnail.png',
        'ship_state': None,
        'expected_graduation': 2009,
        'school_country': 'United States',
        'school_name': 'Test School',
        'tshirt_size': 'XS',
        'tshirt_style': 'male',
        'degree': 'Undergraduate',
        'phone': '1650253000',
        'can_we_contact_you': True,
        'program_knowledge': 'I heard about this program through a friend.'
    }

    melange_student = GSoCStudent(**student_properties)
    melange_student.put()

    student_id = 'test2'
    student_properties.update({
        'key_name': gsoc2009.key().name() + "/" + student_id,
        'link_id': student_id,
        'user': current_user
    })

    melange_student2 = GSoCStudent(**student_properties)
    melange_student2.put()

    project_id = 'test_project'
    project_properties = {
        'key_name': gsoc2009.key().name() + "/org_1/" + project_id,
        'link_id': project_id,
        'scope_path': gsoc2009.key().name() + "/org_1",
        'scope': orgs[1].key(),
        'title': 'test project',
        'abstract': 'test abstract',
        'status': 'accepted',
        'student': melange_student,
        'mentor': profile,
        'program': gsoc2009
    }

    melange_project = StudentProject(**project_properties)
    melange_project.put()

    project_id = 'test_project2'
    project_properties.update({
        'key_name': gsoc2009.key().name() + "/org_1/" + project_id,
        'link_id': project_id,
        'student': melange_student2,
        'title': 'test project2'
    })

    melange_project2 = StudentProject(**project_properties)
    melange_project2.put()

    document_properties = {
        'key_name': 'site/site/home',
        'link_id': 'home',
        'scope_path': 'site',
        'scope': site,
        'prefix': 'site',
        'author': current_user,
        'title': 'Home Page',
        'short_name': 'Home',
        'content': 'This is the Home Page',
        'modified_by': current_user,
    }

    home_document = Document(**document_properties)
    home_document.put()
    document_logic._onCreate(home_document)

    document_properties = {
        'key_name': 'user/test/notes',
        'link_id': 'notes',
        'scope_path': 'test',
        'scope': current_user,
        'prefix': 'user',
        'author': current_user,
        'title': 'My Notes',
        'short_name': 'Notes',
        'content': 'These are my notes',
        'modified_by': current_user,
    }

    notes_document = Document(**document_properties)
    notes_document.put()
    document_logic._onCreate(home_document)

    site.home = home_document
    site.put()
    # pylint: disable=E1101
    memcache.flush_all()

    return http.HttpResponse('Done')
Esempio n. 44
0
def seed(request, *args, **kwargs):
  """Seeds the datastore with some default values.
  """

  site_properties = {
      'key_name': 'site',
      'link_id': 'site',
      }

  site = Site(**site_properties)
  site.put()

  account = accounts.getCurrentAccount()

  if not account:
    account = users.User(email='*****@*****.**')

  user_properties = {
      'key_name': 'test',
      'link_id': 'test',
      'account': account,
      'name': 'Test',
      }

  current_user = User(**user_properties)
  current_user.put()

  group_properties = {
       'key_name': 'google',
       'link_id': 'google',
       'name': 'Google Inc.',
       'short_name': 'Google',
       'founder': current_user,
       'home_page': 'http://www.google.com',
       'email': '*****@*****.**',
       'description': 'This is the profile for Google.',
       'contact_street': 'Some Street',
       'contact_city': 'Some City',
       'contact_country': 'United States',
       'contact_postalcode': '12345',
       'phone': '1-555-BANANA',
       'status': 'active',
       }

  google = Sponsor(**group_properties)
  google.put()


  role_properties = {
      'key_name': 'google/test',
      'link_id': 'test',
      'public_name': 'test',
      'scope': google,
      'scope_path': 'google',
      'user': current_user,
      'given_name': 'Test',
      'surname': 'Example',
      '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,
      'is_org_admin': True,
      'is_mentor': True,
      }


  current_user.host_for = [google.key()]
  current_user.put()

  google_host = Host(**role_properties)
  google_host.put()

  from datetime import datetime
  from datetime import timedelta

  now = datetime.now()
  before = now - timedelta(365)
  after = now + timedelta(365)

  timeline_properties = {
      'key_name': 'google/gsoc2009',
      'link_id': 'gsoc2009',
      'scope_path': 'google',
      'scope': google,
      'program_start': before,
      'program_end': after,
      'accepted_organization_announced_deadline': before,
      'student_signup_start': before,
      'student_signup_end': after,
  }

  gsoc2009_timeline = GSoCTimeline(**timeline_properties)
  gsoc2009_timeline.put()


  program_properties = {
      'key_name': 'google/gsoc2009',
      'link_id': 'gsoc2009',
      'scope_path': 'google',
      'scope': google,
      'name': 'Google Summer of Code 2009',
      'short_name': 'GSoC 2009',
      'group_label': 'GSOC',
      'description': 'This is the program for GSoC 2009.',
      'apps_tasks_limit': 42,
      'slots': 42,
      'timeline': gsoc2009_timeline,
      'status': 'visible',
      }

  gsoc2009 = GSoCProgram(**program_properties)
  gsoc2009.put()


  timeline_properties.update({
      'key_name': 'google/gsoc2010',
      'link_id': 'gsoc2010',
  })

  gsoc2010_timeline = GSoCTimeline(**timeline_properties)
  gsoc2010_timeline.put()

  program_properties.update({
      'key_name': 'google/gsoc2010',
      'link_id': 'gsoc2010',
      'name': 'Google Summer of Code 2010',
      'description': 'This is the program for GSoC 2010.',
      'short_name': 'GSoC 2010',
      'timeline': gsoc2010_timeline,
  })

  gsoc2010 = GSoCProgram(**program_properties)
  gsoc2010.put()

  timeline_properties = {
        'key_name': 'google/gci2009',
        'link_id': 'gci2009',
        'scope_path': 'google',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': before,
        'student_signup_start': before,
        'student_signup_end': after,
        'tasks_publicly_visible': before,
        'task_claim_deadline': after,
        'stop_all_work_deadline': after,
  }

  gci2009_timeline = GCITimeline(**timeline_properties)
  gci2009_timeline.put()


  program_properties.update({
      'key_name': 'google/gci2009',
      'link_id': 'gci2009',
      'name': 'Google Code In Contest 2009',
      'short_name': 'GCI 2009',
      'group_label': 'GCI',
      'description': 'This is the program for GCI 2009.',
      'timeline': gci2009_timeline,
      })

  gci2009 = GCIProgram(**program_properties)
  gci2009.put()

  site.active_program = gci2009
  site.put()


  group_properties.update({
    'key_name': 'google/gci2009/melange',
    'link_id': 'melange',
    'name': 'Melange Development Team',
    'short_name': 'Melange',
    'scope_path': 'google/gci2009',
    'scope': gci2009,
    'home_page': 'http://code.google.com/p/soc',
    'description': 'Melange, share the love!',
    'license_name': 'Apache License',
    'ideas': 'http://code.google.com/p/soc/issues',
    })

  melange = GCIOrganization(**group_properties)
  melange.put()

  group_properties.update({
    'scope_path': 'google/gsoc2009',
    'scope': gsoc2009,
    })

  role_properties.update({
      'key_name': 'google/gsoc2009/test',
      'link_id': 'test',
      'scope_path': 'google/gsoc2009',
      'scope': gsoc2009,
      'program': gsoc2009,
      'parent': current_user,
      })

  profile = GSoCProfile(**role_properties)
  role_properties.pop('parent')

  orgs = []
  for i in range(15):
    group_properties.update({
        'key_name': 'google/gsoc2009/org_%d' % i,
        'link_id': 'org_%d' % i,
        'name': 'Organization %d' % i,
        'short_name': 'Org %d' % i,
        'description': 'Organization %d!' % i,
        })

    entity = GSoCOrganization(**group_properties)
    orgs.append(entity)
    entity.put()

    # Admin (and thus mentor) for the first org
    if i == 0:
      profile.org_admin_for.append(entity.key())
      profile.mentor_for.append(entity.key())
      profile.is_mentor = True
      profile.is_org_admin = True
      profile.put()

    # Mentor for the second org
    if i == 1:
      profile.mentor_for.append(entity.key())
      profile.is_mentor = True
      profile.put()

  role_properties.update({
      'key_name': 'google/gci2009/test',
      'link_id': 'test',
      'scope_path': 'google/gci2009',
      'scope': gci2009,
      'program': gci2009,
      'org_admin_for': [melange.key()],
      'mentor_for': [melange.key()],
      'parent': current_user,
      })

  melange_admin = GCIProfile(**role_properties)
  # TODO: add GCI orgs
  melange_admin.put()

  task_properties = {
      'status': 'Open',
      'modified_by': melange_admin.key(),
      'subscribers': [melange_admin.key()],
      'title': 'Awesomeness',
      'created_by': melange_admin.key(),
      'created_on': now,
      'program': gci2009,
      'time_to_complete': 1337,
      'modified_on': now,
      'org': melange.key(),
      'description': '<p>AWESOME</p>',
      'difficulty_level': DifficultyLevel.MEDIUM,
      'types': ['Code']
  }

  gci_task = GCITask(**task_properties)
  gci_task.put()

  user_properties = {
      'key_name': 'student',
      'link_id': 'student',
      'account': users.User(email='*****@*****.**'),
      'name': 'Student',
      }

  student_user = User(**user_properties)
  student_user.put()

  student_id = 'student'
  student_properties = {
      'key_name': gsoc2009.key().name() + "/" + student_id,
      'link_id': student_id, 
      'scope_path': gsoc2009.key().name(),
      'parent': student_user,
      'scope': gsoc2009,
      'program': gsoc2009,
      'user': student_user,
      'is_student': True,
      'public_name': 'Student',
      'given_name': 'Student',
      'surname': 'Student',
      'birth_date': db.DateProperty.now(),
      'email': '*****@*****.**',
      'im_handle': 'student_im_handle',
      'major': 'test major',
      'name_on_documents': 'Student',
      'res_country': 'United States',
      'res_city': 'city',
      'res_street': 'test street',
      'res_postalcode': '12345',
      'publish_location': True,
      'blog': 'http://www.blog.com/',
      'home_page': 'http://www.homepage.com/',
      'photo_url': 'http://www.photosite.com/thumbnail.png',
      'ship_state': None,
      'tshirt_size': 'XS',
      'tshirt_style': 'male',
      'degree': 'Undergraduate',
      'phone': '1650253000',
      'can_we_contact_you': True, 
      'program_knowledge': 'I heard about this program through a friend.'
      }

  melange_student = GSoCProfile(**student_properties)

  student_info_properties = {
      'key_name': melange_student.key().name(),
      'parent': melange_student,
      'expected_graduation': 2009,
      'program': gsoc2009,
      'school_country': 'United States',
      'school_name': 'Test School',
      'school_home_page': 'http://www.example.com',
      'program': gsoc2009,
  }
  student_info = GSoCStudentInfo(**student_info_properties)
  student_info.put()

  melange_student.student_info = student_info
  melange_student.put()

  user_properties = {
      'key_name': 'student2',
      'link_id': 'student2',
      'account': users.User(email='*****@*****.**'),
      'name': 'Student 2',
      }

  student_user2 = User(**user_properties)
  student_user2.put()
  student_id = 'student2'
  student_properties.update({
      'key_name': gsoc2009.key().name() + "/" + student_id,
      'link_id': student_id,
      'user': student_user2,
      'parent': student_user2,
  })

  melange_student2 = GSoCProfile(**student_properties)
  melange_student2.put()

  project_id = 'test_project'
  project_properties = {
      'key_name':  gsoc2009.key().name() + "/org_1/" + project_id,
      'link_id': project_id, 
      'scope_path': gsoc2009.key().name() + "/org_1",
      'scope': orgs[1].key(),

      'title': 'test project',
      'abstract': 'test abstract',
      'status': 'accepted',
      'student': melange_student,
      'mentor': profile,
      'program':  gsoc2009
       }

  melange_project = StudentProject(**project_properties)
  melange_project.put()
  student_info_properties.update({'number_of_projects': 1,
                                  'project_for_orgs': [orgs[1].key()]})
  student_info = GSoCStudentInfo(**student_info_properties)
  student_info.put()

  melange_student.student_info = student_info
  melange_student.put()

  project_id = 'test_project2'
  project_properties.update({
      'key_name':  gsoc2009.key().name() + "/org_1/" + project_id,
      'link_id': project_id,
      'student': melange_student2,
      'title': 'test project2'
      })
      
  student_info_properties.update({
      'key_name': gsoc2009.key().name() + "/" + student_id,
      'link_id': student_id,
      'parent': melange_student2,
  })
  student_info2 = GSoCStudentInfo(**student_info_properties)
  student_info2.put()

  melange_student2.student_info = student_info2
  melange_student2.put()

  melange_project2 = StudentProject(**project_properties)
  melange_project2.put()

  student_id = 'student'
  student_properties.update({
      'key_name': gci2009.key().name() + '/' + student_id,
      'parent': student_user,
      'scope': gci2009,
      'scope_path': gci2009.key().name(),
  })
  gci_student = GCIProfile(**student_properties)
  gci_student.put()

  student_info_properties.update({
      'key_name': gci_student.key().name(),
      'parent': gci_student,
      'program': gci2009,
  })
  student_info = GCIStudentInfo(**student_info_properties)
  student_info.put()
  gci_student.student_info = student_info
  gci_student.put()

  score_properties = {
      'parent': gci_student,
      'program': gci2009,
      'points': 5,
      'tasks': [gci_task.key()]
      }
  score = GCIScore(**score_properties)
  score.put()

  document_properties = {
      'key_name': 'site/site/home',
      'link_id': 'home',
      'scope_path': 'site',
      'scope': site,
      'prefix': 'site',
      'author': current_user,
      'title': 'Home Page',
      'short_name': 'Home',
      'content': 'This is the Home Page',
      'modified_by': current_user,
      }

  home_document = Document(**document_properties)
  home_document.put()


  document_properties = {
      'key_name': 'user/test/notes',
      'link_id': 'notes',
      'scope_path': 'test',
      'scope': current_user,
      'prefix': 'user',
      'author': current_user,
      'title': 'My Notes',
      'short_name': 'Notes',
      'content': 'These are my notes',
      'modified_by': current_user,
      }

  notes_document = Document(**document_properties)
  notes_document.put()

  site.home = home_document
  site.put()
  # pylint: disable=E1101
  memcache.flush_all()

  return http.HttpResponse('Done')
Esempio n. 45
0
 def setUp(self):
     """Set up required for the view tests.
 """
     # Setup TaskQueueTestCase and MailTestCase first
     super(SurveysTasksTest, self).setUp()
     # Create a user for the founder of sponsor
     email = "*****@*****.**"
     account = users.User(email=email)
     link_id = 'a_sponsor_user'
     name = 'A Sponsor User'
     sponsor_user_properties = {
         'account': account,
         'link_id': link_id,
         'name': name,
     }
     sponsor_user = user_logic.updateOrCreateFromFields(
         sponsor_user_properties)
     # Create sponsor
     link_id = 'a_sponsor'
     name = 'A Sponsor'
     founder = 'a_founder'
     phone = '01234567'
     contact_postalcode = 'A postalcode'
     description = 'A description'
     contact_country = 'United States'
     short_name = 'AS'
     contact_city = 'A city'
     home_page = 'http://www.asponsor.com'
     email = '*****@*****.**'
     sponsor_properties = {
         'link_id': link_id,
         'name': name,
         'short_name': short_name,
         'founder': sponsor_user,
         'phone': phone,
         'description': description,
         'contact_country': contact_country,
         'contact_city': 'A City',
         'contact_street': 'A Street',
         'contact_postalcode': contact_postalcode,
         'home_page': home_page,
         'email': email,
         'status': 'active',
     }
     sponsor = sponsor_logic.updateOrCreateFromFields(sponsor_properties)
     # Create a timeline for a program
     timeline_properties = {
         'link_id': 'a_program',
         'scope_path': 'a_sponsor',
         'scope': sponsor,
     }
     timeline = timeline_logic.updateOrCreateFromFields(timeline_properties)
     # Create a program for a_sponsor
     program_properties = {
         'key_name': 'a_sponsor/a_program',
         'link_id': 'a_program',
         'scope': sponsor,
         'scope_path': 'a_sponsor',
         'name': 'A Program 2010',
         'short_name': 'AP2010',
         'group_label': 'AP',
         'description': 'This is the program for AP2010.',
         'apps_tasks_limit': 42,
         'slots': 42,
         'allocations_visible': True,
         'timeline': timeline,
         'status': 'visible',
     }
     # GSoC program logic does not work: error in updatePredefinedOrgTags
     from soc.modules.gsoc.models.program import GSoCProgram
     program = GSoCProgram(**program_properties)
     program.put()
     self.program = program
     # Create an organization for a_program
     organization_properties = {
         'link_id': 'an_org',
         'name': 'An Organization',
         'short_name': 'AO',
         'scope_path': 'a_sponsor/a_program',
         'scope': program,
         'founder': sponsor_user,
         'home_page': 'http://www.an_org.com',
         'phone': '1-555-2222',
         'description': 'An Organization',
         'license_name': 'Apache License',
         'ideas': 'http://www.an_org.com/ideas',
         'contact_country': contact_country,
         'contact_city': 'A City',
         'contact_street': 'A Street',
         'contact_postalcode': contact_postalcode,
         'home_page': home_page,
         'email': email,
         'status': 'active',
     }
     organization = gsoc_organization_logic.updateOrCreateFromFields(
         organization_properties)
     # Create a user for all roles except sponsor
     email = "*****@*****.**"
     account = users.User(email=email)
     link_id = 'a_role_user'
     name = 'A Role User'
     properties = {
         'account': account,
         'link_id': link_id,
         'name': name,
     }
     key_name = user_logic.getKeyNameFromFields(properties)
     role_user = user_logic.updateOrCreateFromKeyName(properties, key_name)
     # Create an admin for an_org
     gsoc_org_admin_properties = {
         'link_id': 'an_org_admin',
         'given_name': 'A',
         'surname': 'Orgadmin',
         'scope_path': organization.scope_path + '/' + organization.link_id,
         'scope': organization,
         'program': program,
         'phone': '1-555-2222',
         'email': '*****@*****.**',
         'res_country': 'United States',
         'res_city': 'A City',
         'res_street': 'A Street',
         'res_postalcode': '12345',
         'birth_date': db.DateProperty.now(),
         'user': role_user,
     }
     gsoc_org_admin_logic.updateOrCreateFromFields(
         gsoc_org_admin_properties)
     # Create a mentor for an_org
     mentor_properties = gsoc_org_admin_properties.copy()
     mentor_properties.update({
         'link_id': 'a_mentor',
         'given_name': 'A',
         'surname': 'Mentor',
         'email': '*****@*****.**',
     })
     mentor = mentor_logic.updateOrCreateFromFields(mentor_properties)
     self.mentor = mentor
     # Create students for a_program
     student_properties = gsoc_org_admin_properties.copy()
     student_properties.update({
         'scope_path':
         program.scope_path + '/' + program.link_id,
         'scope':
         program,
         'program':
         program,
         'given_name':
         'A',
         'surname':
         'Student',
         'major':
         'A Major',
         'name_on_documents':
         'A Name on Documents',
         'publish_location':
         True,
         'blog':
         'http://www.ablog.com/',
         'home_page':
         'http://www.ahomepage.com/',
         'photo_url':
         'http://www.astudent.com/aphoto.png',
         'expected_graduation':
         2011,
         'school_country':
         'United States',
         'school_name':
         'A School',
         'tshirt_size':
         'XS',
         'tshirt_style':
         'male',
         'degree':
         'Undergraduate',
         'phone':
         '1650253000',
         'can_we_contact_you':
         True,
         'program_knowledge':
         'I heard about this program through a friend.'
     })
     # Create projects for a_program, an_org and a_mentor
     project_properties = {
         'scope_path': organization.scope_path + '/' + organization.link_id,
         'scope': organization,
         'title': 'test project',
         'abstract': 'test abstract',
         'status': 'accepted',
         'mentor': mentor,
         'program': program,
     }
     #The string order of students' link_id is the same with that of students
     #in the array in order to make sure the last student is handled last
     size = 10
     self.num_projects = size + 1
     num_digits = 0
     while True:
         size /= 10
         num_digits += 1
         if size == 0:
             break
     students, projects = [], []
     for i in xrange(self.num_projects):
         student_link_id = ('student%0' + str(num_digits) + 'd') % i
         student_properties.update({
             'link_id': student_link_id,
             'email': student_link_id + '@email.com',
         })
         student = student_logic.updateOrCreateFromFields(
             student_properties)
         students.append(student)
         project_link_id = ('project%0' + str(num_digits) + 'd') % i
         project_properties.update({
             'link_id': project_link_id,
             'student': student,
         })
         project = student_project_logic.updateOrCreateFromFields(
             project_properties)
         projects.append(project)
     self.students = students
     self.projects = projects
     # Create a project survey for a_program
     link_id = 'a_project_survey'
     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'
         }
     }
     survey_properties = {
         'link_id': link_id,
         'scope_path': program.scope_path + '/' + program.link_id,
         'scope': None,
         'prefix': 'program',
         'author': role_user,
         'title': 'A Project Survey',
         'short_name': 'APS',
         'modified_by': role_user,
         'is_featured': True,
         'fields': fields,
         'schema': schema,
         'deadline': datetime.datetime.now() + datetime.timedelta(10),
         'taking_access': 'student',
     }
     project_survey = project_survey_logic.updateOrCreateFromFields(
         survey_properties)
     self.project_survey = project_survey
     # Create a grading survey for a_program
     link_id = 'a_grading_survey'
     survey_properties.update({
         'link_id': link_id,
         'title': 'A Grading Survey',
         'short_name': 'AGS',
         'taking_access': 'mentor',
     })
     grading_survey = grading_survey_logic.updateOrCreateFromFields(
         survey_properties)
     self.grading_survey = grading_survey
Esempio n. 46
0
def seed(request, *args, **kwargs):
    """Seeds the datastore with some default values.
  """

    site_properties = {
        'key_name': 'site',
        'latest_gsoc': 'google/gsoc2014',
        'latest_gci': 'google/gci2013',
    }
    site = Site(**site_properties)
    site.put()

    account = accounts.getCurrentAccount()

    if not account:
        account = users.User(email='*****@*****.**')

    user_properties = {
        'id': 'test',
        'account_id': account.user_id(),
        'account': account,
    }
    current_user = user.User(**user_properties)
    current_user.put()

    group_properties = {
        'key_name': 'google',
        'link_id': 'google',
        'name': 'Google Inc.',
        'short_name': 'Google',
        'home_page': 'http://www.google.com',
        'email': '*****@*****.**',
        'description': 'This is the profile for Google.',
        'contact_street': 'Some Street',
        'contact_city': 'Some City',
        'contact_country': 'United States',
        'contact_postalcode': '12345',
        'phone': '15551110000',
        'status': 'active',
    }
    google = Sponsor(**group_properties)
    google.put()

    now = datetime.datetime.now()
    before = now - datetime.timedelta(365)
    after = now + datetime.timedelta(365)
    past_before = before - datetime.timedelta(2 * 365)
    past_after = after - datetime.timedelta(2 * 365)

    timeline_properties = {
        'key_name': 'google/gsoc2014',
        'link_id': 'gsoc2014',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': before,
        'accepted_students_announced_deadline': after,
        'student_signup_start': before,
        'student_signup_end': after,
        'application_review_deadline': after,
        'student_application_matched_deadline': after,
        'accepted_students_announced_deadline': after,
        'form_submission_start': before,
    }
    gsoc2014_timeline = GSoCTimeline(**timeline_properties)
    gsoc2014_timeline.put()

    program_properties = {
        'key_name': 'google/gsoc2014',
        'link_id': 'gsoc2014',
        'program_id': 'gsoc2014',
        'sponsor': google,
        'scope': google,
        'name': 'Google Summer of Code 2014',
        'short_name': 'GSoC 2014',
        'description': 'This is the program for GSoC 2014.',
        'apps_tasks_limit': 42,
        'slots': 42,
        'timeline': gsoc2014_timeline,
        'status': program_model.STATUS_VISIBLE,
    }
    gsoc2014 = GSoCProgram(**program_properties)
    gsoc2014.put()

    timeline_properties.update({
        'key_name': 'google/gsoc2010',
        'link_id': 'gsoc2010',
        'program_start': past_before,
        'program_end': past_after,
        'accepted_organization_announced_deadline': past_before,
        'accepted_students_announced_deadline': past_after,
        'student_signup_start': past_before,
        'student_signup_end': past_after,
        'application_review_deadline': past_after,
        'student_application_matched_deadline': past_after,
        'accepted_students_announced_deadline': past_after,
        'form_submission_start': past_before,
    })
    gsoc2010_timeline = GSoCTimeline(**timeline_properties)
    gsoc2010_timeline.put()

    program_properties.update({
        'key_name': 'google/gsoc2010',
        'link_id': 'gsoc2010',
        'program_id': 'gsoc2010',
        'name': 'Google Summer of Code 2010',
        'description': 'This is the program for GSoC 2010.',
        'short_name': 'GSoC 2010',
        'timeline': gsoc2010_timeline,
    })
    gsoc2010 = GSoCProgram(**program_properties)
    gsoc2010.put()

    # TODO(drew): Replace gsoc2014.prefix with whatever its replacement becomes
    # once prefix is removed from program and no longer used in the query for
    # OrgAppSurvey in soc.views.helper.RequestData._getProgramWideFields().
    org_app_survey_properties = {
        'key_name': '%s/%s/orgapp' % (gsoc2014.prefix, gsoc2014.key().name()),
        'program': gsoc2014,
        'title': 'Org App Survey',
        'content': 'Here is some content.',
        'modified_by': current_user.key.to_old_key(),
        'survey_start': before,
        'survey_end': after
    }
    org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

    org_app_survey_properties['key_name'] = (
        '%s/%s/orgapp' % (gsoc2010.prefix, gsoc2010.key().name()))
    org_app_survey_properties['program'] = gsoc2010
    org_app_survey_properties['survey_start'] = past_before
    org_app_survey_properties['survey_end'] = past_after
    org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

    timeline_properties = {
        'key_name': 'google/gci2013',
        'link_id': 'gci2013',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': before,
        'student_signup_start': before,
        'student_signup_end': after,
        'tasks_publicly_visible': before,
        'task_claim_deadline': after,
        'stop_all_work_deadline': after,
    }
    gci2013_timeline = GCITimeline(**timeline_properties)
    gci2013_timeline.put()

    program_properties.update({
        'key_name': 'google/gci2013',
        'link_id': 'gci2013',
        'program_id': 'gci2013',
        'name': 'Google Code In Contest 2013',
        'short_name': 'GCI 2009',
        'description': 'This is the program for GCI 2013.',
        'timeline': gci2013_timeline,
    })
    gci2013 = GCIProgram(**program_properties)
    gci2013.put()

    site.active_program = gci2013
    site.put()

    current_user.host_for = [
        ndb.Key.from_old_key(gsoc2010.key()),
        ndb.Key.from_old_key(gsoc2014.key()),
        ndb.Key.from_old_key(gci2013.key())
    ]
    current_user.put()

    group_properties.update({
        'key_name': 'google/gci2013/melange',
        'link_id': 'melange',
        'name': 'Melange Development Team',
        'short_name': 'Melange',
        'scope': gci2013,
        'program': gci2013,
        'sponsor': google,
        'home_page': 'http://code.google.com/p/soc',
        'description': 'Melange, share the love!',
        'license_name': 'Apache License',
        'ideas': 'http://code.google.com/p/soc/issues',
    })
    melange = GCIOrganization(**group_properties)
    melange.put()

    group_properties.update({
        'scope': gsoc2014,
        'program': gsoc2014,
    })

    address_properties = address.Address(street='1 Test St.',
                                         city='Some City',
                                         country='United States',
                                         postal_code='12345')
    address_properties.put()

    contact_info = contact.Contact(email='*****@*****.**')
    contact_info.put()

    gsoc_delta = datetime.timedelta(days=(365 * 18))

    profile_properties = {
        'id': gsoc2014.key().name() + '/' + current_user.key.id(),
        'parent': current_user.key,
        'public_name': 'test',
        'program': ndb.Key.from_old_key(gsoc2014.key()),
        'first_name': 'Test',
        'last_name': 'Example',
        'contact': contact_info,
        'residential_address': address_properties,
        'shipping_address': address_properties,
        'birth_date': datetime.date.today() - gsoc_delta,
        'program_knowledge': 'Friend referral',
    }
    profile = profile_model.Profile(**profile_properties)

    ndb_orgs = []
    for i in range(15):
        group_properties.update({
            'key_name': 'google/gsoc2014/org_%d' % i,
            'link_id': 'org_%d' % i,
            'name': 'Organization %d' % i,
            'short_name': 'Org %d' % i,
            'description': 'Organization %d!' % i,
        })

        org_properties = {
            'name': 'Organization %d' % i,
            'org_id': 'org_%d' % i,
            'program': ndb.Key.from_old_key(gsoc2014.key()),
            'description': 'Organization %d!' % i,
        }
        org = soc_org_model.SOCOrganization(id='google/gsoc2014/org_%d' % i,
                                            **org_properties)
        org.put()
        ndb_orgs.append(org)

        # Admin (and thus mentor) for the first org
        if i == 0:
            profile.admin_for.append(org.key)
            profile.mentor_for.append(org.key)
            profile.put()

        # Mentor for the second org
        if i == 1:
            profile.mentor_for.append(org.key)
            profile.put()

    profile_properties.update({
        'id':
        gci2013.key().name() + '/' + current_user.key.id(),
        'parent':
        current_user.key,
        'program':
        ndb.Key.from_old_key(gci2013.key()),
        'admin_for': [ndb.Key.from_old_key(melange.key())],
        'mentor_for': [ndb.Key.from_old_key(melange.key())],
    })
    melange_admin = profile_model.Profile(**profile_properties)
    # TODO: add GCI orgs
    melange_admin.put()

    task_properties = {
        'status': 'Open',
        'modified_by': melange_admin.key.to_old_key(),
        'subscribers': [melange_admin.key.to_old_key()],
        'title': 'Awesomeness',
        'created_by': melange_admin.key.to_old_key(),
        'created_on': now,
        'program': gci2013,
        'time_to_complete': 1337,
        'modified_on': now,
        'org': melange.key(),
        'description': '<p>AWESOME</p>',
        'difficulty_level': DifficultyLevel.MEDIUM,
        'types': ['Code']
    }
    gci_task = GCITask(**task_properties)
    gci_task.put()

    user_properties = {
        'id': 'student',
        'account_id': '12345',
        'account': users.User(email='*****@*****.**'),
    }
    student_user = user.User(**user_properties)
    student_user.put()

    gci_delta = datetime.timedelta(days=(365 * 14))

    contact_properties = contact.Contact(email='*****@*****.**',
                                         web_page='http://www.homepage.com/',
                                         blog='http://www.blog.com/',
                                         phone='1650253000')
    contact_properties.put()

    graduation_year = datetime.date.today() + datetime.timedelta(days=365)

    student_data = soc_profile.SOCStudentData(education=education.Education(
        school_id="123",
        school_country="United States",
        expected_graduation=int(graduation_year.strftime('%Y')),
        major='Some Major',
        degree=education.Degree.UNDERGRADUATE))
    student_data.put()

    student_id = 'student'
    student_properties = {
        'id': gsoc2014.key().name() + "/" + student_id,
        'parent': student_user.key,
        'program': ndb.Key.from_old_key(gsoc2014.key()),
        'public_name': 'Student',
        'first_name': 'Student',
        'last_name': 'Student',
        'contact': contact_properties,
        'residential_address': address_properties,
        'shipping_address': address_properties,
        'birth_date': datetime.date.today() - gci_delta,
        'tee_size': profile_model.TeeSize.L,
        'tee_style': profile_model.TeeStyle.MALE,
        'gender': profile_model.Gender.MALE,
        'program_knowledge': 'Friend referral.',
        'student_data': student_data,
    }
    melange_student = profile_model.Profile(**student_properties)
    melange_student.put()

    student_id = 'student2'
    user_properties = {
        'id': student_id,
        'account_id': 'student2',
        'account': users.User(email='*****@*****.**'),
    }
    student_user2 = user.User(**user_properties)
    student_user2.put()

    student_properties.update({
        'id': gsoc2014.key().name() + "/" + student_id,
        'parent': student_user2.key,
        'first_name': 'Student 2',
        'last_name': 'Example'
    })
    melange_student2 = profile_model.Profile(**student_properties)
    melange_student2.put()

    proposal_properties = {
        'parent': melange_student.key.to_old_key(),
        'program': gsoc2014,
        'title': 'test proposal',
        'abstract': 'test abstract',
        'content': 'test content',
        'mentor': profile.key.to_old_key(),
        'status': 'accepted',
        'has_mentor': True,
        'org': ndb_orgs[0].key.to_old_key(),
        'possible_mentors': [profile.key.to_old_key()]
    }
    melange_proposal = GSoCProposal(**proposal_properties)
    melange_proposal.put()

    project_properties = {
        'title': 'test project',
        'abstract': 'test abstract',
        'status': 'accepted',
        'parent': melange_student.key.to_old_key(),
        'mentors': [profile.key.to_old_key()],
        'program': gsoc2014,
        'org': ndb_orgs[0].key.to_old_key(),
        'proposal': melange_proposal.key(),
    }
    melange_project = GSoCProject(**project_properties)
    melange_project.put()
    ndb_orgs[1].slot_allocation = 1
    ndb_orgs[1].put()

    student_data.number_of_projects = 1
    student_data.number_of_proposals = 1
    student_data.project_for_orgs = [ndb_orgs[1].key]

    melange_student.put()
    melange_student2.put()

    project_properties.update({
        'student': melange_student2,
        'title': 'test project2'
    })
    melange_project2 = GSoCProject(**project_properties)
    melange_project2.put()
    ndb_orgs[1].slot_allocation += 1
    ndb_orgs[1].put()

    student_id = 'student'
    student_properties.update({
        'id': gci2013.key().name() + '/' + student_id,
        'parent': student_user.key,
        'program': ndb.Key.from_old_key(gci2013.key()),
    })
    gci_student = profile_model.Profile(**student_properties)
    gci_student.put()

    score_properties = {
        'parent': gci_student.key.to_old_key(),
        'program': gci2013,
        'points': 5,
        'tasks': [gci_task.key()]
    }
    score = GCIScore(**score_properties)
    score.put()

    document_properties = {
        'key_name': 'site/site/home',
        'link_id': 'home',
        'scope': site,
        'prefix': 'site',
        'author': current_user.key.to_old_key(),
        'title': 'Home Page',
        'content': 'This is the Home Page',
        'modified_by': current_user.key.to_old_key(),
    }
    home_document = Document(**document_properties)
    home_document.put()

    document_properties = {
        'key_name': 'user/test/notes',
        'link_id': 'notes',
        'scope': current_user.key.to_old_key(),
        'prefix': 'user',
        'author': current_user.key.to_old_key(),
        'title': 'My Notes',
        'content': 'These are my notes',
        'modified_by': current_user.key.to_old_key(),
    }
    notes_document = Document(**document_properties)
    notes_document.put()

    site.home = home_document
    site.put()

    memcache.flush_all()

    return http.HttpResponse('Done')
Esempio n. 47
0
def seed(request, *args, **kwargs):
  """Seeds the datastore with some default values.
  """

  site_properties = {
      'key_name': 'site',
      'latest_gsoc': 'google/gsoc2014',
      'latest_gci': 'google/gci2013',
      }
  site = Site(**site_properties)
  site.put()

  account = accounts.getCurrentAccount()

  if not account:
    account = users.User(email='*****@*****.**')

  user_properties = {
      'id': 'test',
      'account_id': account.user_id(),
      'account': account,
      }
  current_user = user.User(**user_properties)
  current_user.put()

  group_properties = {
       'key_name': 'google',
       'link_id': 'google',
       'name': 'Google Inc.',
       'short_name': 'Google',
       'home_page': 'http://www.google.com',
       'email': '*****@*****.**',
       'description': 'This is the profile for Google.',
       'contact_street': 'Some Street',
       'contact_city': 'Some City',
       'contact_country': 'United States',
       'contact_postalcode': '12345',
       'phone': '15551110000',
       'status': 'active',
       }
  google = Sponsor(**group_properties)
  google.put()

  now = datetime.datetime.now()
  before = now - datetime.timedelta(365)
  after = now + datetime.timedelta(365)
  past_before = before - datetime.timedelta(2 * 365)
  past_after = after - datetime.timedelta(2 * 365)

  timeline_properties = {
      'key_name': 'google/gsoc2014',
      'link_id': 'gsoc2014',
      'scope': google,
      'program_start': before,
      'program_end': after,
      'accepted_organization_announced_deadline': before,
      'accepted_students_announced_deadline' : after,
      'student_signup_start': before,
      'student_signup_end': after,
      'application_review_deadline': after,
      'student_application_matched_deadline': after,
      'accepted_students_announced_deadline': after,
      'form_submission_start': before,
  }
  gsoc2014_timeline = GSoCTimeline(**timeline_properties)
  gsoc2014_timeline.put()

  program_properties = {
      'key_name': 'google/gsoc2014',
      'link_id': 'gsoc2014',
      'program_id': 'gsoc2014',
      'sponsor': google,
      'scope': google,
      'name': 'Google Summer of Code 2014',
      'short_name': 'GSoC 2014',
      'description': 'This is the program for GSoC 2014.',
      'apps_tasks_limit': 42,
      'slots': 42,
      'timeline': gsoc2014_timeline,
      'status': program_model.STATUS_VISIBLE,
      }
  gsoc2014 = GSoCProgram(**program_properties)
  gsoc2014.put()

  timeline_properties.update({
      'key_name': 'google/gsoc2010',
      'link_id': 'gsoc2010',
      'program_start': past_before,
      'program_end': past_after,
      'accepted_organization_announced_deadline': past_before,
      'accepted_students_announced_deadline' : past_after,
      'student_signup_start': past_before,
      'student_signup_end': past_after,
      'application_review_deadline': past_after,
      'student_application_matched_deadline': past_after,
      'accepted_students_announced_deadline': past_after,
      'form_submission_start': past_before,
  })
  gsoc2010_timeline = GSoCTimeline(**timeline_properties)
  gsoc2010_timeline.put()

  program_properties.update({
      'key_name': 'google/gsoc2010',
      'link_id': 'gsoc2010',
      'program_id': 'gsoc2010',
      'name': 'Google Summer of Code 2010',
      'description': 'This is the program for GSoC 2010.',
      'short_name': 'GSoC 2010',
      'timeline': gsoc2010_timeline,
  })
  gsoc2010 = GSoCProgram(**program_properties)
  gsoc2010.put()

  # TODO(drew): Replace gsoc2014.prefix with whatever its replacement becomes
  # once prefix is removed from program and no longer used in the query for
  # OrgAppSurvey in soc.views.helper.RequestData._getProgramWideFields().
  org_app_survey_properties = {
    'key_name' : '%s/%s/orgapp' % (gsoc2014.prefix, gsoc2014.key().name()),
    'program' : gsoc2014,
    'title' : 'Org App Survey',
    'content' : 'Here is some content.',
    'modified_by' : current_user.key.to_old_key(),
    'survey_start' : before,
    'survey_end' : after
  }
  org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

  org_app_survey_properties['key_name'] = ('%s/%s/orgapp' % (
      gsoc2010.prefix, gsoc2010.key().name()))
  org_app_survey_properties['program'] = gsoc2010
  org_app_survey_properties['survey_start'] = past_before
  org_app_survey_properties['survey_end'] = past_after
  org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

  timeline_properties = {
        'key_name': 'google/gci2013',
        'link_id': 'gci2013',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': before,
        'student_signup_start': before,
        'student_signup_end': after,
        'tasks_publicly_visible': before,
        'task_claim_deadline': after,
        'stop_all_work_deadline': after,
  }
  gci2013_timeline = GCITimeline(**timeline_properties)
  gci2013_timeline.put()

  program_properties.update({
      'key_name': 'google/gci2013',
      'link_id': 'gci2013',
      'program_id': 'gci2013',
      'name': 'Google Code In Contest 2013',
      'short_name': 'GCI 2009',
      'description': 'This is the program for GCI 2013.',
      'timeline': gci2013_timeline,
      })
  gci2013 = GCIProgram(**program_properties)
  gci2013.put()

  site.active_program = gci2013
  site.put()

  current_user.host_for = [
      ndb.Key.from_old_key(gsoc2010.key()),
      ndb.Key.from_old_key(gsoc2014.key()),
      ndb.Key.from_old_key(gci2013.key())]
  current_user.put()

  group_properties.update({
    'key_name': 'google/gci2013/melange',
    'link_id': 'melange',
    'name': 'Melange Development Team',
    'short_name': 'Melange',
    'scope': gci2013,
    'program': gci2013,
    'sponsor': google,
    'home_page': 'http://code.google.com/p/soc',
    'description': 'Melange, share the love!',
    'license_name': 'Apache License',
    'ideas': 'http://code.google.com/p/soc/issues',
    })
  melange = GCIOrganization(**group_properties)
  melange.put()

  group_properties.update({
    'scope': gsoc2014,
    'program': gsoc2014,
    })

  address_properties = address.Address(
      street='1 Test St.',
      city='Some City',
      country='United States',
      postal_code='12345')
  address_properties.put()

  contact_info = contact.Contact(email='*****@*****.**')
  contact_info.put()

  gsoc_delta = datetime.timedelta(days=(365 * 18))

  profile_properties = {
      'id': gsoc2014.key().name() + '/' + current_user.key.id(),
      'parent': current_user.key,
      'public_name': 'test',
      'program': ndb.Key.from_old_key(gsoc2014.key()),
      'first_name': 'Test',
      'last_name': 'Example',
      'contact' : contact_info,
      'residential_address' : address_properties,
      'shipping_address' : address_properties,
      'birth_date' : datetime.date.today() - gsoc_delta,
      'program_knowledge' : 'Friend referral',
      }
  profile = profile_model.Profile(**profile_properties)

  ndb_orgs = []
  for i in range(15):
    group_properties.update({
        'key_name': 'google/gsoc2014/org_%d' % i,
        'link_id': 'org_%d' % i,
        'name': 'Organization %d' % i,
        'short_name': 'Org %d' % i,
        'description': 'Organization %d!' % i,
        })

    org_properties = {
        'name': 'Organization %d' % i,
        'org_id': 'org_%d' % i,
        'program': ndb.Key.from_old_key(gsoc2014.key()),
        'description': 'Organization %d!' % i,
        }
    org = soc_org_model.SOCOrganization(
        id='google/gsoc2014/org_%d' % i, **org_properties)
    org.put()
    ndb_orgs.append(org)

    # Admin (and thus mentor) for the first org
    if i == 0:
      profile.admin_for.append(org.key)
      profile.mentor_for.append(org.key)
      profile.put()

    # Mentor for the second org
    if i == 1:
      profile.mentor_for.append(org.key)
      profile.put()

  profile_properties.update({
      'id': gci2013.key().name() + '/' + current_user.key.id(),
      'parent': current_user.key,
      'program': ndb.Key.from_old_key(gci2013.key()),
      'admin_for': [ndb.Key.from_old_key(melange.key())],
      'mentor_for': [ndb.Key.from_old_key(melange.key())],
      })
  melange_admin = profile_model.Profile(**profile_properties)
  # TODO: add GCI orgs
  melange_admin.put()

  task_properties = {
      'status': 'Open',
      'modified_by': melange_admin.key.to_old_key(),
      'subscribers': [melange_admin.key.to_old_key()],
      'title': 'Awesomeness',
      'created_by': melange_admin.key.to_old_key(),
      'created_on': now,
      'program': gci2013,
      'time_to_complete': 1337,
      'modified_on': now,
      'org': melange.key(),
      'description': '<p>AWESOME</p>',
      'difficulty_level': DifficultyLevel.MEDIUM,
      'types': ['Code']
  }
  gci_task = GCITask(**task_properties)
  gci_task.put()

  user_properties = {
      'id': 'student',
      'account_id': '12345',
      'account': users.User(email='*****@*****.**'),
      }
  student_user = user.User(**user_properties)
  student_user.put()

  gci_delta = datetime.timedelta(days=(365 * 14))

  contact_properties = contact.Contact(
      email='*****@*****.**',
      web_page='http://www.homepage.com/',
      blog='http://www.blog.com/',
      phone='1650253000')
  contact_properties.put()

  graduation_year = datetime.date.today() + datetime.timedelta(days=365)

  student_data = soc_profile.SOCStudentData(
      education=education.Education(
          school_id="123",
          school_country="United States",
          expected_graduation=int(graduation_year.strftime('%Y')),
          major='Some Major',
          degree=education.Degree.UNDERGRADUATE)
      )
  student_data.put()

  student_id = 'student'
  student_properties = {
      'id': gsoc2014.key().name() + "/" + student_id,
      'parent': student_user.key,
      'program': ndb.Key.from_old_key(gsoc2014.key()),
      'public_name': 'Student',
      'first_name': 'Student',
      'last_name': 'Student',
      'contact' : contact_properties,
      'residential_address' : address_properties,
      'shipping_address' : address_properties,
      'birth_date': datetime.date.today() - gci_delta,
      'tee_size': profile_model.TeeSize.L,
      'tee_style': profile_model.TeeStyle.MALE,
      'gender' : profile_model.Gender.MALE,
      'program_knowledge': 'Friend referral.',
      'student_data' : student_data,
      }
  melange_student = profile_model.Profile(**student_properties)
  melange_student.put()

  student_id = 'student2'
  user_properties = {
      'id': student_id,
      'account_id': 'student2',
      'account': users.User(email='*****@*****.**'),
      }
  student_user2 = user.User(**user_properties)
  student_user2.put()

  student_properties.update({
      'id': gsoc2014.key().name() + "/" + student_id,
      'parent': student_user2.key,
      'first_name' : 'Student 2',
      'last_name' : 'Example'
  })
  melange_student2 = profile_model.Profile(**student_properties)
  melange_student2.put()

  proposal_properties = {
      'parent': melange_student.key.to_old_key(),
      'program': gsoc2014,
      'title': 'test proposal',
      'abstract': 'test abstract',
      'content': 'test content',
      'mentor': profile.key.to_old_key(),
      'status': 'accepted',
      'has_mentor': True,
      'org': ndb_orgs[0].key.to_old_key(),
      'possible_mentors': [profile.key.to_old_key()]
      }
  melange_proposal = GSoCProposal(**proposal_properties)
  melange_proposal.put()

  project_properties = {
      'title': 'test project',
      'abstract': 'test abstract',
      'status': 'accepted',
      'parent': melange_student.key.to_old_key(),
      'mentors': [profile.key.to_old_key()],
      'program':  gsoc2014,
      'org': ndb_orgs[0].key.to_old_key(),
      'proposal' : melange_proposal.key(),
       }
  melange_project = GSoCProject(**project_properties)
  melange_project.put()
  ndb_orgs[1].slot_allocation = 1
  ndb_orgs[1].put()

  student_data.number_of_projects = 1
  student_data.number_of_proposals = 1
  student_data.project_for_orgs = [ndb_orgs[1].key]

  melange_student.put()
  melange_student2.put()

  project_properties.update({
      'student': melange_student2,
      'title': 'test project2'
      })
  melange_project2 = GSoCProject(**project_properties)
  melange_project2.put()
  ndb_orgs[1].slot_allocation += 1
  ndb_orgs[1].put()

  student_id = 'student'
  student_properties.update({
      'id': gci2013.key().name() + '/' + student_id,
      'parent': student_user.key,
      'program': ndb.Key.from_old_key(gci2013.key()),
  })
  gci_student = profile_model.Profile(**student_properties)
  gci_student.put()

  score_properties = {
      'parent': gci_student.key.to_old_key(),
      'program': gci2013,
      'points': 5,
      'tasks': [gci_task.key()]
      }
  score = GCIScore(**score_properties)
  score.put()

  document_properties = {
      'key_name': 'site/site/home',
      'link_id': 'home',
      'scope': site,
      'prefix': 'site',
      'author': current_user.key.to_old_key(),
      'title': 'Home Page',
      'content': 'This is the Home Page',
      'modified_by': current_user.key.to_old_key(),
      }
  home_document = Document(**document_properties)
  home_document.put()

  document_properties = {
      'key_name': 'user/test/notes',
      'link_id': 'notes',
      'scope': current_user.key.to_old_key(),
      'prefix': 'user',
      'author': current_user.key.to_old_key(),
      'title': 'My Notes',
      'content': 'These are my notes',
      'modified_by': current_user.key.to_old_key(),
      }
  notes_document = Document(**document_properties)
  notes_document.put()

  site.home = home_document
  site.put()

  memcache.flush_all()

  return http.HttpResponse('Done')
Esempio n. 48
0
 def __init__(self):
   self.programs = GSoCProgram.all().fetch(1000)
Esempio n. 49
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()