Conditions | 1 |
Total Lines | 381 |
Code Lines | 330 |
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 -*- |
||
81 | def __init__(self, context, request): |
||
82 | super(SamplesView, self).__init__(context, request) |
||
83 | |||
84 | self.catalog = SAMPLE_CATALOG |
||
85 | self.contentFilter = { |
||
86 | "sort_on": "created", |
||
87 | "sort_order": "descending", |
||
88 | "isRootAncestor": True, # only root ancestors |
||
89 | } |
||
90 | |||
91 | self.title = self.context.translate(_("Samples")) |
||
92 | self.description = "" |
||
93 | |||
94 | self.show_select_column = True |
||
95 | self.form_id = "samples" |
||
96 | self.context_actions = {} |
||
97 | self.icon = "{}{}".format( |
||
98 | self.portal_url, "/senaite_theme/icon/sample") |
||
99 | |||
100 | self.url = api.get_url(self.context) |
||
101 | |||
102 | # Toggle some columns if the sampling workflow is enabled |
||
103 | sampling_enabled = api.get_setup().getSamplingWorkflowEnabled() |
||
104 | |||
105 | now = DateTime().strftime("%Y-%m-%d %H:%M") |
||
106 | |||
107 | self.columns = collections.OrderedDict(( |
||
108 | ("Priority", { |
||
109 | "title": "", |
||
110 | "index": "getPrioritySortkey", |
||
111 | "sortable": True, }), |
||
112 | ("Progress", { |
||
113 | "title": _("Progress"), |
||
114 | "index": "getProgress", |
||
115 | "sortable": True, |
||
116 | "toggle": True}), |
||
117 | ("getId", { |
||
118 | "title": _("Sample ID"), |
||
119 | "attr": "getId", |
||
120 | "replace_url": "getURL", |
||
121 | "index": "getId"}), |
||
122 | ("getClientOrderNumber", { |
||
123 | "title": _("Client Order"), |
||
124 | "sortable": True, |
||
125 | "toggle": False}), |
||
126 | ("Creator", { |
||
127 | "title": _("Creator"), |
||
128 | "index": "Creator", |
||
129 | "sortable": True, |
||
130 | "toggle": True}), |
||
131 | ("Created", { |
||
132 | "title": _("Date Registered"), |
||
133 | "index": "created", |
||
134 | "toggle": False}), |
||
135 | ("SamplingDate", { |
||
136 | "title": _("Expected Sampling Date"), |
||
137 | "index": "getSamplingDate", |
||
138 | "toggle": sampling_enabled}), |
||
139 | ("getDateSampled", { |
||
140 | "title": _("Date Sampled"), |
||
141 | "toggle": True, |
||
142 | "type": "datetime", |
||
143 | "max": now, |
||
144 | "sortable": True}), |
||
145 | ("getDatePreserved", { |
||
146 | "title": _("Date Preserved"), |
||
147 | "toggle": False, |
||
148 | "type": "datetime", |
||
149 | "max": now, |
||
150 | "sortable": False}), # no datesort without index |
||
151 | ("getDateReceived", { |
||
152 | "title": _("Date Received"), |
||
153 | "toggle": False}), |
||
154 | ("getDueDate", { |
||
155 | "title": _("Due Date"), |
||
156 | "toggle": False}), |
||
157 | ("getDateVerified", { |
||
158 | "title": _("Date Verified"), |
||
159 | "input_width": "10", |
||
160 | "toggle": False}), |
||
161 | ("getDatePublished", { |
||
162 | "title": _("Date Published"), |
||
163 | "toggle": False}), |
||
164 | ("BatchID", { |
||
165 | "title": _("Batch ID"), |
||
166 | "index": "getBatchID", |
||
167 | "sortable": True, |
||
168 | "toggle": False}), |
||
169 | ("Client", { |
||
170 | "title": _("Client"), |
||
171 | "index": "getClientTitle", |
||
172 | "attr": "getClientTitle", |
||
173 | "replace_url": "getClientURL", |
||
174 | "toggle": True}), |
||
175 | ("ClientID", { |
||
176 | "title": _("Client ID"), |
||
177 | "index": "getClientID", |
||
178 | "attr": "getClientID", |
||
179 | "replace_url": "getClientURL", |
||
180 | "toggle": True}), |
||
181 | ("Province", { |
||
182 | "title": _("Province"), |
||
183 | "sortable": True, |
||
184 | "index": "getProvince", |
||
185 | "attr": "getProvince", |
||
186 | "toggle": False}), |
||
187 | ("District", { |
||
188 | "title": _("District"), |
||
189 | "sortable": True, |
||
190 | "index": "getDistrict", |
||
191 | "attr": "getDistrict", |
||
192 | "toggle": False}), |
||
193 | ("getClientReference", { |
||
194 | "title": _("Client Ref"), |
||
195 | "sortable": True, |
||
196 | "index": "getClientReference", |
||
197 | "toggle": False}), |
||
198 | ("getClientSampleID", { |
||
199 | "title": _("Client SID"), |
||
200 | "toggle": False}), |
||
201 | ("ClientContact", { |
||
202 | "title": _("Contact"), |
||
203 | "sortable": False, |
||
204 | "toggle": False}), |
||
205 | ("getSampleTypeTitle", { |
||
206 | "title": _("Sample Type"), |
||
207 | "sortable": True, |
||
208 | "toggle": True}), |
||
209 | ("getSamplePointTitle", { |
||
210 | "title": _("Sample Point"), |
||
211 | "sortable": True, |
||
212 | "index": "getSamplePointTitle", |
||
213 | "toggle": False}), |
||
214 | ("getStorageLocation", { |
||
215 | "title": _("Storage Location"), |
||
216 | "sortable": True, |
||
217 | "index": "getStorageLocationTitle", |
||
218 | "toggle": False}), |
||
219 | ("SamplingDeviation", { |
||
220 | "title": _("Sampling Deviation"), |
||
221 | "sortable": True, |
||
222 | "index": "getSamplingDeviationTitle", |
||
223 | "toggle": False}), |
||
224 | ("getSampler", { |
||
225 | "title": _("Sampler"), |
||
226 | "toggle": sampling_enabled}), |
||
227 | ("getPreserver", { |
||
228 | "title": _("Preserver"), |
||
229 | "sortable": False, |
||
230 | "toggle": False}), |
||
231 | ("getProfilesTitle", { |
||
232 | "title": _("Profile"), |
||
233 | "sortable": False, |
||
234 | "toggle": False}), |
||
235 | ("getAnalysesNum", { |
||
236 | "title": _("Number of Analyses"), |
||
237 | "alt": _("Open / To be verified / Verified / Total"), |
||
238 | "sortable": True, |
||
239 | "index": "getAnalysesNum", |
||
240 | "toggle": False}), |
||
241 | ("getTemplateTitle", { |
||
242 | "title": _("Template"), |
||
243 | "sortable": True, |
||
244 | "index": "getTemplateTitle", |
||
245 | "toggle": False}), |
||
246 | ("Printed", { |
||
247 | "title": _("Printed"), |
||
248 | "sortable": False, |
||
249 | "index": "getPrinted", |
||
250 | "toggle": False}), |
||
251 | ("state_title", { |
||
252 | "title": _("State"), |
||
253 | "sortable": True, |
||
254 | "index": "review_state"}), |
||
255 | )) |
||
256 | |||
257 | # custom print transition |
||
258 | print_stickers = { |
||
259 | "id": "print_stickers", |
||
260 | "title": _("Print stickers"), |
||
261 | "url": "{}/workflow_action?action=print_stickers".format(self.url) |
||
262 | } |
||
263 | |||
264 | self.review_states = [ |
||
265 | { |
||
266 | "id": "default", |
||
267 | "title": _("Active"), |
||
268 | "contentFilter": { |
||
269 | "review_state": ( |
||
270 | "sample_registered", |
||
271 | "scheduled_sampling", |
||
272 | "to_be_sampled", |
||
273 | "sample_due", |
||
274 | "sample_received", |
||
275 | "to_be_preserved", |
||
276 | "to_be_verified", |
||
277 | "verified", |
||
278 | ), |
||
279 | "sort_on": "created", |
||
280 | "sort_order": "descending", |
||
281 | }, |
||
282 | "custom_transitions": [print_stickers], |
||
283 | "columns": self.columns.keys(), |
||
284 | }, { |
||
285 | "id": "to_be_sampled", |
||
286 | "title": _("To Be Sampled"), |
||
287 | "contentFilter": { |
||
288 | "review_state": ("to_be_sampled",), |
||
289 | "sort_on": "created", |
||
290 | "sort_order": "descending"}, |
||
291 | "custom_transitions": [print_stickers], |
||
292 | "columns": self.columns.keys() |
||
293 | }, { |
||
294 | "id": "to_be_preserved", |
||
295 | "title": _("To Be Preserved"), |
||
296 | "contentFilter": { |
||
297 | "review_state": ("to_be_preserved",), |
||
298 | "sort_on": "created", |
||
299 | "sort_order": "descending", |
||
300 | }, |
||
301 | "custom_transitions": [print_stickers], |
||
302 | "columns": self.columns.keys(), |
||
303 | }, { |
||
304 | "id": "scheduled_sampling", |
||
305 | "title": _("Scheduled sampling"), |
||
306 | "contentFilter": { |
||
307 | "review_state": ("scheduled_sampling",), |
||
308 | "sort_on": "created", |
||
309 | "sort_order": "descending", |
||
310 | }, |
||
311 | "custom_transitions": [print_stickers], |
||
312 | "columns": self.columns.keys(), |
||
313 | }, { |
||
314 | "id": "sample_due", |
||
315 | "title": _("Due"), |
||
316 | "contentFilter": { |
||
317 | "review_state": ( |
||
318 | "to_be_sampled", |
||
319 | "to_be_preserved", |
||
320 | "sample_due"), |
||
321 | "sort_on": "created", |
||
322 | "sort_order": "descending"}, |
||
323 | "custom_transitions": [print_stickers], |
||
324 | "columns": self.columns.keys(), |
||
325 | }, { |
||
326 | "id": "sample_received", |
||
327 | "title": _("Received"), |
||
328 | "contentFilter": { |
||
329 | "review_state": "sample_received", |
||
330 | "sort_on": "created", |
||
331 | "sort_order": "descending", |
||
332 | }, |
||
333 | "custom_transitions": [print_stickers], |
||
334 | "columns": self.columns.keys(), |
||
335 | }, { |
||
336 | "id": "to_be_verified", |
||
337 | "title": _("To be verified"), |
||
338 | "contentFilter": { |
||
339 | "review_state": "to_be_verified", |
||
340 | "sort_on": "created", |
||
341 | "sort_order": "descending", |
||
342 | }, |
||
343 | "custom_transitions": [print_stickers], |
||
344 | "columns": self.columns.keys(), |
||
345 | }, { |
||
346 | "id": "verified", |
||
347 | "title": _("Verified"), |
||
348 | "contentFilter": { |
||
349 | "review_state": "verified", |
||
350 | "sort_on": "created", |
||
351 | "sort_order": "descending", |
||
352 | }, |
||
353 | "custom_transitions": [print_stickers], |
||
354 | "columns": self.columns.keys(), |
||
355 | }, { |
||
356 | "id": "published", |
||
357 | "title": _("Published"), |
||
358 | "contentFilter": { |
||
359 | "review_state": ("published"), |
||
360 | "sort_on": "created", |
||
361 | "sort_order": "descending", |
||
362 | }, |
||
363 | "custom_transitions": [], |
||
364 | "columns": self.columns.keys(), |
||
365 | }, { |
||
366 | "id": "dispatched", |
||
367 | "title": _("Dispatched"), |
||
368 | "flat_listing": True, |
||
369 | "confirm_transitions": ["restore"], |
||
370 | "contentFilter": { |
||
371 | "review_state": ("dispatched"), |
||
372 | "sort_on": "created", |
||
373 | "sort_order": "descending", |
||
374 | }, |
||
375 | "custom_transitions": [], |
||
376 | "columns": self.columns.keys(), |
||
377 | }, { |
||
378 | "id": "cancelled", |
||
379 | "title": _("Cancelled"), |
||
380 | "contentFilter": { |
||
381 | "review_state": "cancelled", |
||
382 | "sort_on": "created", |
||
383 | "sort_order": "descending", |
||
384 | }, |
||
385 | "custom_transitions": [], |
||
386 | "columns": self.columns.keys(), |
||
387 | }, { |
||
388 | "id": "invalid", |
||
389 | "title": _("Invalid"), |
||
390 | "contentFilter": { |
||
391 | "review_state": "invalid", |
||
392 | "sort_on": "created", |
||
393 | "sort_order": "descending", |
||
394 | }, |
||
395 | "custom_transitions": [print_stickers], |
||
396 | "columns": self.columns.keys(), |
||
397 | }, { |
||
398 | "id": "all", |
||
399 | "title": _("All"), |
||
400 | "contentFilter": { |
||
401 | "sort_on": "created", |
||
402 | "sort_order": "descending", |
||
403 | }, |
||
404 | "custom_transitions": [print_stickers], |
||
405 | "columns": self.columns.keys(), |
||
406 | }, { |
||
407 | "id": "rejected", |
||
408 | "title": _("Rejected"), |
||
409 | "contentFilter": { |
||
410 | "review_state": "rejected", |
||
411 | "sort_on": "created", |
||
412 | "sort_order": "descending", |
||
413 | }, |
||
414 | "custom_transitions": [print_stickers], |
||
415 | "columns": self.columns.keys(), |
||
416 | }, { |
||
417 | "id": "assigned", |
||
418 | "title": get_image("assigned.png", |
||
419 | title=t(_("Assigned"))), |
||
420 | "contentFilter": { |
||
421 | "assigned_state": "assigned", |
||
422 | "review_state": ("sample_received",), |
||
423 | "sort_on": "created", |
||
424 | "sort_order": "descending", |
||
425 | }, |
||
426 | "custom_transitions": [print_stickers], |
||
427 | "columns": self.columns.keys(), |
||
428 | }, { |
||
429 | "id": "unassigned", |
||
430 | "title": get_image("unassigned.png", |
||
431 | title=t(_("Unsassigned"))), |
||
432 | "contentFilter": { |
||
433 | "assigned_state": "unassigned", |
||
434 | "review_state": ( |
||
435 | "sample_received", |
||
436 | ), |
||
437 | "sort_on": "created", |
||
438 | "sort_order": "descending", |
||
439 | }, |
||
440 | "custom_transitions": [print_stickers], |
||
441 | "columns": self.columns.keys(), |
||
442 | }, { |
||
443 | "id": "late", |
||
444 | "title": get_image("late.png", |
||
445 | title=t(_("Late"))), |
||
446 | "contentFilter": { |
||
447 | # Query only for unpublished ARs that are late |
||
448 | "review_state": ( |
||
449 | "sample_received", |
||
450 | "to_be_verified", |
||
451 | "verified", |
||
452 | ), |
||
453 | "getDueDate": { |
||
454 | "query": DateTime(), |
||
455 | "range": "max", |
||
456 | }, |
||
457 | "sort_on": "created", |
||
458 | "sort_order": "descending", |
||
459 | }, |
||
460 | "custom_transitions": [print_stickers], |
||
461 | "columns": self.columns.keys(), |
||
462 | } |
||
819 |