Implement ad management

This commit is contained in:
2023-03-10 02:21:36 +00:00
parent de559f8c40
commit 3d43107586
12 changed files with 500 additions and 199 deletions

View File

@@ -1,5 +1,4 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse
from django.shortcuts import render
from django.urls import reverse
from django.views import View
@@ -19,16 +18,64 @@ from core.util import logs
from core.views.helpers import synchronize_async_helper
class AdDist(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.dist_countries(ad))
context = {"class": "success", "message": "Distributing ads"}
return render(request, self.template_name, context)
class AdRedist(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.redist_countries(ad))
context = {"class": "success", "message": "Updating ads"}
return render(request, self.template_name, context)
class AdList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
list_template = "partials/ad-list.html"
model = Ad
page_title = "List of ad connections"
page_title = "List of ads"
list_url_name = "ads"
list_url_args = ["type"]
submit_url_name = "ad_create"
def get_context_data(self):
context = super().get_context_data()
self.extra_buttons = [
{
"url": reverse("ad_dist"),
"action": "distribute",
"method": "get",
"label": "Distribute ads",
"icon": "fa-solid fa-upload",
},
{
"url": reverse("ad_redist"),
"action": "redistribute",
"method": "get",
"label": "Update ads",
"icon": "fa-solid fa-refresh",
},
]
return context
class AdCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate):
model = Ad

View File

@@ -36,7 +36,6 @@ class PlatformTrades(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
for platform in platforms:
run = synchronize_async_helper(AgoraClient(platform))
dash = synchronize_async_helper(run.wrap_dashboard())
print("DASH", dash)
total_trades[platform.name] = dash
return total_trades