Проблема TypeError при создании "context_processor" в django

что здесь не так? Я создал 2 класса в файле context_processor, с этой проблемой я столкнулся, когда пытался вернуть не словарные объекты, но теперь не понимаю, что здесь не так.

settings.py

TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'context_processors': [
                ...
                'accounts.context_processor.CreateNotification',
                'accounts.context_processor.NotificationFeatures'
            ],
        },
    },
]

context_processor.py

from accounts.models import Notification, User


class CreateNotification:

    def __init__(self, from_user, to_user, notification_type, role_sender, role_receiver, read_notif=False, active=False):
        self.from_user = from_user
        self.to_user = to_user
        self.notification_type = notification_type
        self.role_sender = role_sender
        self.role_receiver = role_receiver
        self.active = active
        self.read_notif = read_notif

    def send(self):
        if self.notification_type == "register":
            self.active = True
            Notification.objects.create(
                from_user=self.from_user,
                to_user=self.to_user,
                notification_type=self.notification_type,
                role_sender=self.role_sender,
                role_receiver=self.role_receiver,
                read_notif=self.read_notif,
                active=self.active
            )
        return {}

    def read(self, id=None):
        if id:
            if self.active == True:
                self.read_notif = True
            return Notification.objects.filter(id=id).update(read_notif=self.read_notif)
        return {}


class NotificationFeatures:

    def NotificationObject(self, req):
        notifications = Notification.objects.all()
        user_request = User.objects.get(username=req.user.username)

        if req.user.is_authenticated:
            # who is sender
            three_roles = notifications.distinct()
            for roles in three_roles:
                print(user_request.roles)
                if user_request.roles == roles:
                    notifications.filter(from_user__roles__id=roles)
        return {}

отслеживание:

init() отсутствуют 4 обязательных позиционных аргумента: 'to_user', 'notification_type', 'role_sender', and 'role_receiver'

.

зная это: когда я использую те же классы, которые находятся в "context_processor file" в других местах, таких как index views, например, это работает.

Итак, я думаю, что проблема каким-то образом исходит от контекстного_процессора.

любая помощь, пожалуйста?

thx in advance

Вернуться на верх