OpenStack Workflow Workflows Use principle detailed introduction _openstack

Source: Internet
Author: User
Tags http request

Workflows

Workflows are complex forms (forms) and tabs, and each Workflow must contain Workflow,step and Action

Here are examples of workflow usage:

The next example illustrates how data is passed from one URL to another, views, workflows, and templates.

In urls.py, a parameter is defined. For example. resource_class_id.

Resource_class = R ' ^ (? p<resource_class_id>[^/]+)/%s$ '

urlpatterns = patterns (
' ",
url (resource_class% ' update '), Updateview.as_view (), name= ' Update ')

In views.py, we can pass data to template (template) and action (form). (Action can also pass data to the Get_context_data method or template)

 class Updateview (workflows. Workflowview): Workflow_class = Updateresourceclass def get_context_data (self, **kwargs): Context = Super (Updatev Iew, self). Get_context_data (**kwargs) # The data in the URL is usually in Self.kwargs, where we can pass the data to Template.url context["resource_class_id "] = self.kwargs[' resource_class_id '] # data comes from the workflow ' s Steps and is stored in the context[' workflow '].context list, we can also template Use them to return the context def _get_object (self, *args, **kwargs): #url中的数据通常在self. Kwargs, where we can load objects of interest Resour ce_class_id = self.kwargs[' resource_class_id '] # eg:my_objects = api.nova.get_by_id (resource_class_id) def Get_ini
    Tial (self): Resource_class = Self._get_object () # The data here can be used by the action method and the workflow ' handle method, but steps must depend on the value return {' resource_class_id ': resource_class.id, ' name ': Resource_class.name, ' service_type ': resource_cl Ass.service_type} 

In workflows.py, we work with data, workflows is essentially a more complex Django form (form)

Class Resourcesaction (Workflows. Action): # The Name field value defined below can be obtained in all action methods if we expect this value to be used in other steps or other workflow, it must originate from the current step and establish depend on the other step NA me = forms.

  Charfield (max_length=255, Label=_ ("Testing Name"), help_text= "", Required=true) def handle (self, request, data): Pass # If you want to use the parameter value in the URL, you must establish a depend on relationship on the step corresponding to the action # can self.initial[' Reso urce_class_id '] or data[' resource_class_id ' gets the value # if we want to use the data in another step, then the other step must contribute the data and the two step is ordered class up Dateresources (Workflows. Step): # Here to pass the Workflow data to the action method Handle/clean, the value you want to use in the action, where depends_on must define the # Workflow context data including the data in the URL and from the other The data in step contributed depends_on = ("resource_class_id",) # through the contributes parameter, the data here can be used by other workflow or other step, it is noteworthy that obj 
    Ect_ids key needs to be manually added to contributes contributes = ("Resources_object_ids", "name") def contribute (self, data, context): # Here you can get workflow HTTP request data Request = Self.workflow.request if Data: # Only those defined in the action can be obtained here, and if you want to get other values, you need to overwrite the contribute method and manually add it to the dictionary context["Resources_object_ids" =\ Request. Post.getlist ("Resources_object_ids") # merges the data passed above, or it can be handed to the parent class to merge the Context.update (data) return context class Updat Eresourceclass (Workflows. Workflow): Default_steps = (updateresources,) def handle (self, request, data): Pass # This method is executed at the last (hand of all action) Le method after) # Here you can use all the ' contributes= ' and ' depends_on= ' data in step # Here you can handle complex business logic #此处可用值: data["Resources_object_ids"] 



 , data["name"] data["resources_class_id"]

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.