Exemplo n.º 1
0
from __future__ import unicode_literals
from uuid import UUID
from django.db.backends.mysql.base import django_conversions
from django.db import models


def prep_uuid(
        o,
        *args # pylint: disable=unused-argument
):
    return '0x%s' % o.hex


django_conversions.update({
    UUID: prep_uuid
})


class UuidField(models.fields.Field):
    """
    A Uuid field for MySQL (and MySQL only!) that converts to
    a `binary(16)` on the DB backend.  Unlike many of the implementations
    of binary fields out there (I'm looking at you django 1.6), this
    field does allow the user to do a lookup based on the UUID.

    The related value type of a Uuid field is the `uuid.UUID` class
    from python.
    """
    __metaclass__ = models.SubfieldBase
Exemplo n.º 2
0
# -*- coding: utf-8 -*-
import datetime
import six

from pymysql.constants import FIELD_TYPE
from django.core.exceptions import ValidationError
from django.db.models.fields import IntegerField
from django.db.models.fields import BooleanField
from django.db.backends.mysql.base import django_conversions

from tcms.core.forms.fields import DurationField as DurationFormField

django_conversions.update({FIELD_TYPE.TIME: None})


class DurationField(IntegerField):
    """Duration field for test run

    Value is stored as number of seconds in database and presents in Nitrate in
    timedelta type.

    Value should also be able to be serialized to integer as seconds, and then
    deserialized from value of seconds.
    """

    def to_python(self, value):
        if isinstance(value, six.integer_types):
            return datetime.timedelta(seconds=value)
        elif isinstance(value, datetime.timedelta):
            return value
        else:
Exemplo n.º 3
0
    # looks like pymysql is a tad different in his
    # typecast_* function
    def _with_more_args(function):
        def __with_more_args(data, *args):
            if len(args) > 0:
                data = args[-1]
                return function(data)
        return __with_more_args

    from pymysql.constants import FIELD_TYPE
    from django.db.backends.mysql.base import django_conversions
    from django.db.backends import util

    django_conversions.update({
            FIELD_TYPE.TIME: _with_more_args(util.typecast_time),
            FIELD_TYPE.DECIMAL: _with_more_args(util.typecast_decimal),
            FIELD_TYPE.NEWDECIMAL: _with_more_args(util.typecast_decimal),
                })
except ImportError:
        pass



if not settings.DEBUG:
    warnings.simplefilter('ignore')

# The first thing execute_manager does is call `setup_environ`.  Logging config
# needs to access settings, so we'll setup the environ early.
setup_environ(settings)

# Hardcore monkeypatching action.
Exemplo n.º 4
0
#   Xuqing Kuang <*****@*****.**>

# Suppress warning about string statement:
# pylint: disable-msg=W0105

import datetime

from django.db import models
from django.db.backends.mysql.base import django_conversions
from django.conf import settings

from MySQLdb.constants import FIELD_TYPE

from tcms.core.forms import TimedeltaFormField, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MIN

django_conversions.update({FIELD_TYPE.TIME: None})

class TimedeltaField(models.Field):
    u'''
    Store Python's datetime.timedelta in an integer column.
    Most databasesystems only support 32 Bit integers by default.
    '''
    __metaclass__=models.SubfieldBase
    def __init__(self, *args, **kwargs):
        super(TimedeltaField, self).__init__(*args, **kwargs)
    
    def to_python(self, value):
        if (value is None) or value == '':
            return datetime.timedelta(seconds=0)
        
        if isinstance(value, datetime.timedelta):
Exemplo n.º 5
0
# encoding: utf-8
from uuid import UUID
from django.db.backends.mysql.base import django_conversions
from django.db import models


def prep_uuid(
        o,
        *args  # pylint: disable=unused-argument
):
    return '0x%s' % o.hex


django_conversions.update({UUID: prep_uuid})


class UuidField(models.fields.Field):
    """
    A Uuid field for MySQL (and MySQL only!) that converts to
    a `binary(16)` on the DB backend.  Unlike many of the implementations
    of binary fields out there (I'm looking at you django 1.6), this
    field does allow the user to do a lookup based on the UUID.

    The related value type of a Uuid field is the `uuid.UUID` class
    from python.
    """
    def to_python(self, value):
        if isinstance(value, UUID):
            return value
        if value is None:
            return None