def add_contributor(username): """ Used when adding an existent contributor to an existent album """ try: get_contributor_by_username(username) raise AttributeError("%s username alredy exists" % username) except DynamoDBKeyNotFoundError: pass # print( "Username: %s" % username) contrib = Contributor(username=username) contrib.save() return contrib
def add_contributor_album(slug, username): """ Used when adding an existent contributor to an existent album """ contrib = Contributor.get(username) album = Album.get(slug) ContributorAlbum(slug=album.slug, username=contrib.username).save()
def get_contributors(): return Contributor.scan({})
def get_album_contributors(album): return [Contributor.get(x.username) for x in ContributorAlbum.scan({"slug": condition.EQ(album.slug)})]
def delete_contributor_by_username(username): Contributor.get(username).delete() [x.delete() for x in ContributorAlbum.scan({"username": condition.EQ(username)})]
def get_contributor_by_username(username): return Contributor.get(username)