Conditions | 8 |
Total Lines | 83 |
Code Lines | 53 |
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 -*- |
||
203 | def folderitem(self, obj, item, index): |
||
204 | """Service triggered each time an item is iterated in folderitems. |
||
205 | |||
206 | The use of this service prevents the extra-loops in child objects. |
||
207 | |||
208 | :obj: the instance of the class to be foldered |
||
209 | :item: dict containing the properties of the object to be used by |
||
210 | the template |
||
211 | :index: current index of the item |
||
212 | """ |
||
213 | # ensure we have an object and not a brain |
||
214 | obj = api.get_object(obj) |
||
215 | uid = api.get_uid(obj) |
||
216 | |||
217 | # settings for this analysis |
||
218 | service_settings = self.context.getAnalysisServiceSettings(uid) |
||
219 | hidden = service_settings.get("hidden", obj.getHidden()) |
||
220 | |||
221 | # get the category |
||
222 | category = obj.getCategoryTitle() |
||
223 | item["category"] = category |
||
224 | if category not in self.categories: |
||
225 | self.categories.append(category) |
||
226 | |||
227 | parts = filter(api.is_active, self.get_partitions()) |
||
228 | partitions = map(lambda part: { |
||
229 | "ResultValue": part.Title(), "ResultText": part.getId()}, parts) |
||
230 | |||
231 | keyword = obj.getKeyword() |
||
232 | partition = None |
||
233 | if uid in self.analyses: |
||
234 | analysis = self.analyses[uid] |
||
235 | # Might differ from the service keyword |
||
236 | keyword = analysis.getKeyword() |
||
237 | # Mark the row as disabled if the analysis is not in an open state |
||
238 | item["disabled"] = not analysis.isOpen() |
||
239 | # get the hidden status of the analysis |
||
240 | hidden = analysis.getHidden() |
||
241 | # get the partition of the analysis |
||
242 | partition = self.get_partition(analysis) |
||
243 | else: |
||
244 | partition = self.get_partitions()[0] |
||
245 | |||
246 | # get the specification of this object |
||
247 | rr = self.get_results_range() |
||
248 | spec = rr.get(keyword, ResultsRangeDict()) |
||
249 | |||
250 | item["Title"] = obj.Title() |
||
251 | item["Unit"] = obj.getUnit() |
||
252 | item["Price"] = obj.getPrice() |
||
253 | item["before"]["Price"] = self.get_currency_symbol() |
||
254 | item["allow_edit"] = self.get_editable_columns(obj) |
||
255 | item["selected"] = uid in self.selected |
||
256 | item["min"] = str(spec.get("min", "")) |
||
257 | item["max"] = str(spec.get("max", "")) |
||
258 | item["warn_min"] = str(spec.get("warn_min", "")) |
||
259 | item["warn_max"] = str(spec.get("warn_max", "")) |
||
260 | item["Hidden"] = hidden |
||
261 | item["Partition"] = partition.getId() |
||
262 | item["choices"]["Partition"] = partitions |
||
263 | |||
264 | # Append info link before the service |
||
265 | # see: bika.lims.site.coffee for the attached event handler |
||
266 | item["before"]["Title"] = get_link( |
||
267 | "analysisservice_info?service_uid={}".format(uid), |
||
268 | value="<span class='glyphicon glyphicon-info-sign'></span>", |
||
269 | css_class="service_info") |
||
270 | |||
271 | # Icons |
||
272 | after_icons = "" |
||
273 | if obj.getAccredited(): |
||
274 | after_icons += get_image( |
||
275 | "accredited.png", title=t(_("Accredited"))) |
||
276 | if obj.getAttachmentOption() == "r": |
||
277 | after_icons += get_image( |
||
278 | "attach_reqd.png", title=t(_("Attachment required"))) |
||
279 | if obj.getAttachmentOption() == "n": |
||
280 | after_icons += get_image( |
||
281 | "attach_no.png", title=t(_('Attachment not permitted'))) |
||
282 | if after_icons: |
||
283 | item["after"]["Title"] = after_icons |
||
284 | |||
285 | return item |
||
286 |