diff --git a/core/forms.py b/core/forms.py index 135e79e..11278f7 100644 --- a/core/forms.py +++ b/core/forms.py @@ -2,6 +2,7 @@ from django import forms from django.contrib.auth.forms import UserCreationForm from django.core.exceptions import FieldDoesNotExist from django.forms import ModelForm +from mixins.restrictions import RestrictedFormMixin from core.db.storage import db from core.lib.parsing import QueryError @@ -12,36 +13,6 @@ from .models import NotificationRule, NotificationSettings, User # flake8: noqa: E501 -class RestrictedFormMixin: - """ - This mixin is used to restrict the queryset of a form to the current user. - The request object is passed from the view. - Fieldargs is used to pass additional arguments to the queryset filter. - """ - - fieldargs = {} - - def __init__(self, *args, **kwargs): - # self.fieldargs = {} - self.request = kwargs.pop("request") - super().__init__(*args, **kwargs) - for field in self.fields: - # Check it's not something like a CharField which has no queryset - if not hasattr(self.fields[field], "queryset"): - continue - - model = self.fields[field].queryset.model - # Check if the model has a user field - try: - model._meta.get_field("user") - # Add the user to the queryset filters - self.fields[field].queryset = model.objects.filter( - user=self.request.user, **self.fieldargs.get(field, {}) - ) - except FieldDoesNotExist: - pass - - class NewUserForm(UserCreationForm): email = forms.EmailField(required=True) diff --git a/core/templates/modals/context.html b/core/templates/modals/context.html index 99d56b4..2b0c7a4 100644 --- a/core/templates/modals/context.html +++ b/core/templates/modals/context.html @@ -42,7 +42,7 @@ {% endblock %} {% block modal_content %} - {% include 'partials/notify.html' %} + {% include 'mixins/partials/notify.html' %}