Conditions | 4 |
Total Lines | 95 |
Code Lines | 69 |
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 -*- |
||
21 | def __init__(self, field, request): |
||
22 | super(ServicesWidget, self).__init__(field, request) |
||
23 | |||
24 | self.catalog = SETUP_CATALOG |
||
25 | self.contentFilter = { |
||
26 | "portal_type": "AnalysisService", |
||
27 | "sort_on": "sortable_title", |
||
28 | "sort_order": "ascending", |
||
29 | "is_active": True, |
||
30 | } |
||
31 | |||
32 | # group the current records by UID |
||
33 | self.records = {} |
||
34 | for record in self.get_value(): |
||
35 | uid = record.get("uid") |
||
36 | self.records[uid] = record |
||
37 | |||
38 | # listing config |
||
39 | self.allow_edit = True |
||
40 | self.context_actions = {} |
||
41 | self.fetch_transitions_on_select = False |
||
42 | self.omit_form = True |
||
43 | self.pagesize = 999999 |
||
44 | self.show_column_toggles = False |
||
45 | self.show_search = True |
||
46 | self.show_select_all_checkbox = False |
||
47 | self.show_select_column = True |
||
48 | self.show_table_footer = False |
||
49 | |||
50 | # Categories |
||
51 | if self.show_categories_enabled(): |
||
52 | self.categories = [] |
||
53 | self.show_categories = True |
||
54 | self.expand_all_categories = False |
||
55 | |||
56 | self.columns = collections.OrderedDict(( |
||
57 | ("Title", { |
||
58 | "title": _( |
||
59 | u"listing_services_column_title", |
||
60 | default=u"Service" |
||
61 | ), |
||
62 | "index": "sortable_title", |
||
63 | "sortable": False |
||
64 | }), |
||
65 | ("Keyword", { |
||
66 | "title": _( |
||
67 | u"listing_services_column_keyword", |
||
68 | default=u"Keyword" |
||
69 | ), |
||
70 | "sortable": False |
||
71 | }), |
||
72 | ("Methods", { |
||
73 | "title": _( |
||
74 | u"listing_services_column_methods", |
||
75 | default=u"Methods" |
||
76 | ), |
||
77 | "sortable": False |
||
78 | }), |
||
79 | ("Unit", { |
||
80 | "title": _( |
||
81 | u"listing_services_column_unit", |
||
82 | default=u"Unit" |
||
83 | ), |
||
84 | "sortable": False |
||
85 | }), |
||
86 | ("Price", { |
||
87 | "title": _( |
||
88 | u"listing_services_column_price", |
||
89 | default=u"Price" |
||
90 | ), |
||
91 | "sortable": False, |
||
92 | }), |
||
93 | ("Hidden", { |
||
94 | "title": _( |
||
95 | u"listing_services_column_hidden", |
||
96 | default=u"Hidden" |
||
97 | ), |
||
98 | "sortable": False, |
||
99 | }), |
||
100 | )) |
||
101 | |||
102 | cols = self.columns.keys() |
||
103 | if not self.show_prices(): |
||
104 | cols.remove("Price") |
||
105 | |||
106 | self.review_states = [ |
||
107 | { |
||
108 | "id": "default", |
||
109 | "title": _( |
||
110 | u"listing_services_state_all", |
||
111 | default=u"All" |
||
112 | ), |
||
113 | "contentFilter": {}, |
||
114 | "transitions": [{"id": "disallow-all-possible-transitions"}], |
||
115 | "columns": cols, |
||
116 | }, |
||
273 |