Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_tabs is caching with server start #4

Open
kamilgregorczyk opened this issue Aug 8, 2016 · 3 comments
Open

get_tabs is caching with server start #4

kamilgregorczyk opened this issue Aug 8, 2016 · 3 comments

Comments

@kamilgregorczyk
Copy link

kamilgregorczyk commented Aug 8, 2016

So I'm changing tabs dynamically like so:

def get_tabs(self, request, obj=None):
        tabs = self.tabs
        if obj and request.user != obj.created_by:
            tabs = [
                (u'Podstawowe dane', self.tab_main),
                (u'Pytania', self.tab_questions),
                (u'Tokeny', self.tab_tokens)
            ]

        self.tabs = tabs
        return super(PollAdmin, self).get_tabs(request, obj)

and when i run server and go to change view of my model it's cached with these three tabs for all users, it's omitting my base tabs config even if the condition is false

tabs = [
        (u'Podstawowe dane', tab_main),
        (u'Pytania', tab_questions),
        (u'Tokeny', tab_tokens),
        (u'Uprawnienia', tab_permissions)
    ]
@kamilgregorczyk
Copy link
Author

my solution

def get_tabs(self, request, obj=None):
        if obj and request.user != obj.created_by:
            return [
                (u'Podstawowe dane', self.tab_main),
                (u'Pytania', self.tab_questions),
                (u'Tokeny', self.tab_tokens)
            ]
        return [
            (u'Podstawowe dane', self.tab_main),
            (u'Pytania', self.tab_questions),
            (u'Tokeny', self.tab_tokens),
            (u'Uprawnienia', self.tab_permissions)
        ]

@omji
Copy link
Owner

omji commented Aug 9, 2016

Hi Kamil,

Thanks a million for your feedback on this issue. I have just added some test against your specific code and it passes successfully (see above & travis).

I understand you mention some caching but then your solution should not pass as well? Maybe its something to do with the self.tabs. The strange thing is that there should be no caching in django admin and there is no cache implemented in this app.

Out of curiosity, what is the django version you are using?

Thanks again!

@kamilgregorczyk
Copy link
Author

kamilgregorczyk commented Aug 10, 2016

I'm sorry it wasn't caching it was static -> instance variable transformation in admin, once someone opened admin change view with modified tabs self.tabs was changed for everyone else.

Here's my project and now it works ok https://github.com/kamilgregorczyk/sententia/blob/master/poll/admin.py#L108

Someday I'm gonna make it more pretty, someday.

django 1.9.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants