Beispiel #1
0
 def get_db_fields(self):
     if not self._db_fields:
         self._db_fields = []
         fields = self.fields.values() if isinstance(self.fields, dict) else self.fields
         for field in fields:
             if RE_FORMATTED.match(field):
                 self._db_fields.extend(RE_FORMATTED.findall(field))
             else:
                 self._db_fields.append(field)
     return self._db_fields
Beispiel #2
0
 def get_db_fields(self):
     if not self._db_fields:
         self._db_fields = []
         fields = self.fields.values() if isinstance(self.fields,
                                                     dict) else self.fields
         for field in fields:
             if RE_FORMATTED.match(field):
                 self._db_fields.extend(RE_FORMATTED.findall(field))
             else:
                 self._db_fields.append(field)
     return self._db_fields
Beispiel #3
0
    def get_row(self, row):
        '''Format a single row (if necessary)'''

        if isinstance(self.fields, dict):
            return dict([(key, text_type(value).format(
                **row) if RE_FORMATTED.match(value) else row[value])
                         for key, value in self.fields.items()])
        else:
            return [
                text_type(field).format(
                    **row) if RE_FORMATTED.match(field) else row[field]
                for field in self.fields
            ]
Beispiel #4
0
    def get_row(self, row):
        """Format a single row (if necessary)"""

        if isinstance(self.fields, dict):
            return dict(
                [
                    (key, text_type(value).format(**row) if RE_FORMATTED.match(value) else row[value])
                    for key, value in self.fields.items()
                ]
            )
        else:
            return [
                text_type(field).format(**row) if RE_FORMATTED.match(field) else row[field] for field in self.fields
            ]
Beispiel #5
0
 def search_col_4(self, search, queryset):
     idx=4
     field = self.get_field(idx)
     fields = RE_FORMATTED.findall(field) if RE_FORMATTED.match(field) else [field]
     if not search.startswith('-'):
         if self.dt_data['bRegex_%s' % idx]:
             criterions = [Q(**{'%s__iregex' % field: search}) for field in fields if self.can_regex(field)]
             if len(criterions) > 0:
                 search = reduce(or_, criterions)
                 queryset = queryset.filter(search)
         else:
             for term in search.split():
                 criterions = (Q(**{'%s__icontains' % field: term}) for field in fields)
                 search = reduce(or_, criterions)
                 queryset = queryset.filter(search)
     return queryset
Beispiel #6
0
	def test_formatted_nester_token(self):
		'''Should match a formatted field description with a single token'''
		matches = RE_FORMATTED.findall('{nested__field_0}-{nested__field_1}: {nested__field_2}')
		self.assertEqual(len(matches), 3)
		for i in xrange(3):
			self.assertEqual(matches[i], 'nested__field_%s' % i)
		return
Beispiel #7
0
 def test_formatted_nester_token(self):
     '''Should match a formatted field description with a single token'''
     matches = RE_FORMATTED.findall(
         '{nested__field_0}-{nested__field_1}: {nested__field_2}')
     self.assertEqual(len(matches), 3)
     for i in range(3):
         self.assertEqual(matches[i], 'nested__field_%s' % i)
Beispiel #8
0
 def search_col_4(self, search, queryset):
     idx = 4
     field = self.get_field(idx)
     fields = RE_FORMATTED.findall(field) if RE_FORMATTED.match(
         field) else [field]
     if not search.startswith('-'):
         if self.dt_data['bRegex_%s' % idx]:
             criterions = [
                 Q(**{'%s__iregex' % field: search}) for field in fields
                 if self.can_regex(field)
             ]
             if len(criterions) > 0:
                 search = reduce(or_, criterions)
                 queryset = queryset.filter(search)
         else:
             for term in search.split():
                 criterions = (Q(**{'%s__icontains' % field: term})
                               for field in fields)
                 search = reduce(or_, criterions)
                 queryset = queryset.filter(search)
     return queryset
Beispiel #9
0
	def test_formatted_single_token(self):
		'''Should match a formatted field description with a single token'''
		matches = RE_FORMATTED.findall('{field}')
		self.assertEqual(len(matches), 1)
		self.assertEqual(matches[0], 'field')
Beispiel #10
0
	def test_not_formatted(self):
		'''Should not match unformatted field descriptions'''
		self.assertIsNone(RE_FORMATTED.match('my_field'))
Beispiel #11
0
 def test_formatted_single_token(self):
     '''Should match a formatted field description with a single token'''
     matches = RE_FORMATTED.findall('{field}')
     self.assertEqual(len(matches), 1)
     self.assertEqual(matches[0], 'field')
Beispiel #12
0
 def test_not_formatted(self):
     '''Should not match unformatted field descriptions'''
     self.assertIsNone(RE_FORMATTED.match('my_field'))