models.py 1.8 KB
Newer Older
1
"""
vkaracic committed
2
Commerce-related models.
3
"""
4
from config_models.models import ConfigurationModel
vkaracic committed
5 6 7 8 9 10 11
from django.db import models
from django.utils.translation import ugettext_lazy as _


class CommerceConfiguration(ConfigurationModel):
    """ Commerce configuration """

12 13 14
    class Meta(object):
        app_label = "commerce"

15 16
    API_NAME = 'commerce'
    CACHE_KEY = 'commerce.api.data'
17
    DEFAULT_RECEIPT_PAGE_URL = '/checkout/receipt/?order_number='
18
    MULTIPLE_ITEMS_BASKET_PAGE_URL = '/basket/add/'
19

vkaracic committed
20 21 22 23 24 25 26 27 28 29
    checkout_on_ecommerce_service = models.BooleanField(
        default=False,
        help_text=_('Use the checkout page hosted by the E-Commerce service.')
    )

    single_course_checkout_page = models.CharField(
        max_length=255,
        default='/basket/single-item/',
        help_text=_('Path to single course checkout page hosted by the E-Commerce service.')
    )
30 31 32 33 34 35 36
    cache_ttl = models.PositiveIntegerField(
        verbose_name=_('Cache Time To Live'),
        default=0,
        help_text=_(
            'Specified in seconds. Enable caching by setting this to a value greater than 0.'
        )
    )
37 38
    # receipt_page no longer used but remains in the model until we can purge old data.
    # removing this will casue 500 errors when trying to access the Django admin.
39 40 41 42 43
    receipt_page = models.CharField(
        max_length=255,
        default=DEFAULT_RECEIPT_PAGE_URL,
        help_text=_('Path to order receipt page.')
    )
44 45 46 47
    enable_automatic_refund_approval = models.BooleanField(
        default=True,
        help_text=_('Automatically approve valid refund requests, without manual processing')
    )
vkaracic committed
48 49 50

    def __unicode__(self):
        return "Commerce configuration"
51 52 53 54 55

    @property
    def is_cache_enabled(self):
        """Whether responses from the Ecommerce API will be cached."""
        return self.cache_ttl > 0