Implement nuking ads

This commit is contained in:
Mark Veidemanis 2023-03-10 15:27:30 +00:00
parent bf65d028f1
commit 7f088d15c2
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 35 additions and 7 deletions

View File

@ -20,7 +20,7 @@ from django.contrib.auth.views import LogoutView
from django.urls import include, path from django.urls import include, path
from two_factor.urls import urlpatterns as tf_urls from two_factor.urls import urlpatterns as tf_urls
from core.views import ads, aggregators, banks, base, notifications, platforms from core.views import aggregators, banks, base, notifications, platforms, ads
# from core.views.stripe_callbacks import Callback # from core.views.stripe_callbacks import Callback
@ -175,6 +175,11 @@ urlpatterns = [
ads.AdDist.as_view(), ads.AdDist.as_view(),
name="ad_dist", name="ad_dist",
), ),
path(
"ops/ads/nuke/",
ads.AdNuke.as_view(),
name="ad_nuke",
),
path( path(
"ops/ads/redist/", "ops/ads/redist/",
ads.AdRedist.as_view(), ads.AdRedist.as_view(),

View File

@ -667,14 +667,17 @@ class LocalPlatformClient(ABC):
account_info, account_info,
) = self.get_valid_account_details(ad) ) = self.get_valid_account_details(ad)
# Let's get rid of the ad IDs and make it a tuple like dist_list # Let's get rid of the ad IDs and make it a tuple like dist_list
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads] if our_ads in [None, False]:
if not our_ads: log.error("Could not get our ads")
log.error("Could not get our ads.")
return False return False
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]
to_return = [] to_return = []
for asset, countrycode, currency, provider in dist_list: for asset, countrycode, currency, provider in dist_list:
if (asset, countrycode, currency, provider) not in our_ads: if (asset, countrycode, currency, provider) not in our_ads:
if currency in supported_currencies: if currency in supported_currencies:
if currency not in account_info:
continue
# Create the actual ad and pass in all the stuff # Create the actual ad and pass in all the stuff
rtrn = await self.create_ad( rtrn = await self.create_ad(
asset, asset,

View File

@ -14,7 +14,8 @@ class ContactDataAd(BaseModel):
trade_type: str trade_type: str
advertiser: ContactDataBuyerSeller advertiser: ContactDataBuyerSeller
asset: str asset: str
id: str id: str | None
contact_id: str | None
class ContactData(BaseModel): class ContactData(BaseModel):
@ -51,8 +52,8 @@ class ContactData(BaseModel):
class ContactActions(BaseModel): class ContactActions(BaseModel):
advertisement_public_view: str advertisement_public_view: str | None
advertisement_url: str advertisement_url: str | None
message_post_url: str message_post_url: str
messages_url: str messages_url: str
release_url: str release_url: str

View File

@ -17,6 +17,18 @@ from core.models import Ad
from core.util import logs from core.util import logs
from core.views.helpers import synchronize_async_helper from core.views.helpers import synchronize_async_helper
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())
context = {"class": "success", "message": "Nuking ads"}
return render(request, self.template_name, context)
class AdDist(LoginRequiredMixin, OTPRequiredMixin, View): class AdDist(LoginRequiredMixin, OTPRequiredMixin, View):
template_name = "mixins/partials/notify.html" template_name = "mixins/partials/notify.html"
@ -73,6 +85,13 @@ class AdList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
"label": "Update ads", "label": "Update ads",
"icon": "fa-solid fa-refresh", "icon": "fa-solid fa-refresh",
}, },
{
"url": reverse("ad_nuke"),
"action": "nuke",
"method": "get",
"label": "Nuke ads",
"icon": "fa-solid fa-bomb",
},
] ]
return context return context