You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.1 KiB
Python

1 year ago
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.views import View
from mixins.views import (
ObjectCreate,
ObjectDelete,
ObjectList,
ObjectNameMixin,
ObjectUpdate,
)
1 year ago
from two_factor.views.mixins import OTPRequiredMixin
from core.forms import PayoutForm
from core.models import Payout
class PayoutList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
list_template = "partials/payout-list.html"
model = Payout
page_title = "List of payouts"
page_subtitle = (
"Payouts are informational only. "
"Adjustments and creations will not have any effect."
)
list_url_name = "payouts"
list_url_args = ["type"]
submit_url_name = "payout_create"
delete_all_url_name = "payout_delete_all"
1 year ago
# 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",
# },
# {
# "url": reverse("cheat"),
# "action": "cheat",
# "method": "get",
# "label": "Run cheat",
# "icon": "fa-solid fa-bolt",
# },
# {
# "url": reverse("ad_nuke"),
# "action": "nuke",
# "method": "get",
# "label": "Nuke ads",
# "icon": "fa-solid fa-bomb",
# "confirm": True,
# },
# {
# "url": reverse("ad_dedup"),
# "action": "deduplicate",
# "method": "get",
# "label": "Deduplicate ads",
# "icon": "fa-thin fa-copy",
# "confirm": True,
# },
# ]
# return context
class PayoutCreate(LoginRequiredMixin, OTPRequiredMixin, ObjectCreate):
model = Payout
form_class = PayoutForm
submit_url_name = "payout_create"
class PayoutUpdate(LoginRequiredMixin, OTPRequiredMixin, ObjectUpdate):
model = Payout
form_class = PayoutForm
submit_url_name = "payout_update"
class PayoutDelete(LoginRequiredMixin, OTPRequiredMixin, ObjectDelete):
model = Payout
class PayoutDeleteAll(LoginRequiredMixin, OTPRequiredMixin, ObjectNameMixin, View):
template_name = "mixins/partials/notify.html"
model = Payout
def delete(self, request):
"""
Delete all payouts by the current user.
"""
Payout.objects.filter(user=request.user).delete()
context = {"message": "All payouts deleted", "class": "success"}
response = render(request, self.template_name, context)
response["HX-Trigger"] = f"{self.context_object_name_singular}Event"
return response