def post(self, request, capability_id, target_organization_id): capability = get_object_or_404(Capability, id=capability_id, type=Capability.MILITARY_STANCE) target_organization = get_object_or_404( Organization, id=target_organization_id, world=capability.applying_to.world, violence_monopoly=True) target_stance = request.POST.get('new_stance') if target_stance not in [o[0] for o in MilitaryStance.STANCE_CHOICES]: raise Http404() proposal = { 'target_organization_id': target_organization.id, 'target_stance': target_stance, } if 'region_id' in request.POST.keys(): region = get_object_or_404(Tile, id=request.POST['region_id'], world=capability.applying_to.world) if not region.is_on_ground(): raise Http404() proposal['region_id'] = region.id capability.create_proposal(request.hero, proposal) capability_success(capability, request) return redirect( reverse('organization:military_stance_capability', kwargs={ 'capability_id': capability_id, 'target_organization_id': target_organization_id }))
def conquest_capability_view(request, capability_id): capability = get_object_or_404(Capability, id=capability_id, type=Capability.CONQUEST) tile_to_conquer = get_object_or_404( Tile, id=request.POST.get('tile_to_conquest_id')) if request.POST.get('stop'): try: tile_event = TileEvent.objects.get( tile=tile_to_conquer, organization=capability.applying_to, active=True) except TileEvent.DoesNotExist: raise Http404 else: if tile_to_conquer not in capability.applying_to.conquestable_tiles(): raise Http404 proposal = { 'tile_id': tile_to_conquer.id, 'stop': request.POST.get('stop') } capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def post(self, request, capability_id, target_organization_id): capability = get_object_or_404(Capability, id=capability_id, type=Capability.DIPLOMACY) target_organization = get_object_or_404(Organization, id=target_organization_id, barbaric=False) target_relationship = request.POST.get('target_relationship') if target_relationship in ("accept", "refuse"): if not target_organization.get_relationship_to( capability.applying_to).is_proposal(): return self.fail_post_with_error(capability_id, request, target_organization_id) proposal = { 'type': target_relationship, 'target_organization_id': target_organization.id, 'target_relationship': target_organization.get_relationship_to( capability.applying_to).desired_relationship } elif target_relationship == "take back": if not capability.applying_to.get_relationship_to( target_organization).is_proposal(): return self.fail_post_with_error(capability_id, request, target_organization_id) proposal = { 'type': target_relationship, 'target_organization_id': target_organization.id, 'target_relationship': capability.applying_to.get_relationship_to( target_organization).desired_relationship } else: if capability.applying_to.get_relationship_to( target_organization).is_proposal(): return self.fail_post_with_error(capability_id, request, target_organization_id) if target_relationship not in [ choice[0] for choice in OrganizationRelationship.RELATIONSHIP_CHOICES ]: return self.fail_post_with_error(capability_id, request, target_organization_id) proposal = { 'type': 'propose', 'target_organization_id': target_organization.id, 'target_relationship': target_relationship } capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def arrest_warrant_revoke_capability_view(request, capability_id, warrant_id): capability = get_object_or_404(Capability, id=capability_id, type=Capability.ARREST_WARRANT) warrant = get_object_or_404(CharacterEvent, id=warrant_id, active=True, organization=capability.applying_to, type=CharacterEvent.ARREST_WARRANT) proposal = {'action': 'revoke', 'warrant_id': warrant.id} capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def election_convoke_capability_view(request, capability_id): capability = get_object_or_404(Capability, id=capability_id, type=Capability.CONVOKE_ELECTIONS) months_to_election = int(request.POST.get('months_to_election')) if not 6 <= months_to_election <= 16: messages.error(request, "The time period must be between 6 and 18 months", "danger") return redirect(capability.get_absolute_url()) proposal = {'months_to_election': months_to_election} capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def banning_capability_view(request, capability_id): capability = get_object_or_404(Capability, id=capability_id, type=Capability.BAN) character_to_ban = get_object_or_404( Character, id=request.POST.get('character_to_ban_id')) if character_to_ban not in capability.applying_to.character_members.all(): return redirect_back(request, reverse('character:character_home'), error_message="You cannot do that") proposal = {'character_id': character_to_ban.id} capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def arrest_warrant_capability_view(request, capability_id): capability = get_object_or_404(Capability, id=capability_id, type=Capability.ARREST_WARRANT) target_character = get_object_or_404( Character, id=request.POST.get('character_to_imprison_id')) if target_character.world != capability.applying_to.world: return redirect_back(request, reverse('character:character_home'), error_message="You cannot do that") proposal = {'action': 'issue', 'character_id': target_character.id} capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def formation_capability_view(request, capability_id): capability = get_object_or_404(Capability, id=capability_id, type=Capability.BATTLE_FORMATION) new_formation = request.POST['new_formation'] if new_formation not in formation_validity_checks.keys(): raise Http404("Invalid formation") else: element_size, spacing = formation_validity_checks[new_formation]( request) proposal = { 'formation': new_formation, 'spacing': spacing, 'element_size': element_size } capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def guilds_settings_capability_view(request, capability_id): capability = get_object_or_404( Capability, id=capability_id, type=Capability.GUILDS) settlement = get_object_or_404( Settlement, id=request.POST.get('settlement_id')) target_option = request.POST.get('option') if target_option not in [choice[0] for choice in Settlement.GUILDS_CHOICES]: raise Http404("Chosen option not valid") if (settlement.tile not in capability.applying_to.get_all_controlled_tiles()): raise Http404("Settlement not under control") proposal = { 'settlement_id': settlement.id, 'option': target_option } capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def heir_capability_view(request, capability_id): capability = get_object_or_404( Capability, id=capability_id, type=Capability.HEIR) first_heir_id = request.POST.get('first_heir') second_heir_id = request.POST.get('second_heir') try: first_heir = Character.objects.get(id=first_heir_id) except Character.DoesNotExist: first_heir = None try: second_heir = Character.objects.get(id=second_heir_id) except Character.DoesNotExist: second_heir = None if ( first_heir not in capability.applying_to.get_heir_candidates() or first_heir == capability.applying_to.get_position_occupier() ): messages.error(request, "Invalid first heir", "danger") return redirect(capability.get_absolute_url()) if ( second_heir not in capability.applying_to.get_heir_candidates() or second_heir == capability.applying_to.get_position_occupier() ) and second_heir is not None: messages.error(request, "Invalid second heir", "danger") return redirect(capability.get_absolute_url()) proposal = { 'first_heir': first_heir.id, 'second_heir': second_heir.id if second_heir is not None else 0 } capability.create_proposal(request.hero, proposal) return capability_success(capability, request)
def post(self, request, capability_id, document_id=None): if 'delete' in request.POST.keys() and document_id is None: return redirect_back(request, reverse('character:character_home'), error_message="You cannot do that") capability = get_object_or_404( Capability, id=capability_id, type=Capability.POLICY_DOCUMENT) if document_id is None: new_document = True else: document = get_object_or_404(PolicyDocument, id=document_id) new_document = False proposal = { 'new': new_document, 'document_id': None if new_document else document.id, 'delete': 'delete' in request.POST.keys(), 'title': request.POST.get('title'), 'body': request.POST.get('body'), 'public': request.POST.get('public'), } capability.create_proposal(request.hero, proposal) return capability_success(capability, request)