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 @@
Status | Update | Dibs | +A | A | D | F | +RW | {% 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" %} ++ {% if targetId in faction_targets %} + + {% else %} + + {% endif %} + | {% else %}No recorded id. Will be deleted soon. | {% endif %}
---|