97 lines
3.4 KiB
Python
97 lines
3.4 KiB
Python
from django.shortcuts import render, redirect
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.urls import reverse_lazy
|
|
from accounts import resource_action
|
|
from django.views import generic
|
|
from django.contrib import messages
|
|
from goodtimes import constants
|
|
from .models import PrincipalBankAccount, Wallet, Transaction, WithdrawalRequest
|
|
|
|
"""Wallet Related VIew"""
|
|
|
|
|
|
class WalletListView(LoginRequiredMixin, generic.TemplateView):
|
|
page_name = resource_action.RESOURCE_MANAGE_WALLET
|
|
template_name = "manage_wallets/wallet_list.html"
|
|
model = Wallet
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context["page_name"] = self.page_name
|
|
context["wallet_objs"] = Wallet.objects.filter(deleted=False)
|
|
return context
|
|
|
|
|
|
"""Payment Related View"""
|
|
|
|
|
|
class PaymentListView(LoginRequiredMixin, generic.TemplateView):
|
|
page_name = resource_action.RESOURCE_MANAGE_PAYMENT
|
|
template_name = "manage_wallets/payment_list.html"
|
|
model = Transaction
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context["page_name"] = self.page_name
|
|
context["transaction_objs"] = Transaction.objects.filter(deleted=False)
|
|
return context
|
|
|
|
|
|
"""Withdrawals Related View"""
|
|
|
|
|
|
class WithdrawalListView(LoginRequiredMixin, generic.TemplateView):
|
|
page_name = resource_action.RESOURCE_MANAGE_WITHDRAWALS
|
|
template_name = "manage_wallets/withdrawal_list.html"
|
|
model = WithdrawalRequest
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context["page_name"] = self.page_name
|
|
context["withdrawal_objs"] = WithdrawalRequest.objects.filter(deleted=False)
|
|
return context
|
|
|
|
|
|
"""Bank Accounts Related View"""
|
|
|
|
|
|
class BankAccountListView(LoginRequiredMixin, generic.TemplateView):
|
|
page_name = resource_action.RESOURCE_MANAGE_BANK_ACCOUNTS
|
|
template_name = "manage_wallets/account_list.html"
|
|
model = PrincipalBankAccount
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context["page_name"] = self.page_name
|
|
context["account_objs"] = PrincipalBankAccount.objects.filter(deleted=False)
|
|
return context
|
|
|
|
|
|
class StatusUpdateView(LoginRequiredMixin, generic.View):
|
|
page_name = resource_action.RESOURCE_MANAGE_WITHDRAWALS
|
|
model = WithdrawalRequest
|
|
success_message = constants.DATA_SAVED
|
|
success_url = reverse_lazy("manage_wallets:withdrawal_list")
|
|
|
|
def post(self, request):
|
|
id = request.POST.get("id")
|
|
message = request.POST.get("message")
|
|
status = request.POST.get("status")
|
|
print("Request.POST: ", request.POST)
|
|
if id or message:
|
|
try:
|
|
instance = self.model.objects.get(id=id)
|
|
instance.reply = message
|
|
instance.status = status
|
|
instance.save()
|
|
messages.success(request, self.success_message)
|
|
except self.model.DoesNotExist:
|
|
messages.error(request, "Contact Us entry not found")
|
|
except Exception as e:
|
|
messages.error(request, str(e))
|
|
else:
|
|
messages.error(request, "Missing 'id' or 'message' in the request")
|
|
|
|
# Redirect to the desired URL after form submission
|
|
return redirect(self.success_url)
|