Commits

Alexander Solovyov committed 4a95fc4

fix svarga.contrib and samples/ to use new database system

  • Participants
  • Parent commits f4e5765

Comments (0)

Files changed (27)

File samples/simple/admin/sampleapp/models.py

-import random
+from svarga import db
 
-from svarga.db.models import factory
+Base = db('sampleapp')
 
-ModelBase, columns = factory('sampleapp')
-
-class Sample(ModelBase):
-     name = columns.String()
-     value = columns.String()
-     number = columns.String()
+class Sample(Base):
+     name = db.String()
+     value = db.String()
+     number = db.String()

File samples/simple/admin/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/bundle/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/customauth/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/customauth/testapp/user.py

-from svarga.db.models import *
+from svarga import db
 
-from svarga.contrib.auth.models_impl import User, Permission
+from svarga.contrib.auth.models_impl import User
 
 class MyUser(User):
-    login = StringColumn(max_length=128, unique=True, index=True)
+    login = db.String(max_length=128, unique=True, index=True)
 
-    #email = StringColumn(max_length=128)
+    #email = db.String(max_length=128)
 
     def __unicode__(self):
         return self.login

File samples/simple/metadata/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/metadata/testapp/models.py

-import random
+from svarga import db
 
-from svarga.db.models import *
+Base = db('sampleapp')
 
-ModelBase, c = factory('sampleapp')
 
-class Sample(ModelBase):
-     name = c.String()
-     value = c.String()
-     number = c.String()
+class Sample(Base):
+     name = db.String()
+     value = db.String()
+     number = db.String()
 
-class Test(ModelBase):
-     name = c.String(max_length=32)
-     value = c.String()
-     number = c.String(max_length=16)
+class Test(Base):
+     name = db.String(max_length=32)
+     value = db.String()
+     number = db.String(max_length=16)
 
-class Ref(ModelBase):
-     name = c.Unicode()
-     test = c.ForeignKey(Test, backref='refs')
+class Ref(Base):
+     name = db.Unicode()
+     test = db.ForeignKey(Test, backref='refs')
 
-class Tag(ModelBase):
-     name = c.Unicode()
-     tests = c.ManyToMany(Test, backref='tags')
+class Tag(Base):
+     name = db.Unicode()
+     tests = db.ManyToMany(Test, backref='tags')
 
-class OneTag(ModelBase):
-     name = c.Unicode()
-     test = c.OneToOne(Test, backref='onetag')
+class OneTag(Base):
+     name = db.Unicode()
+     test = db.OneToOne(Test, backref='onetag')

File samples/simple/modelform/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/modelform/testapp/models.py

-import random
+from svarga import db
 
-from svarga.db.models import factory
+Base = db('sampleapp')
 
-ModelBase, columns = factory('sampleapp')
 
-class Test(ModelBase):
-     id = columns.Integer(primary_key=True)
-     name = columns.String(max_length=32)
-     value = columns.String()
-     number = columns.String(max_length=16)
+class Test(Base):
+     id = db.Integer(primary_key=True)
+     name = db.String(max_length=32)
+     value = db.String()
+     number = db.String(max_length=16)
 
      def __unicode__(self):
           return self.name
 
-class Ref(ModelBase):
-     name = columns.Unicode()
-     test = columns.ForeignKey(Test, backref='refs')
+class Ref(Base):
+     name = db.Unicode()
+     test = db.ForeignKey(Test, backref='refs')
 
      def __unicode__(self):
           return self.name
 
-class Tag(ModelBase):
+class Tag(Base):
      class Meta:
           description = {
                'name': 'User name',
                'tests': 'All tests',
                }
 
-     name = columns.Unicode()
-     tests = columns.ManyToMany(Test, backref='tags')
+     name = db.Unicode()
+     tests = db.ManyToMany(Test, backref='tags')
 
      def __unicode__(self):
           return self.name

File samples/simple/modelformset/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/modelformset/testapp/models.py

