def index(): """ Demonstrating a simple list-based directory index. """ items = ['hostname', 'hostname.txt', 'subdir'] return DirectoryResponse(items)
def fuse_album(artist_dir_name, dir_name): try: album = Album.objects.get_from_dir_name(artist_dir_name, dir_name) except Album.DoesNotExist: raise Http404 tracks = album.get_nonclassical_tracks() return DirectoryResponse(tracks.values_list('dir_name', flat=True))
def subdir(): """ Demonstrating a generator-based approach to populating a directory index. The use of a count callback function is an optimisation to prevent evaluation of the generator when displaying the file in a directory index. Imagine replacing these static results with ones based on a QuerySet- based database query. You may wish to use itertools.imap to lazily format the filename before returning it. """ def items(): for letter in "abc": yield "%s.txt" % letter def count_cb(): return 3 return DirectoryResponse(items, count_cb)
def fuse_artist(dir_name): artist = get_object_or_404(Artist, dir_name=dir_name) return DirectoryResponse()
def fuse_index(): return DirectoryResponse( Artist.objects.composers().values_list('dir_name', flat=True), )
def fuse_artist(dir_name): artist = get_object_or_404(Artist, dir_name=dir_name) albums = artist.albums() return DirectoryResponse(albums.values_list('dir_name', flat=True))
def fuse_index(): artists = Artist.objects.all() return DirectoryResponse(artists.values_list('dir_name', flat=True))
def fuse_index(): return DirectoryResponse(['Albums', 'Classical'])