Beispiel #1
0
 def text_edited(self, text ):
     try:
         date_from_string( self.line_edit.user_input() )
         self.line_edit.set_valid(True)
         self.valueChanged.emit()
     except ParsingError:
         self.line_edit.set_valid(False)
Beispiel #2
0
 def text_edited(self, text ):
     try:
         date_from_string( self.line_edit.user_input() )
         self.line_edit.set_valid(True)
         self.valueChanged.emit()
     except ParsingError:
         self.line_edit.set_valid(False)
Beispiel #3
0
 def get_value(self):
     line_edit = self.findChild(QtWidgets.QWidget, 'date_line_edit')
     if line_edit is not None:
         try:
             value = date_from_string(six.text_type(line_edit.text()))
         except ParsingError:
             value = None
     return CustomEditor.get_value(self) or value
 def test_date_from_string(self):
     self.assertRaises(ParsingError, date_from_string, None)
     
     fmt = constants.strftime_date_format
     d_1 = datetime.strptime('19-11-2009', fmt).date()
     d_2 = date_from_string('19-11-2009', fmt)
     
     self.assertEqual(d_1, d_2)
     self.assertRaises(ParsingError, date_from_string, '2009', fmt)
     self.assertRaises(ParsingError, date_from_string, '11-19-2009', fmt)
     self.assertRaises(ParsingError, date_from_string, '11-19-09', fmt)
     self.assertRaises(ParsingError, date_from_string, '11/09/2009', fmt)
    def test_date_from_string(self):
        self.assertRaises(ParsingError, date_from_string, None)

        fmt = constants.strftime_date_format
        d_1 = datetime.strptime('19-11-2009', fmt).date()
        d_2 = date_from_string('19-11-2009', fmt)

        self.assertEqual(d_1, d_2)
        self.assertRaises(ParsingError, date_from_string, '2009', fmt)
        self.assertRaises(ParsingError, date_from_string, '11-19-2009', fmt)
        self.assertRaises(ParsingError, date_from_string, '11-19-09', fmt)
        self.assertRaises(ParsingError, date_from_string, '11/09/2009', fmt)
Beispiel #6
0
 def test_date_from_string(self):
     from camelot.view.utils import date_from_string
     result = datetime.date(2011,2,22)
     self.assertEqual( date_from_string('02222011'), result )
     self.assertEqual( date_from_string('02-22-2011'), result )
     self.assertEqual( date_from_string('2-22-2011'), result )
     self.assertEqual( date_from_string('2/22/2011'), result )
     result = datetime.date(2011,2,2)
     self.assertEqual( date_from_string('2/2/2011'), result )
     self.assertEqual( date_from_string('2-2-2011'), result )
Beispiel #7
0
    def test_date_from_string(self):
        from camelot.view.utils import date_from_string

        result = datetime.date(2011, 2, 22)
        self.assertEqual(date_from_string("02222011"), result)
        self.assertEqual(date_from_string("02-22-2011"), result)
        self.assertEqual(date_from_string("2-22-2011"), result)
        self.assertEqual(date_from_string("2/22/2011"), result)
        result = datetime.date(2011, 2, 2)
        self.assertEqual(date_from_string("2/2/2011"), result)
        self.assertEqual(date_from_string("2-2-2011"), result)
Beispiel #8
0
        def append_column(c, text, args):
            """add column c to the where clause using a clause that
            is relevant for that type of column"""
            arg = None
            if issubclass(c.type.__class__, camelot.types.Color):
                pass
            elif issubclass(c.type.__class__, camelot.types.File):
                pass
            elif issubclass(c.type.__class__, camelot.types.Code):
                codes = [u'%%%s%%' % s for s in text.split(c.type.separator)]
                codes = codes + ['%'] * (len(c.type.parts) - len(codes))
                arg = c.like(codes)
            elif issubclass(c.type.__class__, camelot.types.VirtualAddress):
                arg = c.like(('%', '%' + text + '%'))
            elif issubclass(c.type.__class__, camelot.types.Image):
                pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Integer):
                try:
                    arg = (c == utils.int_from_string(text))
                except (Exception, utils.ParsingError):
                    pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Date):
                try:
                    arg = (c == utils.date_from_string(text))
                except (Exception, utils.ParsingError):
                    pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Float):
                try:
                    float_value = utils.float_from_string(text)
                    precision = c.type.precision
                    if isinstance(precision, (tuple)):
                        precision = precision[1]
                    delta = 0.1**(precision or 0)
                    arg = sql.and_(c >= float_value - delta,
                                   c <= float_value + delta)
                except (Exception, utils.ParsingError):
                    pass
            elif issubclass(c.type.__class__, (sqlalchemy.types.String, )) or \
                            (hasattr(c.type, 'impl') and \
                             issubclass(c.type.impl.__class__, (sqlalchemy.types.String, ))):
                LOGGER.debug('look in column : %s' % c.name)
                arg = sql.operators.ilike_op(c, '%' + text + '%')

            if arg is not None:
                arg = sql.and_(c != None, arg)
                args.append(arg)
