add access_permissions to sitetree.py
funksen opened this issue · 5 comments
Hi,
first of all thank you for this great package, makes my life much easier
now to my problem, I have the whole definition in the sitetree.py file, and I use to migrate changes with python manage.py sitetree_resync_apps
I need to include a few buttons, just see able for certain users coming from certain groups
this works fine if I simply add this via the admin gui, but when I try to add a line like this to my definition:
item('Administration','/admin',url_as_pattern=False,access_restricted=True,access_perm_type=1,access_permissions=[402]),
I get the error message
TypeError: Direct assignment to the forward side of a many-to-many set is prohibited. Use access_permissions.set() instead.
the number 402 comes from the json dump, even if this would works, can I be sure the permission id is always 402, even with a new installation?
thanks in advance
funksen
Hi,
Thank you.
Please attach a full stracktrace. What Django version do you use, by the way?
About permission id
: this approach is not portable, I'd rather use codenames, but not sure whether this is supported at all.
Hi,
thank you for the response
the full stacktrace:
id: Runid object (1387)
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/usr/lib/python3.7/site-packages/sitetree/management/commands/sitetree_resync_apps.py", line 37, in handle
tree_modules = import_project_sitetree_modules()
File "/usr/lib/python3.7/site-packages/sitetree/utils.py", line 143, in import_project_sitetree_modules
module = import_app_sitetree_module(app)
File "/usr/lib/python3.7/site-packages/sitetree/utils.py", line 126, in import_app_sitetree_module
sub_module = import_module('%s.%s' % (app, module_name))
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/netdar/Dropbox/programming/python/django/uxdb_project/uxdb/sitetrees.py", line 47, in <module>
item('Administration','/admin',url_as_pattern=False,access_restricted=True,access_perm_type=1,access_permissions=[402]),
File "/usr/lib/python3.7/site-packages/sitetree/utils.py", line 71, in item
access_loggedin=access_loggedin, access_guest=access_guest, **kwargs)
File "/usr/lib/python3.7/site-packages/django/db/models/base.py", line 479, in __init__
_setattr(self, prop, kwargs[prop])
File "/usr/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 537, in __set__
% self._get_set_deprecation_msg_params(),
TypeError: Direct assignment to the forward side of a many-to-many set is prohibited. Use access_permissions.set() instead.
I'm not sure where to use access_permissions.set(), and how to pass the permissions
Django Version 2.1
thanks a ton, for your quick response. working perfectly!
I think the confusion came from the sitetreedump with the output "access_permissions": [412]}"
so I thought this is the way to go
cheers
funksen
Considered closed.
Feel free to reopen if required.