Skip to content

Commit

Permalink
Rename StripeObject => StripeModel
Browse files Browse the repository at this point in the history
This makes it clearer that it's not in fact a StripeObject (terminology
which is used by python-stripe), but indeed a Django Model.

Also renames:
- StripeObjectAdmin => StripeModelAdmin
- StripeObjectManager => StripeModelManager
  • Loading branch information
jleclanche committed Jul 25, 2018
1 parent d19ecbb commit 7434f4b
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 65 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ History
corresponding customer is deleted (#654).
- Webhook signature verification is now available and is preferred. Set the
``DJSTRIPE_WEBHOOK_SECRET`` setting to your secret to start using it.
- ``StripeObject`` has been renamed ``StripeModel``. An alias remains but will
be removed in the next version.

1.2.1 (2018-07-18)
------------------
Expand Down
32 changes: 16 additions & 16 deletions djstripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def has_add_permission(self, request):
return False


class StripeObjectAdmin(admin.ModelAdmin):
"""Base class for all StripeObject-based model admins"""
class StripeModelAdmin(admin.ModelAdmin):
"""Base class for all StripeModel-based model admins"""

change_form_template = "djstripe/admin/change_form.html"

Expand Down Expand Up @@ -169,15 +169,15 @@ class InvoiceItemInline(admin.StackedInline):


@admin.register(models.Account)
class AccountAdmin(StripeObjectAdmin):
class AccountAdmin(StripeModelAdmin):
list_display = ("business_url", "country", "default_currency")
list_filter = ("details_submitted", )
search_fields = ("business_name", "display_name", "business_url")
raw_id_fields = ("business_logo", )


@admin.register(models.Charge)
class ChargeAdmin(StripeObjectAdmin):
class ChargeAdmin(StripeModelAdmin):
list_display = (
"customer", "amount", "description", "paid", "disputed", "refunded", "fee"
)
Expand All @@ -189,7 +189,7 @@ class ChargeAdmin(StripeObjectAdmin):


@admin.register(models.Coupon)
class CouponAdmin(StripeObjectAdmin):
class CouponAdmin(StripeModelAdmin):
list_display = (
"amount_off", "percent_off", "duration", "duration_in_months",
"redeem_by", "max_redemptions", "times_redeemed"
Expand All @@ -199,7 +199,7 @@ class CouponAdmin(StripeObjectAdmin):


@admin.register(models.Customer)
class CustomerAdmin(StripeObjectAdmin):
class CustomerAdmin(StripeModelAdmin):
raw_id_fields = ("subscriber", "default_source", "coupon")
list_display = (
"subscriber", "email", "currency", "default_source", "coupon",
Expand All @@ -211,7 +211,7 @@ class CustomerAdmin(StripeObjectAdmin):


@admin.register(models.Dispute)
class DisputeAdmin(StripeObjectAdmin):
class DisputeAdmin(StripeModelAdmin):
list_display = ("reason", "status", "amount", "currency", "is_charge_refundable")
list_filter = ("is_charge_refundable", "reason", "status")

Expand All @@ -220,7 +220,7 @@ def has_add_permission(self, request):


@admin.register(models.Event)
class EventAdmin(StripeObjectAdmin):
class EventAdmin(StripeModelAdmin):
list_display = ("type", "created", "request_id")
list_filter = ("type", "created")
search_fields = ("request_id", )
Expand All @@ -230,14 +230,14 @@ def has_add_permission(self, request):


@admin.register(models.FileUpload)
class FileUploadAdmin(StripeObjectAdmin):
class FileUploadAdmin(StripeModelAdmin):
list_display = ("purpose", "size", "type")
list_filter = ("purpose", "type")
search_fields = ("filename", )


@admin.register(models.Invoice)
class InvoiceAdmin(StripeObjectAdmin):
class InvoiceAdmin(StripeModelAdmin):
list_display = (
"customer", "number", "paid", "forgiven", "closed", "period_start",
"period_end", "subtotal", "tax", "tax_percent", "total"
Expand All @@ -252,7 +252,7 @@ class InvoiceAdmin(StripeObjectAdmin):


@admin.register(models.Plan)
class PlanAdmin(StripeObjectAdmin):
class PlanAdmin(StripeModelAdmin):
radio_fields = {"interval": admin.HORIZONTAL}

def save_model(self, request, obj, form, change):
Expand All @@ -275,28 +275,28 @@ def get_readonly_fields(self, request, obj=None):


@admin.register(models.Product)
class ProductAdmin(StripeObjectAdmin):
class ProductAdmin(StripeModelAdmin):
list_display = ("name", "type", "active", "url", "statement_descriptor")
list_filter = ("type", "active", "shippable")
search_fields = ("name", "statement_descriptor")


@admin.register(models.Refund)
class RefundAdmin(StripeObjectAdmin):
class RefundAdmin(StripeModelAdmin):
list_display = ("amount", "currency", "charge", "reason", "status", "failure_reason")
list_filter = ("reason", "status")
search_fields = ("receipt_number", )


@admin.register(models.Source)
class SourceAdmin(StripeObjectAdmin):
class SourceAdmin(StripeModelAdmin):
raw_id_fields = ("customer", )
list_display = ("customer", "type", "status", "amount", "currency", "usage", "flow")
list_filter = ("type", "status", "usage", "flow")


@admin.register(models.Subscription)
class SubscriptionAdmin(StripeObjectAdmin):
class SubscriptionAdmin(StripeModelAdmin):
raw_id_fields = ("customer", )
list_display = ("customer", "status")
list_filter = ("status", "cancel_at_period_end")
Expand All @@ -311,5 +311,5 @@ def cancel_subscription(self, request, queryset):


@admin.register(models.Transfer)
class TransferAdmin(StripeObjectAdmin):
class TransferAdmin(StripeModelAdmin):
list_display = ("amount", "status", "date", "description")
4 changes: 2 additions & 2 deletions djstripe/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from django.db import models


class StripeObjectManager(models.Manager):
"""Manager used in StripeObject."""
class StripeModelManager(models.Manager):
"""Manager used in StripeModel."""
pass


Expand Down
3 changes: 2 additions & 1 deletion djstripe/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import IdempotencyKey, StripeObject
from .base import IdempotencyKey, StripeModel, StripeObject
from .billing import (
Coupon, Invoice, InvoiceItem, Plan, Product, Subscription, UpcomingInvoice
)
Expand Down Expand Up @@ -28,6 +28,7 @@
"Refund",
"Source",
"StripeObject",
"StripeModel",
"Subscription",
"Transfer",
"UpcomingInvoice",
Expand Down
10 changes: 7 additions & 3 deletions djstripe/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

from .. import settings as djstripe_settings
from ..fields import JSONField, StripeDateTimeField, StripeIdField
from ..managers import StripeObjectManager
from ..managers import StripeModelManager


logger = logging.getLogger(__name__)


class StripeObject(models.Model):
class StripeModel(models.Model):
# This must be defined in descendants of this model/mixin
# e.g. Event, Charge, Customer, etc.
stripe_class = None
expand_fields = []
stripe_dashboard_item_name = ""

objects = models.Manager()
stripe_objects = StripeObjectManager()
stripe_objects = StripeModelManager()

djstripe_id = models.BigAutoField(
verbose_name="ID", serialize=False, primary_key=True
Expand Down Expand Up @@ -439,3 +439,7 @@ def __str__(self):
@property
def is_expired(self):
return timezone.now() > self.created + timedelta(hours=24)


# Alias (Deprecated, remove in 1.4.0)
StripeObject = StripeModel
24 changes: 12 additions & 12 deletions djstripe/models/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
)
from ..managers import SubscriptionManager
from ..utils import QuerySetMock, get_friendly_currency_amount
from .base import StripeObject
from .base import StripeModel
from .core import Charge, Customer, Product


class Coupon(StripeObject):
class Coupon(StripeModel):
id = StripeIdField(max_length=500)
amount_off = StripeDecimalCurrencyAmountField(
null=True,
Expand Down Expand Up @@ -107,7 +107,7 @@ def human_readable(self):
)


class Invoice(StripeObject):
class Invoice(StripeModel):
"""
Invoices are statements of what a customer owes for a particular billing
period, including subscriptions, invoice items, and any automatic proration
Expand Down Expand Up @@ -385,15 +385,15 @@ def upcoming(
"""

# Convert Customer to id
if customer is not None and isinstance(customer, StripeObject):
if customer is not None and isinstance(customer, StripeModel):
customer = customer.id

# Convert Subscription to id
if subscription is not None and isinstance(subscription, StripeObject):
if subscription is not None and isinstance(subscription, StripeModel):
subscription = subscription.id

# Convert Plan to id
if subscription_plan is not None and isinstance(subscription_plan, StripeObject):
if subscription_plan is not None and isinstance(subscription_plan, StripeModel):
subscription_plan = subscription_plan.id

try:
Expand Down Expand Up @@ -545,7 +545,7 @@ def save(self, *args, **kwargs):
return # noop


class InvoiceItem(StripeObject):
class InvoiceItem(StripeModel):
"""
Sometimes you want to add a charge or credit to a customer but only actually
charge the customer's card at the end of a regular billing cycle.
Expand Down Expand Up @@ -672,7 +672,7 @@ def str_parts(self):
] + super().str_parts()


class Plan(StripeObject):
class Plan(StripeModel):
"""
A subscription plan contains the pricing information for different
products and feature levels on your site.
Expand Down Expand Up @@ -887,7 +887,7 @@ def update_name(self):
self.save()


class Subscription(StripeObject):
class Subscription(StripeModel):
"""
Subscriptions allow you to charge a customer's card on a recurring basis.
A subscription ties a customer to a particular plan you've created.
Expand Down Expand Up @@ -1062,7 +1062,7 @@ def update(
"""

# Convert Plan to id
if plan is not None and isinstance(plan, StripeObject):
if plan is not None and isinstance(plan, StripeModel):
plan = plan.id

kwargs = deepcopy(locals())
Expand Down Expand Up @@ -1198,7 +1198,7 @@ def _attach_objects_hook(self, cls, data):
self.plan = cls._stripe_object_to_plan(target_cls=Plan, data=data)


class SubscriptionItem(StripeObject):
class SubscriptionItem(StripeModel):
"""
Subscription items allow you to create customer subscriptions
with more than one plan, making it easy to represent complex billing relationships.
Expand All @@ -1225,7 +1225,7 @@ class SubscriptionItem(StripeObject):
)


class UsageRecord(StripeObject):
class UsageRecord(StripeModel):
"""
Usage records allow you to continually report usage and metrics to
Stripe for metered billing of plans.
Expand Down
6 changes: 3 additions & 3 deletions djstripe/models/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
StripeDecimalCurrencyAmountField, StripeEnumField, StripeIdField
)
from ..managers import TransferManager
from .base import StripeObject
from .base import StripeModel


class Account(StripeObject):
class Account(StripeModel):
"""
Stripe documentation: https://stripe.com/docs/api#account
"""
Expand Down Expand Up @@ -162,7 +162,7 @@ def __str__(self):
return self.display_name or self.business_name


class Transfer(StripeObject):
class Transfer(StripeModel):
"""
When Stripe sends you money or you initiate a transfer to a bank account,
debit card, or connected Stripe account, a transfer object will be created.
Expand Down
Loading

0 comments on commit 7434f4b

Please sign in to comment.