diff --git a/faction/models.py b/faction/models.py index 1219b1c1..3192504a 100644 --- a/faction/models.py +++ b/faction/models.py @@ -1272,7 +1272,9 @@ def getWarStatus(self): war["them"]["faction_id"] = int(fid) self.warAgainst = fid break - + # if you want to debug this + # you can return a crafted dictionary like so: + # return {'them': {'faction_id': 9528}, 'us': {'faction_id': 41363}} return war def updateFactionTargets(self): diff --git a/faction/views.py b/faction/views.py index aad90577..5c329d2a 100644 --- a/faction/views.py +++ b/faction/views.py @@ -57,8 +57,9 @@ RevivesReport, SpyDatabase, Territory, + FactionTarget, ) -from target.models import Target +from target.models import Target, TargetInfo from yata.bulkManager import BulkUpdateManager from yata.handy import ( apiCall, @@ -4670,10 +4671,23 @@ def fightclub(request): # SECTION: war def rankedWar(request): try: - if request.session.get("player"): player = getPlayer(request.session["player"].get("tId")) factionId = player.factionId + if 'remove_or_add' in request.POST: + # get the target list + new_target = request.POST.get('target_id') + add_target = request.POST.get('remove_or_add') == '1' + # get the target id of the ranked war page target + new_targets = FactionTarget.objects.filter(target_id=new_target).values_list('target_id', flat=True) + if not add_target: + player.targetinfo_set.filter(target_id__in=new_targets).delete() + else: + for selected_target in new_targets: + target_object, created = TargetInfo.objects.get_or_create(player=player, target_id=selected_target) + if created: + target_object.getTarget(update=True) + return JsonResponse({'success': 'Target added successfully'}, ) # get page page = "faction/content-reload.html" if request.method == "POST" else "faction.html" @@ -4687,11 +4701,16 @@ def rankedWar(request): error = False + player_targets = FactionTarget.objects.filter( + target_id__in=TargetInfo.objects.filter(player=player).values_list('target_id', flat=True) + ).values_list('target_id', flat=True) + context = { "player": player, "faction": faction, "factioncat": True, "view": {"war": True}, + "player_targets": player_targets, } if error: selectError = "apiErrorSub" if request.method == "POST" else "apiError" @@ -4754,6 +4773,9 @@ def wartargets(request): return render(request, "yata/error.html", context) targets = faction.updateFactionTargets() + player_targets = FactionTarget.objects.filter( + target_id__in=TargetInfo.objects.filter(player=player).values_list('target_id', flat=True) + ).values_list('target_id', flat=True) return render( request, @@ -4762,6 +4784,7 @@ def wartargets(request): "player": player, "faction": faction, "targets": targets, + "player_targets": player_targets, }, ) diff --git a/player/templatetags/app_filters.py b/player/templatetags/app_filters.py index 3ad01d91..bbad58c0 100644 --- a/player/templatetags/app_filters.py +++ b/player/templatetags/app_filters.py @@ -178,10 +178,23 @@ def playerURLShort(value, arg): @register.filter(name="cleanhtml") def cleanhtml(raw_html): - import re + cleanr = re.compile("<.*?>") + cleantext = re.sub(cleanr, "", raw_html) + return cleantext + +@register.filter(name='clean_travel_status') +def clean_travel_status(raw_html): cleanr = re.compile("<.*?>") cleantext = re.sub(cleanr, "", raw_html) + clean_travel_r = re.compile(r"^(?:Returning to Torn|Traveling)") + + if clean_travel_r.match(raw_html): + travel_text = re.sub(clean_travel_r, "", cleantext).strip() + if travel_text[0].islower(): + travel_text = travel_text[0].upper() + travel_text[1:] + return travel_text + return cleantext diff --git a/target/views.py b/target/views.py index 988c1918..dfe234e9 100644 --- a/target/views.py +++ b/target/views.py @@ -28,7 +28,7 @@ from django.shortcuts import redirect, render from django.views.decorators.csrf import csrf_exempt -from faction.models import Faction +from faction.models import Faction, FactionTarget from player.models import Key, Player from target.functions import getTargets, updateAttacks, updateRevives from yata.handy import apiCall, getFaction, getPlayer, returnError @@ -228,8 +228,15 @@ def attack(request): else: returnError(type=403, msg="Unknown request") + faction = getFaction(player.factionId) - context = {"v": attack, "targets": getTargets(player), "ts": int(time.time())} + faction_targets = FactionTarget.objects.filter(target_id__in=faction.getTargetsId()) + context = { + "v": attack, + "targets": getTargets(player), + "ts": int(time.time()), + "faction_targets": faction_targets.values_list("target_id", flat=True), + } return render(request, "target/attacks/button-target.html", context) else: diff --git a/templates/faction/war/index.html b/templates/faction/war/index.html index efb08117..fe090954 100644 --- a/templates/faction/war/index.html +++ b/templates/faction/war/index.html @@ -55,6 +55,9 @@

 Target list
