#NEWLINE# @ menu_item ( MenuItem . MAGIC ) #NEWLINE# @ submenu_item ( MenuItem . Magic . DOMAINS ) #NEWLINE# def spell_domain_detail( request , spell_domain_slug , rulebook_slug = None , rulebook_id = None ) : #NEWLINE# #INDENT# spell_domain = get_object_or_404 ( Domain . objects . select_related ( 'domain_variant' , 'domain_variant__rulebook' ) , slug = spell_domain_slug ) #NEWLINE# try : #NEWLINE# #INDENT# primary_variant = DomainVariant . objects . select_related ( 'rulebook' , 'rulebook__dnd_edition' ) . filter ( domain = spell_domain ) . order_by ( '-rulebook__dnd_edition__core' , '-rulebook__published' ) [ 0 ] #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# primary_variant = None #NEWLINE# #UNINDENT# if ( rulebook_slug and rulebook_id ) : #NEWLINE# #INDENT# use_canonical_link = True #NEWLINE# selected_variant = get_object_or_404 ( DomainVariant . objects . select_related ( 'domain' , 'rulebook' , 'rulebook__dnd_edition' ) , domain__slug = spell_domain_slug , rulebook__pk = rulebook_id ) #NEWLINE# if ( rulebook_slug != selected_variant . rulebook . slug ) : #NEWLINE# #INDENT# return permanent_redirect_object ( request , selected_variant ) #NEWLINE# #UNINDENT# if ( selected_variant == primary_variant ) : #NEWLINE# #INDENT# return permanent_redirect_view ( request , spell_domain_detail , kwargs = { #NEWLINE# #INDENT# 'spell_domain_slug' : spell_domain_slug , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# use_canonical_link = False #NEWLINE# selected_variant = primary_variant #NEWLINE# #UNINDENT# other_variants = [ variant for variant in spell_domain . domainvariant_set . select_related ( 'rulebook' , 'rulebook__dnd_edition' , 'spell_domain' ) . all ( ) if ( variant != selected_variant ) ] #NEWLINE# if selected_variant : #NEWLINE# #INDENT# display_3e_warning = is_3e_edition ( selected_variant . rulebook . dnd_edition ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# display_3e_warning = False #NEWLINE# #UNINDENT# spell_list = spell_domain . spell_set . select_related ( 'rulebook' , 'rulebook__dnd_edition' , 'school' ) . all ( ) #NEWLINE# paginator = DndPaginator ( spell_list , request ) #NEWLINE# return render_to_response ( 'dnd/spells/spell_domain_detail.html' , { #NEWLINE# #INDENT# 'spell_domain' : spell_domain , #NEWLINE# 'spell_list' : paginator . items ( ) , #NEWLINE# 'paginator' : paginator , #NEWLINE# 'request' : request , #NEWLINE# 'i_like_it_url' : request . build_absolute_uri ( ) , #NEWLINE# 'inaccurate_url' : request . build_absolute_uri ( ) , #NEWLINE# 'selected_variant' : selected_variant , #NEWLINE# 'other_variants' : other_variants , #NEWLINE# 'use_canonical_link' : use_canonical_link , #NEWLINE# 'display_3e_warning' : display_3e_warning , #NEWLINE# #UNINDENT# } , context_instance = RequestContext ( request ) )