Beispiel #1
0
def show_search_result(request, query_type, query_string, query_id):
    """
    Display CachedSearchResult.

    If document is missing create new one using RESTful query redirect.

    @param query_type: a string containing query type
    @param query_string: a string containing query
    @param query_id: a string containing an ID of a CachedSearchResult document

    @return: a HttpResponseRedirect object or rendered search result page
    """
    # TODO: add meta-header for robots: nocahe, norobots etc
    try:
        search_result = CachedSearchResult.get(query_id)
    except ResourceNotFound:
        return HttpResponseRedirect(reverse("create-search-result", args=(query_type, query_string)))

    # SEO check
    seo_query_type = slugify2(search_result.query_type)
    seo_query_string = slugify2(search_result.query_string)
    if query_type != seo_query_type or query_string != seo_query_string:
        return HttpResponseRedirect(reverse("show-search-result", args=(seo_query_type, seo_query_string, query_id)))
    # TODO: if only 1 result, redirect to it directly
    return render_to_response("search/%s_results.html" % search_result.query_type, locals())
Beispiel #2
0
def show_release(request, uri_artist, uri_release, mbid):
    """
    Show page of a release specified by mbid.

    @param mbid:        a string containing a MusicBrainz ID of an artist
    @param uri_artist:  a string containing SEO-friendly artist name
    @param uri_release: a string containing SEO-friendly release title

    @return: a rendered release page or redirection to a proper URL
    """
    release_group, release = get_populated_releasegroup_with_release(mbid)

    # basic SEO check
    artist_seo_name     = slugify2(release_group.artist_name)
    release_seo_name    = slugify2(release['title'])
    if uri_artist == artist_seo_name and uri_release == release_seo_name:
        return render_to_response('artists/show_release.html', locals())
    else:
        return HttpResponsePermanentRedirect(reverse('show-release', args=(artist_seo_name, release_seo_name, mbid)))
Beispiel #3
0
def delete_memcached_keys(artist):
    """
    Quick hook that removes artist-related pages from memcached backend.
    """
    if not settings.DEBUG:

        uri_name = slugify2(artist.name)
        uri = (uri_name, artist.get_id)

        # remove all artist pages
        keys = ["/artist/%s/%s/" % uri,
                "/artist/%s/pictures/%s/" % uri,
                "/artist/%s/videos/%s/" % uri,
                "/artist/%s/news/%s/" % uri,
               ]

        # and all artist's releases
        artist_releases = get_db('artists').view('artists/all_artists_releases', key=artist.get_id)
        keys.extend([ "/artist/%s/release/%s/%s/" % (uri_name, slugify2(r['value'][0]), r['value'][1]) for r in artist_releases])

        for key in keys:
            cache.delete("%s:%s" % (settings.NGINX_CACHE_PREFIX, key))
Beispiel #4
0
def create_search_result(request, query_type=None, query_string=None):
    """
    Process POST and RESTful search query and redirect to result page.

    Each query has its own ID and results page has permanent URL.
    (eg. one can copy URL it and show to someone else)

    @param query_type: an optional string containing query type
    @param query_string: an optional string containing query

    @return: a HttpResponseRedirect object
    """
    if request.POST:
        query_string = request.POST.get("query", "").strip().lower()
        query_type = request.POST.get("type", "")
    # TODO: not sure why, but this code makes me feel ugly
    elif not query_string or not query_type:
        return HttpResponseRedirect(reverse("welcome-page"))

    query_id = get_basic_cached_search_result(query_type, query_string)
    return HttpResponseRedirect(
        reverse("show-search-result", args=(slugify2(query_type), slugify2(query_string), query_id))
    )
Beispiel #5
0
def show_artist_videos(request, uri_artist, mbid):
    """
    Show page with videos related to a specified artist.

    @param mbid:        a string containing a MusicBrainz ID of an artist
    @param uri_artist:  a string containing SEO-friendly artist name

    @return: a rendered videos page or a redirection to a proper URL
    """
    artist_videos = get_populated_artist_videos(mbid)

    # basic SEO check
    artist_seo_name = slugify2(artist_videos.artist_name)
    if uri_artist == artist_seo_name:
        return render_to_response('videos/show_artist_videos.html', locals())
    else:
        return HttpResponsePermanentRedirect(reverse('show-artist-videos', args=(artist_seo_name, mbid)))
Beispiel #6
0
Datei: tag.py Projekt: lidel/mmda
def get_populated_tag(tag_string):
    """
    Return populated object required by mmda.tags.show_tag

    Designed to be stored in database only when populated by anything.

    @param tag_id: a string containing an ID of a tag

    @return: a CachedTag object
    """
    tag = CachedTag.get_or_create(slugify2(tag_string))
    tag = populate_tag_lastfm(tag)
    # TODO: abstract from lastfm?

    tag.save_any_changes()

    return tag
Beispiel #7
0
def show_artist(request, uri_artist, mbid):
    """
    Show page of an artist specified by mbid.

    @param mbid:        a string containing a MusicBrainz ID of an artist
    @param uri_artist:  a string containing SEO-friendly artist name

    @return: a rendered artist page or redirection to a proper URL
    """
    artist              = get_populated_artist(mbid)
    primary_releases    = get_artist_primary_releases(mbid)
    artist_pictures     = get_artist_best_pictures(mbid)

    # basic SEO check
    artist_seo_name = slugify2(artist.name)
    if uri_artist == artist_seo_name:
        return render_to_response('artists/show_artist.html', locals())
    else:
        return HttpResponsePermanentRedirect(reverse('show-artist', args=(artist_seo_name, mbid)))
Beispiel #8
0
def show_artist_news(request, uri_artist, mbid):
    """
    Show page with news related to a specified artist.

    @param mbid:        a string containing a MusicBrainz ID of an artist
    @param uri_artist:  a string containing SEO-friendly artist name

    @return: a rendered news page or a redirection to a proper URL
    """
    artist = get_basic_artist(mbid)
    news_stream, news_sources = get_populated_artist_news(artist)
    artist.save_any_changes()

    # basic SEO check
    artist_seo_name = slugify2(artist.name)
    if uri_artist == artist_seo_name:
        return render_to_response('news/show_artist_news.html', locals())
    else:
        return HttpResponsePermanentRedirect(reverse('show-artist-news', args=(artist_seo_name, mbid)))
Beispiel #9
0
 def link(self, artist):
     return reverse('show-artist-news', args=(slugify2(artist.name),'0cd12ab3-9628-45ef-a97b-ff18624f14a0')) # TODO? wtf