Exemplo n.º 1
0
 def fix_dates(orig_obj, db_obj, es_obj):
     """Fix the dates for insert."""
     for date_key in ['created', 'updated', 'deleted']:
         if date_key in orig_obj:
             es_obj[date_key] = db_obj[date_key] = datetime_converts(orig_obj[date_key])
     for date_key in ['created', 'updated']:
         if date_key not in orig_obj:
             es_obj[date_key] = db_obj[date_key] = datetime_converts(datetime_now_nomicrosecond())
     if 'deleted' not in orig_obj:
         db_obj['deleted'] = es_obj['deleted'] = None
Exemplo n.º 2
0
 def test_datetime_converts(self):
     """
     This method supports three types of conversions
     1. a parsable string either unicode or str
     2. a datetime object
     3. an epoch style int
     """
     self.assertEqual(datetime_converts(0), datetime.fromtimestamp(0))
     now_chk = datetime.now().replace(microsecond=0)
     self.assertEqual(datetime_converts(now_chk), now_chk)
     chk_date = datetime(2016, 7, 5, 9, 22, 12)
     uni_date = u'2016-07-05T09:22:12'
     str_date = '2016-07-05T09:22:12'
     self.assertEqual(datetime_converts(uni_date), chk_date)
     self.assertEqual(datetime_converts(str_date), chk_date)
Exemplo n.º 3
0
    def test_datetime_converts(self):
        """
        The method supports three types of conversions.

        1. a parsable string either unicode or str
        2. a datetime object
        3. an epoch style int
        """
        self.assertEqual(datetime_converts(0), datetime.fromtimestamp(0))
        now_chk = datetime_now_nomicrosecond()
        self.assertEqual(datetime_converts(now_chk), now_chk)
        chk_date = datetime(2016, 7, 5, 9, 22, 12)
        uni_date = u'2016-07-05T09:22:12'
        str_date = '2016-07-05T09:22:12'
        self.assertEqual(datetime_converts(uni_date), chk_date)
        self.assertEqual(datetime_converts(str_date), chk_date)
Exemplo n.º 4
0
 def where_clause(self, kwargs):
     """
     PeeWee specific extension meant to be passed to a PeeWee get
     or select.
     """
     my_class = self.__class__
     where_clause = Expression(1, OP.EQ, 1)
     for date in ['deleted', 'updated', 'created']:
         if date in kwargs:
             date_obj = datetime_converts(kwargs[date])
             where_clause &= Expression(getattr(my_class, date), OP.EQ, date_obj)
     return where_clause
Exemplo n.º 5
0
 def where_clause(self, kwargs):
     """
     PeeWee specific where clause used for search.
     """
     where_clause = super(Proposals, self).where_clause(kwargs)
     for date_key in ['accepted_date',
                      'actual_start_date', 'actual_end_date']:
         if date_key in kwargs:
             date_obj = date_converts(kwargs[date_key])
             where_clause &= Expression(getattr(Proposals, date_key), OP.EQ, date_obj)
     for date_key in ['submitted_date']:
         if date_key in kwargs:
             date_obj = datetime_converts(kwargs[date_key])
             where_clause &= Expression(getattr(Proposals, date_key), OP.EQ, date_obj)
     if '_id' in kwargs:
         where_clause &= Expression(Proposals.id, OP.EQ, kwargs['_id'])
     for key in ['title', 'abstract', 'science_theme', 'proposal_type', 'encoding']:
         if key in kwargs:
             where_clause &= Expression(getattr(Proposals, key), OP.EQ, kwargs[key])
     return where_clause
Exemplo n.º 6
0
 def where_clause(self, kwargs):
     """PeeWee specific extension meant to be passed to a PeeWee get or select."""
     my_class = self.__class__
     where_clause = Expression(1, OP.EQ, 1)
     if 'deleted' in kwargs:
         if kwargs['deleted'] is None:
             where_clause &= Expression(
                 getattr(my_class, 'deleted'), OP.IS, None)
         else:
             date_obj = datetime_converts(kwargs['deleted'])
             where_clause &= Expression(
                 getattr(my_class, 'deleted'), OP.EQ, date_obj)
     for date in ['updated', 'created']:
         if date in kwargs:
             # pylint: disable=protected-access
             date_obj, date_oper = my_class._date_operator_compare(date, kwargs)
             # pylint: enable=protected-access
             where_clause &= Expression(
                 getattr(my_class, date), date_oper, date_obj)
     return where_clause
Exemplo n.º 7
0
 def _set_datetime_part(self, time_part, obj):
     self._set_only_if(time_part, obj, time_part,
                       lambda: datetime_converts(obj[time_part]))
Exemplo n.º 8
0
 def _set_datetime_part(self, time_part, obj):
     """
     do more consistent type checking
     """
     if time_part in obj:
         setattr(self, time_part, datetime_converts(obj[time_part]))