# HG changeset patch # User Sylvain Thénault # Date 1307369589 -7200 # Node ID 2455cdbeadcacdb9cdbe3d742616e967a463cc46 # Parent e4399a37674ec759383ed1f35d8a52c06eca0eba [schema] support for BigInt type. Closes #1720995 diff -r e4399a37674e -r 2455cdbeadca cwvreg.py --- a/cwvreg.py Mon Jun 06 15:52:53 2011 +0200 +++ b/cwvreg.py Mon Jun 06 16:13:09 2011 +0200 @@ -194,12 +194,14 @@ _ = unicode from warnings import warn +from datetime import datetime, date, time, timedelta from logilab.common.decorators import cached, clear_cache from logilab.common.deprecation import deprecated, class_deprecated from logilab.common.modutils import cleanup_sys_modules from rql import RQLHelper +from yams.constraints import BASE_CONVERTERS from cubicweb import (ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid, ObjectNotFound, NoSelectableObject, RegistryNotFound, @@ -849,24 +851,15 @@ return self['views'].select(__vid, req, rset=rset, **kwargs) -import decimal -from datetime import datetime, date, time, timedelta - -YAMS_TO_PY = { # XXX unify with yams.constraints.BASE_CONVERTERS? - 'String' : unicode, - 'Bytes': Binary, - 'Password': str, - - 'Boolean': bool, - 'Int': int, - 'Float': float, - 'Decimal': decimal.Decimal, - +# XXX unify with yams.constraints.BASE_CONVERTERS? +YAMS_TO_PY = BASE_CONVERTERS.copy() +YAMS_TO_PY.update({ + 'Bytes': Binary, 'Date': date, 'Datetime': datetime, 'TZDatetime': datetime, 'Time': time, 'TZTime': time, 'Interval': timedelta, - } + }) diff -r e4399a37674e -r 2455cdbeadca hooks/syncschema.py --- a/hooks/syncschema.py Mon Jun 06 15:52:53 2011 +0200 +++ b/hooks/syncschema.py Mon Jun 06 16:13:09 2011 +0200 @@ -42,12 +42,15 @@ TYPE_CONVERTER = { # XXX 'Boolean': bool, 'Int': int, + 'BigInt': int, 'Float': float, 'Password': str, 'String': unicode, 'Date' : unicode, 'Datetime' : unicode, 'Time' : unicode, + 'TZDatetime' : unicode, + 'TZTime' : unicode, } # core entity and relation types which can't be removed diff -r e4399a37674e -r 2455cdbeadca i18n/de.po --- a/i18n/de.po Mon Jun 06 15:52:53 2011 +0200 +++ b/i18n/de.po Mon Jun 06 16:13:09 2011 +0200 @@ -256,6 +256,12 @@ msgid "BaseTransition_plural" msgstr "Übergänge (abstrakt)" +msgid "BigInt" +msgstr "" + +msgid "BigInt_plural" +msgstr "" + msgid "Bookmark" msgstr "Lesezeichen" diff -r e4399a37674e -r 2455cdbeadca i18n/en.po --- a/i18n/en.po Mon Jun 06 15:52:53 2011 +0200 +++ b/i18n/en.po Mon Jun 06 16:13:09 2011 +0200 @@ -245,6 +245,12 @@ msgid "BaseTransition_plural" msgstr "Transitions (abstract)" +msgid "BigInt" +msgstr "Big integer" + +msgid "BigInt_plural" +msgstr "Big integers" + msgid "Bookmark" msgstr "Bookmark" @@ -503,7 +509,7 @@ msgstr "Interval" msgid "IntervalBoundConstraint" -msgstr "interval constraint" +msgstr "Interval constraint" msgid "Interval_plural" msgstr "Intervals" diff -r e4399a37674e -r 2455cdbeadca i18n/es.po --- a/i18n/es.po Mon Jun 06 15:52:53 2011 +0200 +++ b/i18n/es.po Mon Jun 06 16:13:09 2011 +0200 @@ -257,6 +257,12 @@ msgid "BaseTransition_plural" msgstr "Transiciones (abstractas)" +msgid "BigInt" +msgstr "" + +msgid "BigInt_plural" +msgstr "" + msgid "Bookmark" msgstr "Favorito" diff -r e4399a37674e -r 2455cdbeadca i18n/fr.po --- a/i18n/fr.po Mon Jun 06 15:52:53 2011 +0200 +++ b/i18n/fr.po Mon Jun 06 16:13:09 2011 +0200 @@ -255,6 +255,12 @@ msgid "BaseTransition_plural" msgstr "Transitions (abstraites)" +msgid "BigInt" +msgstr "Entier long" + +msgid "BigInt_plural" +msgstr "Entiers longs" + msgid "Bookmark" msgstr "Signet" diff -r e4399a37674e -r 2455cdbeadca misc/migration/3.13.0_Any.py --- a/misc/migration/3.13.0_Any.py Mon Jun 06 15:52:53 2011 +0200 +++ b/misc/migration/3.13.0_Any.py Mon Jun 06 16:13:09 2011 +0200 @@ -1,2 +1,3 @@ sync_schema_props_perms('cw_source', syncprops=False) add_attribute('CWSource', 'synchronizing') +add_entity_type('BigInt') diff -r e4399a37674e -r 2455cdbeadca test/unittest_schema.py --- a/test/unittest_schema.py Mon Jun 06 15:52:53 2011 +0200 +++ b/test/unittest_schema.py Mon Jun 06 16:13:09 2011 +0200 @@ -158,7 +158,7 @@ self.assert_(isinstance(schema, CubicWebSchema)) self.assertEqual(schema.name, 'data') entities = sorted([str(e) for e in schema.entities()]) - expected_entities = ['BaseTransition', 'Bookmark', 'Boolean', 'Bytes', 'Card', + expected_entities = ['BaseTransition', 'BigInt', 'Bookmark', 'Boolean', 'Bytes', 'Card', 'Date', 'Datetime', 'Decimal', 'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType', 'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation', diff -r e4399a37674e -r 2455cdbeadca web/formfields.py --- a/web/formfields.py Mon Jun 06 15:52:53 2011 +0200 +++ b/web/formfields.py Mon Jun 06 16:13:09 2011 +0200 @@ -37,6 +37,7 @@ .. autoclass:: cubicweb.web.formfields.StringField() .. autoclass:: cubicweb.web.formfields.PasswordField() .. autoclass:: cubicweb.web.formfields.IntField() +.. autoclass:: cubicweb.web.formfields.BigIntField() .. autoclass:: cubicweb.web.formfields.FloatField() .. autoclass:: cubicweb.web.formfields.BooleanField() .. autoclass:: cubicweb.web.formfields.DateField() @@ -830,21 +831,25 @@ return super(EditableFileField, self)._process_form_value(form) -class IntField(Field): - """Use this field to edit integers (`Int` yams type). This field additionaly - support `min` and `max` attributes that specify a minimum and/or maximum - value for the integer (`None` meaning no boundary). +class BigIntField(Field): + """Use this field to edit big integers (`BigInt` yams type). This field + additionaly support `min` and `max` attributes that specify a minimum and/or + maximum value for the integer (`None` meaning no boundary). Unless explicitly specified, the widget for this field will be a :class:`~cubicweb.web.formwidgets.TextInput`. """ + default_text_input_size = 10 + def __init__(self, min=None, max=None, **kwargs): - super(IntField, self).__init__(**kwargs) + super(BigIntField, self).__init__(**kwargs) self.min = min self.max = max + + def init_widget(self, widget): + super(BigIntField, self).init_widget(widget): if isinstance(self.widget, fw.TextInput): - self.widget.attrs.setdefault('size', 5) - self.widget.attrs.setdefault('maxlength', 15) + self.widget.attrs.setdefault('size', self.default_text_input_size) def _ensure_correctly_typed(self, form, value): if isinstance(value, basestring): @@ -858,6 +863,19 @@ return value +class IntField(BigIntField): + """Use this field to edit integers (`Int` yams type). Similar to + :class:`~cubicweb.web.formfields.BigIntField` but set max length when text + input widget is used (the default). + """ + default_text_input_size = 5 + + def init_widget(self, widget): + super(IntField, self).init_widget(widget): + if isinstance(self.widget, fw.TextInput): + self.widget.attrs.setdefault('maxlength', 15) + + class BooleanField(Field): """Use this field to edit booleans (`Boolean` yams type). @@ -1208,6 +1226,7 @@ 'Boolean': BooleanField, 'Int': IntField, + 'BigInt': BigIntField, 'Float': FloatField, 'Decimal': StringField, diff -r e4399a37674e -r 2455cdbeadca web/views/owl.py --- a/web/views/owl.py Mon Jun 06 15:52:53 2011 +0200 +++ b/web/views/owl.py Mon Jun 06 16:13:09 2011 +0200 @@ -40,6 +40,7 @@ 'Boolean': 'xsd:boolean', 'Int': 'xsd:int', + 'BigInt': 'xsd:int', 'Float': 'xsd:float', 'Decimal' : 'xsd:decimal', diff -r e4399a37674e -r 2455cdbeadca web/views/plots.py --- a/web/views/plots.py Mon Jun 06 15:52:53 2011 +0200 +++ b/web/views/plots.py Mon Jun 06 16:13:09 2011 +0200 @@ -1,4 +1,4 @@ -# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of CubicWeb. @@ -33,14 +33,14 @@ """accept result set with at least one line and two columns of result all columns after second must be of numerical types""" for etype in rset.description[0]: - if etype not in ('Int', 'Float'): + if etype not in ('Int', 'BigInt', 'Float'): return 0 return 1 @objectify_selector def second_column_is_number(cls, req, rset=None, *args, **kwargs): etype = rset.description[0][1] - if etype not in ('Int', 'Float'): + if etype not in ('Int', 'BigInt', 'Float'): return 0 return 1 @@ -50,7 +50,7 @@ if etypes[0] not in ('Date', 'Datetime', 'TZDatetime'): return 0 for etype in etypes[1:]: - if etype not in ('Int', 'Float'): + if etype not in ('Int', 'BigInt', 'Float'): return 0 return 1 diff -r e4399a37674e -r 2455cdbeadca web/views/sparql.py --- a/web/views/sparql.py Mon Jun 06 15:52:53 2011 +0200 +++ b/web/views/sparql.py Mon Jun 06 16:13:09 2011 +0200 @@ -80,6 +80,7 @@ 'Boolean': 'boolean', 'Int': 'integer', + 'BigInt': 'integer', 'Float': 'float', 'Datetime': 'dateTime',