Skip to content

Commit

Permalink
Implement ScheduledQueryRun Sigma model
Browse files Browse the repository at this point in the history
This upgrades stripe python dependency to 2.3.0

Closes dj-stripe#673
  • Loading branch information
jleclanche committed Aug 7, 2018
1 parent 9b0deef commit ccc61a2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ History
1.3.0 (unreleased)
------------------

- The Python stripe library minimum version is now ``2.3.0``.
- Dropped previously-deprecated ``Charge.receipt_number`` field.
- Dropped previously-deprecated ``SubscriptionView``,
``CancelSubscriptionView`` and ``CancelSubscriptionForm``.
Expand All @@ -22,6 +23,7 @@ History
- ``ApplicationFeeRefund``
- ``BalanceTransaction``
- ``CountrySpec``
- ``ScheduledQuery``
- ``SubscriptionItem``
- ``TransferReversal``
- ``UsageRecord``
Expand Down
6 changes: 6 additions & 0 deletions djstripe/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ class ProductType(Enum):
service = _("Service")


class ScheduledQueryRunStatus(Enum):
canceled = _("Canceled")
failed = _("Failed")
timed_out = _("Timed out")


class SourceFlow(Enum):
redirect = _("Redirect")
receiver = _("Receiver")
Expand Down
24 changes: 24 additions & 0 deletions djstripe/migrations/0002_auto_20180627_1121.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,30 @@ class Migration(migrations.Migration):
"abstract": False,
},
),
migrations.CreateModel(
name="ScheduledQueryRun",
fields=[
("djstripe_id", models.BigAutoField(primary_key=True, serialize=False, verbose_name="ID")),
("id", djstripe.fields.StripeIdField(max_length=255, unique=True)),
("livemode", models.NullBooleanField(default=None, help_text="Null here indicates that the livemode status is unknown or was previously unrecorded. Otherwise, this field indicates whether this record comes from Stripe test mode or live mode operation.")),
("created", djstripe.fields.StripeDateTimeField(blank=True, help_text="The datetime this object was created in stripe.", null=True)),
("metadata", djstripe.fields.JSONField(blank=True, help_text="A set of key/value pairs that you can attach to an object. It can be useful for storing additional information about an object in a structured format.", null=True)),
("description", models.TextField(blank=True, help_text="A description of this object.", null=True)),
("djstripe_created", models.DateTimeField(auto_now_add=True)),
("djstripe_updated", models.DateTimeField(auto_now=True)),
("data_load_time", djstripe.fields.StripeDateTimeField(help_text="When the query was run, Sigma contained a snapshot of your Stripe data at this time.")),
("error", djstripe.fields.JSONField(blank=True, help_text="If the query run was not succeesful, contains information about the failure.", null=True)),
("result_available_until", djstripe.fields.StripeDateTimeField(help_text="Time at which the result expires and is no longer available for download.")),
("sql", models.CharField(help_text="SQL for the query.", max_length=5000)),
("status", djstripe.fields.StripeEnumField(enum=djstripe.enums.ScheduledQueryRunStatus, help_text="The query's execution status.", max_length=9)),
("title", models.CharField(help_text="Title of the query.", max_length=5000)),
("file", models.ForeignKey(blank=True, help_text="The file object representing the results of the query.", null=True, on_delete=django.db.models.deletion.SET_NULL, to="djstripe.FileUpload")),
],
options={
"get_latest_by": "created",
"abstract": False,
},
),
migrations.CreateModel(
name="SubscriptionItem",
fields=[
Expand Down
2 changes: 2 additions & 0 deletions djstripe/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
BalanceTransaction, Charge, Customer, Dispute, Event, FileUpload, Payout, Refund
)
from .payment_methods import BankAccount, Card, PaymentMethod, Source
from .sigma import ScheduledQueryRun
from .webhooks import WebhookEventTrigger


Expand All @@ -36,6 +37,7 @@
"Plan",
"Product",
"Refund",
"ScheduledQueryRun",
"Source",
"StripeObject",
"StripeModel",
Expand Down
32 changes: 31 additions & 1 deletion djstripe/models/sigma.py
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# TODO: class ScheduledQuery
import stripe
from django.db import models

from .. import enums
from ..fields import JSONField, StripeDateTimeField, StripeEnumField
from .base import StripeModel


class ScheduledQueryRun(StripeModel):
"""
Stripe documentation: https://stripe.com/docs/api#scheduled_queries
"""
stripe_class = stripe.sigma.ScheduledQueryRun

data_load_time = StripeDateTimeField(
help_text="When the query was run, Sigma contained a snapshot of your Stripe data at this time."
)
error = JSONField(
null=True, blank=True,
help_text="If the query run was not succeesful, contains information about the failure."
)
file = models.ForeignKey(
"FileUpload", on_delete=models.SET_NULL, null=True, blank=True,
help_text="The file object representing the results of the query."
)
result_available_until = StripeDateTimeField(
help_text="Time at which the result expires and is no longer available for download."
)
sql = models.CharField(max_length=5000, help_text="SQL for the query.")
status = StripeEnumField(enum=enums.ScheduledQueryRunStatus, help_text="The query's execution status.")
title = models.CharField(max_length=5000, help_text="Title of the query.")
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ zip_safe = False
install_requires =
Django >= 2.0
jsonfield >= 2.0.2
stripe >= 1.53.0
stripe >= 2.3.0

[options.packages.find]
exclude =
Expand Down

0 comments on commit ccc61a2

Please sign in to comment.