示例#1
0
    def testCreateUser(self):
        self.timeline.studentSignup()

        self.default_props.update({
            'link_id': 'test',
        })

        response = self.post(self.student_url, self.default_props)
        self.assertResponseRedirect(response, self.validated_url)

        self.assertEqual(1, GCIProfile.all().count())
        student = GCIProfile.all().get()

        self.assertEqual(self.birth_date, str(student.birth_date))
示例#2
0
  def testCreateUser(self):
    self.timeline.studentSignup()

    self.default_props.update({
        'link_id': 'test',
        })

    response = self.post(self.student_url, self.default_props)
    self.assertResponseRedirect(response, self.validated_url)

    self.assertEqual(1, GCIProfile.all().count())
    student = GCIProfile.all().get()

    self.assertEqual(self.birth_date, str(student.birth_date))
示例#3
0
    def clean_email(self):
        email_cleaner = cleaning.clean_email('email')

        try:
            email_address = email_cleaner(self)
        except djangoforms.ValidationError as e:
            if e.code != 'invalid':
                raise
            msg = ugettext(u'Enter a valid email address.')
            raise djangoforms.ValidationError(msg, code='invalid')

        account = users.User(email_address)
        user_account = accounts.normalizeAccount(account)
        user = User.all().filter('account', user_account).get()

        if not user:
            raise djangoforms.ValidationError(
                "There is no user with that email address")

        self.cleaned_data['user'] = user

        q = GCIProfile.all()
        q.filter('program', self.request_data.program)
        q.ancestor(user)
        self.cleaned_data['profile'] = q.get()
示例#4
0
    def testCreateProfile(self):
        from soc.modules.gci.models.profile import GCIStudentInfo

        self.timeline.studentSignup()
        self.data.createUser()
        self._updateDefaultProps(self.data)
        postdata = self.default_props

        response = self.post(self.student_url, postdata)
        self.assertResponseRedirect(response, self.validated_url)

        # hacky
        profile = GCIProfile.all().get()
        profile.delete()

        postdata.update({
            'email': 'somerandominvalid@emailid',
        })

        response = self.post(self.student_url, postdata)

        # yes! this is the protocol for form posts. We get an OK response
        # with the response containing the form's GET request page whenever
        # the form has an error and could not be posted. This is the architecture
        # chosen in order to save the form error state's while rendering the
        # error fields.
        self.assertResponseOK(response)

        error_dict = response.context['error']
        self.assertTrue('email' in error_dict)
示例#5
0
  def testCreateProfile(self):
    from soc.modules.gci.models.profile import GCIStudentInfo

    self.timeline.studentSignup()
    self.data.createUser()
    self._updateDefaultProps(self.data)
    postdata = self.default_props

    response = self.post(self.student_url, postdata)
    self.assertResponseRedirect(response, self.validated_url)

    # hacky
    profile = GCIProfile.all().get()
    profile.delete()

    postdata.update({
        'email': 'somerandominvalid@emailid',
        })

    response = self.post(self.student_url, postdata)

    # yes! this is the protocol for form posts. We get an OK response
    # with the response containing the form's GET request page whenever
    # the form has an error and could not be posted. This is the architecture
    # chosen in order to save the form error state's while rendering the
    # error fields.
    self.assertResponseOK(response)

    error_dict = response.context['error']
    self.assertTrue('email' in error_dict)
示例#6
0
文件: request.py 项目: adviti/melange
  def validate(self):
    """Validates the form data.
    
    Returns a newly created request entity or None if an error occurs.
    """
    assert isSet(self.data.organization)

    request_form = RequestForm(self.data.POST)

    if not request_form.is_valid():
      return None

    request_form.cleaned_data['org'] = self.data.organization
    request_form.cleaned_data['role'] = self.data.kwargs['role']
    request_form.cleaned_data['type'] = 'Request'
    request_form.cleaned_data['user'] = self.data.user

    q = GCIProfile.all().filter('org_admin_for', self.data.organization)
    q = q.filter('status', 'active').filter('notify_new_requests', True)
    admins = q.fetch(1000)
    admin_emails = [i.email for i in admins]

    def create_request_txn():
      request = request_form.create(commit=True)
      context = notifications.requestContext(self.data, request, admin_emails)
      sub_txn = mailer.getSpawnMailTaskTxn(context, parent=request)
      sub_txn()
      return request

    return db.run_in_transaction(create_request_txn)
