我正在尝试将 django-userena 与 django-oscar 一起使用。到目前为止,它运行良好,除了当我尝试将非员工用户链接到履行合作伙伴时(链接到员工用户工作正常)。这是我得到的错误:
Traceback:
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/db/transaction.py" in inner
371. return func(*args, **kwargs)
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
22. return view_func(request, *args, **kwargs)
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
22. return view_func(request, *args, **kwargs)
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/oscar/apps/dashboard/partners/views.py" in post
219. if self.link_user(user, partner):
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/oscar/apps/dashboard/partners/views.py" in link_user
206. content_type__app_label='partner')
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/db/models/manager.py" in get
151. return self.get_queryset().get(*args, **kwargs)
File "/Users/shafiquejamal/allfiles/htdocs/venvs/av4env/lib/python2.7/site-packages/django/db/models/query.py" in get
310. self.model._meta.object_name)
Exception Type: DoesNotExist at /en/store/dashboard/partners/1/users/380/link/
Exception Value: Permission matching query does not exist.
似乎问题出在oscar.apps.dashboards.partners.views
:
class PartnerUserLinkView(generic.View):
def link_user(self, user, partner):
"""
Links a user to a partner, and adds the dashboard permission if needed.
Returns False if the user was linked already; True otherwise.
"""
if partner.users.filter(pk=user.pk).exists():
return False
partner.users.add(user)
if not user.is_staff:
dashboard_access_perm = Permission.objects.get(
codename='dashboard_access',
content_type__app_label='partner')
user.user_permissions.add(dashboard_access_perm)
return True
Permission.objects.get
不返回对象。这是因为check_permissions
in 命令django-userena
检查以下权限:
ASSIGNED_PERMISSIONS = {
'profile':
(('view_profile', 'Can view profile'),
('change_profile', 'Can change profile'),
('delete_profile', 'Can delete profile')),
'user':
(('change_user', 'Can change user'),
('delete_user', 'Can delete user'))
}
其中,不包括dashboard_access
. 我尝试向 中添加另一个配置文件权限('dashboard_access', _('Can access dashboard')),),
, ASSIGNED_PERMISSIONS.profile
但这不起作用 - 我仍然遇到上述相同的错误。我认为问题在于,即使dashboard_access
是权限之一,该link_user
方法也指定content_type__app_label='partner'
,但从content_type__app_label
不partner
(partner
是奥斯卡应用程序之一)。所以我想我应该重写check_permissions
管理命令来检查适应 django-oscar 的权限。我的问题是:
如何在
check_permissions
不触及虚拟环境中的代码的情况下覆盖或扩展管理命令?我咨询了https://docs.djangoproject.com/en/1.6/howto/custom-management-commands/,并首先将 manager.py 代码从我的项目中的一个文件夹复制userena
到一个management/commands
文件夹中,但得到了一个命令未实现错误。如何修改检查权限以引用“合作伙伴”的应用标签?
我什至可以正确地解决这个问题吗?
oscar
也许我误解了如何或是否userena
可以一起工作。