我正在尝试在可能存在一些复杂权限规则的应用中同时使用django-viewflow和django-permission的想法。我了解django-permission的工作方式是,在要应用权限规则的视图中添加装饰器。
我设法通过扩展基本视图流视图并将urls.py指向扩展视图来在流程视图上进行操作。当我尝试遵循相同的想法执行任务时,遇到以下所列错误
类型对象'CBVTask'没有属性'flow_class'
models.py
class CBVArticle(models.Model):
created_by = models.ForeignKey(User)
title = models.CharField(max_length=100)
content = models.TextField()
class CBVArticleProcess(Process):
article = models.ForeignKey(CBVArticle, blank=True, null=True)
class CBVTask(Task):
class Meta:
proxy = True
flow.py
class CBVArticleFlow(Flow):
process_class = models.CBVArticleProcess
task_class = models.CBVTask
start = (
flow.Start(views.ArticleCreate).Next(this.end)
)
end =flow.End()
urls.py
myflow_urls = FlowViewSet(CBVArticleFlow).urls
urlpatterns = [
url(r'^process/(?P<process_pk>\d+)/$', views.TestDetailProcessView.as_view(), kwargs = dict(flow_class=CBVArticleFlow), name='detail'),
url(r'^process/(?P<process_pk>\d+)/start/(?P<task_pk>\d+)/detail/$', views.DetailTaskView.as_view(), kwargs = dict(flow_class=CBVArticleFlow, flow_task=CBVTask), name='start__detail'),
]
views.py
from viewflow.flow.views import DetailProcessView as BaseDetailProcessView, DetailTaskView as BaseDetailTaskView
@permission_required('test_app_cbv.view_cbvarticleprocess')
class TestDetailProcessView(BaseDetailProcessView):
template_name = 'test_app_cbv/detail.html'
def get_queryset(self):
pk = self.kwargs['process_pk']
return models.CBVArticleProcess.objects.filter(process_ptr_id = pk)
class DetailTaskView(BaseDetailTaskView):
template_name = 'test_app_cbv/task_detail.html'
在此先感谢任何指针!
答案 0 :(得分:0)
原来是个菜鸟错误-urls.py文件的内容如下:
urls.py
myflow_urls = FlowViewSet(CBVArticleFlow).urls
urlpatterns = [
url(r'^process/(?P<process_pk>\d+)/$', views.TestDetailProcessView.as_view(), kwargs = dict(flow_class=CBVArticleFlow), name='detail'),
url(r'^process/(?P<process_pk>\d+)/start/(?P<task_pk>\d+)/detail/$', views.DetailTaskView.as_view(), kwargs = dict(flow_class=CBVArticleFlow, flow_task=CBVArticleFlow.start), name='start__detail'),
]