def rulebook_detail(request, edition_slug, edition_id, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, id=rulebook_id) if (rulebook.slug != rulebook_slug or unicode(rulebook.dnd_edition.id) != edition_id or rulebook.dnd_edition.slug != edition_slug): return permanent_redirect_object(request, rulebook) if is_3e_edition(rulebook.dnd_edition): request.submenu_item = MenuItem.Rulebooks.BOOKS_3_0 elif rulebook.dnd_edition.slug == "core-35": request.submenu_item = MenuItem.Rulebooks.CORE_3_5 elif rulebook.dnd_edition.slug == "supplementals-35": request.submenu_item = MenuItem.Rulebooks.SUPPLEMENTS_3_5 elif rulebook.dnd_edition.slug == "dragonlance": request.submenu_item = MenuItem.Rulebooks.DRAGONLANCE_3_5 elif rulebook.dnd_edition.slug == "eberron-35": request.submenu_item = MenuItem.Rulebooks.EBERRON_3_5 elif rulebook.dnd_edition.slug == "forgotten-realms-35": request.submenu_item = MenuItem.Rulebooks.FORGOTTEN_REALMS_3_5 return render_to_response( 'dnd/rulebooks/rulebook_detail.html', { 'rulebook': rulebook, 'dnd_edition': rulebook.dnd_edition, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def edition_detail(request, edition_slug, edition_id): dnd_edition = get_object_or_404(DndEdition, id=edition_id) if dnd_edition.slug != edition_slug: return permanent_redirect_object(request, dnd_edition) rulebook_list = dnd_edition.rulebook_set.select_related('dnd_edition').all() paginator = DndPaginator(rulebook_list, request) if is_3e_edition(dnd_edition): request.submenu_item = MenuItem.Rulebooks.BOOKS_3_0 elif dnd_edition.slug == "core-35": request.submenu_item = MenuItem.Rulebooks.CORE_3_5 elif dnd_edition.slug == "supplementals-35": request.submenu_item = MenuItem.Rulebooks.SUPPLEMENTS_3_5 elif dnd_edition.slug == "dragonlance": request.submenu_item = MenuItem.Rulebooks.DRAGONLANCE_3_5 elif dnd_edition.slug == "eberron-35": request.submenu_item = MenuItem.Rulebooks.EBERRON_3_5 elif dnd_edition.slug == "forgotten-realms-35": request.submenu_item = MenuItem.Rulebooks.FORGOTTEN_REALMS_3_5 return render(request, 'dnd/rulebooks/edition_detail.html', context={ 'dnd_edition': dnd_edition, 'rulebook_list': paginator.items(), 'paginator': paginator, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(dnd_edition)},)
def rulebook_detail(request, edition_slug, edition_id, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, id=rulebook_id) if (rulebook.slug != rulebook_slug or unicode(rulebook.dnd_edition.id) != edition_id or rulebook.dnd_edition.slug != edition_slug): return permanent_redirect_object(request, rulebook) if is_3e_edition(rulebook.dnd_edition): request.submenu_item = MenuItem.Rulebooks.BOOKS_3_0 elif rulebook.dnd_edition.slug == "core-35": request.submenu_item = MenuItem.Rulebooks.CORE_3_5 elif rulebook.dnd_edition.slug == "supplementals-35": request.submenu_item = MenuItem.Rulebooks.SUPPLEMENTS_3_5 elif rulebook.dnd_edition.slug == "dragonlance": request.submenu_item = MenuItem.Rulebooks.DRAGONLANCE_3_5 elif rulebook.dnd_edition.slug == "eberron-35": request.submenu_item = MenuItem.Rulebooks.EBERRON_3_5 elif rulebook.dnd_edition.slug == "forgotten-realms-35": request.submenu_item = MenuItem.Rulebooks.FORGOTTEN_REALMS_3_5 return render_to_response('dnd/rulebooks/rulebook_detail.html', { 'rulebook': rulebook, 'dnd_edition': rulebook.dnd_edition, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def spells_in_rulebook(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, 'spells_in_rulebook', kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) spell_list = rulebook.spell_set.select_related('rulebook', 'rulebook__dnd_edition', 'school').all() paginator = DndPaginator(spell_list, request) return render_to_response( 'dnd/spells/spells_in_rulebook.html', { 'rulebook': rulebook, 'spell_list': paginator.items(), 'paginator': paginator, 'request': request, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def character_classes_in_rulebook_mobile(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, character_classes_in_rulebook_mobile, kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) class_list = [ character_class_variant.character_class for character_class_variant in rulebook.characterclassvariant_set. select_related('character_class').all() ] return render_to_response( 'dnd/mobile/character_classes/character_classes_in_rulebook.html', { 'rulebook': rulebook, 'class_list': class_list, 'request': request, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def feats_in_rulebook_mobile(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404( Rulebook.objects.select_related('dnd_edition'), pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, feats_in_rulebook_mobile, kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) feat_list = rulebook.feat_set.select_related( 'rulebook', 'rulebook__dnd_edition').all() paginator = DndMobilePaginator(feat_list, request) return render_to_response( 'dnd/mobile/feats/feats_in_rulebook.html', { 'rulebook': rulebook, 'feat_list': paginator.items(), 'paginator': paginator, 'request': request, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def item_detail(request, rulebook_slug, rulebook_id, item_slug, item_id): item = get_object_or_404(Item.objects.select_related( 'rulebook', 'rulebook__dnd_edition', 'body_slot', 'aura', 'activation', 'property', 'synergy_prerequisite', ).prefetch_related('aura_schools', 'required_feats', 'required_spells'), pk=item_id) assert isinstance(item, Item) if (item.slug != item_slug or str(item.rulebook.id) != rulebook_id or item.rulebook.slug != rulebook_slug): return permanent_redirect_object(request, item) required_feats = item.required_feats.select_related('rulebook').all() required_spells = item.required_spells.select_related('rulebook').all() cost_to_create = item.cost_to_create # calculate CTC if not cost_to_create: if item.price_gp and not item.price_bonus: cost_to_create = "%s gp, %s XP, %d day(s)" % ( int_with_commas(ceil(item.price_gp / 2.0)), int_with_commas(ceil(item.price_gp / 25.0)), ceil(item.price_gp / 1000.0)) elif not item.price_gp and item.price_bonus: cost_to_create = "Varies" return render(request, 'dnd/items/item_detail.html', context={'item': item, 'aura_schools': item.aura_schools.all(), 'required_feats': required_feats, 'required_spells': required_spells, 'cost_to_create': cost_to_create, 'rulebook': item.rulebook, 'ItemType': Item.ItemType, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(item.rulebook.dnd_edition),},)
def monster_detail_mobile(request, rulebook_slug, rulebook_id, monster_slug, monster_id): monster = get_object_or_404( Monster.objects.select_related('rulebook', 'rulebook__dnd_edition', 'size', 'type', ), pk=monster_id) if (monster.slug != monster_slug or unicode(monster.rulebook.id) != rulebook_id or monster.rulebook.slug != rulebook_slug): return permanent_redirect_object_mobile(request, monster) assert isinstance(monster, Monster) monster_speeds = monster.monsterspeed_set.select_related('type', ).all() monster_subtypes = monster.subtypes.all() monster_skills = monster.skills.select_related('skill').all() monster_feats = monster.feats.select_related('feat', 'feat__rulebook').all() return render_to_response('dnd/mobile/monsters/monster_detail.html', { 'monster': monster, 'rulebook': monster.rulebook, 'request': request, 'monster_speeds': monster_speeds, 'monster_subtypes': monster_subtypes, 'monster_skills': monster_skills, 'monster_feats': monster_feats, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(monster.rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def feat_detail(request, rulebook_slug, rulebook_id, feat_slug, feat_id): feat = get_object_or_404( Feat.objects.select_related('rulebook', 'rulebook__dnd_edition'), pk=feat_id) if (feat.slug != feat_slug or str(feat.rulebook.id) != rulebook_id or feat.rulebook.slug != rulebook_slug): return permanent_redirect_object(request, feat) feat_category_list = feat.feat_categories.select_related().all() required_feats = feat.required_feats.select_related('required_feat', 'required_feat__rulebook').all() required_by_feats = feat.required_by_feats.select_related('source_feat', 'source_feat__rulebook').all() required_skills = feat.required_skills.select_related('skill').all() special_prerequisities = feat.featspecialfeatprerequisite_set.select_related( 'special_feat_prerequisite').all() # related feats related_feats = Feat.objects.filter(slug=feat.slug).exclude(rulebook__id=feat.rulebook.id).select_related( 'rulebook', 'rulebook__dnd_edition').all() return render(request, 'dnd/feats/feat_detail.html', context={'feat': feat, 'rulebook': feat.rulebook, 'feat_category_list': feat_category_list, 'required_feats': required_feats, 'required_by_feats': required_by_feats, 'required_skills': required_skills, 'special_prerequisities': special_prerequisities, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(feat.rulebook.dnd_edition), 'related_feats': related_feats,},)
def race_detail_mobile(request, rulebook_slug, rulebook_id, race_slug, race_id): race = get_object_or_404( Race.objects.select_related('rulebook', 'rulebook__dnd_edition', 'size', 'race_type') .prefetch_related('automatic_languages', 'bonus_languages'), pk=race_id) assert isinstance(race, Race) if (race.slug != race_slug or str(race.rulebook.id) != rulebook_id or race.rulebook.slug != rulebook_slug): return permanent_redirect_view(request, 'dnd:mobile:races:race_detail', kwargs={ 'rulebook_slug': race.rulebook.slug, 'rulebook_id': race.rulebook.id, 'race_slug': race.slug, 'race_id': race.id, }) race_speeds = race.racespeed_set.select_related('type', ).all() favored_classes = race.favored_classes.select_related('character_class', ).all() related_races = Race.objects.filter(slug=race.slug).exclude(rulebook__id=race.rulebook.id).select_related( 'rulebook', 'rulebook__dnd_edition').all() return render(request, 'dnd/mobile/races/race_detail.html', context={'race': race, 'rulebook': race.rulebook, 'race_speeds': race_speeds, 'favored_classes': favored_classes, 'automatic_languages': race.automatic_languages.all(), 'bonus_languages': race.bonus_languages.all(), 'related_races': related_races, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(race.rulebook.dnd_edition),},)
def monster_detail(request, rulebook_slug, rulebook_id, monster_slug, monster_id): monster = get_object_or_404( Monster.objects.select_related("rulebook", "rulebook__dnd_edition", "size", "type"), pk=monster_id ) if ( monster.slug != monster_slug or unicode(monster.rulebook.id) != rulebook_id or monster.rulebook.slug != rulebook_slug ): return permanent_redirect_object(request, monster) assert isinstance(monster, Monster) monster_speeds = monster.monsterspeed_set.select_related("type").all() monster_subtypes = monster.subtypes.all() monster_skills = monster.skills.select_related("skill").all() monster_feats = monster.feats.select_related("feat", "feat__rulebook").all() return render_to_response( "dnd/monsters/monster_detail.html", { "monster": monster, "rulebook": monster.rulebook, "request": request, "monster_speeds": monster_speeds, "monster_subtypes": monster_subtypes, "monster_skills": monster_skills, "monster_feats": monster_feats, "i_like_it_url": request.build_absolute_uri(), "inaccurate_url": request.build_absolute_uri(), "display_3e_warning": is_3e_edition(monster.rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def spell_detail_mobile(request, rulebook_slug, rulebook_id, spell_slug, spell_id): spell = get_object_or_404(Spell.objects.select_related( 'rulebook', 'rulebook__dnd_edition', 'school', 'sub_school').prefetch_related('class_levels'), pk=spell_id) if (spell.slug != spell_slug or str(spell.rulebook.id) != rulebook_id or spell.rulebook.slug != rulebook_slug): return permanent_redirect_object_mobile(request, spell) spell_class_level_set = spell.spellclasslevel_set.select_related('character_class').prefetch_related('spell__rulebook').all() spell_domain_level_set = spell.spelldomainlevel_set.select_related('domain').all() # related spells related_spells = Spell.objects.filter(slug=spell.slug).exclude(rulebook__id=spell.rulebook.id).prefetch_related('rulebook').all() # corrupt component -- will be linked to corrupt rule if spell.corrupt_component: corrupt_rule = Rule.objects.filter(slug='corrupt-magic').all()[0] else: corrupt_rule = None return render(request, 'dnd/mobile/spells/spell_detail.html', context={'spell': spell, 'spellclasslevel_set': spell_class_level_set, 'spelldomainlevel_set': spell_domain_level_set, 'corrupt_rule': corrupt_rule, 'rulebook': spell.rulebook, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(spell.rulebook.dnd_edition), 'related_spells': related_spells,},)
def spell_domain_detail_mobile(request, spell_domain_slug, rulebook_slug=None, rulebook_id=None): # fetch the class spell_domain = get_object_or_404(Domain.objects.prefetch_related( 'variant', 'variant__rulebook'), slug=spell_domain_slug) # fetch primary variant, this is independent of rulebook selected try: primary_variant = DomainVariant.objects.select_related('rulebook__dnd_edition',).prefetch_related('rulebook').filter( domain=spell_domain, ).order_by('-rulebook__dnd_edition__core', '-rulebook__published')[0] except Exception: primary_variant = None # if rulebook is supplied, select find this variant if rulebook_slug and rulebook_id: # use canonical link in head as this is more or less duplicated content use_canonical_link = True selected_variant = get_object_or_404( DomainVariant.objects.select_related('domain', 'rulebook__dnd_edition').prefetch_related('rulebook'), domain__slug=spell_domain_slug, rulebook__pk=rulebook_id) # possible malformed/changed slug if rulebook_slug != selected_variant.rulebook.slug: return permanent_redirect_object_mobile(request, selected_variant) # selected variant is primary! Redirect to canonical url if selected_variant == primary_variant: return permanent_redirect_view( request, spell_domain_detail, kwargs={ 'spell_domain_slug': spell_domain_slug} ) else: # this is canonical, no need to specify it use_canonical_link = False selected_variant = primary_variant other_variants = [ variant for variant in spell_domain.variant.select_related('rulebook__dnd_edition', 'domain').prefetch_related('rulebook').all() if variant != selected_variant ] if selected_variant: display_3e_warning = is_3e_edition(selected_variant.rulebook.dnd_edition) else: display_3e_warning = False spell_list = spell_domain.spell_set.select_related('rulebook__dnd_edition', 'school').prefetch_related('rulebook').all() paginator = DndMobilePaginator(spell_list, request) return render(request, 'dnd/mobile/spells/spell_domain_detail.html', context={'spell_domain': spell_domain, 'spell_list': paginator.items(), 'paginator': paginator, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'selected_variant': selected_variant, 'other_variants': other_variants, 'use_canonical_link': use_canonical_link, 'display_3e_warning': display_3e_warning, },)
def item_detail_mobile(request, rulebook_slug, rulebook_id, item_slug, item_id): item = get_object_or_404(Item.objects.select_related( 'rulebook', 'rulebook__dnd_edition', 'body_slot', 'aura', 'spellschool_set', 'activation', 'required_feats', 'required_spells', 'property', 'synergy_prerequisite', ), pk=item_id) assert isinstance(item, Item) if (item.slug != item_slug or unicode(item.rulebook.id) != rulebook_id or item.rulebook.slug != rulebook_slug): return permanent_redirect_object_mobile(request, item) required_feats = item.required_feats.select_related('rulebook').all() required_spells = item.required_spells.select_related('rulebook').all() cost_to_create = item.cost_to_create # calculate CTC if not cost_to_create: if item.price_gp and not item.price_bonus: cost_to_create = "%s gp, %s XP, %d day(s)" % (int_with_commas( ceil(item.price_gp / 2.0)), int_with_commas(ceil( item.price_gp / 25.0)), ceil(item.price_gp / 1000.0)) elif not item.price_gp and item.price_bonus: cost_to_create = "Varies" return render_to_response( 'dnd/mobile/items/item_detail.html', { 'item': item, 'aura_schools': item.aura_schools.all(), 'required_feats': required_feats, 'required_spells': required_spells, 'cost_to_create': cost_to_create, 'rulebook': item.rulebook, 'request': request, # enum 'ItemType': Item.ItemType, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(item.rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def rulebook_detail_mobile(request, edition_slug, edition_id, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, id=rulebook_id) if (rulebook.slug != rulebook_slug or str(rulebook.dnd_edition.id) != edition_id or rulebook.dnd_edition.slug != edition_slug): return permanent_redirect_object_mobile(request, rulebook) return render(request, 'dnd/mobile/rulebooks/rulebook_detail.html', context={'rulebook': rulebook, 'dnd_edition': rulebook.dnd_edition, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(rulebook.dnd_edition),},)
def rule_detail(request, rulebook_slug, rulebook_id, rule_slug, rule_id): rule = get_object_or_404( Rule.objects.select_related('rulebook', 'rulebook__dnd_edition'), pk=rule_id) if (rule.slug != rule_slug or str(rule.rulebook.id) != rulebook_id or rule.rulebook.slug != rulebook_slug): return permanent_redirect_object(request, rule) return render(request, 'dnd/rules/rule_detail.html', context={'rule': rule, 'rulebook': rule.rulebook, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(rule.rulebook.dnd_edition),},)
def edition_detail_mobile(request, edition_slug, edition_id): dnd_edition = get_object_or_404(DndEdition, id=edition_id) if dnd_edition.slug != edition_slug: return permanent_redirect_object_mobile(request, dnd_edition) rulebook_list = dnd_edition.rulebook_set.select_related('dnd_edition').all() paginator = DndMobilePaginator(rulebook_list, request) return render(request, 'dnd/mobile/rulebooks/edition_detail.html', context= {'dnd_edition': dnd_edition, 'rulebook_list': paginator.items(), 'paginator': paginator, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(dnd_edition),},)
def items_in_rulebook(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, 'dnd:items:items_in_rulebook', kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) item_list = rulebook.item_set.select_related('rulebook', 'rulebook__dnd_edition').all() paginator = DndPaginator(item_list, request) return render(request, 'dnd/items/items_in_rulebook.html', context={'rulebook': rulebook, 'item_list': paginator.items(), 'paginator': paginator, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition),},)
def edition_detail(request, edition_slug, edition_id): dnd_edition = get_object_or_404(DndEdition, id=edition_id) if dnd_edition.slug != edition_slug: return permanent_redirect_object(request, dnd_edition) rulebook_list = dnd_edition.rulebook_set.select_related( 'dnd_edition').all() paginator = DndPaginator(rulebook_list, request) if is_3e_edition(dnd_edition): request.submenu_item = MenuItem.Rulebooks.BOOKS_3_0 elif dnd_edition.slug == "core-35": request.submenu_item = MenuItem.Rulebooks.CORE_3_5 elif dnd_edition.slug == "supplementals-35": request.submenu_item = MenuItem.Rulebooks.SUPPLEMENTS_3_5 elif dnd_edition.slug == "dragonlance": request.submenu_item = MenuItem.Rulebooks.DRAGONLANCE_3_5 elif dnd_edition.slug == "eberron-35": request.submenu_item = MenuItem.Rulebooks.EBERRON_3_5 elif dnd_edition.slug == "forgotten-realms-35": request.submenu_item = MenuItem.Rulebooks.FORGOTTEN_REALMS_3_5 return render_to_response( 'dnd/rulebooks/edition_detail.html', { 'dnd_edition': dnd_edition, 'request': request, 'rulebook_list': paginator.items(), 'paginator': paginator, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(dnd_edition), }, context_instance=RequestContext(request), )
def character_classes_in_rulebook(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, 'character_classes_in_rulebook', kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) class_list = [ character_class_variant.character_class for character_class_variant in rulebook.characterclassvariant_set.select_related('character_class').all() ] return render(request, 'dnd/character_classes/character_classes_in_rulebook.html', context= {'rulebook': rulebook, 'class_list': class_list, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition),},)
def races_in_rulebook_mobile(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, 'dnd:mobile:races:races_in_rulebook_mobile', kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) race_list = rulebook.race_set.select_related( 'rulebook', 'rulebook__dnd_edition').all() paginator = DndMobilePaginator(race_list, request) return render(request, 'dnd/mobile/races/races_in_rulebook.html', context= {'rulebook': rulebook, 'race_list': paginator.items(), 'paginator': paginator, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition),},)
def skills_in_rulebook(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, 'dnd:skills:skills_in_rulebook', kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) skill_list = [ skill_variant.skill for skill_variant in rulebook.skillvariant_set.all() ] return render(request, 'dnd/skills/skill_in_rulebook.html', context={'rulebook': rulebook, 'skill_list': skill_list, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition),},)
def spell_detail(request, rulebook_slug, rulebook_id, spell_slug, spell_id): spell = get_object_or_404(Spell.objects.select_related( 'rulebook', 'rulebook__dnd_edition', 'school', 'sub_school', 'class_levels'), pk=spell_id) if (spell.slug != spell_slug or unicode(spell.rulebook.id) != rulebook_id or spell.rulebook.slug != rulebook_slug): return permanent_redirect_object(request, spell) spell_class_level_set = spell.spellclasslevel_set.select_related( 'rulebook', 'character_class', ).all() spell_domain_level_set = spell.spelldomainlevel_set.select_related( 'rulebook', 'domain', ).all() # related spells related_spells = Spell.objects.filter(slug=spell.slug).exclude( rulebook__id=spell.rulebook.id).select_related('rulebook').all() # corrupt component -- will be linked to corrupt rule if spell.corrupt_component: corrupt_rule = Rule.objects.filter(slug='corrupt-magic').all()[0] else: corrupt_rule = None return render_to_response( 'dnd/spells/spell_detail.html', { 'spell': spell, 'spellclasslevel_set': spell_class_level_set, 'spelldomainlevel_set': spell_domain_level_set, 'corrupt_rule': corrupt_rule, 'rulebook': spell.rulebook, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(spell.rulebook.dnd_edition), 'related_spells': related_spells, }, context_instance=RequestContext(request), )
def rule_detail_mobile(request, rulebook_slug, rulebook_id, rule_slug, rule_id): rule = get_object_or_404( Rule.objects.select_related('rulebook', 'rulebook__dnd_edition'), pk=rule_id) if (rule.slug != rule_slug or unicode(rule.rulebook.id) != rulebook_id or rule.rulebook.slug != rulebook_slug): return permanent_redirect_object_mobile(request, rule) return render_to_response('dnd/mobile/rules/rule_detail.html', { 'rule': rule, 'rulebook': rule.rulebook, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(rule.rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def race_detail_mobile(request, rulebook_slug, rulebook_id, race_slug, race_id): race = get_object_or_404(Race.objects.select_related( 'rulebook', 'rulebook__dnd_edition', 'size', 'automatic_languages', 'bonus_languages', 'race_type'), pk=race_id) assert isinstance(race, Race) if (race.slug != race_slug or unicode(race.rulebook.id) != rulebook_id or race.rulebook.slug != rulebook_slug): return permanent_redirect_view(request, 'race_detail', kwargs={ 'rulebook_slug': race.rulebook.slug, 'rulebook_id': race.rulebook.id, 'race_slug': race.slug, 'race_id': race.id, }) race_speeds = race.racespeed_set.select_related('type', ).all() favored_classes = race.favored_classes.select_related( 'character_class', ).all() related_races = Race.objects.filter( slug=race.slug).exclude(rulebook__id=race.rulebook.id).select_related( 'rulebook', 'rulebook__dnd_edition').all() return render_to_response( 'dnd/mobile/races/race_detail.html', { 'race': race, 'rulebook': race.rulebook, 'request': request, 'race_speeds': race_speeds, 'favored_classes': favored_classes, 'automatic_languages': race.automatic_languages.all(), 'bonus_languages': race.bonus_languages.all(), 'related_races': related_races, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(race.rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def races_in_rulebook(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, 'races_in_rulebook', kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) race_list = rulebook.race_set.select_related( 'rulebook', 'rulebook__dnd_edition', 'school').all() paginator = DndPaginator(race_list, request) return render_to_response('dnd/races/races_in_rulebook.html', { 'rulebook': rulebook, 'race_list': paginator.items(), 'paginator': paginator, 'request': request, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def rulebook_detail_mobile(request, edition_slug, edition_id, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, id=rulebook_id) if ( rulebook.slug != rulebook_slug or unicode(rulebook.dnd_edition.id) != edition_id or rulebook.dnd_edition.slug != edition_slug ): return permanent_redirect_object_mobile(request, rulebook) return render_to_response( "dnd/mobile/rulebooks/rulebook_detail.html", { "rulebook": rulebook, "dnd_edition": rulebook.dnd_edition, "request": request, "i_like_it_url": request.build_absolute_uri(), "inaccurate_url": request.build_absolute_uri(), "display_3e_warning": is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def skills_in_rulebook(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, 'skills_in_rulebook', kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) skill_list = [ skill_variant.skill for skill_variant in rulebook.skillvariant_set.all() ] return render_to_response('dnd/skills/skill_in_rulebook.html', { 'rulebook': rulebook, 'skill_list': skill_list, 'request': request, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def skills_in_rulebook_mobile(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, skills_in_rulebook_mobile, kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) skill_list = [ skill_variant.skill for skill_variant in rulebook.skillvariant_set.all() ] return render_to_response('dnd/mobile/skills/skill_in_rulebook.html', { 'rulebook': rulebook, 'skill_list': skill_list, 'request': request, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def feat_detail_mobile(request, rulebook_slug, rulebook_id, feat_slug, feat_id): feat = get_object_or_404(Feat.objects.select_related( 'rulebook', 'rulebook__dnd_edition'), pk=feat_id) if (feat.slug != feat_slug or unicode(feat.rulebook.id) != rulebook_id or feat.rulebook.slug != rulebook_slug): return permanent_redirect_object_mobile(request, feat) feat_category_list = feat.feat_categories.select_related().all() required_feats = feat.required_feats.select_related( 'required_feat', 'required_feat__rulebook').all() required_by_feats = feat.required_by_feats.select_related( 'source_feat', 'source_feat__rulebook').all() required_skills = feat.required_skills.select_related('skill').all() special_prerequisities = feat.featspecialfeatprerequisite_set.select_related( 'special_feat_prerequisite').all() # related feats related_feats = Feat.objects.filter( slug=feat.slug).exclude(rulebook__id=feat.rulebook.id).select_related( 'rulebook', 'rulebook__dnd_edition').all() return render_to_response( 'dnd/mobile/feats/feat_detail.html', { 'feat': feat, 'rulebook': feat.rulebook, 'feat_category_list': feat_category_list, 'required_feats': required_feats, 'required_by_feats': required_by_feats, 'required_skills': required_skills, 'special_prerequisities': special_prerequisities, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(feat.rulebook.dnd_edition), 'related_feats': related_feats, }, context_instance=RequestContext(request), )
def monsters_in_rulebook(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook, pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view( request, "monsters_in_rulebook", kwargs={"rulebook_slug": rulebook.slug, "rulebook_id": rulebook_id} ) monster_list = rulebook.monster_set.select_related("rulebook", "rulebook__dnd_edition", "school").all() paginator = DndPaginator(monster_list, request) return render_to_response( "dnd/monsters/monsters_in_rulebook.html", { "rulebook": rulebook, "monster_list": paginator.items(), "paginator": paginator, "request": request, "display_3e_warning": is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def edition_detail_mobile(request, edition_slug, edition_id): dnd_edition = get_object_or_404(DndEdition, id=edition_id) if dnd_edition.slug != edition_slug: return permanent_redirect_object_mobile(request, dnd_edition) rulebook_list = dnd_edition.rulebook_set.select_related("dnd_edition").all() paginator = DndMobilePaginator(rulebook_list, request) return render_to_response( "dnd/mobile/rulebooks/edition_detail.html", { "dnd_edition": dnd_edition, "request": request, "rulebook_list": paginator.items(), "paginator": paginator, "i_like_it_url": request.build_absolute_uri(), "inaccurate_url": request.build_absolute_uri(), "display_3e_warning": is_3e_edition(dnd_edition), }, context_instance=RequestContext(request), )
def feats_in_rulebook_mobile(request, rulebook_slug, rulebook_id): rulebook = get_object_or_404(Rulebook.objects.select_related('dnd_edition'), pk=rulebook_id) if not rulebook.slug == rulebook_slug: return permanent_redirect_view(request, feats_in_rulebook_mobile, kwargs={ 'rulebook_slug': rulebook.slug, 'rulebook_id': rulebook_id, }) feat_list = rulebook.feat_set.select_related('rulebook', 'rulebook__dnd_edition').all() paginator = DndMobilePaginator(feat_list, request) return render_to_response('dnd/mobile/feats/feats_in_rulebook.html', { 'rulebook': rulebook, 'feat_list': paginator.items(), 'paginator': paginator, 'request': request, 'display_3e_warning': is_3e_edition(rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def monster_detail_mobile(request, rulebook_slug, rulebook_id, monster_slug, monster_id): monster = get_object_or_404(Monster.objects.select_related( 'rulebook', 'rulebook__dnd_edition', 'size', 'type', ), pk=monster_id) if (monster.slug != monster_slug or unicode(monster.rulebook.id) != rulebook_id or monster.rulebook.slug != rulebook_slug): return permanent_redirect_object_mobile(request, monster) assert isinstance(monster, Monster) monster_speeds = monster.monsterspeed_set.select_related('type', ).all() monster_subtypes = monster.subtypes.all() monster_skills = monster.skills.select_related('skill').all() monster_feats = monster.feats.select_related('feat', 'feat__rulebook').all() return render_to_response( 'dnd/mobile/monsters/monster_detail.html', { 'monster': monster, 'rulebook': monster.rulebook, 'request': request, 'monster_speeds': monster_speeds, 'monster_subtypes': monster_subtypes, 'monster_skills': monster_skills, 'monster_feats': monster_feats, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(monster.rulebook.dnd_edition), }, context_instance=RequestContext(request), )
def spell_detail_mobile(request, rulebook_slug, rulebook_id, spell_slug, spell_id): spell = get_object_or_404( Spell.objects.select_related("rulebook", "rulebook__dnd_edition", "school", "sub_school", "class_levels"), pk=spell_id, ) if spell.slug != spell_slug or unicode(spell.rulebook.id) != rulebook_id or spell.rulebook.slug != rulebook_slug: return permanent_redirect_object_mobile(request, spell) spell_class_level_set = spell.spellclasslevel_set.select_related("rulebook", "character_class").all() spell_domain_level_set = spell.spelldomainlevel_set.select_related("rulebook", "domain").all() # related spells related_spells = ( Spell.objects.filter(slug=spell.slug).exclude(rulebook__id=spell.rulebook.id).select_related("rulebook").all() ) # corrupt component -- will be linked to corrupt rule if spell.corrupt_component: corrupt_rule = Rule.objects.filter(slug="corrupt-magic").all()[0] else: corrupt_rule = None return render_to_response( "dnd/mobile/spells/spell_detail.html", { "spell": spell, "spellclasslevel_set": spell_class_level_set, "spelldomainlevel_set": spell_domain_level_set, "corrupt_rule": corrupt_rule, "rulebook": spell.rulebook, "request": request, "i_like_it_url": request.build_absolute_uri(), "inaccurate_url": request.build_absolute_uri(), "display_3e_warning": is_3e_edition(spell.rulebook.dnd_edition), "related_spells": related_spells, }, context_instance=RequestContext(request), )
def edition_detail_mobile(request, edition_slug, edition_id): dnd_edition = get_object_or_404(DndEdition, id=edition_id) if dnd_edition.slug != edition_slug: return permanent_redirect_object_mobile(request, dnd_edition) rulebook_list = dnd_edition.rulebook_set.select_related( 'dnd_edition').all() paginator = DndMobilePaginator(rulebook_list, request) return render_to_response( 'dnd/mobile/rulebooks/edition_detail.html', { 'dnd_edition': dnd_edition, 'request': request, 'rulebook_list': paginator.items(), 'paginator': paginator, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'display_3e_warning': is_3e_edition(dnd_edition), }, context_instance=RequestContext(request), )
def character_class_detail_mobile(request, character_class_slug, rulebook_slug=None, rulebook_id=None): # fetch the class character_class = get_object_or_404(CharacterClass.objects.select_related( 'character_class_variant', 'character_class_variant__rulebook'), slug=character_class_slug) assert isinstance(character_class, CharacterClass) # fetch primary variant, this is independent of rulebook selected try: primary_variant = CharacterClassVariant.objects.select_related( 'rulebook', 'rulebook__dnd_edition', ).filter(character_class=character_class, ).order_by( '-rulebook__dnd_edition__core', '-rulebook__published')[0] except Exception: primary_variant = None # if rulebook is supplied, select find this variant if rulebook_slug and rulebook_id: # use canonical link in head as this is more or less duplicated content use_canonical_link = True selected_variant = get_object_or_404( CharacterClassVariant.objects.select_related( 'rulebook', 'character_class', 'rulebook__dnd_edition'), character_class__slug=character_class_slug, rulebook__pk=rulebook_id) # possible malformed/changed slug if rulebook_slug != selected_variant.rulebook.slug: return permanent_redirect_object_mobile(request, selected_variant) # selected variant is primary! Redirect to canonical url if selected_variant == primary_variant: return permanent_redirect_view( request, character_class_detail_mobile, kwargs={'character_class_slug': character_class_slug}) else: # this is canonical, no need to specify it use_canonical_link = False selected_variant = primary_variant other_variants = [ variant for variant in character_class.characterclassvariant_set.select_related( 'rulebook', 'rulebook__dnd_edition', 'character_class').all() if variant != selected_variant ] if selected_variant: required_races = selected_variant.required_races.select_related( 'race', 'race__rulebook').all() required_skills = selected_variant.required_skills.select_related( 'skill').all() required_feats = selected_variant.required_feats.select_related( 'feat', 'feat__rulebook').all() display_3e_warning = is_3e_edition( selected_variant.rulebook.dnd_edition) else: required_races = () required_skills = () required_feats = () display_3e_warning = False return render_to_response( 'dnd/mobile/character_classes/character_class_detail.html', { 'character_class': character_class, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'selected_variant': selected_variant, 'required_races': required_races, 'required_skills': required_skills, 'required_feats': required_feats, 'other_variants': other_variants, 'use_canonical_link': use_canonical_link, 'display_3e_warning': display_3e_warning, }, context_instance=RequestContext(request), )
def spell_domain_detail_mobile(request, spell_domain_slug, rulebook_slug=None, rulebook_id=None): # fetch the domain spell_domain = get_object_or_404( Domain.objects.select_related("domain_variant", "domain_variant__rulebook"), slug=spell_domain_slug ) # fetch primary variant, this is independent of rulebook selected try: primary_variant = ( DomainVariant.objects.select_related("rulebook", "rulebook__dnd_edition") .filter(domain=spell_domain) .order_by("-rulebook__dnd_edition__core", "-rulebook__published")[0] ) except Exception: primary_variant = None # if rulebook is supplied, select find this variant if rulebook_slug and rulebook_id: # use canonical link in head as this is more or less duplicated content selected_variant = get_object_or_404( DomainVariant.objects.select_related("domain", "rulebook", "rulebook__dnd_edition"), domain__slug=spell_domain_slug, rulebook__pk=rulebook_id, ) # possible malformed/changed slug if rulebook_slug != selected_variant.rulebook.slug: return permanent_redirect_object_mobile(request, selected_variant) # selected variant is primary! Redirect to canonical url if selected_variant == primary_variant: return permanent_redirect_view( request, spell_domain_detail_mobile, kwargs={"spell_domain_slug": spell_domain_slug} ) else: # this is canonical, no need to specify it selected_variant = primary_variant other_variants = [ variant for variant in spell_domain.domainvariant_set.select_related( "rulebook", "rulebook__dnd_edition", "spell_domain" ).all() if variant != selected_variant ] if selected_variant: display_3e_warning = is_3e_edition(selected_variant.rulebook.dnd_edition) else: display_3e_warning = False spell_list = spell_domain.spell_set.select_related("rulebook", "rulebook__dnd_edition", "school").all() paginator = DndMobilePaginator(spell_list, request) return render_to_response( "dnd/mobile/spells/spell_domain_detail.html", { "spell_domain": spell_domain, "spell_list": paginator.items(), "paginator": paginator, "request": request, "i_like_it_url": request.build_absolute_uri(), "inaccurate_url": request.build_absolute_uri(), "selected_variant": selected_variant, "other_variants": other_variants, "display_3e_warning": display_3e_warning, }, context_instance=RequestContext(request), )
def spell_domain_detail(request, spell_domain_slug, rulebook_slug=None, rulebook_id=None): # fetch the class spell_domain = get_object_or_404(Domain.objects.select_related( 'domain_variant', 'domain_variant__rulebook'), slug=spell_domain_slug) # fetch primary variant, this is independent of rulebook selected try: primary_variant = DomainVariant.objects.select_related( 'rulebook', 'rulebook__dnd_edition', ).filter(domain=spell_domain, ).order_by( '-rulebook__dnd_edition__core', '-rulebook__published')[0] except Exception: primary_variant = None # if rulebook is supplied, select find this variant if rulebook_slug and rulebook_id: # use canonical link in head as this is more or less duplicated content use_canonical_link = True selected_variant = get_object_or_404( DomainVariant.objects.select_related('domain', 'rulebook', 'rulebook__dnd_edition'), domain__slug=spell_domain_slug, rulebook__pk=rulebook_id) # possible malformed/changed slug if rulebook_slug != selected_variant.rulebook.slug: return permanent_redirect_object(request, selected_variant) # selected variant is primary! Redirect to canonical url if selected_variant == primary_variant: return permanent_redirect_view( request, spell_domain_detail, kwargs={'spell_domain_slug': spell_domain_slug}) else: # this is canonical, no need to specify it use_canonical_link = False selected_variant = primary_variant other_variants = [ variant for variant in spell_domain.domainvariant_set.select_related( 'rulebook', 'rulebook__dnd_edition', 'spell_domain').all() if variant != selected_variant ] if selected_variant: display_3e_warning = is_3e_edition( selected_variant.rulebook.dnd_edition) else: display_3e_warning = False spell_list = spell_domain.spell_set.select_related( 'rulebook', 'rulebook__dnd_edition', 'school').all() paginator = DndPaginator(spell_list, request) return render_to_response( 'dnd/spells/spell_domain_detail.html', { 'spell_domain': spell_domain, 'spell_list': paginator.items(), 'paginator': paginator, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'selected_variant': selected_variant, 'other_variants': other_variants, 'use_canonical_link': use_canonical_link, 'display_3e_warning': display_3e_warning, }, context_instance=RequestContext(request), )
def character_class_detail(request, character_class_slug, rulebook_slug=None, rulebook_id=None): # fetch the class character_class = get_object_or_404( CharacterClass.objects.select_related('character_class_variant', 'character_class_variant__rulebook'), slug=character_class_slug) assert isinstance(character_class, CharacterClass) # fetch primary variant, this is independent of rulebook selected try: primary_variant = CharacterClassVariant.objects.select_related( 'rulebook', 'rulebook__dnd_edition', ).filter( character_class=character_class, ).order_by('-rulebook__dnd_edition__core', '-rulebook__published')[0] except Exception: primary_variant = None # if rulebook is supplied, select find this variant if rulebook_slug and rulebook_id: # use canonical link in head as this is more or less duplicated content use_canonical_link = True selected_variant = get_object_or_404( CharacterClassVariant.objects.select_related( 'rulebook', 'character_class', 'rulebook__dnd_edition'), character_class__slug=character_class_slug, rulebook__pk=rulebook_id) # possible malformed/changed slug if rulebook_slug != selected_variant.rulebook.slug: return permanent_redirect_object(request, selected_variant) # selected variant is primary! Redirect to canonical url if selected_variant == primary_variant: return permanent_redirect_view( request, character_class_detail, kwargs={ 'character_class_slug': character_class_slug} ) else: # this is canonical, no need to specify it use_canonical_link = False selected_variant = primary_variant other_variants = [ variant for variant in character_class.characterclassvariant_set.select_related( 'rulebook', 'rulebook__dnd_edition', 'character_class').all() if variant != selected_variant ] if selected_variant: required_races = selected_variant.required_races.select_related('race', 'race__rulebook').all() required_skills = selected_variant.required_skills.select_related('skill').all() required_feats = selected_variant.required_feats.select_related('feat', 'feat__rulebook').all() display_3e_warning = is_3e_edition(selected_variant.rulebook.dnd_edition) else: required_races = () required_skills = () required_feats = () display_3e_warning = False return render_to_response('dnd/character_classes/character_class_detail.html', { 'character_class': character_class, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'selected_variant': selected_variant, 'required_races': required_races, 'required_skills': required_skills, 'required_feats': required_feats, 'other_variants': other_variants, 'use_canonical_link': use_canonical_link, 'display_3e_warning': display_3e_warning, }, context_instance=RequestContext(request), )
def skill_detail(request, skill_slug, rulebook_slug=None, rulebook_id=None): # fetch the class skill = get_object_or_404(Skill.objects.select_related( 'skill_variant', 'skill_variant__rulebook'), slug=skill_slug) # fetch primary variant, this is independent of rulebook selected try: primary_variant = SkillVariant.objects.select_related( 'rulebook', 'rulebook__dnd_edition', ).filter( skill=skill, ).order_by('-rulebook__dnd_edition__core', '-rulebook__published')[0] except Exception: primary_variant = None # if rulebook is supplied, select find this variant if rulebook_slug and rulebook_id: # use canonical link in head as this is more or less duplicated content use_canonical_link = True selected_variant = get_object_or_404( SkillVariant.objects.select_related( 'rulebook', 'skill', 'rulebook__dnd_edition'), skill__slug=skill_slug, rulebook__pk=rulebook_id) # possible malformed/changed slug if rulebook_slug != selected_variant.rulebook.slug: return permanent_redirect_object(request, selected_variant) # selected variant is primary! Redirect to canonical url if selected_variant == primary_variant: return permanent_redirect_view( request, skill_detail, kwargs={ 'skill_slug': skill_slug} ) else: # this is canonical, no need to specify it use_canonical_link = False selected_variant = primary_variant other_variants = [ variant for variant in skill.skillvariant_set.select_related( 'rulebook', 'rulebook__dnd_edition', 'skill').all() if variant != selected_variant ] if selected_variant: display_3e_warning = is_3e_edition(selected_variant.rulebook.dnd_edition) else: display_3e_warning = False feat_list = skill.required_by_feats.select_related('rulebook').all() feat_paginator = DndPaginator(feat_list, request) return render_to_response('dnd/skills/skill_detail.html', { 'skill': skill, 'feat_list': feat_paginator.items(), 'feat_paginator': feat_paginator, 'request': request, 'i_like_it_url': request.build_absolute_uri(), 'inaccurate_url': request.build_absolute_uri(), 'selected_variant': selected_variant, 'other_variants': other_variants, 'use_canonical_link': use_canonical_link, 'display_3e_warning': display_3e_warning, }, context_instance=RequestContext(request), )