Conditions | 7 |
Total Lines | 72 |
Code Lines | 45 |
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 -*- |
||
175 | def folderitem(self, obj, item, index): |
||
176 | """Service triggered each time an item is iterated in folderitems. |
||
177 | |||
178 | The use of this service prevents the extra-loops in child objects. |
||
179 | |||
180 | :obj: the instance of the class to be foldered |
||
181 | :item: dict containing the properties of the object to be used by |
||
182 | the template |
||
183 | :index: current index of the item |
||
184 | """ |
||
185 | # ensure we have an object and not a brain |
||
186 | obj = api.get_object(obj) |
||
187 | uid = api.get_uid(obj) |
||
188 | |||
189 | # settings for this analysis |
||
190 | service_settings = self.context.getAnalysisServiceSettings(uid) |
||
191 | hidden = service_settings.get("hidden", obj.getHidden()) |
||
192 | |||
193 | # get the category |
||
194 | category = obj.getCategoryTitle() |
||
195 | item["category"] = category |
||
196 | if category not in self.categories: |
||
197 | self.categories.append(category) |
||
198 | |||
199 | keyword = obj.getKeyword() |
||
200 | if uid in self.analyses: |
||
201 | analysis = self.analyses[uid] |
||
202 | # Might differ from the service keyword |
||
203 | keyword = analysis.getKeyword() |
||
204 | # Mark the row as disabled if the analysis is not in an open state |
||
205 | item["disabled"] = not analysis.isOpen() |
||
206 | # get the hidden status of the analysis |
||
207 | hidden = analysis.getHidden() |
||
208 | |||
209 | # get the specification of this object |
||
210 | rr = self.get_results_range() |
||
211 | spec = rr.get(keyword, ResultsRangeDict()) |
||
212 | |||
213 | item["Title"] = obj.Title() |
||
214 | item["Unit"] = obj.getUnit() |
||
215 | item["Price"] = obj.getPrice() |
||
216 | item["before"]["Price"] = self.get_currency_symbol() |
||
217 | item["allow_edit"] = self.get_editable_columns(obj) |
||
218 | item["selected"] = uid in self.selected |
||
219 | item["min"] = str(spec.get("min", "")) |
||
220 | item["max"] = str(spec.get("max", "")) |
||
221 | item["warn_min"] = str(spec.get("warn_min", "")) |
||
222 | item["warn_max"] = str(spec.get("warn_max", "")) |
||
223 | item["Hidden"] = hidden |
||
224 | |||
225 | # Append info link before the service |
||
226 | # see: bika.lims.site.coffee for the attached event handler |
||
227 | item["before"]["Title"] = get_link( |
||
228 | "analysisservice_info?service_uid={}".format(uid), |
||
229 | value="<span class='glyphicon glyphicon-info-sign'></span>", |
||
230 | css_class="service_info") |
||
231 | |||
232 | # Icons |
||
233 | after_icons = "" |
||
234 | if obj.getAccredited(): |
||
235 | after_icons += get_image( |
||
236 | "accredited.png", title=t(_("Accredited"))) |
||
237 | if obj.getAttachmentOption() == "r": |
||
238 | after_icons += get_image( |
||
239 | "attach_reqd.png", title=t(_("Attachment required"))) |
||
240 | if obj.getAttachmentOption() == "n": |
||
241 | after_icons += get_image( |
||
242 | "attach_no.png", title=t(_('Attachment not permitted'))) |
||
243 | if after_icons: |
||
244 | item["after"]["Title"] = after_icons |
||
245 | |||
246 | return item |
||
247 |