예제 #1
0
def repository_is_starred(user, repository):
    """ Determines whether a user has starred a repository or not. """
    try:
        (Star.select().where(Star.repository == repository.id,
                             Star.user == user.id).get())
        return True
    except Star.DoesNotExist:
        return False
예제 #2
0
def get_stars(repository_ids):
    """ Returns a map from repository ID to the number of stars for each repository in the
      given repository IDs list.
  """
    if not repository_ids:
        return {}

    tuples = (Star.select(Star.repository, fn.Count(
        Star.id)).where(Star.repository << repository_ids).group_by(
            Star.repository).tuples())

    star_map = {}
    for record in tuples:
        star_map[record[0]] = record[1]

    return star_map