Beispiel #9
0
def create_entity_search_query_decorator(admin, text):
    """create a query decorator to search through a collection of entities
    @param admin: the admin interface of the entity
    @param text: the text to search for
    @return: a function that can be applied to a query to make the query filter
    only the objects related to the requested text or None if no such decorator
    could be build
    """
    from elixir import entities
    from sqlalchemy import orm, sql
    from camelot.view import utils

    if len(text.strip()):
        from sqlalchemy import Unicode, or_
        # arguments for the where clause
        args = []
        # join conditions : list of join entities
        joins = []

        def append_column(c):
            """add column c to the where clause using a clause that
            is relevant for that type of column"""
            arg = None
            if issubclass(c.type.__class__, camelot.types.Color):
                pass
            elif issubclass(c.type.__class__, camelot.types.File):
                pass
            elif issubclass(c.type.__class__, camelot.types.Code):
                codes = [u'%%%s%%' % s for s in text.split(c.type.separator)]
                codes = codes + ['%'] * (len(c.type.parts) - len(codes))
                arg = c.like(codes)
            elif issubclass(c.type.__class__, camelot.types.VirtualAddress):
                arg = c.like(('%', '%' + text + '%'))
            elif issubclass(c.type.__class__, camelot.types.Image):
                pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Integer):
                try:
                    arg = (c == utils.int_from_string(text))
                except Exception, utils.ParsingError:
                    pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Date):
                try:
                    arg = (c == utils.date_from_string(text))
                except Exception, utils.ParsingError:
                    pass
Beispiel #10
0
def create_entity_search_query_decorator(admin, text):
    """create a query decorator to search through a collection of entities
    @param admin: the admin interface of the entity
    @param text: the text to search for
    @return: a function that can be applied to a query to make the query filter
    only the objects related to the requested text or None if no such decorator
    could be build
    """
    from elixir import entities
    from sqlalchemy import orm, sql
    from camelot.view import utils

    if len(text.strip()):
        from sqlalchemy import Unicode, or_
        # arguments for the where clause
        args = []
        # join conditions : list of join entities
        joins = []

        def append_column(c):
            """add column c to the where clause using a clause that
            is relevant for that type of column"""
            arg = None
            if issubclass(c.type.__class__, camelot.types.Color):
                pass
            elif issubclass(c.type.__class__, camelot.types.File):
                pass
            elif issubclass(c.type.__class__, camelot.types.Code):
                codes = [u'%%%s%%'%s for s in text.split(c.type.separator)]
                codes = codes + ['%']*(len(c.type.parts) - len(codes))
                arg = c.like( codes )
            elif issubclass(c.type.__class__, camelot.types.VirtualAddress):
                arg = c.like(('%', '%'+text+'%'))
            elif issubclass(c.type.__class__, camelot.types.Image):
                pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Integer):
                try:
                    arg = (c==utils.int_from_string(text))
                except Exception, utils.ParsingError:
                    pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Date):
                try:
                    arg = (c==utils.date_from_string(text))
                except Exception, utils.ParsingError:
                    pass
Beispiel #11
0
        def append_column( c ):
            """add column c to the where clause using a clause that
            is relevant for that type of column"""
            arg = None
            if issubclass(c.type.__class__, camelot.types.Color):
                pass
            elif issubclass(c.type.__class__, camelot.types.File):
                pass
            elif issubclass(c.type.__class__, camelot.types.Code):
                codes = [u'%%%s%%'%s for s in text.split(c.type.separator)]
                codes = codes + ['%']*(len(c.type.parts) - len(codes))
                arg = c.like( codes )
            elif issubclass(c.type.__class__, camelot.types.VirtualAddress):
                arg = c.like(('%', '%'+text+'%'))
            elif issubclass(c.type.__class__, camelot.types.Image):
                pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Integer):
                try:
                    arg = (c==utils.int_from_string(text))
                except ( Exception, utils.ParsingError ):
                    pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Date):
                try:
                    arg = (c==utils.date_from_string(text))
                except ( Exception, utils.ParsingError ):
                    pass
            elif issubclass(c.type.__class__, sqlalchemy.types.Float):
                try:
                    float_value = utils.float_from_string(text)
                    precision = c.type.precision
                    if isinstance(precision, (tuple)):
                        precision = precision[1]
                    delta = 0.1**( precision or 0 )
                    arg = sql.and_(c>=float_value-delta, c<=float_value+delta)
                except ( Exception, utils.ParsingError ):
                    pass
            elif issubclass(c.type.__class__, (sqlalchemy.types.String, )) or \
                            (hasattr(c.type, 'impl') and \
                             issubclass(c.type.impl.__class__, (sqlalchemy.types.String, ))):
                LOGGER.debug('look in column : %s'%c.name)
                arg = sql.operators.ilike_op(c, '%'+text+'%')

            if arg is not None:
                arg = sql.and_(c != None, arg)
                args.append(arg)
Beispiel #12
0
 def get_value(self):
     try:
         value = date_from_string( self.line_edit.user_input() )
     except ParsingError:
         value = None
     return CustomEditor.get_value(self) or value
Beispiel #13
0
 def get_value(self):
     try:
         value = date_from_string( self.line_edit.user_input() )
     except ParsingError:
         value = None
     return CustomEditor.get_value(self) or value