-import random
+from svarga import db
 
-from svarga.db.models import factory
+Base = db('sampleapp')
 
-ModelBase, c = factory('sampleapp')
 
-class Test(ModelBase):
-     name = c.String(max_length=32)
-     value = c.String()
-     number = c.String(max_length=16)
+class Test(Base):
+     name = db.String(max_length=32)
+     value = db.String()
+     number = db.String(max_length=16)
 
      def __unicode__(self):
           return self.name
 
-class Ref(ModelBase):
-     name = c.Unicode()
-     test = c.ForeignKey(Test, backref='refs')
+class Ref(Base):
+     name = db.Unicode()
+     test = db.ForeignKey(Test, backref='refs')
 
      def __unicode__(self):
           return self.name
 
-class Tag(ModelBase):
+class Tag(Base):
      class Meta:
           description = {
                'name': 'User name',
                'tests': 'All tests',
                }
 
-     name = c.Unicode()
-     tests = c.ManyToMany(Test, backref='tags')
+     name = db.Unicode()
+     tests = db.ManyToMany(Test, backref='tags')
 
      def __unicode__(self):
           return self.name

File samples/simple/models/sampleapp/models.py

-import random
+from svarga import db
 
-from svarga.db.models import factory
+Base = db('sampleapp')
 
-ModelBase, columns = factory('sampleapp')
+class Test(Base):
+     name = db.String()
+     value = db.String()
+     number = db.String(max_length=16)
 
-class Test(ModelBase):
-     name = columns.String()
-     value = columns.String()
-     number = columns.String(max_length=16)
+class Ref(Base):
+     name = db.Unicode()
+     test = db.ForeignKey(Test, backref='refs')
+     tags = db.ForeignKey('Tag')
 
-class Ref(ModelBase):
-     name = columns.Unicode()
-     test = columns.ForeignKey(Test, backref='refs')
-     tags = columns.ForeignKey('Tag')
-
-class Tag(ModelBase):
-     name = columns.Unicode()
-     tests = columns.ManyToMany(Test, backref='tags')
+class Tag(Base):
+     name = db.Unicode()
+     tests = db.ManyToMany(Test, backref='tags')

File samples/simple/models/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/multiapp/app1/models.py

-import random
+from svarga import db
 
-from svarga.db.models import factory
+Base = db('sampleapp')
 
-ModelBase, columns = factory('app1')
-
-class User(ModelBase):
-     name = columns.String()
-     password = columns.String()
+class User(Base):
+     name = db.String()
+     password = db.String()

File samples/simple/multiapp/app2/models.py

-import random
-
-from svarga.db.models import factory
+from svarga import db
 from app1.models import User
 
-ModelBase, columns = factory('app2')
+Base = db('app2')
 
-class Test(ModelBase):
-     name = columns.String()
-     value = columns.String()
-     user = columns.ForeignKey('app1.models.User', backref='tests')
+class Test(Base):
+     name = db.String()
+     value = db.String()
+     user = db.ForeignKey(User, backref='tests')
 

File samples/simple/multiapp/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/tableview/sampleapp/models.py

-import random
+from svarga import db
 
-from svarga.db.models import factory
+Base = db('sampleapp')
 
-ModelBase, columns = factory('sampleapp')
-
-class Related(ModelBase):
-     info = columns.String()
+class Related(Base):
+     info = db.String()
 
      def __init__(self, info):
           self.info = info
      def __unicode__(self):
           return self.info
 
-class Sample(ModelBase):
-     name = columns.String()
-     value = columns.String()
-     number = columns.String()
+class Sample(Base):
+     name = db.String()
+     value = db.String()
+     number = db.String()
 
-     ref = columns.ForeignKey(Related, backref='samples')
+     ref = db.ForeignKey(Related, backref='samples')
 

File samples/simple/tableview/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/simple/test/myapp/models.py

