How to use the sqlobject.ForeignKey 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 iven / Yaner / yaner / Category.py View on Github external
This module contains the L{Category} presentable of L{yaner}.
"""

import sqlobject

from yaner.Presentable import Presentable

class Category(Presentable, sqlobject.SQLObject):
    """
    Category presentable of the L{Pool}s.
    """

    name = sqlobject.UnicodeCol()
    directory = sqlobject.UnicodeCol()

    pool = sqlobject.ForeignKey('Pool')
    tasks = sqlobject.MultipleJoin('Task')

    def _init(self, *args, **kwargs):
        Presentable.__init__(self)
        sqlobject.SQLObject._init(self, *args, **kwargs)

        self.parent = kwargs['queuing']
        self.icon = "gtk-directory"

    @property
    def description(self):
        """Get the description of the presentable."""
        return "This is a category."
github stoq / stoq / stoq / domain / payment.py View on Github external
class AbstractPaymentGroup(InheritableModelAdapter):

    (STATUS_PREVIEW, 
     STATUS_OPEN, 
     STATUS_CLOSED, 
     STATUS_CANCELLED) = range(4)

    __implements__ = IPaymentGroup, IContainer

    status = IntCol(default=STATUS_OPEN)
    open_date = DateTimeCol(default=datetime.now())
    close_date = DateTimeCol(default=None)
    notes = StringCol(default='')
    thirdparty = ForeignKey('Person')


    def set_thirdparty(self, person):
        if not isinstance(person, Person):
            raise TypeError("A Person object is required for set_thirdparty, "
                            "got %s instead." % type(person))
        self.thirdparty = person

    def get_thirdparty(self):
        return self.thirdparty

    def get_balance(self):
        values = [s.value for s in self.get_items()]
        return reduce(operator.add, values, 0.0)

    def add_debit(self, value, reason, category, date=None):
github tortoise / orm-benchmarks / src / sqlobject / models.py View on Github external
timestamp = DateTimeCol(default=datetime.now, notNone=True)
        level = IntCol(notNone=True)
        level_index = DatabaseIndex('level')
        text = UnicodeCol(length=255, notNone=True)
        text_index = DatabaseIndex('text')


if test == 2:
    class Journal(SQLObject):
        timestamp = DateTimeCol(default=datetime.now, notNone=True)
        level = IntCol(notNone=True)
        level_index = DatabaseIndex('level')
        text = UnicodeCol(length=255, notNone=True)
        text_index = DatabaseIndex('text')

        parent = ForeignKey('Journal', default=None)
        children = MultipleJoin('Journal')
        related = RelatedJoin('Journal', joinColumn='journal_id', otherColumn='journal_from_id')
        related_from = RelatedJoin('Journal', joinColumn='journal_from_id', otherColumn='journal_id', createRelatedTable=False)

if test == 3:
    class Journal(SQLObject):
        timestamp = DateTimeCol(default=datetime.now, notNone=True)
        level = IntCol(notNone=True)
        level_index = DatabaseIndex('level')
        text = UnicodeCol(length=255, notNone=True)
        text_index = DatabaseIndex('text')

        col_float1 = FloatCol(default=2.2, notNone=True)
        col_smallint1 = IntCol(default=2, notNone=True)
        col_int1 = IntCol(default=2000000, notNone=True)
        col_bigint1 = IntCol(default=99999999, notNone=True)
github mikrosimage / OpenRenderManagement / src / octopus / dispatcher / db / pulidb.py View on Github external
startTime = DateTimeCol()
    updateTime = DateTimeCol()
    endTime = DateTimeCol()
    archived = BoolCol()
    dependencies = MultipleJoin('Dependencies')
    # Adding autoretry capability on task
    maxAttempt = IntCol()


class Dependencies(SQLObject):
    class sqlmeta:
        lazyUpdate = True
    toNodeId = IntCol()
    statusList = UnicodeCol()
    taskNodes = ForeignKey('TaskNodes')
    folderNodes = ForeignKey('FolderNodes')
    archived = BoolCol()


class TaskGroups(SQLObject):
    class sqlmeta:
        lazyUpdate = True
    name = UnicodeCol()
    parentId = IntCol()
    user = UnicodeCol()
    priority = IntCol()
    dispatchKey = FloatCol()
    maxRN = IntCol()
    environment = UnicodeCol()
    requirements = UnicodeCol()
    tags = UnicodeCol()
    strategy = UnicodeCol()
github stoq / stoq / stoq / domain / payment / base.py View on Github external
# XXX The payment_id attribute will be an alternateID after 
    # fixing bug 2214
    payment_id = IntCol(default=None)
    status = IntCol(default=STATUS_PREVIEW)
    due_date = DateTimeCol()
    paid_date = DateTimeCol(default=None)
    paid_value = FloatCol(default=0.0)
    base_value = FloatCol()
    value = FloatCol()
    interest = FloatCol(default=0.0)
    discount = FloatCol(default=0.0)
    description = StringCol(default=None)
    payment_number = StringCol(default=None)

    method = ForeignKey('AbstractPaymentMethodAdapter')
    method_details = ForeignKey('PaymentMethodDetails', default=None)
    group = ForeignKey('AbstractPaymentGroup')
    destination = ForeignKey('PaymentDestination')
    

    #
    # SQLObject hooks
    #

    def _create(self, id, **kw):
        if not 'value' in kw:
            raise TypeError('You must provide a value argument')
        if not 'base_value' in kw or not kw['base_value']:
            kw['base_value'] = kw['value']
        Domain._create(self, id, **kw)
github stoq / stoq / stoq / domain / service.py View on Github external
#
    # Auxiliary methods
    #

    def sell(self):
        conn = self.get_connection()
        sellable = ISellable(self.get_adapted(), connection=conn)
        if not sellable.can_be_sold():
            msg = '%s is already sold' % self.get_adapted()
            raise SellError(msg)

class DeliveryItem(Domain):
    """Class responsible to store all the products for a certain delivery"""
    
    quantity = FloatCol()
    sellable = ForeignKey('AbstractSellable')
    delivery = ForeignKey('ServiceSellableItemAdaptToDelivery')

    #
    # Accessors
    #

    def get_price(self):
        return self.sellable.get_price()

    def get_total(self):
        return self.get_price() * self.quantity

#
# Adapters
#
github stoq / stoq / stoqlib / domain / payment / base.py View on Github external
open_date = DateTimeCol(default=datetime.now)
    due_date = DateTimeCol()
    paid_date = DateTimeCol(default=None)
    cancel_date = DateTimeCol(default=None)
    paid_value = PriceCol(default=0)
    base_value = PriceCol()
    value = PriceCol()
    interest = PriceCol(default=0)
    discount = PriceCol(default=0)
    description = UnicodeCol(default=None)
    payment_number = UnicodeCol(default=None)
    method = ForeignKey('AbstractPaymentMethodAdapter')
    # FIXME: Move to methods itself?
    method_details = ForeignKey('PaymentMethodDetails', default=None)
    group = ForeignKey('AbstractPaymentGroup')
    till = ForeignKey('Till')
    destination = ForeignKey('PaymentDestination')

    def _check_status(self, status, operation_name):
        assert self.status == status, ('Invalid status for %s '
                                       'operation: %s' % (operation_name,
                                       self.statuses[self.status]))

    #
    # SQLObject hooks
    #

    def _create(self, id, **kw):
        if not 'value' in kw:
            raise TypeError('You must provide a value argument')
        if not 'base_value' in kw or not kw['base_value']:
            kw['base_value'] = kw['value']
github stoq / stoq / stoq / domain / payment / base.py View on Github external
class PaymentAdaptToOutPayment(ModelAdapter):

    implements(IOutPayment)

    def pay(self):
        payment = self.get_adapted()
        if not payment.is_to_pay():
            raise ValueError("This payment is already paid.")
        payment.pay()

Payment.registerFacet(PaymentAdaptToOutPayment, IOutPayment)

class CashAdvanceInfo(Domain):
    employee = ForeignKey("PersonAdaptToEmployee")
    payment = ForeignKey("Payment")
    open_date = DateTimeCol(default=datetime.datetime.now)
github stoq / stoq / stoqlib / domain / payment / methods.py View on Github external
PaymentDestination # pyflakes

#
# Domain Classes
#

class CheckData(Domain):
    """Stores check informations and also a history of possible
    devolutions.

    B{Importante attributes}:
        - I{bank_data}: information about the bank account of this check.
        - I{payment}: the payment object.
    """
    payment = ForeignKey('Payment')
    bank_data = ForeignKey('BankAccount')


class BillCheckGroupData(Domain):
    """Stores general information for payment groups which store checks.

    B{Importante attributes}:
        - I{interest}: a percentage that represents the
                       interest. This value
                       must be betwen 0 and 100.
        - I{interval_types}: a useful attribute when generating multiple
                             payments. callsites you ensure to use it
                             properly sending valid constants which define
                             period types for payment generation. All the
                             interval_types constants are at
                             L{stoq.lib.defaults} path.
    """