Changeset - 44a1f8b7358b
[Not reviewed]
0 2 0
Lance Edgar (lance) - 12 years ago 2012-09-28 16:14:41
lance@edbob.org
ignore changes for batch data
2 files changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rattail/db/__init__.py
Show inline comments
 
@@ -30,48 +30,54 @@ import logging
 

	
 
from sqlalchemy.event import listen
 

	
 
import edbob
 

	
 
import rattail
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
def before_flush(session, flush_context, instances):
 
    """
 
    Listens for session flush events.  This function is responsible for adding
 
    stub records to the 'changes' table, which will in turn be used by the
 
    database synchronizer.
 
    """
 

	
 
    def record_change(instance, deleted=False):
 

	
 
        # No need to record changes for Change. :)
 
        if isinstance(instance, rattail.Change):
 
            return
 

	
 
        # No need to record changes for batch data.
 
        if isinstance(instance, (rattail.Batch,
 
                                 rattail.BatchColumn,
 
                                 rattail.BatchRow)):
 
            return
 

	
 
        # Ignore instances which don't use UUID.
 
        if not hasattr(instance, 'uuid'):
 
            return
 

	
 
        # Provide an UUID value, if necessary.
 
        if not instance.uuid:
 
            instance.uuid = edbob.get_uuid()
 

	
 
        # Record the change.
 
        change = session.query(rattail.Change).get(
 
            (instance.__class__.__name__, instance.uuid))
 
        if not change:
 
            change = rattail.Change(
 
                class_name=instance.__class__.__name__,
 
                uuid=instance.uuid)
 
            session.add(change)
 
        change.deleted = deleted
 
        log.debug("before_flush: recorded change: %s" % repr(change))
 

	
 
    for instance in session.deleted:
 
        log.debug("before_flush: deleted instance: %s" % repr(instance))
 
        record_change(instance, deleted=True)
 

	
 
    for instance in session.new:
rattail/db/extension/model.py
Show inline comments
 
@@ -33,49 +33,49 @@ from sqlalchemy import String, Integer, DateTime, Date, Boolean, Numeric, Text
 
from sqlalchemy import types
 
from sqlalchemy import and_
 
from sqlalchemy.orm import relationship, object_session
 
from sqlalchemy.ext.associationproxy import association_proxy
 
from sqlalchemy.ext.orderinglist import ordering_list
 

	
 
import edbob
 
from edbob.db.model import Base, uuid_column
 
from edbob.db.extensions.contact import Person, EmailAddress, PhoneNumber
 
from edbob.exceptions import LoadSpecError
 
from edbob.sqlalchemy import getset_factory
 

	
 
from rattail import sil
 
from rattail import batches
 
from rattail.gpc import GPCType
 

	
 

	
 
__all__ = ['Change', 'Store', 'StoreEmailAddress', 'StorePhoneNumber',
 
           'Department', 'Subdepartment', 'Brand', 'Category', 'Vendor',
 
           'VendorContact', 'VendorPhoneNumber', 'VendorEmailAddress',
 
           'Product', 'ProductCost', 'ProductPrice', 'Customer',
 
           'CustomerEmailAddress', 'CustomerPhoneNumber', 'CustomerGroup',
 
           'CustomerGroupAssignment', 'CustomerPerson', 'Employee',
 
           'EmployeeEmailAddress', 'EmployeePhoneNumber',
 
           'BatchColumn', 'Batch', 'LabelProfile']
 
           'BatchColumn', 'Batch', 'BatchRow', 'LabelProfile']
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class Change(Base):
 
    """
 
    Represents a changed (or deleted) record, which is pending synchronization
 
    to another database.
 
    """
 

	
 
    __tablename__ = 'changes'
 

	
 
    class_name = Column(String(25), primary_key=True)
 
    uuid = Column(String(32), primary_key=True)
 
    deleted = Column(Boolean)
 

	
 
    def __repr__(self):
 
        status = 'deleted' if self.deleted else 'new/changed'
 
        return "<Change: %s, %s, %s>" % (self.class_name, self.uuid, status)
 

	
 

	
 
class BatchColumn(Base):
 
    """
0 comments (0 inline, 0 general)