Пример #1
0
        song_objects = Songs.objects.filter(hash__in=song_hashes)

        song_obj_hashes = {obj.hash: obj for obj in song_objects}

        songs = []
        for song, song_hash in zip(queue, song_hashes):
            obj = song_obj_hashes.get(song_hash, None)
            if obj is None:
                obj = Songs.objects.create(metadata=song.metadata,
                                           length=song.length,
                                           hash=song_hash)
                song_obj_hashes[obj.hash] = obj

            songs.append(obj)

        Queue.objects.filter(user=dj.user).delete()

        queue_objects = []
        for obj in songs:
            queue_objects.append(
                Queue(song=obj, user=dj, time=copy(current_time))
            )
            current_time += datetime.timedelta(seconds=obj.length)

        Queue.objects.bulk_create(queue_objects)

SongTuple = collections.namedtuple('SongTuple', ('length', 'metadata'))

container.register(QueueResource())
Пример #2
0
        sqs = SearchQuerySet().models(Tracks).load_all()
        sqs = sqs.auto_query(request.GET.get('q', ''))
        paginator = Paginator(sqs, RESULTS_PER_PAGE)

        try:
            page = paginator.page(int(request.GET.get('page', 1)))
        except InvalidPage:
            raise Http404("No such page exists.")
        except ValueError:
            raise Http404("Invalid page number.")

        objects = []

        for result in page.object_list:
            if result is None:
                continue

            bundle = self.build_bundle(obj=result.object, request=request)
            bundle = self.full_dehydrate(bundle)
            objects.append(bundle)

        self.log_throttled_access(request)

        return self.create_response(request, {'objects': objects})


# Register ourself with the API urls
container.register(TrackResource())
container.register(ArtistResource())
container.register(AlbumResource())
Пример #3
0
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        sqs = SearchQuerySet().models(Songs).load_all()
        sqs = sqs.auto_query(request.GET.get('q', ''))

        paginator = Paginator(sqs, 20)

        try:
            page = paginator.page(int(request.GET.get('page', 1)))
        except InvalidPage:
            raise Http404("No such page exists.")
        except ValueError:
            raise Http404("Invalid page number.")

        objects = []

        for result in page.object_list:
            bundle = self.build_bundle(obj=result.object, request=request)
            bundle = self.full_dehydrate(bundle)
            objects.append(bundle)

        self.log_throttled_access(request)

        return self.create_response(request, {'objects': objects})


# Register ourself with the API urls
container.register(SongResource())