From 45d306eb8b4c09425935b6bc53517264e2047ecd Mon Sep 17 00:00:00 2001 From: Swiftkilla123 <165085079+Swiftkilla123@users.noreply.github.com> Date: Tue, 9 Apr 2024 18:16:30 +0100 Subject: [PATCH 1/6] Update target.html move the title to the cell text, also ensure we display something meaningful if we don't have the information on destination resolves: #570 --- templates/faction/war/target.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/faction/war/target.html b/templates/faction/war/target.html index c87f1961..e1edbd89 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 @@ -49,7 +50,7 @@ {% if target.status_color == "blue" %} {{target.status_description}} {% else %} - {{target.status_description}} + {% if target.status_details %}{{target.status_details|cleanhtml}}{% else %}{{target.status_description}}{% endif %} {% endif %} From c724b27037bea84bcd1d532c69f0560d5295a1b9 Mon Sep 17 00:00:00 2001 From: Swiftkilla123 <165085079+Swiftkilla123@users.noreply.github.com> Date: Tue, 9 Apr 2024 18:40:11 +0100 Subject: [PATCH 2/6] move last commit moved to correct if statement, travelling is "blue" resolves: #570 --- templates/faction/war/target.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/faction/war/target.html b/templates/faction/war/target.html index e1edbd89..5c4b7168 100644 --- a/templates/faction/war/target.html +++ b/templates/faction/war/target.html @@ -48,9 +48,9 @@ {% if target.status_color == "blue" %} - {{target.status_description}} + {% if target.status_details %}{{target.status_details|cleanhtml}}{% else %}{{target.status_description}}{% endif %} {% else %} - {% if target.status_details %}{{target.status_details|cleanhtml}}{% else %}{{target.status_description}}{% endif %} + {{target.status_description}} {% endif %} From f656e05360db0ee52d8fba7a68bd16c9127948d7 Mon Sep 17 00:00:00 2001 From: Swiftkilla123 <165085079+Swiftkilla123@users.noreply.github.com> Date: Tue, 9 Apr 2024 18:41:54 +0100 Subject: [PATCH 3/6] Update target.html one small further change to revert --- templates/faction/war/target.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/faction/war/target.html b/templates/faction/war/target.html index 5c4b7168..04373228 100644 --- a/templates/faction/war/target.html +++ b/templates/faction/war/target.html @@ -50,7 +50,7 @@ {% if target.status_color == "blue" %} {% if target.status_details %}{{target.status_details|cleanhtml}}{% else %}{{target.status_description}}{% endif %} {% else %} - {{target.status_description}} + {{target.status_description}} {% endif %} From f63fe86e6a2052b0c8073e71d2a4423e04b582c4 Mon Sep 17 00:00:00 2001 From: Swiftkilla123 <165085079+swiftkilla123@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:36:11 +0100 Subject: [PATCH 4/6] better display for travel status resolves: #570 --- player/templatetags/app_filters.py | 17 +++++++++++++++-- templates/faction/war/target.html | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/player/templatetags/app_filters.py b/player/templatetags/app_filters.py index 3ad01d91..9e15a052 100644 --- a/player/templatetags/app_filters.py +++ b/player/templatetags/app_filters.py @@ -178,13 +178,26 @@ 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 raw_html + + @register.filter(name="string2List") def string2List(string): string = string.replace('"', "'") diff --git a/templates/faction/war/target.html b/templates/faction/war/target.html index 04373228..0fb8280f 100644 --- a/templates/faction/war/target.html +++ b/templates/faction/war/target.html @@ -48,7 +48,7 @@ {% if target.status_color == "blue" %} - {% if target.status_details %}{{target.status_details|cleanhtml}}{% else %}{{target.status_description}}{% endif %} + {% if target.status_details %}{{target.status_details|clean_travel_status}}{% else %}{{target.status_description}}{% endif %} {% else %} {{target.status_description}} {% endif %} From e4a674b91995782fbafc28e2aacb487959d8b327 Mon Sep 17 00:00:00 2001 From: Swiftkilla123 <165085079+Swiftkilla123@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:45:43 +0100 Subject: [PATCH 5/6] correct return fallback resolves: #570 --- player/templatetags/app_filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player/templatetags/app_filters.py b/player/templatetags/app_filters.py index 9e15a052..bbad58c0 100644 --- a/player/templatetags/app_filters.py +++ b/player/templatetags/app_filters.py @@ -195,7 +195,7 @@ def clean_travel_status(raw_html): travel_text = travel_text[0].upper() + travel_text[1:] return travel_text - return raw_html + return cleantext @register.filter(name="string2List") From 202e4617260d1f4bfb38c4099c5e45d07655fa8e Mon Sep 17 00:00:00 2001 From: Swiftkilla123 <165085079+Swiftkilla123@users.noreply.github.com> Date: Sat, 13 Apr 2024 11:45:46 +0100 Subject: [PATCH 6/6] implements transferring rw targets to personal targets --- faction/models.py | 4 +++- faction/views.py | 27 ++++++++++++++++++++++++-- target/views.py | 11 +++++++++-- templates/faction/war/index.html | 3 +++ templates/faction/war/target.html | 5 +++++ templates/faction/war/targets.html | 30 +++++++++++++++++++++++++++-- templates/target/targets/index.html | 2 ++ templates/target/targets/line.html | 7 +++++++ 8 files changed, 82 insertions(+), 7 deletions(-) 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/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 0fb8280f..9a5404e3 100644 --- a/templates/faction/war/target.html +++ b/templates/faction/war/target.html @@ -57,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.