Exemplo n.º 1
0
def start(request):
    feedback = {}
    given = request.GET.get('username')
    if given:
        given = str(given).strip()
        if User.valid_username(given):
            try:
                u = tasks.get_or_add_user(given, _REQUESTER)
                target = overview if (not ldates.sensible_to_update(u.last_updated)) else update
                return redirect(target, u)
            except tasks.GetUserFailed as e:
                logging.error(e)
                feedback['errmessage'] = "Either Last.fm is down or you don't exist."
        else:
            feedback['errmessage'] = "Invalid username"

    # TODO: Make this less ugly.
    return render_to_response('index.html', 
                    { 'feedback' : feedback,
                      'given' : given if given else "",
                      'start' : True },
                    context_instance=RequestContext(request))
Exemplo n.º 2
0
def update(request, username):
    """
    Create a page showing weeks previously retrieved and those still to fetch.
    Queues tasks to be fetched.
    """
    user = tasks.get_or_add_user(username, _REQUESTER)
    alreadyUpdating = Update.objects.is_updating(user)

    # Skip straight to the overview if there's no reason to be on this page
    if not alreadyUpdating and not ldates.sensible_to_update(user.last_updated):
        return redirect(overview, user)

    # Start a new update
    if not alreadyUpdating:
        alreadyUpdating = tasks.update_user(user, _REQUESTER)

    # Presumably no new data for user
    if not alreadyUpdating:
        return redirect(overview, user)

    # Otherwise, we're updating!
    updating_users = Update.objects.updating_users()
    return render_to_response('update-nojs.html', { 'updating_users': updating_users },
        context_instance=RequestContext(request))