<s> from django . shortcuts import render_to_response , get_object_or_404 <EOL> from django . template import RequestContext <EOL> from dnd . dnd_paginator import DndPaginator <EOL> from dnd . filters import RuleFilter <EOL> from dnd . menu import menu_item , MenuItem , submenu_item <EOL> from dnd . views import permanent_redirect_object <EOL> from dnd . models import Rule <EOL> from dnd . views import is_3e_edition <EOL> @ menu_item ( MenuItem . RULEBOOKS ) <EOL> @ submenu_item ( MenuItem . Rulebooks . RULES ) <EOL> def rule_list ( request ) : <EOL> f = RuleFilter ( request . GET , queryset = Rule . objects . all ( ) ) <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 . RULES ) <EOL> def rule_detail ( request , rulebook_slug , rulebook_id , rule_slug , rule_id ) : <EOL> rule = get_object_or_404 ( <EOL> Rule . objects . select_related ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> pk = rule_id ) <EOL> if ( rule . slug != rule_slug or <EOL> unicode ( rule . rulebook . id ) != rulebook_id or <EOL> rule . rulebook . slug != rulebook_slug ) : <EOL> return permanent_redirect_object ( request , rule ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : rule , <EOL> '<STR_LIT>' : rule . rulebook , <EOL> '<STR_LIT>' : request , <EOL> '<STR_LIT>' : request . build_absolute_uri ( ) , <EOL> '<STR_LIT>' : request . build_absolute_uri ( ) , <EOL> '<STR_LIT>' : is_3e_edition ( rule . rulebook . dnd_edition ) , <EOL> } , context_instance = RequestContext ( request ) , ) </s>
