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