CCrypto VPN public website https://vpn.ccrypto.org/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

109 rader
4.2 KiB

  1. from django.shortcuts import resolve_url
  2. from django.contrib import admin
  3. from django.utils.translation import ugettext_lazy as _
  4. from .models import Payment, Subscription
  5. def subscr_mark_as_cancelled(modeladmin, request, queryset):
  6. queryset.update(status='cancelled')
  7. subscr_mark_as_cancelled.short_description = _("Mark as cancelled (do not actually cancel)")
  8. class PaymentAdmin(admin.ModelAdmin):
  9. model = Payment
  10. list_display = ('user', 'backend', 'status', 'amount', 'paid_amount', 'created')
  11. list_filter = ('backend_id', 'status')
  12. fieldsets = (
  13. (None, {
  14. 'fields': ('backend', 'user_link', 'subscription_link', 'time', 'status',
  15. 'status_message'),
  16. }),
  17. (_("Payment Data"), {
  18. 'fields': ('amount_fmt', 'paid_amount_fmt',
  19. 'backend_extid_link', 'backend_data'),
  20. }),
  21. )
  22. readonly_fields = ('backend', 'user_link', 'time', 'status', 'status_message',
  23. 'amount_fmt', 'paid_amount_fmt', 'subscription_link',
  24. 'backend_extid_link', 'backend_data')
  25. search_fields = ('user__username', 'user__email', 'backend_extid', 'backend_data')
  26. def backend(self, object):
  27. return object.backend.backend_verbose_name
  28. def backend_extid_link(self, object):
  29. ext_url = object.backend.get_ext_url(object)
  30. if ext_url:
  31. return '<a href="%s">%s</a>' % (ext_url, object.backend_extid)
  32. return object.backend_extid
  33. backend_extid_link.allow_tags = True
  34. def amount_fmt(self, object):
  35. return '%.2f %s' % (object.amount / 100, object.currency_name)
  36. amount_fmt.short_description = _("Amount")
  37. def paid_amount_fmt(self, object):
  38. return '%.2f %s' % (object.paid_amount / 100, object.currency_name)
  39. paid_amount_fmt.short_description = _("Paid amount")
  40. def user_link(self, object):
  41. change_url = resolve_url('admin:auth_user_change', object.user.id)
  42. return '<a href="%s">%s</a>' % (change_url, object.user.username)
  43. user_link.allow_tags = True
  44. user_link.short_description = 'User'
  45. def subscription_link(self, object):
  46. change_url = resolve_url('admin:payments_subscription_change',
  47. object.subscription.id)
  48. return '<a href="%s">%s</a>' % (change_url, object.subscription.id)
  49. subscription_link.allow_tags = True
  50. subscription_link.short_description = 'Subscription'
  51. class SubscriptionAdmin(admin.ModelAdmin):
  52. model = Subscription
  53. list_display = ('user', 'created', 'status', 'backend', 'backend_extid')
  54. readonly_fields = ('user_link', 'backend', 'period', 'created', 'status',
  55. 'last_confirmed_payment', 'payments_links',
  56. 'backend_extid_link', 'backend_data')
  57. actions = (subscr_mark_as_cancelled,)
  58. fieldsets = (
  59. (None, {
  60. 'fields': ('backend', 'user_link', 'period', 'payments_links', 'status',
  61. 'last_confirmed_payment'),
  62. }),
  63. (_("Payment Data"), {
  64. 'fields': ('backend_extid_link', 'backend_data'),
  65. }),
  66. )
  67. def backend(self, object):
  68. return object.backend.backend_verbose_name
  69. def user_link(self, object):
  70. change_url = resolve_url('admin:auth_user_change', object.user.id)
  71. return '<a href="%s">%s</a>' % (change_url, object.user.username)
  72. user_link.allow_tags = True
  73. user_link.short_description = 'User'
  74. def payments_links(self, object):
  75. fmt = '<a href="%s?subscription__id__exact=%d">%d payments</a>'
  76. payments_url = resolve_url('admin:payments_payment_changelist')
  77. count = Payment.objects.filter(subscription=object).count()
  78. return fmt % (payments_url, object.id, count)
  79. payments_links.allow_tags = True
  80. payments_links.short_description = 'Payments'
  81. def backend_extid_link(self, object):
  82. ext_url = object.backend.get_subscr_ext_url(object)
  83. if ext_url:
  84. return '<a href="%s">%s</a>' % (ext_url, object.backend_extid)
  85. return object.backend_extid
  86. backend_extid_link.allow_tags = True
  87. admin.site.register(Payment, PaymentAdmin)
  88. admin.site.register(Subscription, SubscriptionAdmin)