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.

43 lines
1.3 KiB

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