django-cfg 1.2.27__py3-none-any.whl → 1.2.29__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. django_cfg/__init__.py +1 -1
  2. django_cfg/apps/payments/services/providers/cryptomus.py +2 -1
  3. django_cfg/apps/payments/static/payments/css/payments.css +340 -0
  4. django_cfg/apps/payments/static/payments/js/notifications.js +202 -0
  5. django_cfg/apps/payments/static/payments/js/payment-utils.js +318 -0
  6. django_cfg/apps/payments/static/payments/js/theme.js +86 -0
  7. django_cfg/apps/payments/templates/payments/base.html +182 -0
  8. django_cfg/apps/payments/templates/payments/components/payment_card.html +201 -0
  9. django_cfg/apps/payments/templates/payments/components/payment_qr_code.html +109 -0
  10. django_cfg/apps/payments/templates/payments/components/progress_bar.html +36 -0
  11. django_cfg/apps/payments/templates/payments/components/provider_stats.html +40 -0
  12. django_cfg/apps/payments/templates/payments/components/status_badge.html +27 -0
  13. django_cfg/apps/payments/templates/payments/components/status_overview.html +144 -0
  14. django_cfg/apps/payments/templates/payments/dashboard.html +346 -0
  15. django_cfg/apps/payments/templatetags/__init__.py +1 -0
  16. django_cfg/apps/payments/templatetags/payments_tags.py +315 -0
  17. django_cfg/apps/payments/urls_templates.py +52 -0
  18. django_cfg/apps/payments/views/templates/__init__.py +25 -0
  19. django_cfg/apps/payments/views/templates/ajax.py +312 -0
  20. django_cfg/apps/payments/views/templates/base.py +204 -0
  21. django_cfg/apps/payments/views/templates/dashboard.py +60 -0
  22. django_cfg/apps/payments/views/templates/payment_detail.py +102 -0
  23. django_cfg/apps/payments/views/templates/payment_management.py +164 -0
  24. django_cfg/apps/payments/views/templates/qr_code.py +174 -0
  25. django_cfg/apps/payments/views/templates/stats.py +240 -0
  26. django_cfg/apps/payments/views/templates/utils.py +181 -0
  27. django_cfg/apps/urls.py +3 -0
  28. django_cfg/registry/core.py +1 -0
  29. django_cfg/template_archive/.gitignore +1 -0
  30. django_cfg/template_archive/django_sample.zip +0 -0
  31. {django_cfg-1.2.27.dist-info → django_cfg-1.2.29.dist-info}/METADATA +12 -15
  32. {django_cfg-1.2.27.dist-info → django_cfg-1.2.29.dist-info}/RECORD +35 -10
  33. {django_cfg-1.2.27.dist-info → django_cfg-1.2.29.dist-info}/WHEEL +0 -0
  34. {django_cfg-1.2.27.dist-info → django_cfg-1.2.29.dist-info}/entry_points.txt +0 -0
  35. {django_cfg-1.2.27.dist-info → django_cfg-1.2.29.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,52 @@
1
+ """
2
+ Template URLs for Payment Dashboard.
3
+
4
+ All URLs require superuser access as this is an internal admin tool.
5
+ """
6
+
7
+ from django.urls import path
8
+ from .views.templates import (
9
+ PaymentDashboardView,
10
+ PaymentDetailView,
11
+ PaymentCreateView,
12
+ PaymentStatsView,
13
+ PaymentListView,
14
+ PaymentQRCodeView,
15
+ PaymentTestView,
16
+ payment_status_ajax,
17
+ payment_events_ajax,
18
+ )
19
+ from .views.templates.ajax import (
20
+ payment_stats_ajax,
21
+ payment_search_ajax,
22
+ payment_action_ajax,
23
+ )
24
+ from .views.templates.qr_code import qr_code_data_ajax
25
+
26
+ app_name = 'payments_dashboard'
27
+
28
+ urlpatterns = [
29
+ # Main dashboard
30
+ path('', PaymentDashboardView.as_view(), name='dashboard'),
31
+ path('dashboard/', PaymentDashboardView.as_view(), name='dashboard_alt'),
32
+
33
+ # Payment management
34
+ path('list/', PaymentListView.as_view(), name='list'),
35
+ path('create/', PaymentCreateView.as_view(), name='create'),
36
+ path('stats/', PaymentStatsView.as_view(), name='stats'),
37
+
38
+ # Payment details
39
+ path('payment/<uuid:pk>/', PaymentDetailView.as_view(), name='detail'),
40
+ path('payment/<uuid:pk>/qr/', PaymentQRCodeView.as_view(), name='qr_code'),
41
+
42
+ # AJAX endpoints
43
+ path('ajax/payment/<uuid:payment_id>/status/', payment_status_ajax, name='payment_status_ajax'),
44
+ path('ajax/payment/<uuid:payment_id>/events/', payment_events_ajax, name='payment_events_ajax'),
45
+ path('ajax/payment/<uuid:payment_id>/qr-data/', qr_code_data_ajax, name='qr_data_ajax'),
46
+ path('ajax/payment/<uuid:payment_id>/action/', payment_action_ajax, name='payment_action_ajax'),
47
+ path('ajax/stats/', payment_stats_ajax, name='payment_stats_ajax'),
48
+ path('ajax/search/', payment_search_ajax, name='payment_search_ajax'),
49
+
50
+ # Development/testing
51
+ path('test/', PaymentTestView.as_view(), name='test'),
52
+ ]
@@ -0,0 +1,25 @@
1
+ """
2
+ Template views package for Payment Dashboard.
3
+
4
+ All views require superuser access as this is an internal admin tool.
5
+ """
6
+
7
+ from .dashboard import PaymentDashboardView
8
+ from .payment_detail import PaymentDetailView
9
+ from .payment_management import PaymentCreateView, PaymentListView
10
+ from .stats import PaymentStatsView
11
+ from .qr_code import PaymentQRCodeView
12
+ from .ajax import payment_status_ajax, payment_events_ajax
13
+ from .utils import PaymentTestView
14
+
15
+ __all__ = [
16
+ 'PaymentDashboardView',
17
+ 'PaymentDetailView',
18
+ 'PaymentCreateView',
19
+ 'PaymentListView',
20
+ 'PaymentStatsView',
21
+ 'PaymentQRCodeView',
22
+ 'PaymentTestView',
23
+ 'payment_status_ajax',
24
+ 'payment_events_ajax',
25
+ ]
@@ -0,0 +1,312 @@
1
+ """
2
+ AJAX endpoints for payment dashboard.
3
+
4
+ Provides real-time data updates and interactive functionality.
5
+ """
6
+
7
+ from django.http import JsonResponse
8
+ from django.shortcuts import get_object_or_404
9
+ from django.utils import timezone
10
+ from .base import superuser_required, get_progress_percentage, log_view_access
11
+ from ...models import UniversalPayment, PaymentEvent
12
+
13
+
14
+ @superuser_required
15
+ def payment_status_ajax(request, payment_id):
16
+ """AJAX endpoint for real-time payment status."""
17
+ try:
18
+ payment = get_object_or_404(UniversalPayment, id=payment_id)
19
+
20
+ # Log access for audit
21
+ log_view_access('payment_status_ajax', request.user, payment_id=payment_id)
22
+
23
+ data = {
24
+ 'id': str(payment.id),
25
+ 'status': payment.status,
26
+ 'status_display': payment.get_status_display(),
27
+ 'progress_percentage': get_progress_percentage(payment.status),
28
+ 'amount_usd': float(payment.amount_usd),
29
+ 'currency_code': payment.currency_code,
30
+ 'provider': payment.provider,
31
+ 'provider_display': payment.provider.title(),
32
+ 'created_at': payment.created_at.isoformat(),
33
+ 'updated_at': payment.updated_at.isoformat(),
34
+ }
35
+
36
+ # Add completion time if available
37
+ if payment.completed_at:
38
+ data['completed_at'] = payment.completed_at.isoformat()
39
+
40
+ # Add crypto-specific data
41
+ if payment.provider in ['nowpayments', 'cryptapi', 'cryptomus']:
42
+ data.update({
43
+ 'is_crypto': True,
44
+ 'pay_address': payment.pay_address,
45
+ 'pay_amount': str(payment.pay_amount) if payment.pay_amount else None,
46
+ 'network': getattr(payment, 'network', None),
47
+ 'confirmations': getattr(payment, 'confirmations_count', 0),
48
+ })
49
+ else:
50
+ data['is_crypto'] = False
51
+
52
+ return JsonResponse(data)
53
+
54
+ except Exception as e:
55
+ return JsonResponse({'error': str(e)}, status=400)
56
+
57
+
58
+ @superuser_required
59
+ def payment_events_ajax(request, payment_id):
60
+ """AJAX endpoint for payment events."""
61
+ try:
62
+ payment = get_object_or_404(UniversalPayment, id=payment_id)
63
+
64
+ # Log access for audit
65
+ log_view_access('payment_events_ajax', request.user, payment_id=payment_id)
66
+
67
+ events = PaymentEvent.objects.filter(payment=payment).order_by('-created_at')
68
+
69
+ events_data = []
70
+ for event in events:
71
+ event_data = {
72
+ 'id': event.id,
73
+ 'event_type': event.event_type,
74
+ 'created_at': event.created_at.isoformat(),
75
+ 'metadata': event.metadata or {},
76
+ }
77
+
78
+ # Add human-readable description
79
+ event_data['description'] = _get_event_description(event)
80
+
81
+ events_data.append(event_data)
82
+
83
+ return JsonResponse({
84
+ 'events': events_data,
85
+ 'count': len(events_data)
86
+ })
87
+
88
+ except Exception as e:
89
+ return JsonResponse({'error': str(e)}, status=400)
90
+
91
+
92
+ @superuser_required
93
+ def payment_stats_ajax(request):
94
+ """AJAX endpoint for dashboard statistics."""
95
+ try:
96
+ # Log access for audit
97
+ log_view_access('payment_stats_ajax', request.user)
98
+
99
+ from .base import PaymentStatsMixin
100
+
101
+ # Create instance to use mixin methods
102
+ stats_mixin = PaymentStatsMixin()
103
+
104
+ # Get basic stats
105
+ payment_stats = stats_mixin.get_payment_stats()
106
+ provider_stats = stats_mixin.get_provider_stats()
107
+
108
+ # Get time range stats if requested
109
+ days = int(request.GET.get('days', 30))
110
+ time_range_stats = stats_mixin.get_time_range_stats(days)
111
+
112
+ data = {
113
+ 'payment_stats': payment_stats,
114
+ 'provider_stats': list(provider_stats),
115
+ 'time_range_stats': time_range_stats,
116
+ 'last_updated': timezone.now().isoformat(),
117
+ }
118
+
119
+ return JsonResponse(data)
120
+
121
+ except Exception as e:
122
+ return JsonResponse({'error': str(e)}, status=500)
123
+
124
+
125
+ @superuser_required
126
+ def payment_search_ajax(request):
127
+ """AJAX endpoint for payment search."""
128
+ try:
129
+ query = request.GET.get('q', '').strip()
130
+ if not query:
131
+ return JsonResponse({'results': []})
132
+
133
+ # Log access for audit
134
+ log_view_access('payment_search_ajax', request.user, query=query)
135
+
136
+ from django.db.models import Q
137
+
138
+ # Search payments
139
+ payments = UniversalPayment.objects.filter(
140
+ Q(internal_payment_id__icontains=query) |
141
+ Q(provider_payment_id__icontains=query) |
142
+ Q(user__email__icontains=query) |
143
+ Q(pay_address__icontains=query)
144
+ ).order_by('-created_at')[:20]
145
+
146
+ results = []
147
+ for payment in payments:
148
+ results.append({
149
+ 'id': str(payment.id),
150
+ 'internal_id': payment.internal_payment_id,
151
+ 'provider_id': payment.provider_payment_id,
152
+ 'amount_usd': float(payment.amount_usd),
153
+ 'currency_code': payment.currency_code,
154
+ 'status': payment.status,
155
+ 'status_display': payment.get_status_display(),
156
+ 'provider': payment.provider,
157
+ 'provider_display': payment.provider.title(),
158
+ 'user_email': payment.user.email,
159
+ 'created_at': payment.created_at.isoformat(),
160
+ 'url': f'/payments/payment/{payment.id}/',
161
+ })
162
+
163
+ return JsonResponse({
164
+ 'results': results,
165
+ 'count': len(results),
166
+ 'query': query
167
+ })
168
+
169
+ except Exception as e:
170
+ return JsonResponse({'error': str(e)}, status=500)
171
+
172
+
173
+ @superuser_required
174
+ def payment_action_ajax(request, payment_id):
175
+ """AJAX endpoint for payment actions (cancel, retry, etc.)."""
176
+ try:
177
+ if request.method != 'POST':
178
+ return JsonResponse({'error': 'POST method required'}, status=405)
179
+
180
+ payment = get_object_or_404(UniversalPayment, id=payment_id)
181
+ action = request.POST.get('action')
182
+
183
+ # Log access for audit
184
+ log_view_access('payment_action_ajax', request.user,
185
+ payment_id=payment_id, action=action)
186
+
187
+ if action == 'cancel':
188
+ return _handle_cancel_payment(payment, request.user)
189
+ elif action == 'retry':
190
+ return _handle_retry_payment(payment, request.user)
191
+ elif action == 'refresh':
192
+ return _handle_refresh_payment(payment, request.user)
193
+ else:
194
+ return JsonResponse({'error': 'Invalid action'}, status=400)
195
+
196
+ except Exception as e:
197
+ return JsonResponse({'error': str(e)}, status=500)
198
+
199
+
200
+ def _get_event_description(event):
201
+ """Get human-readable description for payment event."""
202
+ descriptions = {
203
+ 'created': 'Payment was created',
204
+ 'pending': 'Payment is pending confirmation',
205
+ 'confirming': 'Payment is being confirmed',
206
+ 'confirmed': 'Payment has been confirmed',
207
+ 'completed': 'Payment was completed successfully',
208
+ 'failed': 'Payment failed',
209
+ 'cancelled': 'Payment was cancelled',
210
+ 'expired': 'Payment expired',
211
+ 'refunded': 'Payment was refunded',
212
+ 'webhook_received': 'Webhook notification received',
213
+ 'status_updated': 'Payment status was updated',
214
+ }
215
+
216
+ description = descriptions.get(event.event_type, f'Event: {event.event_type}')
217
+
218
+ # Add metadata details if available
219
+ if event.metadata:
220
+ if 'reason' in event.metadata:
221
+ description += f" - {event.metadata['reason']}"
222
+ if 'amount' in event.metadata:
223
+ description += f" (Amount: ${event.metadata['amount']})"
224
+
225
+ return description
226
+
227
+
228
+ def _handle_cancel_payment(payment, user):
229
+ """Handle payment cancellation."""
230
+ if payment.status not in ['pending', 'confirming']:
231
+ return JsonResponse({
232
+ 'error': 'Payment cannot be cancelled in current status'
233
+ }, status=400)
234
+
235
+ try:
236
+ # Update payment status
237
+ payment.status = 'cancelled'
238
+ payment.save()
239
+
240
+ # Create event
241
+ PaymentEvent.objects.create(
242
+ payment=payment,
243
+ event_type='cancelled',
244
+ metadata={'cancelled_by': user.email}
245
+ )
246
+
247
+ return JsonResponse({
248
+ 'success': True,
249
+ 'message': 'Payment cancelled successfully',
250
+ 'new_status': payment.status
251
+ })
252
+
253
+ except Exception as e:
254
+ return JsonResponse({'error': f'Failed to cancel payment: {str(e)}'}, status=500)
255
+
256
+
257
+ def _handle_retry_payment(payment, user):
258
+ """Handle payment retry."""
259
+ if payment.status not in ['failed', 'expired']:
260
+ return JsonResponse({
261
+ 'error': 'Payment cannot be retried in current status'
262
+ }, status=400)
263
+
264
+ try:
265
+ # Reset payment status
266
+ payment.status = 'pending'
267
+ payment.save()
268
+
269
+ # Create event
270
+ PaymentEvent.objects.create(
271
+ payment=payment,
272
+ event_type='retried',
273
+ metadata={'retried_by': user.email}
274
+ )
275
+
276
+ return JsonResponse({
277
+ 'success': True,
278
+ 'message': 'Payment retry initiated',
279
+ 'new_status': payment.status
280
+ })
281
+
282
+ except Exception as e:
283
+ return JsonResponse({'error': f'Failed to retry payment: {str(e)}'}, status=500)
284
+
285
+
286
+ def _handle_refresh_payment(payment, user):
287
+ """Handle payment status refresh."""
288
+ try:
289
+ # Try to refresh payment status from provider
290
+ from ...services.core.payment_service import PaymentService
291
+
292
+ payment_service = PaymentService()
293
+ updated_payment = payment_service.refresh_payment_status(payment.id)
294
+
295
+ # Create event
296
+ PaymentEvent.objects.create(
297
+ payment=payment,
298
+ event_type='refreshed',
299
+ metadata={'refreshed_by': user.email}
300
+ )
301
+
302
+ return JsonResponse({
303
+ 'success': True,
304
+ 'message': 'Payment status refreshed',
305
+ 'new_status': updated_payment.status
306
+ })
307
+
308
+ except Exception as e:
309
+ return JsonResponse({
310
+ 'success': False,
311
+ 'message': f'Failed to refresh payment: {str(e)}'
312
+ })
@@ -0,0 +1,204 @@
1
+ """
2
+ Base mixins and decorators for payment template views.
3
+
4
+ Provides security and common functionality for all payment dashboard views.
5
+ """
6
+
7
+ from django.contrib.auth.decorators import user_passes_test
8
+ from django.utils.decorators import method_decorator
9
+ from django.db.models import Q, Count, Sum
10
+ from django.utils import timezone
11
+ from datetime import timedelta
12
+ import logging
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+
17
+ def superuser_required(function=None):
18
+ """Decorator that checks if user is superuser."""
19
+ actual_decorator = user_passes_test(
20
+ lambda u: u.is_authenticated and u.is_superuser,
21
+ login_url='/admin/login/'
22
+ )
23
+ if function:
24
+ return actual_decorator(function)
25
+ return actual_decorator
26
+
27
+
28
+ class SuperuserRequiredMixin:
29
+ """Mixin that requires superuser access for all views."""
30
+
31
+ @method_decorator(superuser_required)
32
+ def dispatch(self, request, *args, **kwargs):
33
+ return super().dispatch(request, *args, **kwargs)
34
+
35
+
36
+ class PaymentFilterMixin:
37
+ """Mixin that provides common payment filtering functionality."""
38
+
39
+ def get_filtered_payments(self, request=None):
40
+ """Get payments with common filters applied."""
41
+ if request is None:
42
+ request = self.request
43
+
44
+ from ...models import UniversalPayment
45
+
46
+ # Base queryset
47
+ payments_qs = UniversalPayment.objects.select_related('user')
48
+
49
+ # Apply filters from GET parameters
50
+ status_filter = request.GET.get('status', '')
51
+ provider_filter = request.GET.get('provider', '')
52
+ search_query = request.GET.get('search', '')
53
+ date_filter = request.GET.get('date', '')
54
+
55
+ if status_filter:
56
+ payments_qs = payments_qs.filter(status=status_filter)
57
+ if provider_filter:
58
+ payments_qs = payments_qs.filter(provider=provider_filter)
59
+ if search_query:
60
+ payments_qs = payments_qs.filter(
61
+ Q(internal_payment_id__icontains=search_query) |
62
+ Q(provider_payment_id__icontains=search_query) |
63
+ Q(amount_usd__icontains=search_query) |
64
+ Q(user__email__icontains=search_query)
65
+ )
66
+ if date_filter:
67
+ try:
68
+ filter_date = timezone.datetime.strptime(date_filter, '%Y-%m-%d').date()
69
+ payments_qs = payments_qs.filter(created_at__date=filter_date)
70
+ except ValueError:
71
+ pass # Invalid date format, ignore filter
72
+
73
+ return payments_qs
74
+
75
+ def get_filter_context(self, request=None):
76
+ """Get filter values for template context."""
77
+ if request is None:
78
+ request = self.request
79
+
80
+ return {
81
+ 'status': request.GET.get('status', ''),
82
+ 'provider': request.GET.get('provider', ''),
83
+ 'search': request.GET.get('search', ''),
84
+ 'date': request.GET.get('date', ''),
85
+ }
86
+
87
+
88
+ class PaymentStatsMixin:
89
+ """Mixin that provides payment statistics functionality."""
90
+
91
+ def get_payment_stats(self, queryset=None):
92
+ """Get payment statistics from queryset or all payments."""
93
+ if queryset is None:
94
+ from ...models import UniversalPayment
95
+ queryset = UniversalPayment.objects.all()
96
+
97
+ stats = queryset.aggregate(
98
+ total_count=Count('id'),
99
+ pending_count=Count('id', filter=Q(status='pending')),
100
+ confirming_count=Count('id', filter=Q(status='confirming')),
101
+ completed_count=Count('id', filter=Q(status='completed')),
102
+ failed_count=Count('id', filter=Q(status='failed')),
103
+ total_volume=Sum('amount_usd')
104
+ )
105
+
106
+ # Convert Decimal to float for JSON serialization
107
+ if stats['total_volume']:
108
+ stats['total_volume'] = float(stats['total_volume'])
109
+ else:
110
+ stats['total_volume'] = 0.0
111
+
112
+ return stats
113
+
114
+ def get_provider_stats(self, queryset=None):
115
+ """Get provider-specific statistics."""
116
+ if queryset is None:
117
+ from ...models import UniversalPayment
118
+ queryset = UniversalPayment.objects.all()
119
+
120
+ provider_stats = queryset.values('provider').annotate(
121
+ count=Count('id'),
122
+ volume=Sum('amount_usd'),
123
+ completed_count=Count('id', filter=Q(status='completed')),
124
+ ).order_by('-volume')
125
+
126
+ # Calculate success rate
127
+ for stat in provider_stats:
128
+ if stat['count'] > 0:
129
+ stat['success_rate'] = (stat['completed_count'] / stat['count']) * 100
130
+ else:
131
+ stat['success_rate'] = 0
132
+
133
+ # Convert Decimal to float
134
+ if stat['volume']:
135
+ stat['volume'] = float(stat['volume'])
136
+ else:
137
+ stat['volume'] = 0.0
138
+
139
+ return provider_stats
140
+
141
+ def get_time_range_stats(self, days=30):
142
+ """Get statistics for a specific time range."""
143
+ from ...models import UniversalPayment
144
+
145
+ end_date = timezone.now()
146
+ start_date = end_date - timedelta(days=days)
147
+
148
+ queryset = UniversalPayment.objects.filter(
149
+ created_at__gte=start_date,
150
+ created_at__lte=end_date
151
+ )
152
+
153
+ return self.get_payment_stats(queryset)
154
+
155
+
156
+ class PaymentContextMixin:
157
+ """Mixin that provides common context data for payment views."""
158
+
159
+ def get_common_context(self):
160
+ """Get common context data used across multiple views."""
161
+ from ...models import PaymentEvent
162
+
163
+ # Get recent events for activity feed
164
+ recent_events = PaymentEvent.objects.select_related('payment').order_by('-created_at')[:10]
165
+
166
+ return {
167
+ 'recent_events': recent_events,
168
+ 'page_title': self.get_page_title(),
169
+ 'breadcrumbs': self.get_breadcrumbs(),
170
+ }
171
+
172
+ def get_page_title(self):
173
+ """Get page title for the view."""
174
+ return getattr(self, 'page_title', 'Payment Dashboard')
175
+
176
+ def get_breadcrumbs(self):
177
+ """Get breadcrumb navigation for the view."""
178
+ return getattr(self, 'breadcrumbs', [
179
+ {'name': 'Payment Dashboard', 'url': '/payments/admin/'},
180
+ ])
181
+
182
+
183
+ def get_progress_percentage(status):
184
+ """Helper function to calculate progress percentage."""
185
+ progress_map = {
186
+ 'pending': 10,
187
+ 'confirming': 40,
188
+ 'confirmed': 70,
189
+ 'completed': 100,
190
+ 'failed': 0,
191
+ 'expired': 0,
192
+ 'cancelled': 0,
193
+ 'refunded': 50,
194
+ }
195
+ return progress_map.get(status, 0)
196
+
197
+
198
+ def log_view_access(view_name, user, **kwargs):
199
+ """Log access to payment views for audit purposes."""
200
+ extra_info = ', '.join([f"{k}={v}" for k, v in kwargs.items()])
201
+ logger.info(
202
+ f"Payment dashboard access: {view_name} by {user.email} "
203
+ f"(superuser={user.is_superuser}) {extra_info}"
204
+ )
@@ -0,0 +1,60 @@
1
+ """
2
+ Main payment dashboard view.
3
+
4
+ Provides overview, statistics, and recent payments for superuser access.
5
+ """
6
+
7
+ from django.views.generic import TemplateView
8
+ from .base import (
9
+ SuperuserRequiredMixin,
10
+ PaymentFilterMixin,
11
+ PaymentStatsMixin,
12
+ PaymentContextMixin,
13
+ log_view_access
14
+ )
15
+
16
+
17
+ class PaymentDashboardView(
18
+ SuperuserRequiredMixin,
19
+ PaymentFilterMixin,
20
+ PaymentStatsMixin,
21
+ PaymentContextMixin,
22
+ TemplateView
23
+ ):
24
+ """Main payment dashboard with overview and recent payments."""
25
+
26
+ template_name = 'payments/dashboard.html'
27
+ page_title = 'Payment Dashboard'
28
+
29
+ def get_context_data(self, **kwargs):
30
+ context = super().get_context_data(**kwargs)
31
+
32
+ # Log access for audit
33
+ log_view_access('dashboard', self.request.user)
34
+
35
+ # Get filtered payments
36
+ payments_qs = self.get_filtered_payments()
37
+
38
+ # Get recent payments (limit to 20 for performance)
39
+ recent_payments = payments_qs.order_by('-created_at')[:20]
40
+
41
+ # Check if there are more payments for pagination
42
+ has_more = payments_qs.count() > 20
43
+
44
+ # Get statistics
45
+ payment_stats = self.get_payment_stats()
46
+ provider_stats = self.get_provider_stats()
47
+
48
+ # Get common context
49
+ common_context = self.get_common_context()
50
+
51
+ context.update({
52
+ 'payments': recent_payments,
53
+ 'has_more_payments': has_more,
54
+ 'payment_stats': payment_stats,
55
+ 'provider_stats': provider_stats,
56
+ 'filters': self.get_filter_context(),
57
+ **common_context
58
+ })
59
+
60
+ return context