示例#7
0
文件: profile.py 项目: adviti/melange
def queryProfileForUserAndProgram(user, program):
  """Returns the query to fetch GCIProfile entity for the specified user
  and program.

  Args:
    user: User entity for which the profile should be found
    program: GCIProgram entity for which the profile should be found
  """
  return GCIProfile.all().ancestor(user).filter('scope = ', program)
示例#8
0
文件: profile.py 项目: adviti/melange
def orgAdminsForOrg(org, limit=1000):
  """Returns the organization administrators for the given GCI Organization.

  Args:
    org: The GCIOrganization entity for which the admins should be found.
  """
  query = GCIProfile.all()
  query.filter('org_admin_for', org)

  return query.fetch(limit)
示例#9
0
    def recalculateGCIRanking(self, request, *args, **kwargs):
        """Recalculates student ranking for the entire program.

    Args in POST dict:
      cursor: Query cursor to figure out where we need to start processing
    """

        key_name = '%s/%s' % (kwargs['sponsor'], kwargs['program'])
        cursor = request.POST.get('cursor')

        program = GCIProgram.get_by_key_name(key_name)
        if not program:
            logging.warning(
                'Enqueued recalculate ranking task for non-existing program: %s',
                key_name)
            return responses.terminateTask()

        # Retrieve the students for the program
        q = GCIProfile.all()
        q.filter('program', program)
        q.filter('is_student', True)

        if cursor:
            q.with_cursor(cursor)

        students = q.fetch(25)

        for student in students:
            # get all the tasks that the student has completed
            task_q = GCITask.all()
            task_q.filter('student', student)
            task_q.filter('status', 'Closed')

            tasks = task_q.fetch(1000)

            # calculate score with all the tasks
            score_logic.calculateScore(student, tasks, program)

            # calculate org score with all the tasks
            db.run_in_transaction(org_score_logic.updateOrgScoresTxn(tasks))

        if students:
            # schedule task to do the rest of the students
            params = {
                'cursor': q.cursor(),
            }
            taskqueue.add(queue_name='gci-update',
                          url=request.path,
                          params=params)

        return responses.terminateTask()
示例#10
0
  def recalculateGCIRanking(self, request, *args, **kwargs):
    """Recalculates student ranking for the entire program.

    Args in POST dict:
      cursor: Query cursor to figure out where we need to start processing
    """

    key_name = '%s/%s' % (kwargs['sponsor'], kwargs['program'])
    cursor = request.POST.get('cursor')

    program = GCIProgram.get_by_key_name(key_name)
    if not program:
      logging.warning(
          'Enqueued recalculate ranking task for non-existing '
          'program: %s' %key_name)
      return responses.terminateTask()

    # Retrieve the students for the program
    q = GCIProfile.all()
    q.filter('scope', program)
    q.filter('is_student', True)

    if cursor:
      q.with_cursor(cursor)

    students = q.fetch(25)

    for student in students:
      # get all the tasks that the student has completed
      task_q = GCITask.all()
      task_q.filter('student', student)
      task_q.filter('status', 'Closed')

      tasks = task_q.fetch(1000)

      # calculate ranking with all the tasks
     # ranking_logic.calculateRankingForStudent(student, tasks)
      ranking_logic.calculateScore(student, tasks, program)

    if students:
      # schedule task to do the rest of the students
      params = {
          'cursor': q.cursor(),
          }
      taskqueue.add(queue_name='gci-update', url=request.path, params=params)

    return responses.terminateTask()
