File: field_binary.py

package info (click to toggle)
tryton-server 7.0.40-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,748 kB
  • sloc: python: 53,502; xml: 5,194; sh: 803; sql: 217; makefile: 28
file content (59 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

from trytond.model import Check, ModelSQL, fields
from trytond.pool import Pool


class Binary(ModelSQL):
    'Binary'
    __name__ = 'test.binary'
    binary = fields.Binary('Binary')


class BinaryDefault(ModelSQL):
    'Binary Default'
    __name__ = 'test.binary_default'
    binary = fields.Binary('Binary Default')

    @staticmethod
    def default_binary():
        return b'default'


class BinaryRequired(ModelSQL):
    'Binary Required'
    __name__ = 'test.binary_required'
    binary = fields.Binary('Binary Required', required=True)


class BinaryRequiredSQLConstraint(ModelSQL):
    "Binary Required SQL Constraint"
    __name__ = 'test.binary_required_sql_constraint'
    binary = fields.Binary('Binary Required', required=True)
    constraint = fields.Boolean("Constraint")

    @classmethod
    def __setup__(cls):
        super().__setup__()
        t = cls.__table__()
        cls._sql_constraints.append(
            ('constraint', Check(t, t.constraint),
                'tests.msg_binary_required_sql_constraint'))


class BinaryFileStorage(ModelSQL):
    "Binary in FileStorage"
    __name__ = 'test.binary_filestorage'
    binary = fields.Binary('Binary', file_id='binary_id')
    binary_id = fields.Char('Binary ID')


def register(module):
    Pool.register(
        Binary,
        BinaryDefault,
        BinaryRequired,
        BinaryRequiredSQLConstraint,
        BinaryFileStorage,
        module=module, type_='model')