How to use the sqlobject.SQLObject function in SQLObject

To help you get started, we’ve selected a few SQLObject examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jplusplus / rentswatch-scraper / rentswatch_scraper / db.py View on Github external
connection = connectionForURI(DATABASE_URL)
connection.dbEncoding="utf8"

def setup(databaseUrl=DATABASE_URL):
    # Establish the connection
    connection = connectionForURI(databaseUrl)
    connection.dbEncoding="utf8"
    # No pooling
    connection._pool = None
    sqlhub.processConnection = connection
    # Creates tables
    Ad.createTable(ifNotExists=True)
    Report.createTable(ifNotExists=True)


class Ad(SQLObject):
    # "listed" if needs more scraping, "scraped" if it's done
    status = StringCol(length=10, default=None)
    # Name of the website
    site = StringCol(length=30, notNull=True)
    # Date the ad was first scraped
    createdAt = DateTimeCol(default=DateTimeCol.now)
    # The unique ID from the site where it's scrapped from
    siteId = StringCol(length=100, notNull=True)
    # Extra costs (heating mostly)
    serviceCharge = FloatCol(default=None)
    serviceChargeOriginalCurrency = FloatCol(default=None)
    # Base costs (without heating)
    baseRent = FloatCol(default=None)
    baseRentOriginalCurrency = FloatCol(default=None)
    # Total cost
    totalRent = FloatCol(default=None)