示例#11
0
def process(task):
    org = task.org

    q = GCIProfile.all()
    q.filter('org_admin_for', org)

    # It is sufficient to fetch one org admin (and any one is fine).
    org_admin = q.get()

    if not task.created_by:
        task.created_by = org_admin

    if not task.modified_by:
        task.modified_by = org_admin

    yield operation.db.Put(task)
    yield operation.counters.Increment("task_authorship_updated")
示例#12
0
  def getListData(self):
    if lists.getListIndex(self.request) != 0:
      return None

    q = GCIProfile.all()
    q.filter('scope', self.data.program)
    q.filter('is_mentor', True)

    starter = lists.keyStarter

    prefetcher = lists.listPrefetcher(
        GCIProfile, ['org_admin_for', 'mentor_for'])

    response_builder = lists.RawQueryContentResponseBuilder(
        self.request, self._list_config, q, starter, prefetcher=prefetcher)

    return response_builder.build()
示例#13
0
def process(task):
  org = task.org

  q = GCIProfile.all()
  q.filter('org_admin_for', org)

  # It is sufficient to fetch one org admin (and any one is fine).
  org_admin = q.get()

  if not task.created_by:
    task.created_by = org_admin

  if not task.modified_by:
    task.modified_by = org_admin

  yield operation.db.Put(task)
  yield operation.counters.Increment("task_authorship_updated")
示例#14
0
    def getListData(self):
        """Returns the list data as requested by the current request.

    If the lists as requested is not supported by this component None is
    returned.
    """
        if lists.getListIndex(self.request) != 6:
            return None

        q = GCIProfile.all()
        q.filter("mentor_for IN", self.data.org_admin_for)

        starter = lists.keyStarter

        response_builder = lists.RawQueryContentResponseBuilder(self.request, self._list_config, q, starter)

        return response_builder.build()
示例#15
0
    def recalculateGCIRanking(self, request, *args, **kwargs):
        """Recalculates student ranking for the entire program.

    Args in POST dict:
      cursor: Query cursor to figure out where we need to start processing
    """

        key_name = "%s/%s" % (kwargs["sponsor"], kwargs["program"])
        cursor = request.POST.get("cursor")

        program = GCIProgram.get_by_key_name(key_name)
        if not program:
            logging.warning("Enqueued recalculate ranking task for non-existing program: %s", key_name)
            return responses.terminateTask()

        # Retrieve the students for the program
        q = GCIProfile.all()
        q.filter("program", program)
        q.filter("is_student", True)

        if cursor:
            q.with_cursor(cursor)

        students = q.fetch(25)

        for student in students:
            # get all the tasks that the student has completed
            task_q = GCITask.all()
            task_q.filter("student", student)
            task_q.filter("status", "Closed")

            tasks = task_q.fetch(1000)

            # calculate score with all the tasks
            score_logic.calculateScore(student, tasks, program)

            # calculate org score with all the tasks
            db.run_in_transaction(org_score_logic.updateOrgScoresTxn(tasks))

        if students:
            # schedule task to do the rest of the students
            params = {"cursor": q.cursor()}
            taskqueue.add(queue_name="gci-update", url=request.path, params=params)

        return responses.terminateTask()
示例#16
0
    def getListData(self):
        """Returns the list data as requested by the current request.

    If the lists as requested is not supported by this component None is
    returned.
    """
        if lists.getListIndex(self.data.request) != 6:
            return None

        q = GCIProfile.all()
        q.filter('mentor_for IN', self.data.org_admin_for)

        starter = lists.keyStarter

        response_builder = lists.RawQueryContentResponseBuilder(
            self.data.request, self._list_config, q, starter)

        return response_builder.build()
