Skip to content

Access self.request.user #103

@caclement

Description

@caclement

In the documentation it seems you managed to refer to self.request.user when creating customs filters.

https://django-slick-reporting.readthedocs.io/en/latest/topics/filter_form.html

    def get_filters(self):
        # return the filters to be used in the report
        # Note: the use of Q filters and kwargs filters
        filters = {}
        q_filters = []
        if self.cleaned_data["secure"] == "secure":
            filters["is_secure"] = True
        elif self.cleaned_data["secure"] == "non-secure":
            filters["is_secure"] = False
        if self.cleaned_data["method"]:
            filters["method"] = self.cleaned_data["method"]
        if self.cleaned_data["response"]:
            filters["response"] = self.cleaned_data["response"]
        if self.cleaned_data["other_people_only"]:
            q_filters.append(~Q(user=self.request.user))

However when I do it, I get an error :

    def get_filters(self):
        filters = {}
        q_filters = []
        filters["location_id"] = self.cleaned_data["location_id"]
        filters["test"] = self.request.user.email
        return q_filters, filters

The error is : AttributeError: 'ManagerForm' object has no attribute 'request'

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions