From 1c2b63a7fb8bf3b3a2eaa92a4fc511cca7c4b107 Mon Sep 17 00:00:00 2001 From: mahdavi Date: Sun, 4 Sep 2022 17:50:09 +0430 Subject: [PATCH] transaction home --- apps/users/urls.py | 13 +++++++------ apps/users/views.py | 12 ++++++++++++ apps/wallet/urls.py | 20 +++++++++++--------- apps/wallet/views.py | 13 +++++++++++++ templates/wallet/transaction_list.html | 8 ++++++++ 5 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 templates/wallet/transaction_list.html diff --git a/apps/users/urls.py b/apps/users/urls.py index d14083e..f96e414 100644 --- a/apps/users/urls.py +++ b/apps/users/urls.py @@ -1,16 +1,17 @@ from django.urls import path from django.contrib.auth.views import LogoutView from .views import UserListView, UserDetailView, AccountView, RequestOTPView, ChangePasswordView, \ - OTPLoginView + OTPLoginView, ProfileView app_name = "users" urlpatterns = [ path('login/', OTPLoginView.as_view(), name='login'), path('logout/', LogoutView.as_view(), name='logout'), - path('api/account/', AccountView.as_view(), name='account'), - path('api/users/', UserListView.as_view()), - path('api/users//', UserDetailView.as_view(), name='user_detail'), - path('api/request_otp/', RequestOTPView.as_view(), name='request_otp'), - path('api/change_password/', ChangePasswordView.as_view(), name='change_password'), + path('profile/', ProfileView.as_view(), name='profile'), + path('api/account/', AccountView.as_view(), name='account_api'), + path('api/users/', UserListView.as_view(), name='user_list_api'), + path('api/users//', UserDetailView.as_view(), name='user_detail_api'), + path('api/request_otp/', RequestOTPView.as_view(), name='request_otp_api'), + path('api/change_password/', ChangePasswordView.as_view(), name='change_password_api'), ] diff --git a/apps/users/views.py b/apps/users/views.py index 2eb5b0d..4ef4ce4 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -3,6 +3,8 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.views import LoginView from django.shortcuts import render from django.utils import timezone +from django.utils.decorators import method_decorator +from django.views.generic import DetailView from oauth2_provider.contrib.rest_framework import IsAuthenticatedOrTokenHasScope from rest_framework import generics, status, permissions from rest_framework.response import Response @@ -95,6 +97,16 @@ class ChangePasswordView(generics.UpdateAPIView): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) +@method_decorator(login_required, name='dispatch') +class ProfileView(DetailView): + model = User + template_name = 'registration/profile.html' + pk_url_kwarg = 'uuid' + + def get_object(self, queryset=None): + return self.request.user + + class OTPLoginView(LoginView): """ Display the login form and handle the login action. diff --git a/apps/wallet/urls.py b/apps/wallet/urls.py index cb84f3f..47d021c 100644 --- a/apps/wallet/urls.py +++ b/apps/wallet/urls.py @@ -1,17 +1,19 @@ from django.urls import path from .views import TransactionList, TransactionDetail, TransactionPay, TransactionReceipt, \ - WithdrawVerify, WithdrawSubmit, DepositSubmit, DepositVerify + WithdrawVerify, WithdrawSubmit, DepositSubmit, DepositVerify, TransactionListView + app_name = "wallet" urlpatterns = [ - path('transactions/', TransactionList.as_view(), name='transactions'), - path('transactions/', TransactionDetail.as_view(), name='transaction_detail'), - path('transactions//pay', TransactionPay.as_view(), name='transaction_pay'), - path('transactions//receipt', TransactionReceipt.as_view(), name='transaction_receipt'), + path('transactions/', TransactionListView.as_view(), name='transaction_list'), + path('api/transactions/', TransactionList.as_view(), name='transaction_list_api'), + path('api/transactions/', TransactionDetail.as_view(), name='transaction_detail_api'), + path('api/transactions//pay', TransactionPay.as_view(), name='transaction_pay_api'), + path('api/transactions//receipt', TransactionReceipt.as_view(), name='transaction_receipt_api'), # - path('deposit/', DepositSubmit.as_view(), name='deposit_submit'), - path('deposit//verify', DepositVerify.as_view(), name='deposit_verify'), + path('api/deposit/', DepositSubmit.as_view(), name='deposit_submit_api'), + path('api/deposit//verify', DepositVerify.as_view(), name='deposit_verify_api'), # - path('withdraw/', WithdrawSubmit.as_view(), name='withdraw_submit'), - path('withdraw//verify', WithdrawVerify.as_view(), name='withdraw_verify'), + path('api/withdraw/', WithdrawSubmit.as_view(), name='withdraw_submit_api'), + path('api/withdraw//verify', WithdrawVerify.as_view(), name='withdraw_verify_api'), ] \ No newline at end of file diff --git a/apps/wallet/views.py b/apps/wallet/views.py index 1b3dce4..18caa70 100755 --- a/apps/wallet/views.py +++ b/apps/wallet/views.py @@ -1,4 +1,7 @@ +from django.contrib.auth.decorators import login_required from django.db.models import Q +from django.utils.decorators import method_decorator +from django.views.generic import DetailView, ListView from oauth2_provider.contrib.rest_framework import TokenHasScope, IsAuthenticatedOrTokenHasScope from rest_framework import generics, permissions @@ -148,3 +151,13 @@ class WithdrawVerify(generics.RetrieveAPIView): serializer = self.get_serializer(instance) return Response(serializer.data) + + +@method_decorator(login_required, name='dispatch') +class TransactionListView(ListView): + model = Transaction + template_name = 'wallet/transaction_list.html' + + def get_queryset(self): + user = self.request.user + return Transaction.objects.filter(Q(payee=user) | Q(payer=user)).all() diff --git a/templates/wallet/transaction_list.html b/templates/wallet/transaction_list.html new file mode 100644 index 0000000..1c73cc9 --- /dev/null +++ b/templates/wallet/transaction_list.html @@ -0,0 +1,8 @@ +{% extends "base_generic.html" %} + +{% block content %} + {% for transaction in object_list %} + {{ transaction }} + {% endfor %} + +{% endblock %} \ No newline at end of file