| Conditions | 4 |
| Total Lines | 51 |
| Code Lines | 35 |
| 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 -*- |
||
| 34 | def __init__(self, context, request): |
||
| 35 | super(ContactsView, self).__init__(context, request) |
||
| 36 | |||
| 37 | self.contentFilter = { |
||
| 38 | "portal_type": "Contact", |
||
| 39 | "sort_on": "sortable_title", |
||
| 40 | } |
||
| 41 | |||
| 42 | global_contacts_path = "/".join(self.context.getPhysicalPath()) |
||
| 43 | |||
| 44 | # Override the content filter based on the cookie |
||
| 45 | if self.include_client_contacts: |
||
| 46 | self.contentFilter.pop("path", None) |
||
| 47 | else: |
||
| 48 | # Show only global contacts |
||
| 49 | self.contentFilter = { |
||
| 50 | "portal_type": "Contact", |
||
| 51 | "sort_on": "sortable_title", |
||
| 52 | "path": {"query": global_contacts_path, "level": 0} |
||
| 53 | } |
||
| 54 | |||
| 55 | # Add Location column after Full Name |
||
| 56 | self.columns = OrderedDict(( |
||
| 57 | ("getFullname", { |
||
| 58 | "title": _("Full Name"), |
||
| 59 | "index": "getFullname", |
||
| 60 | "sortable": True, }), |
||
| 61 | ("Username", { |
||
| 62 | "title": _("User Name"), }), |
||
| 63 | ("getEmailAddress", { |
||
| 64 | "title": _("Email Address"), }), |
||
| 65 | ("getBusinessPhone", { |
||
| 66 | "title": _("Business Phone"), }), |
||
| 67 | ("getMobilePhone", { |
||
| 68 | "title": _("MobilePhone"), }), |
||
| 69 | ("Location", { |
||
| 70 | "title": _("Location"), |
||
| 71 | "sortable": False, }), |
||
| 72 | )) |
||
| 73 | |||
| 74 | for review_state in self.review_states: |
||
| 75 | # ensure all columns are included |
||
| 76 | review_state["columns"] = self.columns.keys() |
||
| 77 | if self.include_client_contacts: |
||
| 78 | # remove the path query |
||
| 79 | review_state["contentFilter"].pop("path", None) |
||
| 80 | else: |
||
| 81 | # add the path query |
||
| 82 | review_state["contentFilter"]["path"] = { |
||
| 83 | "query": global_contacts_path, |
||
| 84 | "level": 0 |
||
| 85 | } |
||
| 116 |