• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-eth-py / 10527345804

23 Aug 2024 02:20PM UTC coverage: 93.892% (-0.01%) from 93.903%
10527345804

push

github

web-flow
Add addresses 1.4.1 for chain BEVM_TESTNET (#1297)

* Add new master copy address 0x41675C099F32341bf84BFc5382aF534df5C7461a

* Add new master copy address 0x29fcB43b46531BcA003ddC8FCB67FFE91900C762

* Add new proxy address 0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67

* Apply linter fixes

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

8670 of 9234 relevant lines covered (93.89%)

3.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/gnosis/eth/django/admin.py
1
from django.contrib.admin.utils import lookup_spawns_duplicates
×
2
from django.core.exceptions import FieldDoesNotExist, ValidationError
×
3
from django.db import models
×
4
from django.db.models.constants import LOOKUP_SEP
×
5
from django.utils.text import smart_split, unescape_string_literal
×
6

7

8
class AdvancedAdminSearchMixin:
×
9
    """
10
    Use database indexes when using exact search instead
11
    of converting everything to text before searching
12
    """
13

14
    def get_search_results(self, request, queryset, search_term):
×
15
        """
16
        Return a tuple containing a queryset to implement the search
17
        and a boolean indicating if the results may contain duplicates.
18

19
        This function was modified from Django original get_search_results
20
        to allow `exact` search that uses database indexes
21
        """
22

23
        def construct_search(field_name):
×
24
            if field_name.startswith("^"):
×
25
                return "%s__istartswith" % field_name[1:]
×
26
            elif field_name.startswith("=="):
×
27
                return "%s__exact" % field_name[2:]
×
28
            elif field_name.startswith("="):
×
29
                return "%s__iexact" % field_name[1:]
×
30
            elif field_name.startswith("@"):
×
31
                return "%s__search" % field_name[1:]
×
32
            # Use field_name if it includes a lookup.
33
            opts = queryset.model._meta
×
34
            lookup_fields = field_name.split(LOOKUP_SEP)
×
35
            # Go through the fields, following all relations.
36
            prev_field = None
×
37
            for path_part in lookup_fields:
×
38
                if path_part == "pk":
×
39
                    path_part = opts.pk.name
×
40
                try:
×
41
                    field = opts.get_field(path_part)
×
42
                except FieldDoesNotExist:
×
43
                    # Use valid query lookups.
44
                    if prev_field and prev_field.get_lookup(path_part):
×
45
                        return field_name
×
46
                else:
47
                    prev_field = field
×
48
                    if hasattr(field, "path_infos"):
×
49
                        # Update opts to follow the relation.
50
                        opts = field.path_infos[-1].to_opts
×
51
            # Otherwise, use the field with icontains.
52
            return "%s__icontains" % field_name
×
53

54
        may_have_duplicates = False
×
55
        search_fields = self.get_search_fields(request)
×
56
        if search_fields and search_term:
×
57
            orm_lookups = [
×
58
                construct_search(str(search_field)) for search_field in search_fields
59
            ]
60
            term_queries = []
×
61
            for bit in smart_split(search_term):
×
62
                if bit.startswith(('"', "'")) and bit[0] == bit[-1]:
×
63
                    bit = unescape_string_literal(bit)
×
64

65
                valid_queries = []
×
66
                for orm_lookup in orm_lookups:
×
67
                    try:
×
68
                        # Check if query is valid (for example, not a number provided for an integer exact query)
69
                        # This is the main difference comparing to Django official implementation
70
                        queryset.filter(**{orm_lookup: bit})
×
71
                        valid_queries.append((orm_lookup, bit))
×
72
                    except (ValueError, ValidationError):
×
73
                        pass
×
74
                or_queries = models.Q.create(
×
75
                    [valid_query for valid_query in valid_queries],
76
                    connector=models.Q.OR,
77
                )
78
                term_queries.append(or_queries)
×
79
            queryset = queryset.filter(models.Q.create(term_queries))
×
80
            may_have_duplicates |= any(
×
81
                lookup_spawns_duplicates(self.opts, search_spec)
82
                for search_spec in orm_lookups
83
            )
84
        return queryset, may_have_duplicates
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc