ForestAdmin/django-forest

View on GitHub

Showing 19 of 39 total issues

ConditionFactory has 21 functions (exceeds 20 allowed). Consider refactoring.
Open

class ConditionFactory:

    DATE_CONDITION_BUILDERS = {
        'today': 'build_today_condition',
        'yesterday': 'build_yesterday_condition',
Severity: Minor
Found in django_forest/resources/utils/queryset/filters/date/factory.py - About 2 hrs to fix

    Function handle_aggregator has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_aggregator(self, filters, Model, tz):
            q_objects = Q()
            for condition in filters['conditions']:
                if "aggregator" in condition:
                    if condition['aggregator'] == 'or':
    Severity: Minor
    Found in django_forest/resources/utils/queryset/filters/utils.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _handle_smart_field_for_relation has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def _handle_smart_field_for_relation(self, queryset, relation_field, collection_name, params, many):
            if many:
                for item in queryset:
                    if getattr(item, relation_field["field"], None) is not None:
                        self.handle_smart_fields(
    Severity: Minor
    Found in django_forest/resources/utils/smart_field.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_ids_from_request has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_ids_from_request(self, request, Model):
            body = self.get_body(request.body)
    
            if 'data' in body:
                data = body['data']
    Severity: Minor
    Found in django_forest/utils/views/base.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _handle_authent_error has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _handle_authent_error(self, response):
            if response.status_code == 404:
                raise AuthenticationThirdPartyException(
                    MESSAGES['SERVER_TRANSACTION']['SECRET_NOT_FOUND']
                )
    Severity: Minor
    Found in django_forest/authentication/views/callback.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function fill_csv_relationships has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def fill_csv_relationships(self, res, record, data, params):
            pk_name = self.Model._meta.pk.name
            for name, value in record['relationships'].items():
                related_res = self.get_related_res(data, value)
                field_name = params[f'fields[{name}]']
    Severity: Minor
    Found in django_forest/resources/utils/csv.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _rewrite_Q_with_field has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _rewrite_Q_with_field(self, q, condition):
            operator = condition['operator']
            splitted_fields = condition['field'].split(":")
    
            new_children = []
    Severity: Minor
    Found in django_forest/resources/utils/queryset/filters/utils.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_date_range has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def get_date_range(
    Severity: Minor
    Found in django_forest/resources/utils/queryset/filters/date/utils.py - About 35 mins to fix

      Function enhance_queryset has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def enhance_queryset(self, queryset, Model, params, request, apply_pagination=True):
      Severity: Minor
      Found in django_forest/resources/utils/queryset/__init__.py - About 35 mins to fix

        Function handle_smart_fields has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def handle_smart_fields(self, queryset, resource, params=None, many=False, follow_relations=True):
        Severity: Minor
        Found in django_forest/resources/utils/smart_field.py - About 35 mins to fix

          Function _handle_smart_field_for_relation has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _handle_smart_field_for_relation(self, queryset, relation_field, collection_name, params, many):
          Severity: Minor
          Found in django_forest/resources/utils/smart_field.py - About 35 mins to fix

            Function get_fields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_fields(self, current_collection, qs):
                    current_name = current_collection['name']
                    qs_fields = qs.get('fields')
                    if not qs_fields:
                        return {
            Severity: Minor
            Found in django_forest/resources/utils/json_api_serializer.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function get_basic_expression has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_basic_expression(self, field, field_type, operator, value):
                    operators = INSENSITIVE_OPERATORS if isinstance(value, str) else OPERATORS
            
                    try:
                        lookup_field = f"{field}{operators[operator]}"
            Severity: Minor
            Found in django_forest/resources/utils/queryset/filters/utils.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function get_attribute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_attribute(self, obj, attr, default):
                    value = super().get_attribute(obj, attr, default)
                    if value.__class__.__name__ == 'ManyRelatedManager':
                        value = value.all()
                    else:
            Severity: Minor
            Found in django_forest/utils/schema/json_api_schema.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function _get_action has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def _get_action(self, action_name):
                    for collection_schema in Collection._registry.values():
                        for action in collection_schema.actions:
                            if self.action_name_from_endpoint(action) == action_name:
                                return action
            Severity: Minor
            Found in django_forest/actions/hooks/views/utils.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function populate_query_request_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def populate_query_request_info(self, permission_name, body, kwargs):
                    if permission_name in 'liveQueries':
                        kwargs['query_request_info'] = body['query']
                    elif permission_name in 'statsWithParameters':
                        if 'timezone' in body:
            Severity: Minor
            Found in django_forest/middleware/permissions.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function handle_validators has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            def handle_validators(validators, f):
                if len(validators):
                    for validator in validators:
                        if hasattr(validator, 'code'):
                            f = handle_validator(validator, f)
            Severity: Minor
            Found in django_forest/utils/schema/validations.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function handle_smart_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def handle_smart_fields(self, queryset, resource, params=None, many=False, follow_relations=True):
                    collection = Schema.get_collection(resource)
            
                    # Rather than calculate and then filter out smart fields, we want to ignore them entirely
                    smart_fields = self._get_smart_fields_for_request(collection, params)
            Severity: Minor
            Found in django_forest/resources/utils/smart_field.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function get_expression_smart_field has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_expression_smart_field(self, smart_fields, condition, resource):
                    operator = condition['operator']
                    splitted_fields = condition['field'].split(":")
                    value = condition['value']
            
            
            Severity: Minor
            Found in django_forest/resources/utils/queryset/filters/utils.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Severity
            Category
            Status
            Source
            Language