-from sqlalchemy.orm import backref
+from svarga import db
 
-from svarga.db.models import factory
+Base = db('myapp')
 
-ModelBase, columns = factory('myapp')
-
-class User(ModelBase):
-     name = columns.String()
-     fullname = columns.String()
-     password = columns.String()
+class User(Base):
+     name = db.String()
+     fullname = db.String()
+     password = db.String()
 
      def __init__(self, name, fullname, password):
          self.name = name
      def __repr__(self):
         return "<User('%s','%s', '%s')>" % (self.name, self.fullname, self.password)
 
-class Address(ModelBase):
-     email_address = columns.String(nullable=False)
-     user = columns.ForeignKey(User, backref='addresses')
+class Address(Base):
+     email_address = db.String(nullable=False)
+     user = db.ForeignKey(User, backref='addresses')
 
      def __init__(self, email_address):
          self.email_address = email_address
          return "<Address('%s')>" % self.email_address
 
 
-class Author(ModelBase):
-     name = columns.String()
+class Author(Base):
+     name = db.String()
 
-class Book(ModelBase):
-     name = columns.String()
-     authors = columns.ManyToMany(Author, backref='books')
+class Book(Base):
+     name = db.String()
+     authors = db.ManyToMany(Author, backref='books')

File samples/simple/test/settings.py

 # Jinja2 template path
 TEMPLATE_PATHS = [op.join(ROOT, 'templates')]
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.db'
-SQLA_ENGINE_SETTINGS = {
-    'echo': True,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.db'))}
 
 # Cache
 CACHE_URL = 'locmem://'

File samples/tutorials/blog/blog/models.py

 from datetime import datetime
 
-from svarga.db.models import factory
+from svarga import db
 
-Model, columns = factory('blog')
+Base = db('blog')
 
-class Post(Model):
-    title = columns.Unicode()
-    text = columns.UnicodeText()
-    date = columns.DateTime(default=datetime.now)
+class Post(Base):
+    title = db.String()
+    text = db.Text()
+    date = db.DateTime(default=datetime.now)
 
     def __unicode__(self):
         return self.title
 
-class Comment(Model):
-    post = columns.ForeignKey(Post, backref='comments')
-    text = columns.UnicodeText()
-    date = columns.DateTime(default=datetime.now)
+class Comment(Base):
+    post = db.ForeignKey(Post, backref='comments')
+    text = db.Text()
+    date = db.DateTime(default=datetime.now)

File samples/tutorials/blog/settings.py

+import os.path as op
+ROOT = op.normpath(op.dirname(__file__))
+
 # Default url configuration
 URLCONF = 'urls.url_map'
 
-# SQL Alchemy settings
-SQLA_URL = 'sqlite:///data.sqlite'
-SQLA_ENGINE_SETTINGS = {
-    'echo': False,
-    }
+DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.sqlite'))}
 
 # Your secret key
 SECRET_KEY = 'd7HNxTHOSaoNvBU8jNMBtIg0JtnSoM1O'

File svarga/bootstrap/project_template/settings.py_tmpl

 DATABASES = {'default': ('sqla', 'sqlite:///' + op.join(ROOT, 'data.sqlite'),
                          {'engine_options': {'echo': False}})}
 
-# Your secret key
 SECRET_KEY = %(secretkey)r
 
-# Applications
-LOCAL_APPS = (
-    )
+LOCAL_APPS = [
+    ]

File svarga/contrib/auth/models_impl.py

 import datetime
 
-from svarga.db.models import factory
+from svarga import db
 
 from svarga.contrib.auth import utils
 
-ModelBase, columns = factory('auth')
+Base = db('auth')
 
 # This will never be a valid hash
 
-class Permission(ModelBase):
+class Permission(Base):
     '''Database permission model'''
-    name = columns.String(max_length=32, unique=True)
-    description = columns.String(max_length=50)
+    name = db.String(max_length=32, unique=True)
+    description = db.String(max_length=50)
 
     def __unicode__(self):
         return unicode(self.name)
     def __getitem__(self, perm_name):
         return self.user.has_permission(perm_name)
 
-class User(ModelBase):
-    email = columns.String(max_length=128, index=True, unique=True)
+class User(Base):
+    email = db.String(max_length=128, index=True, unique=True)
 
-    first_name = columns.String(max_length=32)
-    last_name = columns.String(max_length=32)
+    first_name = db.String(max_length=32)
+    last_name = db.String(max_length=32)
 
-    password = columns.String(max_length=128)
+    password = db.String(max_length=128)
 
-    is_active = columns.Boolean(default=True)
-    is_admin = columns.Boolean(default=False)
+    is_active = db.Boolean(default=True)
+    is_admin = db.Boolean(default=False)
 
-    last_login = columns.DateTime(default=datetime.datetime.now)
-    date_joined = columns.DateTime(default=datetime.datetime.now)
+    last_login = db.DateTime(default=datetime.datetime.now)
+    date_joined = db.DateTime(default=datetime.datetime.now)
 
-    permissions = columns.ManyToMany(Permission, backref='users')
+    permissions = db.ManyToMany(Permission, backref='users')
 
     def __init__(self, *args, **kwargs):
         self.__modelinit__()

File svarga/contrib/dberrorlog/models.py

 import datetime
 
-from sqlalchemy import Column, String, Text, Integer, DateTime
+from svarga import db
 
-from svarga.db.models import factory
+Base = db('dberrlog')
 
-ModelBase, columns = factory('dberrlog')
+class Error(Base):
+    class_name = db.String(max_length=128, index=True)
+    server_name = db.String(max_length=128, index=True)
+    checksum = db.String(max_length=32, index=True)
 
-class Error(ModelBase):
-    class_name = columns.String(max_length=128, index=True)
-    server_name = columns.String(max_length=128, index=True)
-    checksum = columns.String(max_length=32, index=True)
-
-    user = columns.String(max_length=128)
-    message = columns.Text()
-    traceback = columns.Text()
-    times_seen = columns.Integer(default=0)
-    first_seen = columns.DateTime(default=datetime.datetime.now)
-    last_seen = columns.DateTime()
-    url = columns.Text()
+    user = db.String(max_length=128)
+    message = db.Text()
+    traceback = db.Text()
+    times_seen = db.Integer(default=0)
+    first_seen = db.DateTime(default=datetime.datetime.now)
+    last_seen = db.DateTime()
+    url = db.Text()

File svarga/contrib/sessions/backends/db.py

 import datetime
 
-from svarga.core.env import env
+from svarga import env, db
 from svarga.core.exceptions import SuspiciousOperation
 
 from svarga.contrib.sessions.backends.base import SessionBase, CreateError
-from svarga.db.models import factory
-from svarga.utils.imports import import_module
 
-ModelBase, columns = factory('svarga')
+Base = db('svarga')
 
-class Session(ModelBase):
-    session_key = columns.String(max_length=80, unique=True, index=True)
-    session_data = columns.String(max_length=65535)
-    expire_date = columns.DateTime()
+class Session(Base):
+    session_key = db.String(max_length=80, unique=True, index=True)
+    session_data = db.String(max_length=65535)
+    expire_date = db.DateTime()
 
 class SessionProvider(SessionBase):
     '''
         try:
             Session.objects.add(obj)
             env.sqla.session.commit()
-        except session.IntegrityError:
-            raise CreateError
+        except Session.IntegrityError:
+            raise CreateError()
 
     def exists(self, session_key):
         return (Session.objects.query

File svarga/core/database.py

 
         if 'default' in databases:
             opts, kwargs = getopts(databases.pop('default'))
-            self.databases['default'] = self.default
+            self.databases['default'] = amalgam.amalgam(*opts, **kwargs)
         else:
             self.databases['default'] = NotDeclared()