SILENT KILLERPanel

Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > site-packages > pylint_django > checkers >


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt/cloudlinux/venv/lib64/python3.11/site-packages/pylint_django/checkers/

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
__init__.py File 802 bytes April 17 2025 13:10:59.
auth_user.py File 1392 bytes April 17 2025 13:10:59.
django_installed.py File 1319 bytes April 17 2025 13:10:59.
foreign_key_strings.py File 6321 bytes April 17 2025 13:10:59.
forms.py File 1517 bytes April 17 2025 13:10:59.
json_response.py File 2701 bytes April 17 2025 13:10:59.
migrations.py File 6428 bytes April 17 2025 13:10:59.
models.py File 4609 bytes April 17 2025 13:10:59.

Reading File: //opt/cloudlinux/venv/lib64/python3.11/site-packages/pylint_django/checkers//forms.py

"""Models."""
from astroid.nodes import Assign, AssignName, ClassDef
from pylint.checkers import BaseChecker
from pylint.checkers.utils import check_messages
from pylint.interfaces import IAstroidChecker

from pylint_django.__pkginfo__ import BASE_ID
from pylint_django.utils import node_is_subclass


def _get_child_meta(node):
    for child in node.get_children():
        if isinstance(child, ClassDef) and child.name == "Meta":
            return child
    return None


class FormChecker(BaseChecker):
    """Django model checker."""

    __implements__ = IAstroidChecker

    name = "django-form-checker"
    msgs = {
        f"W{BASE_ID}04": (
            "Use explicit fields instead of exclude in ModelForm",
            "modelform-uses-exclude",
            "Prevents accidentally allowing users to set fields, especially when adding new fields to a Model",
        )
    }

    @check_messages("modelform-uses-exclude")
    def visit_classdef(self, node):
        """Class visitor."""
        if not node_is_subclass(node, "django.forms.models.ModelForm", ".ModelForm"):
            # we only care about forms
            return

        meta = _get_child_meta(node)

        if not meta:
            return

        for child in meta.get_children():
            if not isinstance(child, Assign) or not isinstance(child.targets[0], AssignName):
                continue

            if child.targets[0].name == "exclude":
                self.add_message(f"W{BASE_ID}04", node=child)
                break

SILENT KILLER Tool