コード例 #1
0
ファイル: admin.py プロジェクト: rhyolight/nupic.son
    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()
コード例 #2
0
ファイル: export_kml.py プロジェクト: rhyolight/nupic.son
def _getAllUsers():
    """Returns a list of all valid users.
  """

    from soc.models.user import User

    gen = lambda: User.all().filter('status =', 'valid')
    return interactive.deepFetch(gen)
コード例 #3
0
ファイル: export_kml.py プロジェクト: rhyolight/nupic.son
def _getAllUsers():
  """Returns a list of all valid users.
  """

  from soc.models.user import User

  gen = lambda: User.all().filter('status =', 'valid')
  return interactive.deepFetch(gen)
コード例 #4
0
ファイル: invite.py プロジェクト: pombredanne/Melange-1
class InviteForm(forms.ModelForm):
  """Django form for the invite page.
  """

  link_id = djangoforms.CharField(label='Link ID/Email')

  class Meta:
    model = Request
    css_prefix = 'gsoc_intivation'
    fields = ['message']

  def __init__(self, request_data, *args, **kwargs):
    super(InviteForm, self).__init__(*args, **kwargs)

    # store request object to cache results of queries
    self.request_data = request_data

    # reorder the fields so that link_id is the first one
    field = self.fields.pop('link_id')
    self.fields.insert(0, 'link_id', field)
    field.help_text = "The link_id or email address of the invitee"
    
  def clean_link_id(self):
    """Accepts link_id of users which may be invited.
    """

    assert isSet(self.request_data.organization)

    invited_user = None

    link_id_cleaner = cleaning.clean_link_id('link_id')

    try:
      link_id = link_id_cleaner(self)
    except djangoforms.ValidationError, e:
      if e.code != 'invalid':
        raise

      email_cleaner = cleaning.clean_email('link_id')

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

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

      if not invited_user:
        raise djangoforms.ValidationError(
            "There is no user with that email address")
コード例 #5
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')
コード例 #6
0
ファイル: seed_db.py プロジェクト: SRabbelier/Melange
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')
コード例 #7
0
ファイル: user.py プロジェクト: adviti/melange
def forUserId(user_id):
  """Retrieves the user entity for the specified user id.

  If there is no user logged in, or they have no valid associated User
  entity, None is returned.
  """

  if not user_id:
    raise base.InvalidArgumentError("Missing argument 'user_id'")

  q = User.all()
  q.filter('user_id', user_id)
  q.filter('status', 'valid')
  return q.get()
コード例 #8
0
ファイル: cleaning.py プロジェクト: adviti/melange
  def wrapped(self):
    """Decorator wrapper method.
    """
    email_adress = self.cleaned_data.get(field_name).lower()

    # get the user account for this email and check if it's in use
    user_account = users.User(email_adress)

    user_entity = User.all().filter('account', user_account).get()

    if user_entity or user.isFormerAccount(user_account):
      raise forms.ValidationError("There is already a user "
          "with this email address.")

    return user_account
コード例 #9
0
ファイル: user.py プロジェクト: adviti/melange
def forAccount(account):
  """Retrieves the user entity for the specified account.

  If there is no user logged in, or they have no valid associated User
  entity, None is returned.
  """

  if not account:
    raise base.InvalidArgumentError("Missing argument 'account'")

  account = accounts.normalizeAccount(account)

  q = User.all()
  q.filter('account', account)
  q.filter('status', 'valid')
  return q.get()
コード例 #10
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')
コード例 #11
0
ファイル: host.py プロジェクト: adviti/melange
def getHostsForProgram(program_entity, limit=1000):
  """Returns all the host entities for the given program.

  Args:
    program_entity: The Program entity for which the hosts must be determined

  Returns:
    The list of host entities for the specified program entity
  """
  sponsor_key = Program.scope.get_value_for_datastore(
      program_entity)
  q = User.all()
  q.filter('host_for', sponsor_key)
  host_users = q.fetch(1000)

  # TODO(Madhu): to be simplified after host_for is moved from user entity
  # to host entity
  hosts = []
  for user in host_users:
    q = Host.all()
    q.ancestor(user)
    hosts.append(q.get())

  return hosts
コード例 #12
0
ファイル: admin.py プロジェクト: rhyolight/nupic.son
    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()
コード例 #13
0
ファイル: user.py プロジェクト: adviti/melange
def isFormerAccount(account):
  """Returns true if account is a former account of some User.
  """
  return User.all().filter('former_accounts', account).count() > 0