Example #1
0
    def validate(self, data):
        request = self.context.get('request')
        data['user_id'] = request.token.user_id
        input_fh = self.context.get('request').FILES.get('file')

        # Get the artists from the request!
        if request.data.get('artists'):
            artists = request.data.getlist('artists')
            # Get the artist objects and filter out the Nones if there are any
            data['artist_objects'] = [artist for artist in [Artist.get_or_create_artist(artist) for artist in artists] if artist]

        if not input_fh:
            raise serializers.ValidationError('No file given')

        if not input_fh.name:
            raise serializers.ValidationError('File unnamed?')

        extension = os.path.splitext(input_fh.name)[1].lower()

        if extension not in ['.mp4','.avi','.mov']:
            raise serializers.ValidationError('Unacceptable file type: {}'.format(extension))

        # Create the filename and size with the file
        data['original_filename'] = input_fh.name
        data['file_size'] = input_fh.size
        data['file'] = input_fh

        return data
Example #2
0
    def post(self, request):
        # Validate the request
        spotify_ids = request.data.get('spotify_ids')
        if spotify_ids == None:
            return self.error_response("spotify_ids required", 400)

        artists = []

        for spotify_id in spotify_ids:
          artist = Artist.get_or_create_artist(spotify_id)

          if not artist:
            return self.error_response("Unable to get or create an artist with this spotify_id: {}".format(spotify_id), 400)
          else:
            artists.append(artist)

        self.serializer = self.get_serializer(artists,many=True)

        return self.success_response(self.serializer.data)
Example #3
0
 def get(self, request, search_string):
     artists = Artist.search_artist(search_string)
     return self.success_response(artists)