Open sfPPP opened 6 years ago
workflow讲解博客 workflows本质就是一个更加复杂的django form(表单) Workflows三要素:
action steps workflow
WorkFlows分析------>以launch instance为例 首先前台发送的url请求,在urls.py里面进行映射
openstack_dashboard/dashboards/project/instances/urls.py
urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), _url(r'^launch$', views.LaunchInstanceView.as_view(), name='launch'),_ url(r'^(?P<instance_id>[^/]+)/$', views.DetailView.as_view(), name='detail'), url(INSTANCES % 'update', views.UpdateView.as_view(), name='update'), url(INSTANCES % 'rebuild', views.RebuildView.as_view(), name='rebuild'), url(INSTANCES % 'serial', views.SerialConsoleView.as_view(), name='serial'), url(INSTANCES % 'console', views.console, name='console'), url(INSTANCES % 'auto_console', views.auto_console, name='auto_console'), url(INSTANCES % 'vnc', views.vnc, name='vnc'), url(INSTANCES % 'spice', views.spice, name='spice'),
_url(r'^launch$', views.LaunchInstanceView.as_view(), name='launch')为对应url映射_ 映射到openstack_dashboard/dashboards/project/instances/views.py的LaunchInstanceView
class LaunchInstanceView(workflows.WorkflowView): workflow_class = project_workflows.LaunchInstance
该类继承了horizon/workflows/views.py的WorkflowView, 在WorkflowView中我们可以传递数据到template(模板)和action(form)中。(action 也能够传递数据到get_context_data 方法或者template中)
class WorkflowView(hz_views.ModalBackdropMixin, generic.TemplateView): workflow_class = None template_name = 'horizon/common/_workflow_base.html' context_object_name = "workflow" ajax_template_name = 'horizon/common/_workflow.html' step_errors = {} def __init__(self): super(WorkflowView, self).__init__() def get_initial(self): return copy.copy(self.request.GET) def get_workflow(self): """Returns the instantiated workflow class.""" extra_context = self.get_initial() entry_point = self.request.GET.get("step", None) workflow = self.workflow_class(self.request, context_seed=extra_context, entry_point=entry_point) return workflow def get_context_data(self, **kwargs): return context def get_layout(self): return layout def get_template_names(self): return template def get_object_id(self, obj): return getattr(obj, "id", None) def get_object_display(self, obj): return getattr(obj, "name", None) def add_error_to_step(self, error_msg, step): self.step_errors[step] = error_msg def set_workflow_step_errors(self, context): def get(self, request, *args, **kwargs): return self.render_to_response(context) def validate_steps(self, request, workflow, start, end): def post(self, request, *args, **kwargs): return shortcuts.redirect(next_url or workflow.get_success_url())
workflow讲解博客 workflows本质就是一个更加复杂的django form(表单) Workflows三要素:
WorkFlows分析------>以launch instance为例 首先前台发送的url请求,在urls.py里面进行映射
openstack_dashboard/dashboards/project/instances/urls.py
_url(r'^launch$', views.LaunchInstanceView.as_view(), name='launch')为对应url映射_ 映射到openstack_dashboard/dashboards/project/instances/views.py的LaunchInstanceView
该类继承了horizon/workflows/views.py的WorkflowView, 在WorkflowView中我们可以传递数据到template(模板)和action(form)中。(action 也能够传递数据到get_context_data 方法或者template中)