<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Sumit Chachra&#039;s Blog &#187; Coding</title> <atom:link href="http://blog.chachra.us/category/coding/feed/" rel="self" type="application/rss+xml" /><link>http://blog.chachra.us</link> <description>Tivix, Technology, Django, Startups, Social Media</description> <lastBuildDate>Mon, 30 Jan 2012 09:00:27 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Django-cron : Let the open sourcing begin</title><link>http://blog.chachra.us/2011/02/09/django-cron-let-the-open-sourcing-begin/</link> <comments>http://blog.chachra.us/2011/02/09/django-cron-let-the-open-sourcing-begin/#comments</comments> <pubDate>Thu, 10 Feb 2011 04:53:12 +0000</pubDate> <dc:creator>Sumit Chachra</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Django]]></category> <category><![CDATA[open source]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[Tivix]]></category><guid
isPermaLink="false">http://chachra.tivixsites.com/?p=139</guid> <description><![CDATA[So after more than a year of thinking/pondering/procrastinating I found myself with 2 spare hours (Wife busy will 9:30 and me not wanting to go to the Gym&#8230;. the stars aligned!) and took advantage of it to open source Tivix&#8217;s first application.
Its not the sexiest, but makes running python crons / automated tasks in Django [...]]]></description> <content:encoded><![CDATA[<p></p><p>So after more than a year of thinking/pondering/procrastinating I found myself with 2 spare hours (Wife busy will 9:30 and me not wanting to go to the Gym&#8230;. the stars aligned!) and took advantage of it to <a
class="zem_slink" title="Open source" rel="wikipedia" href="http://en.wikipedia.org/wiki/Open_source">open source</a> <a
href="http://tivix.com" target="_blank">Tivix&#8217;s</a> first application.</p><p>Its not the sexiest, but makes running <strong>python crons / automated tasks </strong>in <a
class="zem_slink" title="Django (web framework)" rel="homepage" href="http://www.djangoproject.com">Django</a> hopefully a tad bit easier. If nothing else someone can extend this app and make it even better.</p><p>Here is it: <a
title="django-cron" href="https://github.com/Tivix/django-cron" target="_blank"><strong>https://github.com/Tivix/django-cron</strong></a></p><p>Hopefully we&#8217;ll open source 2-3 other applications / <a
class="zem_slink" title="Snippet (programming)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Snippet_%28programming%29">code snippets</a> which we find really useful as time goes on. This a small way in which we &#8220;give back&#8221; to the open source community (<strong>Django</strong> and <strong><a
class="zem_slink" title="WordPress" rel="homepage" href="http://wordpress.org">Wordpress</a></strong> I am looking at you!) on whose shoulders we&#8217;ve built some great products for some great companies!</p><p>Thoughts/comments welcome <img
src='http://blog.chachra.us/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><div
class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a
class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img
class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=c467c826-eb92-405f-918a-8b0c57b0a252" alt="Enhanced by Zemanta" /></a><span
class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div> ]]></content:encoded> <wfw:commentRss>http://blog.chachra.us/2011/02/09/django-cron-let-the-open-sourcing-begin/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Selling tickets or variable inventory items using Satchmo</title><link>http://blog.chachra.us/2010/09/08/selling-tickets-or-variable-inventory-items-using-satchmo/</link> <comments>http://blog.chachra.us/2010/09/08/selling-tickets-or-variable-inventory-items-using-satchmo/#comments</comments> <pubDate>Wed, 08 Sep 2010 07:10:41 +0000</pubDate> <dc:creator>Sumit Chachra</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Django]]></category> <category><![CDATA[ecommerce]]></category> <category><![CDATA[open source]]></category><guid
isPermaLink="false">http://chachra.tivixsites.com/?p=130</guid> <description><![CDATA[Satchmo is a popular Django based e-commerce system. Its well suited for the most part to sell things like shirts and shoes that come in various sizes / colors (variations) etc. These are items that a seller would have a certain amount of in stock, and sell out when the inventory hits 0.
There are situations [...]]]></description> <content:encoded><![CDATA[<p></p><p><a
href="http://www.satchmoproject.com/" target="_blank">Satchmo</a> is a popular <a
href="http://www.djangoproject.com/" target="_blank">Django</a> based e-commerce system. Its well suited for the most part to sell things like shirts and shoes that come in various sizes / colors (variations) etc. These are items that a seller would have a certain amount of in stock, and sell out when the inventory hits 0.</p><p>There are situations however this doesn&#8217;t work as well. Say you&#8217;re a bakery that sells cupcakes and macaroons. Lets assume you bake 100 cupcakes and 50 macaroons every day. So thats the max you can sell on a daily basis. Some days you won&#8217;t sell all, but the next day you may run out. This means your inventory number is not fixed.</p><p>Moreover the way you&#8217;ll define your &#8220;product&#8221; (thing that customer buys) will need to change. Instead of saying that &#8220;I sold a cupcake&#8221;, you have to say &#8220;I sold a cupcake on Sep. 7, 2010&#8243;. The temporal aspect is important, since your inventory is not static. The date may represent the order date or a date in the future (say you take pre-orders).</p><p>The exact same scenario applies to sellers of theater tickets (or tickets of any kind really), hotel rooms etc. Almost any kind of commerce online that has daily or variable inventory levels and / or perishable items.</p><p>OK, so how to go about solving this problem. Without going into too many details, its obvious we need to use what Satchmo calls <a
href="http://www.satchmoproject.com/docs/dev/custom-product.html" target="_blank">Custom Product(s)</a>. Apart from that we need to capture the core product type (cupcake or macaroon or hotel room) etc. Below you will find a <code>VariableInventoryProductType</code> class that represents a typical type of product and a <code>VariableInventoryProduct</code> class that has a FK to a core Satchmo product, a day and a type of product. This is the product the customer is really buying (executive suite on December 25, 2010&#8230; room would be a product type and executive suite would be a &#8220;variation&#8221; of that).</p><pre class="brush:python">import logging

from django.conf import settings as django_settings
from django.db import models
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _

from product.models import SHIP_CLASS_CHOICES, Product, OptionGroup, Price
from product.modules.configurable.models import ConfigurableProduct

class VariableInventoryProductType(models.Model):
    """
    Represents a type of product thats sold by the seller. In case of a Theater for example only one instance of
    this would exist. In case of a bakery say, the number of instances would be the same as the number of different
    types of items the bakery sells.
    """
    name = models.CharField(max_length=255)
    description = models.TextField()
    slug = models.CharField(max_length=255, db_index=True)
    image = ImageField()
    default_inventory = models.IntegerField(verbose_name='Default daily inventory')
    active = models.BooleanField(default=True, db_index=True)
    order = models.IntegerField(db_index=True, default=0)
    base_price = models.DecimalField(max_digits=6, decimal_places=2)
    option_group = models.ForeignKey(OptionGroup, blank=True, null=True)
    shipclass = models.CharField(_('Shipping'), choices=SHIP_CLASS_CHOICES, default="YES", max_length=10)
    featured = models.BooleanField(default=False, db_index=True)

    class Meta:
        ordering = ('order', )

    def __unicode__(self):
        return self.name

class VariableInventoryProductManager(models.Manager):
    def get_product(self, product_type, day, create=True):
        qset = self.filter(product_type=product_type, day=day)
        if qset:
            return qset.get()
        elif create:
            logging.info('Creating new product of type: %s and day: %s' % (product_type.name, day))
            # create real satchmo product first.
            product = Product()
            product.site = Site.objects.get_current()
            product.name = '%s on %s' % (product_type.name, day)
            product.items_in_stock = product_type.default_inventory
            product.shipclass = product_type.shipclass
            product.save()

            p = Price()
            p.product = product
            p.price = product_type.base_price
            p.save()

            # Create Variations
            if product_type.option_group:
                configurable_product = ConfigurableProduct(product=product)
                configurable_product.save()
                configurable_product.option_group.add(product_type.option_group)
                configurable_product.create_subs = True
                configurable_product.save()

            return self.create(product=product, product_type=product_type, day=day)
        else:
            return None

class VariableInventoryProduct(models.Model):
    """
    Actual product thats sold by the store. FKed to an actual satchmo product.
    """
    product = models.OneToOneField(Product)
    product_type = models.ForeignKey(VariableInventoryProductType)
    day = models.DateField(db_index=True)

    objects = VariableInventoryProductManager()

    class Meta:
        unique_together = ('product_type', 'day')

    def _get_subtype(self):
        return 'VariableInventoryProduct'

    def __unicode__(self):
        return '%s on %s' % (self.product_type.name, self.day)</pre>]]></content:encoded> <wfw:commentRss>http://blog.chachra.us/2010/09/08/selling-tickets-or-variable-inventory-items-using-satchmo/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Sandboxing emails in Django</title><link>http://blog.chachra.us/2010/07/10/sandboxing-emails-in-django/</link> <comments>http://blog.chachra.us/2010/07/10/sandboxing-emails-in-django/#comments</comments> <pubDate>Sun, 11 Jul 2010 05:14:42 +0000</pubDate> <dc:creator>Sumit Chachra</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Django]]></category> <category><![CDATA[Technology]]></category><guid
isPermaLink="false">http://chachra.tivixsites.com/?p=99</guid> <description><![CDATA[Its usually good to sandbox your QA / staging environments so that they don&#8217;t shoot out emails to real email addresses (say you&#8217;ve made a copy of your production database). Django 1.2 and their email backends make it really easy to do so.Here&#8217;s a testing email backend I wrote. Simply drop in a email address [...]]]></description> <content:encoded><![CDATA[<p></p><div>Its usually good to sandbox your QA / staging environments so that they don&#8217;t shoot out emails to real email addresses (say you&#8217;ve made a copy of your production database). Django 1.2 and their email backends make it really easy to do so.</div><p><br/></p><div>Here&#8217;s a testing email backend I wrote. Simply drop in a email address associated with the DEFAULT_TO_EMAIL setting in your settings.py. Also set the EMAIL_BACKEND in settings.py to the class below.</div><p><br/></p><div>This also takes care of cases where in your code you&#8217;re sending a &#8220;mass mail&#8221; (using send_mass_mail), it&#8217;ll only send one out.</div><pre class="brush:python">from django.core.mail.backends.smtp import EmailBackend
class TestingEmailBackend(EmailBackend):
    """
    Used in dev and qa
    """
    def send_messages(self, email_messages):
        """
        Overrides the to email address. Also if there are tons of messages being sent out then it reduces them to
        1 message.
        """
        if len(email_messages) &gt; 1:
            email_messages = (email_messages[0],)
        email_messages[0].to = [django_settings.DEFAULT_TO_EMAIL,]
        super(TestingEmailBackend, self).send_messages(email_messages)</pre>]]></content:encoded> <wfw:commentRss>http://blog.chachra.us/2010/07/10/sandboxing-emails-in-django/feed/</wfw:commentRss> <slash:comments>105</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 6/42 queries in 0.004 seconds using disk

Served from: blog.chachra.us @ 2012-02-04 20:42:25 -->
