Example #1
0
def import_artists(request):
    if request.method == 'GET':
        return render(request, 'import.html')

    type = request.POST.get('type', '')
    if type == 'last.fm':
        username = request.POST.get('username', '')
        if not username:
            messages.error(request, 'Please enter your Last.fm user name.')
            return redirect('/import')
        if Job.has_import_lastfm(request.user) or Job.importing_artists(request.user):
            messages.error(
                request, 'You already have a pending import. Please wait until '
                'the import finishes before importing again. '
                'Refresh this page to track the progress.')
            return redirect('/artists')
        if not lastfm.has_user(username):
            messages.error(request, 'Unknown user: %s' % username)
            return redirect('/import')

        count = request.POST.get('count', '')
        count = int(count) if count.isdigit() else 50
        count = min(500, count)
        period = request.POST.get('period', '')
        if period not in ['overall', '12month', '6month', '3month', '7day']:
            period = 'overall'
        Job.import_lastfm(request.user, username, count, period)
        messages.info(
            request, 'Your artists will be imported in a few minutes. '
            'Refresh this page to track the progress of the import.')
        return redirect('/artists')

    return redirect('/import')
Example #2
0
def import_artists(request):
    if request.method == 'GET':
        return render(request, 'import.html')

    type = request.POST.get('type', '')
    if type == 'last.fm':
        username = request.POST.get('username', '')
        if not username:
            messages.error(request, 'Please enter your Last.fm user name.')
            return redirect('/import')
        if Job.has_import_lastfm(request.user) or Job.importing_artists(
                request.user):
            messages.error(
                request,
                'You already have a pending import. Please wait until '
                'the import finishes before importing again. '
                'Refresh this page to track the progress.')
            return redirect('/artists')
        if not lastfm.has_user(username):
            messages.error(request, 'Unknown user: %s' % username)
            return redirect('/import')

        count = request.POST.get('count', '')
        count = int(count) if count.isdigit() else 50
        count = min(500, count)
        period = request.POST.get('period', '')
        if period not in ['overall', '12month', '6month', '3month', '7day']:
            period = 'overall'
        Job.import_lastfm(request.user, username, count, period)
        messages.info(
            request, 'Your artists will be imported in a few minutes. '
            'Refresh this page to track the progress of the import.')
        return redirect('/artists')

    return redirect('/import')
Example #3
0
    def update(self, request, userid, mbid):
        if request.user.username != userid:
            return rc.FORBIDDEN

        if mbid:
            try:
                artist = Artist.get_by_mbid(mbid)
            except (Artist.Blacklisted, Artist.Unknown):
                return rc.BAD_REQUEST
            if not artist:
                return rc.NOT_FOUND

            UserArtist.add(request.user, artist)
            response = rc.ALL_OK
            response.content = {
                'mbid': artist.mbid,
                'name': artist.name,
                'sort_name': artist.sort_name,
                'disambiguation': artist.disambiguation,
            }
            return response

        import_from = request.POST.get('import', '')
        username = request.POST.get('username', '')
        count = min(500, max(0, int(request.POST.get('count', 0))))
        period = request.POST.get('period', '')

        if (import_from != 'last.fm' or not username or not count or period
                not in ['overall', '12month', '6month', '3month', '7day']):
            return rc.BAD_REQUEST

        if Job.has_import_lastfm(request.user) or Job.importing_artists(
                request.user):
            response = rc.THROTTLED
            response.write(
                ': The user already has a pending import. '
                'Please wait until the import finishes before importing again.'
            )
            return response

        if not lastfm.has_user(username):
            response = rc.BAD_REQUEST
            response.write(': Unknown user: %s' % username)
            return response

        Job.import_lastfm(request.user, username, count, period)
        return rc.ALL_OK
Example #4
0
    def update(self, request, userid, mbid):
        if request.user.username != userid:
            return rc.FORBIDDEN

        if mbid:
            try:
                artist = Artist.get_by_mbid(mbid)
            except (Artist.Blacklisted, Artist.Unknown):
                return rc.BAD_REQUEST
            if not artist:
                return rc.NOT_FOUND

            UserArtist.add(request.user, artist)
            response = rc.ALL_OK
            response.content = {
                'mbid': artist.mbid,
                'name': artist.name,
                'sort_name': artist.sort_name,
                'disambiguation': artist.disambiguation,
                }
            return response

        import_from = request.POST.get('import', '')
        username = request.POST.get('username', '')
        count = min(500, max(0, int(request.POST.get('count', 0))))
        period = request.POST.get('period', '')

        if (import_from != 'last.fm' or not username or not count or
            period not in ['overall', '12month', '6month', '3month', '7day']):
            return rc.BAD_REQUEST

        if Job.has_import_lastfm(request.user) or Job.importing_artists(request.user):
            response = rc.THROTTLED
            response.write(
                ': The user already has a pending import. '
                'Please wait until the import finishes before importing again.')
            return response

        if not lastfm.has_user(username):
            response = rc.BAD_REQUEST
            response.write(': Unknown user: %s' % username)
            return response

        Job.import_lastfm(request.user, username, count, period)
        return rc.ALL_OK