2020-12-25 09:11:13 +00:00
|
|
|
from django.views.generic.base import TemplateView
|
2021-07-19 14:36:10 +00:00
|
|
|
from django.contrib import messages
|
|
|
|
from django.shortcuts import redirect
|
2020-12-25 09:11:13 +00:00
|
|
|
|
2021-05-25 17:55:33 +00:00
|
|
|
from uncloud_pay.selectors import get_balance_for_user
|
2021-07-19 14:36:10 +00:00
|
|
|
from .forms import UserDeleteForm
|
2021-05-25 17:55:33 +00:00
|
|
|
|
2020-12-25 09:11:13 +00:00
|
|
|
class UncloudIndex(TemplateView):
|
|
|
|
template_name = "uncloud/index.html"
|
2021-05-25 17:55:33 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
if self.request.user.is_authenticated:
|
|
|
|
context['balance'] = get_balance_for_user(self.request.user)
|
2021-07-19 14:36:10 +00:00
|
|
|
context['delete_form'] = UserDeleteForm(instance=self.request.user)
|
2021-05-25 17:55:33 +00:00
|
|
|
return context
|
2021-07-19 14:36:10 +00:00
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
UserDeleteForm(request.POST, instance=request.user)
|
|
|
|
user = request.user
|
|
|
|
user.delete()
|
|
|
|
messages.info(request, 'Your account has been deleted.')
|
|
|
|
return redirect('uncloudindex')
|