Site Sections: Satchmo Main | Wiki | Demo Store |

Changeset 1004

Show
Ignore:
Timestamp:
01/16/08 04:46:10 (1 year ago)
Author:
chris
Message:

Initial commit of the UPS shipping module.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • satchmo/trunk/satchmo/product/models.py

    r991 r1004  
    2020from sets import Set 
    2121import logging 
     22from django.core.validators import RequiredIfOtherFieldGiven 
    2223try: 
    2324    from django.utils.safestring import mark_safe 
     
    4142def protected_dir(): 
    4243    return normalize_dir(config_value('PRODUCT', 'PROTECTED_DIR')) 
     44 
     45def dimension_units(): 
     46    if config_value('SHOP','MEASUREMENT_SYSTEM')[0] == 'metric': 
     47        return ([('cm','cm')]) 
     48    else: 
     49        return ([('in','in')]) 
     50 
     51def weight_units(): 
     52    if config_value('SHOP','MEASUREMENT_SYSTEM')[0] == 'metric': 
     53        return ([('kg','kg')]) 
     54    else: 
     55        return ([('lb','lb')]) 
     56 
     57length_validator = RequiredIfOtherFieldGiven('length', _("A unit of measure must be entered for the length")) 
     58width_validator = RequiredIfOtherFieldGiven('width', _("A unit of measure must be entered for the width")) 
     59height_validator = RequiredIfOtherFieldGiven('height', _("A unit of measure must be entered for the height")) 
     60weight_validator = RequiredIfOtherFieldGiven('weight', _("A unit of measure must be entered for the weight")) 
    4361 
    4462class Category(models.Model): 
     
    371389    name = models.CharField(_("Full Name"), max_length=255, help_text=_("This is what the product will be called in the default site language.  To add non-default translations, use the Product Translation section below.")) 
    372390    slug = models.SlugField(_("Slug Name"), unique=True, prepopulate_from=('name',), core=True, blank=False) 
    373     sku = models.CharField(_("SKU"), max_length=255, blank=True, null=True, unique=True
     391    sku = models.CharField(_("SKU"), max_length=255, blank=True, null=True, unique=True, help_text=_("Defaults to slug if left blank")
    374392    short_description = models.TextField(_("Short description of product"), help_text=_("This should be a 1 or 2 line description in the default site language for use in product listing screens"), max_length=200, default='', blank=True) 
    375393    description = models.TextField(_("Description of product"), help_text=_("This field can contain HTML and should be a few paragraphs in the default site language explaining the background of the product, and anything that would help the potential customer make their purchase."), default='', blank=True) 
     
    382400    ordering = models.IntegerField(_("Ordering"), default=0, help_text=_("Override alphabetical order in category display")) 
    383401    weight = models.DecimalField(_("Weight"), max_digits=8, decimal_places=2, null=True, blank=True) 
     402    weight_units = models.CharField(_("Weight units"), max_length=3, choices=weight_units(), null=True, blank=True, validator_list=[weight_validator]) 
    384403    length = models.DecimalField(_("Length"), max_digits=6, decimal_places=2, null=True, blank=True) 
     404    length_units = models.CharField(_("Length units"), max_length=3, choices=dimension_units(), null=True, blank=True, validator_list=[length_validator]) 
    385405    width = models.DecimalField(_("Width"), max_digits=6, decimal_places=2, null=True, blank=True) 
     406    width_units = models.CharField(_("Width units"), max_length=3, choices=dimension_units(), null=True, blank=True, validator_list=[width_validator]) 
    386407    height = models.DecimalField(_("Height"), max_digits=6, decimal_places=2, null=True, blank=True) 
     408    height_units = models.CharField(_("Height units"), max_length=3, choices=dimension_units(), null=True, blank=True, validator_list=[height_validator]) 
    387409    related_items = models.ManyToManyField('self', blank=True, null=True, verbose_name=_('Related Items'), related_name='related_products') 
    388410    also_purchased = models.ManyToManyField('self', blank=True, null=True, verbose_name=_('Previously Purchased'), related_name='also_products') 
     
    495517        else: 
    496518            return False; 
     519             
     520    def _has_full_dimensions(self): 
     521        """Return true if the dimensions all have units and values. Used in shipping calcs. """ 
     522        if self.length and self.length_units and self.width and self.width_units and self.height and self.height_units: 
     523            return True 
     524        return False 
     525    has_full_dimensions = property(_has_full_dimensions) 
     526     
     527    def _has_full_weight(self): 
     528        """Return True if we have weight and weight units""" 
     529        if self.weight and self.weight_units: 
     530            return True 
     531        return False 
     532    has_full_weight = property(_has_full_weight)             
    497533 
    498534    def __unicode__(self): 
     
    509545        (None, {'fields': ('category', 'name', 'slug', 'sku', 'description', 'short_description', 'date_added', 'active', 'featured', 'items_in_stock','ordering')}), 
    510546        (_('Meta Data'), {'fields': ('meta',), 'classes': 'collapse'}), 
    511         (_('Item Dimensions'), {'fields': (('length', 'width','height',),'weight'), 'classes': 'collapse'}), 
     547        (_('Item Dimensions'), {'fields': (('length', 'length_units','width','width_units','height','height_units'),('weight','weight_units')), 'classes': 'collapse'}), 
    512548        (_('Tax'), {'fields':('taxable', 'taxClass'), 'classes': 'collapse'}), 
    513549        (_('Related Products'), {'fields':('related_items','also_purchased'),'classes':'collapse'}), 
     
    523559        if not self.id: 
    524560            self.date_added = datetime.date.today() 
    525  
     561        if not self.sku: 
     562            self.sku = self.slug 
    526563        super(Product, self).save() 
    527564 
  • satchmo/trunk/satchmo/shipping/config.py

    r941 r1004  
    2020# just add satchmo.shipping.modules.tiered to your INSTALLED_APPS, you don't 
    2121# need to add it to CUSTOM_SHIPPING_MODULES either. 
    22 _default_modules = ('dummy', 'flat', 'per'
     22_default_modules = ('dummy', 'flat', 'per', 'ups'
    2323 
    2424for module in _default_modules: 
    25     try: 
    26         load_module("satchmo.shipping.modules.%s.config" % module) 
    27     except ImportError: 
    28         log.debug('Could not load default shipping module configuration: %s', module) 
     25    #try: 
     26    load_module("satchmo.shipping.modules.%s.config" % module) 
     27    #except ImportError: 
     28    #    log.debug('Could not load default shipping module configuration: %s', module) 
    2929 
    3030# --- Load any extra shipping modules. --- 
  • satchmo/trunk/satchmo/shop/config.py

    r955 r1004  
    2828        description= _("Number of featured items to display"), 
    2929        default=20)) 
    30          
     30 
     31MEASUREMENT_SYSTEM = config_register( 
     32    MultipleStringValue(SHOP_GROUP, 
     33    'MEASUREMENT_SYSTEM', 
     34    description = _("Measurement system to use in store"), 
     35    choices = [('metric',_('Metric')), 
     36                ('imperial',_('Imperial'))], 
     37    default = "imperial")) 
    3138#### Google Group #### 
    3239