Plone的一个简单工作流使用示例

Getting Started with Content Types

If you don’t know what a content type is, don’t worry! Sit back, relax, and do the tutorial! I’ll save the mumbo jumbo definitions for another day. In this first part, we will make a Todo list without touching any code. It won’t be fancy, but it will give you a good idea of how things work in Plone.

The way that Plone handles content is a little different than your average relational database driven framework, so if you don’t understand something right away, sit back, relax, and finish the tutorial.

Create a New Content Type

First we need to create a new content type to represent an item on our Todo list. This will be a type with one field, that which needs to be done.

  1. Navigate to site setup as shown below, or just enterhttp://localhost:8080/Plone/@@overview-controlpanel in your browser. This is where you can configure Plone for happy fun time.

    _images/site_setup.jpg
  2. Now comes the fun part. We want to create our own type Through-The-Web aka.TTW. This type will be a Todo Item. Let’s click Dexterity Content Types (or go directly tohttp://localhost:8080/Plone/@@dexterity-types).

    _images/plone_configuration_panel.jpg
  3. Create a Todo List Item by clicking Add New ContentType.

    _images/add_content_type.jpg
  4. Fill in the fields as seen below and then click Add.

    _images/add_todo_content_type.jpg
  5. Now you will see that there is a new type to play with. Let’s adjust a few

things. Click the name of the new type to edit.

_images/edit_todo_item.jpg
  1. There are two important things we need to do here: we need to adjust somebehaviors, and add some fields. Let’s look at the behaviors first.

    _images/todo_item_behaviors.jpg
  2. By default, all Plone content-types have Dublin Core metadata enabled (you may know it astitle and description. We don’t need this for our über simple Todo list item. UncheckDublin Coremetadata and then click Save.

    _images/behaviors_config.jpg
  3. Next we need to add some fields. Because this type is so simple, we will add just one field, but feel free to go CRAZY. Start by clickingAdd newfield....

    _images/add_new_field.jpg
  4. Add a field called Todo, or anything else you want. But! Note that it’s very important that theshort name is title. By using this key short name, we make sure that all Todo Items are searchable from smart search. Update the field as seen below and clickAdd.

    _images/add_todo_field.jpg
  5. You will see that a new field has been added to your content type. If you are feeling adventuresome, click on the settings tab next to the field to set other properties, or just see what’s available.

    _images/final_todo_fields_config.jpg

Trying out the Todo Item content-type

Now it’s time to reap the rewards of all of your effort. Let’s put all of our Todo Items in one particular folder so that we can have collections of items throughout the site. For this tutorial, we will be putting everything in the root of the site so it’s easy to debug.

  1. From the root, add a new folder called Todo.

    _images/add_folder_menu.jpg_images/save_todo_folder.jpg
  2. Add a new Todo Item to the new Todo folder.

    _images/add_todo_item.jpg_images/save_todo_item.jpg
  3. Celebrate!

    _images/todo_item.jpg

    You may be wondering about earlier, when we asked you to make sure that the short name for the Todo Item was called title. The time has come to let you in on a little secret. Calling the short name eithertitle or description will automatically add that text to the livesearch menu. WHAT?!? I know! When life gives you lemonade, spike it with vodka and enjoy liberally! You can now search for your Todo Items in Live Search.

    _images/live_search_title.jpg

But wait a minute... This todo item is marked private, and that doesn’t really make sense. It’s a good thing Plone has an easy solution for that. In the next section, we will go over the basics of that magical, mystical word: workflow.

Getting Started with Workflows

The Todo Item we added in the last section is marked as private because by default all new Plone content types are assigned a complex publication workflow. I know what you are thinking: Publication whodie whatie grble gobble??!?! Just like before, let’s bypass trying to explain what that means and just fix it. Relax, enjoy, and finish the tutorial!

If you aren’t interested in workflows, or already know all about this stuff, feel free to skip straight to the next chapter!

Todo Items really have 2 states that we are interested in: open andcomplete. Let’s make that happen.

  1. Head over to the ZMI at http://localhost:8080/Plone/manage_main.

  2. In the ZMI, open the portal_workflow tool.

    _images/manage_portal_workflow.jpg

    On this page, we see all content-types in our portal mapped to a workflow. Our new type, Todo Item, is mapped to(Default). You can see right below that the default isSimple PublicationWorkflow. This is just too complex for our little Todo Item.

    _images/default_workflow.jpg
  3. So let’s create a new one that suites our needs perfectly! Click thecontents tab at the top of the page to get a listing of all the available workflows.

    _images/portal_workflow_contents.jpg

    You can poke around here all you like, but the details of each one of these workflows are better left to another tutorial. When in doubt, you can always come back to these workflows to see examples of how things can be done. Onwards and upwards!

  4. Let’s create a new workflow for our Todo Items and call it todo_item_workflow. We will make a new workflow by copying and customizing one of the workflows that are already there. Copy simple_pubication_workflow

    TODO: Break this into several different images to be more clear.

    _images/copy_workflow.jpg
  5. Rename the copied workflow to ‘todo_item_workflow’

    _images/rename_workflow.jpg_images/save_rename_workflow.jpg
  6. You will be spit back out and the workflow contents page. Click the workflow to start editing

    _images/edit_todo_workflow.jpg
  7. Let’s update the name of the workflow so we don’t double take later on

    _images/retitle_workflow.jpg
  8. Workflow is something that takes time to get used to if you have never encoutered the concept. The best analogy in our case is to a car. The car engine has two simple states: on and off. To transition from on to off and vice versa, it needs some action from the driver. The same for our TODO items. They have to states: incomplete and complete. In order to get them from Incomplete to Complete, the user needs to click something. Don’t understand yet? Relax, sit back, and finish the tutorial.

    Lets start by adding out base states. We will call them “open” and “complete”. From the edit workflow screen, click on the “States” tab.

    _images/workflow_base_view.jpg
  9. Delete the currently listed state

    _images/cleanup_states.jpg
  10. Add two states with the ids “open” and “completed”.

    _images/add_open.jpg_images/add_completed.jpg
  11. Next lets add the transitions. The transitions will take the TODO item from open to completed and vice versa (in case a user accidentally marks an item as complete. Click on the transitions tab.

    _images/transitions_tab.jpg
  12. Add two transitions: complete, and reopen. When a user “complete”s a task, it will move into the “completed” state. When a user “reopens” a task, it will go back to the “open” state.

    _images/add_transitions.jpg
  13. Let’s add a few details to these new transitions. Let’s start with complete. Click on “complete” to edit the transition.

    _images/edit_complete.jpg
  14. First add a title so you remember later what this does. Description is optional but adding one will help you keep your thoughts clear and remind future you what now you is thinking. The destination state should be set tocompleted. We also want to make sure that only people with mega permissions, or the owner itself, can change the state so we addModify portalcontent to the Permissions box.

    All this means nothing if we don’t give the user a chance to change the state. Next toDisplay inactions box, we can set the title for what will be displayed in the workflow drop down box of the item (where Pending, Reject, etc where earlier). Let’s call itComplete. Last but not least, we need to add the url that the action points to. I could make this tutorial 100 years long and explain why you have to do this, but accept that it has to be done, relax, and follow this formula:

    URL = %(content_url)s/content_status_modify?workflow_action=X
    

    where X is the id of the transition. So for this case, in the URL box, you will add

    %(content_url)s/content_status_modify?workflow_action=complete
    
    _images/complete_details.jpg

    Double check everything and click “Save”.

  15. If your brain isn’t hurting yet it will be soon. Go back to the transitions listing.

    _images/youre_welcome.jpg_images/edit_reopen.jpg
  16. Let’s update the reopen transition and update in a similar manner. This time, the destination state is “open”, and following the formula above, the URL is “%(content_url)s/content_status_modify?workflow_action=reopen”.

    _images/save_reopen.jpg
  17. Now we have 2 states and 2 transitions, but they aren’t 100% linked together... yet. Go back to the workflow listing, click the states tab and then and click on “completed” to edit the state.

    _images/back_to_workflow.jpg_images/edit_completed.jpg
  18. Add a title, since this is what users see in the top right corner of the TODO items, and then check “reopen” as a possible transition. This means that when a TODO item is completed, it will only allow the user to reopen it (and not re-complete it, for example). In the same respect, open the open transition, add a title, and mark “complete” as a possible transition.

    _images/save_completed.jpg_images/save_open.jpg
  19. When we create a new TODO item, we need to tell Plone what the first state is. Go back to the workflow states listing, and make “open” the initial state.

    _images/initial_state.jpg
  20. And that’s it! Almost... Last but not least, we need to assign our new workflow to our TODO item type. Go back to the main workflow screen.

    _images/home_base.jpg
  21. Instead of mapping to the “(Default)” workflow, we are going to map to the id of our new workflow, todo_item_workflow, and then click “Change”.

    If you already have TODO items in your site, you MUST click “Update Security Settings” to update the workflow for the items. Instead of going into gross detail about why this is the case, just sit back, relax, finish the tutorial, and remember to click this button any time you make changes (yes! you can continue to change and update your workflows!).

    _images/map_to_workflow.jpg
  22. Could the time have arrived? Time to test? YES! Go to your TODO Items folder and add a new TODO Item. Validate that the workflow works as expected. By toggling between the states.

    _images/works.jpg

Congrats! You have now passed Plone Workflow 101. Next we will transition from editing through the web (TTW) to developing. With plone.api, it’s as easy as pie.

 
包括了视图定制的方法
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值