<s> from django . shortcuts import get_object_or_404 , render_to_response <EOL> from django . template . context import RequestContext <EOL> from dnd . filters import RulebookFilter <EOL> from dnd . menu import menu_item , submenu_item , MenuItem <EOL> from dnd . dnd_paginator import DndPaginator <EOL> from dnd . models import Rulebook , DndEdition <EOL> from dnd . views import is_3e_edition , permanent_redirect_object <EOL> @ menu_item ( MenuItem . RULEBOOKS ) <EOL> @ submenu_item ( MenuItem . Rulebooks . RULEBOOKS ) <EOL> def rulebook_list ( request ) : <EOL> f = RulebookFilter ( request . GET , queryset = Rulebook . objects . select_related ( <EOL> '<STR_LIT>' ) ) <EOL> form_submitted = <NUM_LIT:1> if '<STR_LIT>' in request . GET else <NUM_LIT:0> <EOL> paginator = DndPaginator ( f . qs , request ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : request , <EOL> '<STR_LIT>' : paginator . items ( ) , <EOL> '<STR_LIT>' : paginator , <EOL> '<STR_LIT>' : f , <EOL> '<STR_LIT>' : form_submitted , <EOL> } , context_instance = RequestContext ( request ) , ) <EOL> @ menu_item ( MenuItem . RULEBOOKS ) <EOL> @ submenu_item ( MenuItem . Rulebooks . EDITIONS ) <EOL> def edition_list ( request ) : <EOL> edition_list = DndEdition . objects . all ( ) <EOL> paginator = DndPaginator ( edition_list , request ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : paginator . items ( ) , <EOL> '<STR_LIT>' : paginator , <EOL> '<STR_LIT>' : request , <EOL> } , context_instance = RequestContext ( request ) , ) <EOL> @ menu_item ( MenuItem . RULEBOOKS ) <EOL> @ submenu_item ( MenuItem . Rulebooks . EDITIONS ) <EOL> def edition_detail ( request , edition_slug , edition_id ) : <EOL> dnd_edition = get_object_or_404 ( DndEdition , id = edition_id ) <EOL> if dnd_edition . slug != edition_slug : <EOL> return permanent_redirect_object ( request , dnd_edition ) <EOL> rulebook_list = dnd_edition . rulebook_set . select_related ( '<STR_LIT>' ) . all ( ) <EOL> paginator = DndPaginator ( rulebook_list , request ) <EOL> if is_3e_edition ( dnd_edition ) : <EOL> request . submenu_item = MenuItem . Rulebooks . BOOKS_3_0 <EOL> elif dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . CORE_3_5 <EOL> elif dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . SUPPLEMENTS_3_5 <EOL> elif dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . DRAGONLANCE_3_5 <EOL> elif dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . EBERRON_3_5 <EOL> elif dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . FORGOTTEN_REALMS_3_5 <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : dnd_edition , <EOL> '<STR_LIT>' : request , <EOL> '<STR_LIT>' : paginator . items ( ) , <EOL> '<STR_LIT>' : paginator , <EOL> '<STR_LIT>' : request . build_absolute_uri ( ) , <EOL> '<STR_LIT>' : request . build_absolute_uri ( ) , <EOL> '<STR_LIT>' : is_3e_edition ( dnd_edition ) , <EOL> } , context_instance = RequestContext ( request ) , ) <EOL> @ menu_item ( MenuItem . RULEBOOKS ) <EOL> @ submenu_item ( MenuItem . Rulebooks . RULEBOOKS ) <EOL> def rulebook_detail ( request , edition_slug , edition_id , rulebook_slug , rulebook_id ) : <EOL> rulebook = get_object_or_404 ( Rulebook , id = rulebook_id ) <EOL> if ( rulebook . slug != rulebook_slug or <EOL> unicode ( rulebook . dnd_edition . id ) != edition_id or <EOL> rulebook . dnd_edition . slug != edition_slug ) : <EOL> return permanent_redirect_object ( request , rulebook ) <EOL> if is_3e_edition ( rulebook . dnd_edition ) : <EOL> request . submenu_item = MenuItem . Rulebooks . BOOKS_3_0 <EOL> elif rulebook . dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . CORE_3_5 <EOL> elif rulebook . dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . SUPPLEMENTS_3_5 <EOL> elif rulebook . dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . DRAGONLANCE_3_5 <EOL> elif rulebook . dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . EBERRON_3_5 <EOL> elif rulebook . dnd_edition . slug == "<STR_LIT>" : <EOL> request . submenu_item = MenuItem . Rulebooks . FORGOTTEN_REALMS_3_5 <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : rulebook , <EOL> '<STR_LIT>' : rulebook . dnd_edition , <EOL> '<STR_LIT>' : request , <EOL> '<STR_LIT>' : request . build_absolute_uri ( ) , <EOL> '<STR_LIT>' : request . build_absolute_uri ( ) , <EOL> '<STR_LIT>' : is_3e_edition ( rulebook . dnd_edition ) , <EOL> } , context_instance = RequestContext ( request ) , ) </s>
