コード例 #1
0
ファイル: projects.py プロジェクト: shuhaowu/spm
def get_member_emails(project_key):
  project = Project.get(project_key)
  participants = project.indexes("participants_bin", [])
  owners = project.indexes("owners_bin", [])
  unregistered = project.indexes("unregistered_bin", [])
  participants_email = []
  owners_email = []
  unregistered_emails = []
  for owner_key in owners:
    try:
      owners_email.append(list(User.get(owner_key).index("email_bin", []))[0])
    except NotFoundError:
      raise Exception("User '%s' does not exist!" % owner_key)

  for participants_key in participants:
    try:
      participants_email.append(list(User.get(participants_key).index("email_bin", []))[0])
    except NotFoundError:
      raise Exception("User '%s' does not exist!" % participants_key)

  for u in unregistered:
    temp = u.split(" ")
    unregistered_emails.append([temp[0], temp[1][:-1]])

  return {"participants_email" : participants_email, "owners_email" : owners_email, "unregistered_emails" : unregistered_emails}
コード例 #2
0
ファイル: users.py プロジェクト: shuhaowu/spm
def get_personalized_data(key):
  user = User.get(key)

  todo_query = TodoItem.indexLookup("assigned_to_bin", key)
  todos = []
  now = datetime.now()
  for todo in todo_query.run():
    print todo.done
    if not todo.done:
      t = {"title" : todo.title, "desc" : todo.desc["html"]}
      if todo.duedate:
        t["time_remaining"] = (todo.duedate - now).total_seconds()
      else:
        t["time_remaining"] = None

      todos.append(t)

  todos.sort(key=lambda x: x["time_remaining"])

  user_json = {
    "projects" : get_user_projects_with_simple(user),
    "todos" : todos,
    "name" : user.name
  }

  return user_json
コード例 #3
0
ファイル: projects.py プロジェクト: shuhaowu/spm
def get_members_list(project_key):
  project = Project.get(project_key)
  members = list(project.index("owners_bin", [])) + list(project.index("participants_bin", []))
  members_list = []
  for member in members:
    u = User.get(member)
    members_list.append({"key" : u.key, "name" : u.name if u.name else list(u.index("email_bin"))[0]})
  return members_list
コード例 #4
0
ファイル: users.py プロジェクト: shuhaowu/spm
def get_user_simple(key):
  user = User.get(key)
  user_json = {
    "key" : key,
    "name" : user.name,
    "positions" : user.positions,
    "emails" : list(user.indexes("email_bin"))
  }
  return user_json
コード例 #5
0
ファイル: users.py プロジェクト: shuhaowu/spm
def get_user_profile(key):
  user = User.get(key)

  user_json = {
    "key" : user.key,
    "name": user.name,
    "positions": user.positions,
    "projects": get_user_projects_with_simple(user),
    "emails" : list(user.indexes("email_bin"))
  }

  return user_json
コード例 #6
0
ファイル: projects.py プロジェクト: shuhaowu/spm
def set_owners(project_key, emails):
  project = Project.get(project_key)
  project.removeIndex("owners_bin")
  for email in emails:
    user_queries = User.indexLookup("email_bin", email)
    if len(user_queries) == 0:
      add_unregistered_to_project(project, email, "owners")
    else:
      project.addIndex("owners_bin", user_queries.all()[0].key)

  project.save()
  return True
コード例 #7
0
ファイル: projects.py プロジェクト: shuhaowu/spm
def set_participants(project_key, emails):
  project = Project.get(project_key)
  project.removeIndex("participants_bin", silent=True)
  if len(emails) == 1 and emails[0] == "":
    project.save()
    return True

  for email in emails:
    user_queries = User.indexLookup("email_bin", email)
    if len(user_queries) == 0:
      add_unregistered_to_project(project, email, "participants")
    else:
      project.addIndex("participants_bin", user_queries.all()[0].key)

  project.save()
  return True
コード例 #8
0
ファイル: users.py プロジェクト: shuhaowu/spm
def do_login(assertion):
  data = {"assertion" : assertion, "audience" : SERVER_URL}
  resp = requests.post("https://verifier.login.persona.org/verify", data=data, verify=True)

  if resp.status_code == 200:
    verification_data = json.loads(resp.content)

    if verification_data["status"] == "okay":

      users = User.indexLookup("email_bin", verification_data["email"])
      if len(users) == 0:
        key = do_registration(verification_data["email"])
      else: # There <rage>BETTER BE</rage> only 1 users in this list. lawl. DD2. lawl.
        for user in users.run():
          key = user.key
          break

      verification_data["key"] = key
      return verification_data
    elif verification_data["status"] == "failure":
      return verification_data
コード例 #9
0
ファイル: users.py プロジェクト: shuhaowu/spm
def change_name(key, name):
  user = User.get(key)
  user.name = name
  user.save()
コード例 #10
0
ファイル: users.py プロジェクト: shuhaowu/spm
def do_registration(email):
  u = User()
  u.addIndex("email_bin", email)
  u.save()
  add_to_projects(email, u)
  return u.key