From de559f8c4041502f576986ee07f73e20133d5d11 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 10 Mar 2023 00:42:28 +0000 Subject: [PATCH] Begin ad CRUD --- core/migrations/0009_asset_provider_ad.py | 48 +++++++++++++++++++++ core/models.py | 52 +++++++++++++++++++++++ core/views/ads.py | 48 +++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 core/migrations/0009_asset_provider_ad.py create mode 100644 core/views/ads.py diff --git a/core/migrations/0009_asset_provider_ad.py b/core/migrations/0009_asset_provider_ad.py new file mode 100644 index 0000000..3de5488 --- /dev/null +++ b/core/migrations/0009_asset_provider_ad.py @@ -0,0 +1,48 @@ +# Generated by Django 4.1.7 on 2023-03-10 00:41 + +import uuid + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0008_platform'), + ] + + operations = [ + migrations.CreateModel( + name='Asset', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('code', models.CharField(max_length=64)), + ('name', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Provider', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('code', models.CharField(max_length=64)), + ('name', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Ad', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=255)), + ('text', models.TextField()), + ('payment_details', models.TextField()), + ('payment_details_real', models.TextField()), + ('payment_method_details', models.CharField(max_length=255)), + ('dist_list', models.TextField()), + ('asset_list', models.ManyToManyField(to='core.asset')), + ('provider_list', models.ManyToManyField(to='core.provider')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/core/models.py b/core/models.py index d111065..fb97414 100644 --- a/core/models.py +++ b/core/models.py @@ -133,3 +133,55 @@ class Platform(models.Model): @property def account_info(self): return Aggregator.get_account_info_for_platform(self) + + +class Asset(models.Model): + code = models.CharField(max_length=64) + name = models.CharField(max_length=255) + + +class Provider(models.Model): + code = models.CharField(max_length=64) + name = models.CharField(max_length=255) + + +class Ad(models.Model): + """ + An advert definition + """ + + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + user = models.ForeignKey(User, on_delete=models.CASCADE) + name = models.CharField(max_length=255) + + text = models.TextField() + + # Shown when the user opens a trade + payment_details = models.TextField() + + # Shown after + payment_details_real = models.TextField() + + payment_method_details = models.CharField(max_length=255) + + dist_list = models.TextField() + + asset_list = models.ManyToManyField(Asset) + provider_list = models.ManyToManyField(Provider) + + +# assets = { +# "XMR": "Monero", +# "BTC": "Bitcoin", +# } +# providers = { +# "REVOLUT": "Revolut", +# "NATIONAL_BANK": "Bank transfer", +# } +# for code, name in assets.items(): +# if not Asset.objects.filter(code=code).exists(): +# Asset.objects.create(code=code, name=name) + +# for code, name in providers.items(): +# if not Provider.objects.filter(code=code).exists(): +# Provider.objects.create(code=code, name=name) diff --git a/core/views/ads.py b/core/views/ads.py new file mode 100644 index 0000000..149b828 --- /dev/null +++ b/core/views/ads.py @@ -0,0 +1,48 @@ +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 +from mixins.views import ( + ObjectCreate, + ObjectDelete, + ObjectList, + ObjectRead, + ObjectUpdate, +) +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.util import logs +from core.views.helpers import synchronize_async_helper + + +class AdList(LoginRequiredMixin, OTPRequiredMixin, ObjectList): + list_template = "partials/ad-list.html" + model = Ad + page_title = "List of ad connections" + + list_url_name = "ads" + list_url_args = ["type"] + + submit_url_name = "ad_create" + + +class AdCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate): + model = Ad + form_class = AdForm + + submit_url_name = "ad_create" + + +class AdUpdate(LoginRequiredMixin, OTPRequiredMixin, ObjectUpdate): + model = Ad + form_class = AdForm + + submit_url_name = "ad_update" + + +class AdDelete(LoginRequiredMixin, OTPRequiredMixin, ObjectDelete): + model = Ad