Fix referencing link groups in ad functions
This commit is contained in:
parent
44b85796fa
commit
ae4e5ae964
|
@ -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,17 +7,30 @@ 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():
|
||||
platforms = get_platforms(request.user)
|
||||
for platform in platforms:
|
||||
run = synchronize_async_helper(AgoraClient(platform))
|
||||
synchronize_async_helper(run.cheat())
|
||||
|
||||
|
@ -29,9 +42,8 @@ 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():
|
||||
platforms = get_platforms(request.user)
|
||||
for platform in platforms:
|
||||
run = synchronize_async_helper(AgoraClient(platform))
|
||||
synchronize_async_helper(run.nuke_ads())
|
||||
|
||||
|
@ -45,7 +57,8 @@ 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():
|
||||
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))
|
||||
|
||||
|
@ -59,7 +72,8 @@ 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():
|
||||
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))
|
||||
|
||||
|
|
Loading…
Reference in New Issue