| Conditions | 6 |
| Total Lines | 54 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 -*- |
||
| 73 | def setup_data_load(self, portal, request): |
||
| 74 | login(portal.aq_parent, SITE_OWNER_NAME) |
||
| 75 | |||
| 76 | wf = getToolByName(portal, 'portal_workflow') |
||
| 77 | wf.setDefaultChain('plone_workflow') |
||
| 78 | setupPortalContent(portal) |
||
| 79 | |||
| 80 | # make sure we have folder_listing as a template |
||
| 81 | portal.getTypeInfo().manage_changeProperties( |
||
| 82 | view_methods=['folder_listing'], |
||
| 83 | default_view='folder_listing') |
||
| 84 | # Add some test users |
||
| 85 | for role in ('LabManager', |
||
| 86 | 'LabClerk', |
||
| 87 | 'Analyst', |
||
| 88 | 'Verifier', |
||
| 89 | 'Sampler', |
||
| 90 | 'Preserver', |
||
| 91 | 'Publisher', |
||
| 92 | 'Member', |
||
| 93 | 'Reviewer', |
||
| 94 | 'RegulatoryInspector'): |
||
| 95 | for user_nr in range(2): |
||
| 96 | if user_nr == 0: |
||
| 97 | username = "test_%s" % (role.lower()) |
||
| 98 | else: |
||
| 99 | username = "test_%s%s" % (role.lower(), user_nr) |
||
| 100 | member = portal.portal_registration.addMember( |
||
| 101 | username, |
||
| 102 | username, |
||
| 103 | properties={ |
||
| 104 | 'username': username, |
||
| 105 | 'email': username + "@example.com", |
||
| 106 | 'fullname': username} |
||
| 107 | ) |
||
| 108 | # Add user to all specified groups |
||
| 109 | group_id = role + "s" |
||
| 110 | group = portal.portal_groups.getGroupById(group_id) |
||
| 111 | if group: |
||
| 112 | group.addMember(username) |
||
| 113 | # Add user to all specified roles |
||
| 114 | member._addRole(role) |
||
| 115 | # If user is in LabManagers, add Owner local role on clients folder |
||
| 116 | if role == 'LabManager': |
||
| 117 | portal.clients.manage_setLocalRoles(username, ['Owner', ]) |
||
| 118 | |||
| 119 | # load test data |
||
| 120 | request = makerequest(portal.aq_parent).REQUEST |
||
| 121 | request.form['setupexisting'] = 1 |
||
| 122 | request.form['existing'] = "bika.health:test" |
||
| 123 | lsd = LoadSetupData(portal, request) |
||
| 124 | lsd() |
||
| 125 | |||
| 126 | logout() |
||
| 127 | |||
| 142 |