+ diff --git a/templates/faction/war/target.html b/templates/faction/war/target.html index c87f1961..9a5404e3 100644 --- a/templates/faction/war/target.html +++ b/templates/faction/war/target.html @@ -1,3 +1,4 @@ +{% load i18n %} {% comment %} Copyright 2019 kivou.2000607@gmail.com @@ -47,7 +48,7 @@
{% if target.status_color == "blue" %} - {{target.status_description}} + {% if target.status_details %}{{target.status_details|clean_travel_status}}{% else %}{{target.status_description}}{% endif %} {% else %} {{target.status_description}} {% endif %} @@ -56,4 +57,9 @@ {% include "faction/war/dibs.html" %} + + + + + {% endif %} diff --git a/templates/faction/war/targets.html b/templates/faction/war/targets.html index 99504fae..c01f70ac 100644 --- a/templates/faction/war/targets.html +++ b/templates/faction/war/targets.html @@ -43,20 +43,45 @@ 9: function(node, table, cellIndex) { return $(node).attr("data-val"); }, 10: function(node, table, cellIndex) { return $(node).attr("data-val"); }, 11: function(node, table, cellIndex) { return $(node).attr("data-val"); }, + 14: function(node, table, cellIndex) {return $(node).attr("data-val"); }, }, cssAsc: 'up', cssDesc: 'down', - sortList: [[11,0],[7,1],[6,0]] + sortList: [[11,0],[7,1],[6,0],[14,0]] }); var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) }) + + $('.add-target').on('click tap', function (e) { + e.preventDefault(); + + var target_id = $(this).attr('data-val'); + var csrf_token = getCookie('csrftoken'); + var faction_id = "{{ faction.tId }}"; + var removeOrAdd = $(this).find('i').hasClass('fa-toggle-off') ? 1 : 0; + $(this).find('i').toggleClass('fa-toggle-off').toggleClass('fa-toggle-on'); + + const params = new URLSearchParams(); + params.set('target_id', target_id); + params.set('faction_id', faction_id); + params.set('csrfmiddlewaretoken', csrf_token); + params.set('remove_or_add', ''+removeOrAdd) + $.ajax({ + type: 'POST', + url: './?rank_target=1', + data: params.toString(), + success: function(data) { + // do something to show success + } + }); + }); }); -
+ @@ -74,6 +99,7 @@ + {% for target in targets %} diff --git a/templates/target/targets/index.html b/templates/target/targets/index.html index a9e02110..fb94631a 100644 --- a/templates/target/targets/index.html +++ b/templates/target/targets/index.html @@ -36,6 +36,7 @@ // console.log($(node).attr("data-col") + $(node).find("input.target-list-note").val() + "->" + a + "-" + b); return a + "-" + b; }, 12: function(node, table, cellIndex) { return $(node).attr("data-val"); }, + 15: function(node, table, cellIndex) { return $(node).attr("data-val"); }, }, cssAsc: 'up', cssDesc: 'down', @@ -83,6 +84,7 @@

+ {% for targetId, target in targets.items %} diff --git a/templates/target/targets/line.html b/templates/target/targets/line.html index b1397be3..0cedd245 100644 --- a/templates/target/targets/line.html +++ b/templates/target/targets/line.html @@ -69,6 +69,13 @@ {% include "target/targets/faction.html" %} + {% else %} {% endif %}
Status Update DibsA
A D FRW
+ {% if targetId in faction_targets %} + + {% else %} + + {% endif %} + No recorded id. Will be deleted soon.