{"body": "<div class=\"section\" id=\"module-lastfm.views\">\n<span id=\"views\"></span><span id=\"ref-views\"></span><h1>Views<a class=\"headerlink\" href=\"#module-lastfm.views\" title=\"Permalink to this headline\">\u00b6</a></h1>\n<p>The AJAX code generate by the template tag (see\n<a class=\"reference internal\" href=\"../templatetags/#module-lastfm.templatetags.lastfm_widget\"><tt class=\"xref py py-mod docutils literal\"><span class=\"pre\">lastfm.templatetags.lastfm_widget</span></tt></a>) doesn\u2019t contact Last.fm directly, but\nuses a Django view as proxy. The advantage of this is, that you can exactly\ncontrol what data your site gets. Another advantage is, that visitors can\u2019t see\nyour Last.fm username by inspecting the HTML source of your site.</p>\n<p>In addition to the view itself this module also defines some helper classes that\nare responsible for handling the different types of charts (e.g. top tracks or\ntop artists).</p>\n<dl class=\"function\">\n<dt id=\"lastfm.views.lastfm_data\">\n<tt class=\"descclassname\">lastfm.views.</tt><tt class=\"descname\">lastfm_data</tt><big>(</big><em>request</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class=\"headerlink\" href=\"#lastfm.views.lastfm_data\" title=\"Permalink to this definition\">\u00b6</a></dt>\n<dd><p>This view retrievs the data from Last.fm and returns a JSON encoded list.\nThe template tag\u2019s AJAX code will retrive this list and generate the chart\nfrom it.</p>\n<dl class=\"docutils\">\n<dt>Each list entry is a dict with three elements:</dt>\n<dd><ul class=\"first last simple\">\n<li><tt class=\"docutils literal\"><span class=\"pre\">title</span></tt>: Contains the song title or artist name and can be displayed as\nalternative text or link title.</li>\n<li><tt class=\"docutils literal\"><span class=\"pre\">url</span></tt>: A url pointing to the track or artist on Last.fm.</li>\n<li><tt class=\"docutils literal\"><span class=\"pre\">img_url</span></tt>: A url pointing to the track\u2019s cover or artist image.</li>\n</ul>\n</dd>\n</dl>\n<p>For each chart type there is a class that handles its data. They are\nnecessary to unify Last.fm\u2019s different key names to those three explained\nabove. Currently, there is no abstract base class which they must inherit\nfrom, but each class is expected to implement the following attributes and\nmethods:</p>\n<p><tt class=\"docutils literal\"><span class=\"pre\">params</span></tt>: A dict that contains all parameters required by the <a class=\"reference external\" href=\"http://www.lastfm.de/api\">Last.fm API\ncall</a></p>\n<p><tt class=\"docutils literal\"><span class=\"pre\">get_data(data)</span></tt>: Last.fm\u2019s JSON data is quite nested. This method should\nextract the list with the actual items from the raw data.</p>\n<p><tt class=\"docutils literal\"><span class=\"pre\">get_item_title(item)</span></tt>: Return an item\u2019s text for the <tt class=\"docutils literal\"><span class=\"pre\">title</span></tt> attribute\nin the data dict.</p>\n<p><tt class=\"docutils literal\"><span class=\"pre\">get_default_image()</span></tt>: Return a url to a default image that will be used\nif a track or artist has no image on its own.</p>\n<p><tt class=\"docutils literal\"><span class=\"pre\">get_img_url(img_size,</span> <span class=\"pre\">item)</span></tt>: This method needs to be implemented only if\nan item has no <tt class=\"docutils literal\"><span class=\"pre\">image</span></tt> key (which is the case for e.g. the weekly top\nartist). It gets the desired image size (small, medium, large, \u2026) and the\nitem. It might do another API call and extract a custom image URL for that\nitem.</p>\n</dd></dl>\n\n<dl class=\"class\">\n<dt id=\"lastfm.views.RecentTracks\">\n<em class=\"property\">class </em><tt class=\"descclassname\">lastfm.views.</tt><tt class=\"descname\">RecentTracks</tt><a class=\"headerlink\" href=\"#lastfm.views.RecentTracks\" title=\"Permalink to this definition\">\u00b6</a></dt>\n<dd><p>This class handles the API call <tt class=\"docutils literal\"><span class=\"pre\">user.getRecentTracks</span></tt>.</p>\n</dd></dl>\n\n<dl class=\"class\">\n<dt id=\"lastfm.views.WeeklyTopArtists\">\n<em class=\"property\">class </em><tt class=\"descclassname\">lastfm.views.</tt><tt class=\"descname\">WeeklyTopArtists</tt><a class=\"headerlink\" href=\"#lastfm.views.WeeklyTopArtists\" title=\"Permalink to this definition\">\u00b6</a></dt>\n<dd><p>This class handles the API call <tt class=\"docutils literal\"><span class=\"pre\">user.getWeeklyArtistChart</span></tt>.</p>\n</dd></dl>\n\n<dl class=\"class\">\n<dt id=\"lastfm.views.TopArtists\">\n<em class=\"property\">class </em><tt class=\"descclassname\">lastfm.views.</tt><tt class=\"descname\">TopArtists</tt><a class=\"headerlink\" href=\"#lastfm.views.TopArtists\" title=\"Permalink to this definition\">\u00b6</a></dt>\n<dd><p>This class handles the API call <tt class=\"docutils literal\"><span class=\"pre\">user.getTopArtists</span></tt>. The period must \nbe defined in the site\u2019s settings module.</p>\n</dd></dl>\n\n</div>\n", "display_toc": false, "title": "Views", "sourcename": "ref/views.txt", "customsidebar": null, "current_page_name": "ref/views", "next": null, "rellinks": [["genindex", "General Index", "I", "index"], ["py-modindex", "Python Module Index", "", "modules"], ["ref/templatetags", "Template Tags", "P", "previous"]], "meta": {}, "parents": [{"link": "../", "title": "API-Reference"}], "sidebars": null, "toc": "<ul>\n<li><a class=\"reference internal\" href=\"#\">Views</a></li>\n</ul>\n", "prev": {"link": "../templatetags/", "title": "Template Tags"}, "metatags": ""}