github fedora-infra / python-fedora / fedora / tg / identity / soprovidercsrf.py View on Github external
Must return an object with the following properties:
            user_name: original user name
            user: a provider dependant object (TG_User or similar)
            groups: a set of group names
            permissions: a set of permission names

        """
        return SqlObjectCsrfIdentity()

    def authenticated_identity(self, user):
        """Constructs Identity object for users with no visit_key."""
        return SqlObjectCsrfIdentity(user=user)


class TG_VisitIdentity(SQLObject):
    """A visit to your website."""
    class sqlmeta:
        table = "tg_visit_identity"

    visit_key = StringCol(length=40, alternateID=True,
        alternateMethodName="by_visit_key")
    user_id = IntCol()


class TG_Group(InheritableSQLObject):
    """An ultra-simple group definition."""
    class sqlmeta:
        table = "tg_group"

    group_name = UnicodeCol(length=16, alternateID=True,
        alternateMethodName="by_group_name")
github AGProjects / openxcap / xcap / backend / sipthor.py View on Github external
SipAccountData(account=self, profile=value)
        else:
            data[0].profile = value

    def _get_profile(self):
        return self.data[0].profile

    def set(self, **kwargs):
        kwargs = kwargs.copy()
        profile = kwargs.pop('profile', None)
        SQLObject.set(self, **kwargs)
        if profile is not None:
            self._set_profile(profile)


class SipAccountData(SQLObject):
    class sqlmeta:
        table = 'sip_accounts_data'
    account  = ForeignKey('SipAccount', cascade=True)
    profile  = JSONCol()


class ThorEntityAddress(str):
    def __new__(cls, ip, control_port=None, version='unknown'):
        instance = str.__new__(cls, ip)
        instance.ip = ip
        instance.version = version
        instance.control_port = control_port
        return instance


class GetSIPWatchers(Request):
github edsu / mediatypes / lib / rdflib / store / _sqlobject.py View on Github external
from rdflib.Literal import Literal
from rdflib.URIRef import URIRef
from rdflib.BNode import BNode
from rdflib.exceptions import ContextTypeError

from rdflib.compat import rsplit

import sqlobject
from sqlobject import *

LITERAL = 0
URI = 1
NO_URI = 'uri://oops/'
Any = None

class BaseObject(sqlobject.SQLObject):

    _lazyUpdate = True
    _cacheValues = False

class Literals(BaseObject):

    hash = IntCol(notNull=1)
    value = StringCol(notNull=1, validator=validators.String(strip_spaces=1))
    hashIndex = DatabaseIndex('hash')

class Namespaces(BaseObject):

    hash = IntCol(notNull=1)
    value = StringCol(length=255, notNull=1,
                      validator=validators.String(strip_spaces=1))
    hashIndex = DatabaseIndex('hash')
github okfn / vdm / vdm / sqlobject / base.py View on Github external
def history(self):
        """Get the history of the repository.

        Revisions will not allow you to be at the model as that will not
        work correctly (see comments at top of module).

        @return: a list of ordered revisions with youngest first.
        """
        active = State.byName('active') 
        revisions = Revision.selectBy(state=active)
        revisions = revisions.orderBy('number')
        revisions = revisions.reversed()
        return revisions


class ObjectRevisionSQLObject(sqlobject.SQLObject):

    # to be defined in inheriting classes
    # base_object_name = ''
    
    state = sqlobject.ForeignKey('State', default=1)
    revision = sqlobject.ForeignKey('Revision')

    def copy(self, transaction):
        newvals = {}
        for col in self.sqlmeta.columns:
            if not col.startswith('revision'):
                value = getattr(self, col)
                newvals[col] = value
        newvals['revision'] = transaction
        newrev = self.__class__(**newvals)
        return newrev
github jplusplus / rentswatch-scraper / rentswatch_scraper / db.py View on Github external
# Floor the flat is at
    floor = StringCol(length=100, default=None)
    # y if there is a garden
    garden = BoolCol(default=None)
    # y if the flat is wheelchair accessible
    barrierFree = BoolCol(default=None)
    # Country, 2 letter code
    country = StringCol(length=2, default=None)
    # URL of the page
    sourceUrl = StringCol(length=1000, default=None)
    # URL of the page
    description = StringCol(default=None)
    # An ad must be unique on the website
    adIndex = DatabaseIndex('siteId', 'site', unique=True)

class Rent(SQLObject):
    # Total cost
    totalRent = FloatCol(default=None)
    # Surface in square meters
    livingSpace = FloatCol(default=None)
    # Currency, 3 letter code
    currency = StringCol(length=3, default='EUR')
    # Date of arrival
    moveIn = DateCol(default=None)
    # IP of the user hashed
    ipHash = StringCol(length=512,default=None)
    # Date of creating
    createdAt = DateTimeCol(default=DateTimeCol.now)

class Report(SQLObject):
    createdAt = DateTimeCol(default=DateTimeCol.now)                            # Date the ad was first scraped
    country = StringCol(length=2, default=None)                                 # Country, 2 letter code
github RDFLib / rdflib / rdflib / store / _sqlobject.py View on Github external
from rdflib.Literal import Literal
from rdflib.URIRef import URIRef
from rdflib.BNode import BNode
from rdflib.exceptions import ContextTypeError

from rdflib.compat import rsplit

import sqlobject
from sqlobject import *

LITERAL = 0
URI = 1
NO_URI = 'uri://oops/'
Any = None

class BaseObject(sqlobject.SQLObject):

    _lazyUpdate = True
    _cacheValues = False

class Literals(BaseObject):

    hash = IntCol(notNull=1)
    value = StringCol(notNull=1, validator=validators.String(strip_spaces=1))
    hashIndex = DatabaseIndex('hash')

class Namespaces(BaseObject):

    hash = IntCol(notNull=1)
    value = StringCol(length=255, notNull=1,
                      validator=validators.String(strip_spaces=1))
    hashIndex = DatabaseIndex('hash')
github saghul / TunnelIt / tunnelit / database.py View on Github external
from application import log
from application.python import Null
from application.python.types import Singleton
from sqlobject import connectionForURI, sqlhub, IntCol, SQLObject, StringCol
from twisted.internet.threads import deferToThread


def defer_to_thread(func):
    """Decorator to run DB queries in Twisted's thread pool"""
    def wrapper(*args, **kw):
        return deferToThread(func, *args, **kw)
    return wrapper


class Users(SQLObject):
    username = StringCol()


class UserKeys(SQLObject):
    user_id = IntCol()
    key = StringCol(sqlType='LONGTEXT')


class DatabaseError(Exception): pass

class Database(object):
    __metaclass__ = Singleton

    def __init__(self, dburi):
        if ':memory:' in dburi:
            log.warn('SQLite in-memory DB is not supported')