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.

46 lines
1.4 KiB

6 years ago
  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. "plan_name", "profile")
  14. list_filter = ("plan_id", )
  15. raw_id_fields = ("user", )
  16. actions = ("cancel", )
  17. def email(self, obj):
  18. return obj.user.email if obj.user else None
  19. @mark_safe
  20. def profile(self, obj):
  21. if obj.user.profile:
  22. url = reverse("admin:accounts_profile_change",
  23. args=[obj.user.profile.id])
  24. return "<a href='%s'>View Profile</a>" % url
  25. return ""
  26. profile.allow_tags = True
  27. def cancel(self, request, qs):
  28. for sub in qs.all():
  29. sub.cancel()
  30. profile = Profile.objects.for_user(sub.user)
  31. profile.check_limit = 20
  32. profile.team_limit = 2
  33. profile.sms_limit = 0
  34. profile.save()
  35. self.message_user(request, "%d subscriptions cancelled" % qs.count())