示例#17
0
文件: profile.py 项目: adviti/melange
def queryAllMentorsForOrg(org, keys_only=False, limit=1000):
  """Returns a list of keys of all the mentors for the organization

  Args:
    org: the organization entity for which we need to get all the mentors
    keys_only: True if only the entity keys must be fetched instead of the
        entities themselves.
    limit: the maximum number of entities that must be fetched

  returns:
    List of all the mentors for the organization
  """

  # get all mentors keys first
  query = GCIProfile.all(keys_only=keys_only)
  query.filter('mentor_for', org)
  mentors = query.fetch(limit=limit)

  return mentors
示例#18
0
文件: seed_db.py 项目: adviti/melange
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')
示例#19
0
  def canTakeOrgApp(self):
    """A user can take the GCI org app if he/she participated in GSoC or GCI
    as a non-student.
    """
    from soc.modules.gsoc.models.profile import GSoCProfile

    self.isUser()

    q = GSoCProfile.all()
    q.filter('is_student', False)
    q.filter('status', 'active')
    q.filter('user', self.data.user)
    gsoc_profile = q.get()

    q = GCIProfile.all()
    q.filter('is_student', False)
    q.filter('status', 'active')
    q.filter('user', self.data.user)
    gci_profile = q.get()

    if not (gsoc_profile or gci_profile):
      raise AccessViolation(DEF_NO_PREV_ORG_MEMBER)
示例#20
0
    def clean_email(self):
        email_cleaner = cleaning.clean_email("email")

        try:
            email_address = email_cleaner(self)
        except djangoforms.ValidationError as e:
            if e.code != "invalid":
                raise
            msg = ugettext(u"Enter a valid email address.")
            raise djangoforms.ValidationError(msg, code="invalid")

        account = users.User(email_address)
        user_account = accounts.normalizeAccount(account)
        user = User.all().filter("account", user_account).get()

        if not user:
            raise djangoforms.ValidationError("There is no user with that email address")

        self.cleaned_data["user"] = user

        q = GCIProfile.all()
        q.filter("program", self.request_data.program)
        q.ancestor(user)
        self.cleaned_data["profile"] = q.get()
示例#21
0
    def _cleanTask(self, task, org):
        """Cleans the data given so that it can be safely stored as a task.

      Args:
        task: Dictionary as constructed by the csv.DictReader().
        org: the GCIOrganization for which the task is created.

      Returns:
          A list of error messages if any have occurred.
    """

        errors = []

        # check title
        if not task['title']:
            errors.append('No valid title present.')

        # clean description
        try:
            parser = HTMLParser(tokenizer=sanitizer.HTMLSanitizer)
            parsed = parser.parseFragment(task['description'],
                                          encoding='utf-8')
            cleaned_string = ''.join(
                [tag.toxml() for tag in parsed.childNodes])
            task['description'] = cleaned_string.strip().replace('\r\n', '\n')
        except (HTMLParseError, ParseError, TypeError) as e:
            logging.warning('Cleaning of description failed with: %s', e)
            errors.append(
                'Failed to clean the description, do not use naughty HTML such as '
                '<script>.')

        # clean time to complete
        try:
            hours_to_complete = int(task['time_to_complete'])

            # Must be at least 2 days (48hrs)
            if hours_to_complete < 2 * 24:
                errors.append(
                    'Time to complete must be at least 48 hrs, given was: %s' %
                    hours_to_complete)
            else:
                task['time_to_complete'] = hours_to_complete
        except (ValueError, TypeError) as e:
            errors.append('No valid time to completion found, given was: %s.' %
                          task['time_to_complete'])

        # clean mentors
        mentor_ids = set(task['mentors'].split(','))

        mentors = []
        mentor_entities = []
        for mentor_id in mentor_ids:
            q = GCIProfile.all()
            q.filter('link_id', mentor_id.strip())
            q.filter('mentor_for', org)
            q.filter('status', 'active')
            mentor = q.get()
            if mentor:
                mentors.append(mentor.key())
                mentor_entities.append(mentor)
            else:
                errors.append('%s is not a mentor.' % mentor_id)

        task['mentors'] = mentors
        task['mentor_entities'] = mentor_entities

        program_entity = org.program

        # clean task types
        types = []
        for task_type in set(task['task_type'].split(',')):
            task_type = task_type.strip()
            if task_type in program_entity.task_types:
                types.append(task_type)
            else:
                errors.append('%s is not a valid task type.' % task_type)
        task['types'] = types

        # clean task tags
        tags = []
        for tag in set(task['arbit_tag'].split(',')):
            tags.append(tag.strip())
        task['tags'] = tags

        return errors
