You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3 KiB

  1. from django.contrib import admin
  2. from django.urls import reverse
  3. from django.utils.safestring import mark_safe
  4. from hc.accounts.models import Profile
  5. from hc.payments.models import Subscription
  6. @admin.register(Subscription)
  7. class SubsAdmin(admin.ModelAdmin):
  8. readonly_fields = ("email", )
  9. search_fields = ("customer_id", "payment_method_token", "subscription_id",
  10. "user__email")
  11. list_display = ("id", "email", "customer_id", "address_id",
  12. "payment_method_token", "subscription_id", "plan_id",
  13. "profile")
  14. list_filter = ("plan_id", )
  15. actions = ("cancel", )
  16. def email(self, obj):
  17. return obj.user.email if obj.user else None
  18. @mark_safe
  19. def profile(self, obj):
  20. if obj.user.profile:
  21. url = reverse("admin:accounts_profile_change",
  22. args=[obj.user.profile.id])
  23. return "<a href='%s'>View Profile</a>" % url
  24. return ""
  25. profile.allow_tags = True
  26. def cancel(self, request, qs):
  27. for sub in qs.all():
  28. sub.cancel()
  29. profile = Profile.objects.for_user(sub.user)
  30. profile.check_limit = 20
  31. profile.team_limit = 2
  32. profile.sms_limit = 0
  33. profile.save()
  34. self.message_user(request, "%d subscriptions cancelled" % qs.count())