Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Possibility to create items only staff can see #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sshkm
Copy link

@sshkm sshkm commented Feb 13, 2017

With this changes it is possible to create items only visible to the staff group.
I would need this in my own django project.
Would be nice to see it in your master branch.

Copy link
Owner

@rossp rossp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I like this idea. Can you please make a few minor changes to the MenuItem filtering to keep it in line with existing functionality?

setup.py Outdated
@@ -4,7 +4,7 @@
from fnmatch import fnmatchcase
from setuptools import setup, find_packages

version = '0.1.10'
version = '0.1.10.1'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please revise this to be 0.1.11?

@@ -92,7 +92,15 @@ def get_items(menu_name, current_path, user):
if not menu:
return []

for i in MenuItem.objects.filter(menu=menu).order_by('order'):
if (str(user) == 'AnonymousUser' or str(user) == 'None'):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at line #74, there are some checks for user type - ie anonymous or logged-in. Can you please add to those for is_staff, and build it into the cache key? Lastly, you can go back to a single MenuItem.objects() query and build in the is_staff filtering on line #114 (see menuitems.append when conditions are met).

This keeps your change in line with the previous structure of this file. It also means all similar checks occur in a similar manner.

@sshkm
Copy link
Author

sshkm commented Feb 21, 2017

Appreciate that you like the idea.
I did my best to make it fit better in your code.
The changes worked for me.
What's missing is the south migrations file. I have no experience with this stuff. But it can't be much difference to the "normal" migrations.

@elkinlrc
Copy link

Good afternoon, I would like to extend the model to add more fields to the menu, is there a way to do it? i want to create the icon field and the permissions field, i'm sorry beforehand i know this is not the place for the question but i'm a little lost

@rossp
Copy link
Owner

rossp commented May 21, 2018

@elkinlrc There is no supported way to do this at present. It would likely be easy to fork the project and make this change yourself.

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

Successfully merging this pull request may close these issues.

5 participants