src/n/o/notmm-0.4.1/examples/lib/livesettings/values.py notmm(Download)
log = logging.getLogger('configuration')
NOTSET = object()
class SortedDotDict(SortedDict):
class Value(object):
creation_counter = 0
def __init__(self, group, key, **kwargs):
"""
Create a new Value object for configuration.
if self.use_default:
val = self.default
else:
val = NOTSET
except AttributeError, ae:
log.error("Attribute error: %s", ae)
def to_python(self, value):
"Returns a native Python object suitable for immediate use"
if value == NOTSET:
value = None
return value
def get_db_prep_save(self, value):
"Returns a value suitable for storage into a CharField"
if value == NOTSET:
def to_editor(self, value):
"Returns a value suitable for display in a form widget"
if value == NOTSET:
return NOTSET
return unicode(value)
###############
def to_python(self, value):
if value==NOTSET:
return Decimal("0")
try:
return Decimal(value)
except TypeError, te:
log.warning("Can't convert %s to Decimal for settings %s.%s", value, self.group.key, self.key)
raise TypeError(te)
def to_editor(self, value):
if value == NOTSET:
def to_python(self, value):
if value == NOTSET:
value = 0
if isinstance(value, datetime.timedelta):
return value
try:
return datetime.timedelta(seconds=float(value))
except (ValueError, TypeError):
raise forms.ValidationError('This value must be a real number.')
except OverflowError:
raise forms.ValidationError('The maximum allowed value is %s' % datetime.timedelta.max)
def get_db_prep_save(self, value):
if value == NOTSET:
def get_db_prep_save(self, value):
if value == NOTSET:
return NOTSET
else:
return unicode(value.days * 24 * 3600 + value.seconds + float(value.microseconds) / 1000000)
class FloatValue(Value):
def to_python(self, value):
if value == NOTSET:
value = 0
return float(value)
def to_editor(self, value):
if value == NOTSET:
def to_python(self, value):
if value == NOTSET:
value = 0
return int(value)
def to_editor(self, value):
if value == NOTSET:
def to_python(self, value):
if value == NOTSET:
value = 0
return Decimal(value) / 100
def to_editor(self, value):
if value == NOTSET:
def to_python(self, value):
if value == NOTSET:
value = ""
return unicode(value)
to_editor = to_python
def to_python(self, value):
if value == NOTSET:
value = ""
return unicode(value)
to_editor = to_python
def to_python(self, value):
if not value or value == NOTSET:
return []
if is_list_or_tuple(value):
return value
else:
try:
def load_module(self, module):
"""Load a child module"""
value = self._value()
if value == NOTSET:
raise SettingNotSet("%s.%s", self.group.key, self.key)
else:
return load_module("%s.%s" % (value, module))
def to_python(self, value):
if value == NOTSET:
def to_editor(self, value):
if value == NOTSET:
value = ""
return value
src/n/o/notmm-0.4.1/examples/lib/payment/modules/base.py notmm(Download)
log = logging.getLogger('payment.modules.base')
NOTSET = object()
class BasePaymentProcessor(object):
def authorize_and_release(self, order=None, amount=NOTSET, testing=False):
if not order:
order = self.order
else:
self.order = order
if amount == NOTSET:
amount = Decimal('0.01')
class PaymentRecorder(object):
"""Manages proper recording of pending payments, payments, and authorizations."""
def __init__(self, order, config):
self.order = order
self.key = unicode(config.KEY.value)
self.config = config
self._amount = NOTSET
def _set_amount(self, amount):
if amount != NOTSET:
self._amount = amount
def _get_amount(self):
if self._amount == NOTSET:
return self.order.balance
self.orderpayment = OrderAuthorization()
self.orderpayment.capture = self.pending.capture
if amount == NOTSET:
self.set_amount_from_pending()
else:
self.orderpayment = self.pending.capture
log.debug("Using linked payment: %s", self.orderpayment)
if amount == NOTSET:
self.set_amount_from_pending()
else:
def create_pending(self, amount=NOTSET):
"""Create a placeholder payment entry for the order.
This is done by step 2 of the payment process."""
if amount == NOTSET:
amount = Decimal("0.00")
self.amount = amount
class ProcessorResult(object):
"""The result from a processor.process call"""
def __init__(self, processor, success, message, payment=None):
"""Initialize with:
processor - the key of the processor setting the result
src/n/o/notmm-0.4.1/examples/lib/livesettings/functions.py notmm(Download)
log = logging.getLogger('configuration')
_NOTSET = object()
class ConfigurationSettings(object):
"""A singleton manager for ConfigurationSettings"""
class __impl(object):
def config_value(group, key, default=_NOTSET):
"""Get a value from the configuration system"""
try:
return config_get(group, key).value
except SettingNotSet:
if default != _NOTSET:
return default
src/n/o/notmm-0.4.1/examples/lib/product/models.py notmm(Download)
class NullDiscount(object):
def __init__(self):
self.description = _("No Discount")
self.total = Decimal("0.00")
self.item_discounts = {}
self.discounted_prices = []
verbose_name = _("Tax Class")
verbose_name_plural = _("Tax Classes")
UNSET = object()
# --------------- helpers ------------------
if not trans:
trans = obj
val = getattr(trans, attr, UNSET)
if trans != obj and (val in (None, UNSET)):
val = getattr(obj, attr)
class PriceAdjustmentCalc(object):
"""Helper class to handle adding up product pricing adjustments"""
def __init__(self, price, product=None):
self.price = price
self.base_product = product
self.adjustments = []
class PriceAdjustment(object):
"""A single product pricing adjustment"""
def __init__(self, key, label=None, amount=None):
if label is None:
label = key.capitalize()
if amount is None:
src/n/o/notmm-0.4.1/examples/lib/product/views/__init__.py notmm(Download)
log = logging.getLogger('product.views')
NOTSET = object()
# ---- Helpers ----
def display_featured(num_to_display=NOTSET, random_display=NOTSET):
"""
Used by the index generic view to choose how the featured products are displayed.
Items can be displayed randomly or all in order
"""
if num_to_display == NOTSET:
num_to_display = config_value('PRODUCT','NUM_DISPLAY')
if random_display == NOTSET:
except Product.DoesNotExist:
return bad_or_missing(request, _('The product you have requested does not exist.'))
if default_view_tax == NOTSET:
default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX')
subtype_names = product.get_subtypes()
src/n/o/notmm-0.4.1/examples/lib/satchmo_ext/newsletter/models.py notmm(Download)
log = logging.getLogger('newsletter.models')
_NOTSET = object()
class NullContact(object):
"""Simple object emulating a Contact, so that we can add users who aren't Satchmo Contacts.
def attribute_value(self, name, value=_NOTSET):
"""Get a value from an attribute."""
try:
att = self.attributes.get(name=name)
value = att.value
except SubscriptionAttribute.DoesNotExist:
if value != _NOTSET:
src/p/y/python-cookbook-HEAD/cb2_examples/cb2_16_7_sol_1.py python-cookbook(Download)
class peek_ahead(object):
sentinel = object()
def __init__(self, it):
self._nit = iter(it).next
self.preview = None
self._step()
def __iter__(self):
src/n/o/notmm-0.4.1/examples/lib/satchmo_store/shop/views/cart.py notmm(Download)
log = logging.getLogger('shop.views.cart')
NOTSET = object()
def _json_response(data, template="shop/json.html"):
return HttpResponse(loader.render_to_string(template,
def display(request, cart=None, error_message='', default_view_tax=NOTSET):
"""Display the items in the cart."""
if default_view_tax == NOTSET:
default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX')
if not cart:
src/n/o/notmm-0.4.1/examples/lib/satchmo_utils/thumbnail/field.py notmm(Download)
return os.path.join(updir, filename)
NOTSET = object()
class ImageWithThumbnailField(ImageField):
""" ImageField with thumbnail support
def _save_rename(self, instance, **kwargs):
if hasattr(self, '_renaming') and self._renaming:
return
if self.auto_rename == NOTSET:
try:
self.auto_rename = config_value('THUMBNAIL', 'RENAME_IMAGES')
except SettingNotSet:
src/n/o/notmm-0.4.1/examples/lib/satchmo_ext/newsletter/forms.py notmm(Download)
from satchmo_ext.newsletter import update_subscription
from satchmo_ext.newsletter.models import get_contact_or_fake
_NOTSET = object()
class OptionalBoolean(forms.BooleanField):
def __init__(self, *args, **kwargs):
def save(self, state=_NOTSET, attributes={}):
contact = self.get_contact()
if state == _NOTSET:
state = self.cleaned_data['subscribed']
return update_subscription(contact, state, attributes=attributes)
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next