Fix referencing link groups in ad functions

master
Mark Veidemanis 1 year ago
parent 44b85796fa
commit ae4e5ae964
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -87,6 +87,14 @@ class LinkGroup(models.Model):
return payees
@property
def platforms(self):
return Platform.objects.filter(link_group=self)
@property
def aggregators(self):
return Aggregator.objects.filter(link_group=self)
class Aggregator(models.Model):
"""

@ -7,19 +7,32 @@ from two_factor.views.mixins import OTPRequiredMixin
from core.clients.platforms.agora import AgoraClient
from core.forms import AdForm
from core.models import Ad
from core.models import Ad, LinkGroup
from core.views.helpers import synchronize_async_helper
def get_linkgroups(user):
return LinkGroup.objects.filter(user=user, enabled=True)
def get_platforms(user):
groups = get_linkgroups(user)
platforms = []
for group in groups:
for platform in group.platforms.all():
platforms.append(platform)
return platforms
class Cheat(LoginRequiredMixin, OTPRequiredMixin, View):
template_name = "mixins/partials/notify.html"
def get(self, request):
ads = Ad.objects.filter(user=request.user, enabled=True)
for ad in ads:
for platform in ad.platforms.all():
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.cheat())
platforms = get_platforms(request.user)
for platform in platforms:
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.cheat())
context = {"class": "success", "message": "Cheat run"}
return render(request, self.template_name, context)
@ -29,11 +42,10 @@ class AdNuke(LoginRequiredMixin, OTPRequiredMixin, View):
template_name = "mixins/partials/notify.html"
def get(self, request):
ads = Ad.objects.filter(user=request.user, enabled=True)
for ad in ads:
for platform in ad.platforms.all():
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.nuke_ads())
platforms = get_platforms(request.user)
for platform in platforms:
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.nuke_ads())
context = {"class": "success", "message": "Ads nuked"}
return render(request, self.template_name, context)
@ -45,9 +57,10 @@ class AdDist(LoginRequiredMixin, OTPRequiredMixin, View):
def get(self, request):
ads = Ad.objects.filter(user=request.user, enabled=True)
for ad in ads:
for platform in ad.platforms.all():
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.dist_countries(ad))
if ad.link_group is not None:
for platform in ad.link_group.platforms.all():
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.dist_countries(ad))
context = {"class": "success", "message": "Ads distributed"}
return render(request, self.template_name, context)
@ -59,9 +72,10 @@ class AdRedist(LoginRequiredMixin, OTPRequiredMixin, View):
def get(self, request):
ads = Ad.objects.filter(user=request.user, enabled=True)
for ad in ads:
for platform in ad.platforms.all():
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.redist_countries(ad))
if ad.link_group is not None:
for platform in ad.link_group.platforms.all():
run = synchronize_async_helper(AgoraClient(platform))
synchronize_async_helper(run.redist_countries(ad))
context = {"class": "success", "message": "Ads updated"}
return render(request, self.template_name, context)

Loading…
Cancel
Save