Commits

Rafał Kos  committed db007d2

fixed saving company, first steps of gathering info about changes in database

  • Participants
  • Parent commits 398aa10

Comments (0)

Files changed (5)

File pytis/controllers/companies.py

         c.place_form = PlaceForm(request.POST, prefix='place', idCompany=c.company.id)
 
         if request.method == 'POST' and 'action' in request.POST:
-
-            #raise Exception(c.company)
-
-            def test(value, name):
-                raise Exception('name')
-
+            
             if request.POST['action'] == 'company' and c.form.validate(c.company):
                 c.form.populate_obj(c.company)
                 c.company.save()

File pytis/lib/database/mappers.py

 from sqlalchemy.orm.interfaces import MapperExtension
+from sqlalchemy.orm.attributes import get_history
 from pytis.model.document import Document
 
 class DocumentMapper(MapperExtension):
+    '''Get next number of document before insert'''
     def before_insert(self, mapper, connection, instance):        
-        Document.obtain_number(instance)
+        Document.obtain_number(instance)
+
+class HistoryMapper(MapperExtension):
+    '''Versioning system'''
+    def after_update(self, mapper, connection, instance):
+        history = []
+
+        for column in instance.__table__.columns:
+            change = get_history(instance, column.name)
+            if change.has_changes():
+                history.append({column.name : [change.added, change.deleted]})
+        
+        raise Exception(history)

File pytis/model/company.py

 ## -*- coding: utf-8 -*-
 
 from meta import Base, db
+from pytis.lib.database.mappers import HistoryMapper
 from pytis.model import meta
 from pytis.model.dictionary import Dictionary, Tax, Country
 from sqlalchemy import types, orm
             raise sa.exc.SQLAlchemyError
 
 class Company(Base):
-    __tablename__ = 'company'   
+    __tablename__ = 'company'      
 
     query = db.query_property(db.Query)
 

File pytis/model/form.py

                     u'Nie można zmieniać nazwy oraz akronimu kontrahenta jeśli zostały już na niego wystawione faktury'
                 )
 
-        super(EditCompanyForm, self).validate()
+        return super(EditCompanyForm, self).validate()
 
 class PlaceForm(PytisForm):
     id = HiddenField()

File pytis/model/meta.py

 class AbstractBase(object):    
     pass
 
-class MyMeta(DeclarativeMeta):
-    def __init__(cls, classname, bases, dict_):        
-        setattr(cls, 'content_type', cls.__name__.lower())
-        if hasattr(cls, '__log_changes__'):
-            if getattr(cls, '__log_changes__') == True:                
-                setattr(cls, '__mapper_args__', {'extension': ChangeLogger()})
-                
-        DeclarativeMeta.__init__(cls, classname, bases, dict_)       
-
 class Query(orm.Query):
     """Default query class."""