示例#22
0
  def _cleanTask(self, task, org):
    """Cleans the data given so that it can be safely stored as a task.

      Args:
        task: Dictionary as constructed by the csv.DictReader().
        org: the GCIOrganization for which the task is created.

      Returns:
          A list of error messages if any have occurred.
    """

    errors = []

    # check title
    if not task['title']:
      errors.append('No valid title present.')

    # clean description
    try:
      parser = HTMLParser(tokenizer=sanitizer.HTMLSanitizer)
      parsed = parser.parseFragment(task['description'], encoding='utf-8')
      cleaned_string = ''.join([tag.toxml() for tag in parsed.childNodes])
      task['description'] = cleaned_string.strip().replace('\r\n', '\n')
    except (HTMLParseError, ParseError, TypeError) as e:
      logging.warning('Cleaning of description failed with: %s', e)
      errors.append(
          'Failed to clean the description, do not use naughty HTML such as '
          '<script>.')

    # clean time to complete
    try:
      hours_to_complete = int(task['time_to_complete'])

      # Must be at least 2 days (48hrs)
      if hours_to_complete < 2*24:
        errors.append('Time to complete must be at least 48 hrs, given was: %s'
                      % hours_to_complete)
      else:
        task['time_to_complete'] = hours_to_complete
    except (ValueError, TypeError) as e:
      errors.append('No valid time to completion found, given was: %s.'
                    % task['time_to_complete'])

    # clean mentors
    mentor_ids = set(task['mentors'].split(','))

    mentors = []
    mentor_entities = []
    for mentor_id in mentor_ids:
      q = GCIProfile.all()
      q.filter('link_id', mentor_id.strip())
      q.filter('mentor_for', org)
      q.filter('status', 'active')
      mentor = q.get()
      if mentor:
        mentors.append(mentor.key())
        mentor_entities.append(mentor)
      else:
        errors.append('%s is not a mentor.' % mentor_id)

    task['mentors'] = mentors
    task['mentor_entities'] = mentor_entities

    program_entity = org.program

    # clean task types
    types = []
    for task_type in set(task['task_type'].split(',')):
      task_type = task_type.strip()
      if task_type in program_entity.task_types:
        types.append(task_type)
      else:
        errors.append('%s is not a valid task type.' % task_type)
    task['types'] = types

    # clean task tags
    tags = []
    for tag in set(task['arbit_tag'].split(',')):
      tags.append(tag.strip())
    task['tags'] = tags

    return errors
示例#23
0
          '<script>.')

    # clean time to complete
    try:
      task['time_to_complete'] = int(task['time_to_complete'])
    except (ValueError, TypeError), e:
      errors.append('No valid time to completion found, given was: %s.'
                    % task['time_to_complete'])

    # clean mentors
    mentor_ids = set(task['mentors'].split(','))

    mentors = []
    mentor_entities = []
    for mentor_id in mentor_ids:
      q = GCIProfile.all()
      q.filter('link_id', mentor_id.strip())
      q.filter('mentor_for', org)
      q.filter('status', 'active')
      mentor = q.get()
      if mentor:
        mentors.append(mentor.key())
        mentor_entities.append(mentor)
      else:
        errors.append('%s is not a mentor.' % mentor_id)

    task['mentors'] = mentors
    task['mentor_entities'] = mentor_entities

    program_entity = org.scope