| Conditions | 4 |
| Total Lines | 496 |
| Code Lines | 421 |
| 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 -*- |
||
| 42 | def __init__(self, context, request): |
||
| 43 | super(AnalysisRequestsView, self).__init__(context, request) |
||
| 44 | |||
| 45 | # hide the right column |
||
| 46 | request.set("disable_plone.rightcolumn", 1) |
||
| 47 | |||
| 48 | # hide the editable border |
||
| 49 | if self.context.portal_type == "AnalysisRequestsFolder": |
||
| 50 | self.request.set("disable_border", 1) |
||
| 51 | |||
| 52 | # catalog used for the query |
||
| 53 | self.catalog = CATALOG_ANALYSIS_REQUEST_LISTING |
||
| 54 | |||
| 55 | # https://docs.plone.org/develop/plone/searching_and_indexing/query.html#searching-for-content-within-a-folder |
||
| 56 | self.contentFilter = { |
||
| 57 | "sort_on": "created", |
||
| 58 | "sort_order": "descending", |
||
| 59 | "cancellation_state": "active", |
||
| 60 | } |
||
| 61 | |||
| 62 | # Filter by Department |
||
| 63 | if self.context.bika_setup.getAllowDepartmentFiltering(): |
||
| 64 | deps = self.request.get('filter_by_department_info', '') |
||
| 65 | dep_uids = deps.split(",") |
||
| 66 | dep_query = {"query": dep_uids, "operator": "or"} |
||
| 67 | self.contentFilter['getDepartmentUIDs'] = dep_query |
||
| 68 | |||
| 69 | self.context_actions = {} |
||
| 70 | |||
| 71 | if self.view_url.find("analysisrequests") == -1: |
||
| 72 | self.view_url = self.view_url + "/analysisrequests" |
||
| 73 | |||
| 74 | self.allow_edit = True |
||
| 75 | self.show_sort_column = False |
||
| 76 | self.show_select_row = False |
||
| 77 | self.show_select_column = True |
||
| 78 | self.form_id = "analysisrequests" |
||
| 79 | |||
| 80 | ar_image_path = "/++resource++bika.lims.images/analysisrequest_big.png" |
||
| 81 | self.icon = "{}{}".format(self.portal_url, ar_image_path) |
||
| 82 | self.title = self.context.translate(_("Analysis Requests")) |
||
| 83 | self.description = "" |
||
| 84 | |||
| 85 | SamplingWorkflowEnabled = \ |
||
| 86 | self.context.bika_setup.getSamplingWorkflowEnabled() |
||
| 87 | |||
| 88 | # Check if the filter bar functionality is activated or not |
||
| 89 | self.filter_bar_enabled =\ |
||
| 90 | self.context.bika_setup.\ |
||
| 91 | getDisplayAdvancedFilterBarForAnalysisRequests() |
||
| 92 | |||
| 93 | self.columns = collections.OrderedDict(( |
||
| 94 | ("Priority", { |
||
| 95 | "title": "", |
||
| 96 | "index": "getPrioritySortkey", |
||
| 97 | "sortable": True, }), |
||
| 98 | ("Progress", { |
||
| 99 | "title": "Progress", |
||
| 100 | "sortable": False, |
||
| 101 | "toggle": True}), |
||
| 102 | ("getId", { |
||
| 103 | "title": _("Request ID"), |
||
| 104 | "attr": "getId", |
||
| 105 | "replace_url": "getURL", |
||
| 106 | "index": "getId"}), |
||
| 107 | ("getClientOrderNumber", { |
||
| 108 | "title": _("Client Order"), |
||
| 109 | "sortable": True, |
||
| 110 | "toggle": False}), |
||
| 111 | ("Creator", { |
||
| 112 | "title": _("Creator"), |
||
| 113 | "index": "getCreatorFullName", |
||
| 114 | "sortable": True, |
||
| 115 | "toggle": True}), |
||
| 116 | ("Created", { |
||
| 117 | "title": _("Date Registered"), |
||
| 118 | "index": "created", |
||
| 119 | "toggle": False}), |
||
| 120 | ("SamplingDate", { |
||
| 121 | "title": _("Expected Sampling Date"), |
||
| 122 | "index": "getSamplingDate", |
||
| 123 | "toggle": SamplingWorkflowEnabled}), |
||
| 124 | ("getDateSampled", { |
||
| 125 | "title": _("Date Sampled"), |
||
| 126 | "toggle": True, |
||
| 127 | "input_class": "datetimepicker_nofuture", |
||
| 128 | "input_width": "10"}), |
||
| 129 | ("getDatePreserved", { |
||
| 130 | "title": _("Date Preserved"), |
||
| 131 | "toggle": False, |
||
| 132 | "input_class": "datetimepicker_nofuture", |
||
| 133 | "input_width": "10", |
||
| 134 | "sortable": False}), # no datesort without index |
||
| 135 | ("getDateReceived", { |
||
| 136 | "title": _("Date Received"), |
||
| 137 | "toggle": False}), |
||
| 138 | ("getDueDate", { |
||
| 139 | "title": _("Due Date"), |
||
| 140 | "toggle": False}), |
||
| 141 | ("getDateVerified", { |
||
| 142 | "title": _("Date Verified"), |
||
| 143 | "input_width": "10", |
||
| 144 | "toggle": False}), |
||
| 145 | ("getDatePublished", { |
||
| 146 | "title": _("Date Published"), |
||
| 147 | "toggle": False}), |
||
| 148 | ("getSample", { |
||
| 149 | "title": _("Sample"), |
||
| 150 | "attr": "getSampleID", |
||
| 151 | "index": "getSampleID", |
||
| 152 | "replace_url": "getSampleURL", |
||
| 153 | "toggle": False}), |
||
| 154 | ("BatchID", { |
||
| 155 | "title": _("Batch ID"), |
||
| 156 | "index": "getBatchID", |
||
| 157 | "sortable": True, |
||
| 158 | "toggle": False}), |
||
| 159 | ("Client", { |
||
| 160 | "title": _("Client"), |
||
| 161 | "index": "getClientTitle", |
||
| 162 | "attr": "getClientTitle", |
||
| 163 | "replace_url": "getClientURL", |
||
| 164 | "toggle": True}), |
||
| 165 | ("Province", { |
||
| 166 | "title": _("Province"), |
||
| 167 | "sortable": True, |
||
| 168 | "index": "getProvince", |
||
| 169 | "attr": "getProvince", |
||
| 170 | "toggle": False}), |
||
| 171 | ("District", { |
||
| 172 | "title": _("District"), |
||
| 173 | "sortable": True, |
||
| 174 | "index": "getDistrict", |
||
| 175 | "attr": "getDistrict", |
||
| 176 | "toggle": False}), |
||
| 177 | ("getClientReference", { |
||
| 178 | "title": _("Client Ref"), |
||
| 179 | "sortable": True, |
||
| 180 | "index": "getClientReference", |
||
| 181 | "toggle": False}), |
||
| 182 | ("getClientSampleID", { |
||
| 183 | "title": _("Client SID"), |
||
| 184 | "toggle": False}), |
||
| 185 | ("ClientContact", { |
||
| 186 | "title": _("Contact"), |
||
| 187 | "sortable": True, |
||
| 188 | "index": "getContactFullName", |
||
| 189 | "toggle": False}), |
||
| 190 | ("getSampleTypeTitle", { |
||
| 191 | "title": _("Sample Type"), |
||
| 192 | "sortable": True, |
||
| 193 | "toggle": True}), |
||
| 194 | ("getSamplePointTitle", { |
||
| 195 | "title": _("Sample Point"), |
||
| 196 | "sortable": True, |
||
| 197 | "index": "getSamplePointTitle", |
||
| 198 | "toggle": False}), |
||
| 199 | ("getStorageLocation", { |
||
| 200 | "title": _("Storage Location"), |
||
| 201 | "sortable": True, |
||
| 202 | "index": "getStorageLocationTitle", |
||
| 203 | "toggle": False}), |
||
| 204 | ("SamplingDeviation", { |
||
| 205 | "title": _("Sampling Deviation"), |
||
| 206 | "sortable": True, |
||
| 207 | "index": "getSamplingDeviationTitle", |
||
| 208 | "toggle": False}), |
||
| 209 | ("getSampler", { |
||
| 210 | "title": _("Sampler"), |
||
| 211 | "toggle": SamplingWorkflowEnabled}), |
||
| 212 | ("getPreserver", { |
||
| 213 | "title": _("Preserver"), |
||
| 214 | "sortable": False, |
||
| 215 | "toggle": False}), |
||
| 216 | ("getProfilesTitle", { |
||
| 217 | "title": _("Profile"), |
||
| 218 | "sortable": True, |
||
| 219 | "index": "getProfilesTitle", |
||
| 220 | "toggle": False}), |
||
| 221 | ("getAnalysesNum", { |
||
| 222 | "title": _("Number of Analyses"), |
||
| 223 | "sortable": True, |
||
| 224 | "index": "getAnalysesNum", |
||
| 225 | "toggle": False}), |
||
| 226 | ("getTemplateTitle", { |
||
| 227 | "title": _("Template"), |
||
| 228 | "sortable": True, |
||
| 229 | "index": "getTemplateTitle", |
||
| 230 | "toggle": False}), |
||
| 231 | ("Printed", { |
||
| 232 | "title": _("Printed"), |
||
| 233 | "sortable": False, |
||
| 234 | "index": "getPrinted", |
||
| 235 | "toggle": False}), |
||
| 236 | ("state_title", { |
||
| 237 | "title": _("State"), |
||
| 238 | "sortable": True, |
||
| 239 | "index": "review_state"}), |
||
| 240 | )) |
||
| 241 | |||
| 242 | # custom print transition |
||
| 243 | print_stickers = { |
||
| 244 | "id": "print_stickers", |
||
| 245 | "title": _("Print stickers"), |
||
| 246 | "url": "workflow_action?action=print_stickers" |
||
| 247 | } |
||
| 248 | |||
| 249 | self.review_states = [ |
||
| 250 | { |
||
| 251 | "id": "default", |
||
| 252 | "title": _("Active"), |
||
| 253 | "contentFilter": { |
||
| 254 | "sort_on": "created", |
||
| 255 | "sort_order": "descending", |
||
| 256 | }, |
||
| 257 | "transitions": [ |
||
| 258 | {"id": "sample"}, |
||
| 259 | {"id": "preserve"}, |
||
| 260 | {"id": "receive"}, |
||
| 261 | {"id": "retract"}, |
||
| 262 | {"id": "verify"}, |
||
| 263 | {"id": "prepublish"}, |
||
| 264 | {"id": "publish"}, |
||
| 265 | {"id": "republish"}, |
||
| 266 | {"id": "cancel"}, |
||
| 267 | {"id": "reinstate"}, |
||
| 268 | ], |
||
| 269 | "custom_transitions": [print_stickers], |
||
| 270 | "columns": self.columns.keys(), |
||
| 271 | }, { |
||
| 272 | "id": "to_be_sampled", |
||
| 273 | "title": _("To Be Sampled"), |
||
| 274 | "contentFilter": { |
||
| 275 | "review_state": ("to_be_sampled",), |
||
| 276 | "sort_on": "created", |
||
| 277 | "sort_order": "descending"}, |
||
| 278 | "transitions": [ |
||
| 279 | {"id": "sample"}, |
||
| 280 | {"id": "submit"}, |
||
| 281 | {"id": "cancel"}, |
||
| 282 | ], |
||
| 283 | "custom_transitions": [print_stickers], |
||
| 284 | "columns": self.columns.keys() |
||
| 285 | }, { |
||
| 286 | "id": "to_be_preserved", |
||
| 287 | "title": _("To Be Preserved"), |
||
| 288 | "contentFilter": { |
||
| 289 | "review_state": ("to_be_preserved",), |
||
| 290 | "sort_on": "created", |
||
| 291 | "sort_order": "descending", |
||
| 292 | }, |
||
| 293 | "transitions": [ |
||
| 294 | {"id": "preserve"}, |
||
| 295 | {"id": "cancel"}, |
||
| 296 | ], |
||
| 297 | "custom_transitions": [print_stickers], |
||
| 298 | "columns": self.columns.keys(), |
||
| 299 | }, { |
||
| 300 | "id": "scheduled_sampling", |
||
| 301 | "title": _("Scheduled sampling"), |
||
| 302 | "contentFilter": { |
||
| 303 | "review_state": ("scheduled_sampling",), |
||
| 304 | "sort_on": "created", |
||
| 305 | "sort_order": "descending", |
||
| 306 | }, |
||
| 307 | "transitions": [ |
||
| 308 | {"id": "sample"}, |
||
| 309 | {"id": "cancel"}, |
||
| 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 | "transitions": [ |
||
| 324 | {"id": "sample"}, |
||
| 325 | {"id": "preserve"}, |
||
| 326 | {"id": "receive"}, |
||
| 327 | {"id": "cancel"}, |
||
| 328 | {"id": "reinstate"}, |
||
| 329 | ], |
||
| 330 | "custom_transitions": [print_stickers], |
||
| 331 | "columns": self.columns.keys(), |
||
| 332 | }, { |
||
| 333 | "id": "sample_received", |
||
| 334 | "title": _("Received"), |
||
| 335 | "contentFilter": { |
||
| 336 | "review_state": "sample_received", |
||
| 337 | "sort_on": "created", |
||
| 338 | "sort_order": "descending", |
||
| 339 | }, |
||
| 340 | "transitions": [ |
||
| 341 | {"id": "prepublish"}, |
||
| 342 | {"id": "cancel"}, |
||
| 343 | {"id": "reinstate"}, |
||
| 344 | ], |
||
| 345 | "custom_transitions": [print_stickers], |
||
| 346 | "columns": self.columns.keys(), |
||
| 347 | }, { |
||
| 348 | "id": "to_be_verified", |
||
| 349 | "title": _("To be verified"), |
||
| 350 | "contentFilter": { |
||
| 351 | "review_state": "to_be_verified", |
||
| 352 | "sort_on": "created", |
||
| 353 | "sort_order": "descending", |
||
| 354 | }, |
||
| 355 | "transitions": [ |
||
| 356 | {"id": "retract"}, |
||
| 357 | {"id": "verify"}, |
||
| 358 | {"id": "prepublish"}, |
||
| 359 | {"id": "cancel"}, |
||
| 360 | {"id": "reinstate"}, |
||
| 361 | ], |
||
| 362 | "custom_transitions": [print_stickers], |
||
| 363 | "columns": self.columns.keys(), |
||
| 364 | }, { |
||
| 365 | "id": "verified", |
||
| 366 | "title": _("Verified"), |
||
| 367 | "contentFilter": { |
||
| 368 | "review_state": "verified", |
||
| 369 | "sort_on": "created", |
||
| 370 | "sort_order": "descending", |
||
| 371 | }, |
||
| 372 | "transitions": [ |
||
| 373 | {"id": "publish"}, |
||
| 374 | {"id": "cancel"}, |
||
| 375 | ], |
||
| 376 | "custom_transitions": [print_stickers], |
||
| 377 | "columns": self.columns.keys(), |
||
| 378 | }, { |
||
| 379 | "id": "published", |
||
| 380 | "title": _("Published"), |
||
| 381 | "contentFilter": { |
||
| 382 | "review_state": ("published"), |
||
| 383 | "sort_on": "created", |
||
| 384 | "sort_order": "descending", |
||
| 385 | }, |
||
| 386 | "transitions": [ |
||
| 387 | {"id": "republish"}, |
||
| 388 | ], |
||
| 389 | "custom_transitions": [], |
||
| 390 | "columns": self.columns.keys(), |
||
| 391 | }, { |
||
| 392 | "id": "unpublished", |
||
| 393 | "title": _("Unpublished"), |
||
| 394 | "contentFilter": { |
||
| 395 | "cancellation_state": "active", |
||
| 396 | "review_state": ( |
||
| 397 | "sample_registered", |
||
| 398 | "to_be_sampled", |
||
| 399 | "to_be_preserved", |
||
| 400 | "sample_due", |
||
| 401 | "sample_received", |
||
| 402 | "to_be_verified", |
||
| 403 | "attachment_due", |
||
| 404 | "verified", |
||
| 405 | ), |
||
| 406 | "sort_on": "created", |
||
| 407 | "sort_order": "descending", |
||
| 408 | }, |
||
| 409 | "transitions": [ |
||
| 410 | {"id": "sample"}, |
||
| 411 | {"id": "preserve"}, |
||
| 412 | {"id": "receive"}, |
||
| 413 | {"id": "retract"}, |
||
| 414 | {"id": "verify"}, |
||
| 415 | {"id": "prepublish"}, |
||
| 416 | {"id": "publish"}, |
||
| 417 | {"id": "republish"}, |
||
| 418 | {"id": "cancel"}, |
||
| 419 | {"id": "reinstate"}, |
||
| 420 | ], |
||
| 421 | "custom_transitions": [print_stickers], |
||
| 422 | "columns": self.columns.keys(), |
||
| 423 | }, { |
||
| 424 | "id": "cancelled", |
||
| 425 | "title": _("Cancelled"), |
||
| 426 | "contentFilter": { |
||
| 427 | "cancellation_state": "cancelled", |
||
| 428 | "review_state": ( |
||
| 429 | "sample_registered", |
||
| 430 | "to_be_sampled", |
||
| 431 | "to_be_preserved", |
||
| 432 | "sample_due", |
||
| 433 | "sample_received", |
||
| 434 | "to_be_verified", |
||
| 435 | "attachment_due", |
||
| 436 | "verified", |
||
| 437 | "published", |
||
| 438 | ), |
||
| 439 | "sort_on": "created", |
||
| 440 | "sort_order": "descending", |
||
| 441 | }, |
||
| 442 | "transitions": [ |
||
| 443 | {"id": "reinstate"}, |
||
| 444 | ], |
||
| 445 | "custom_transitions": [], |
||
| 446 | "columns": self.columns.keys(), |
||
| 447 | }, { |
||
| 448 | "id": "invalid", |
||
| 449 | "title": _("Invalid"), |
||
| 450 | "contentFilter": { |
||
| 451 | "review_state": "invalid", |
||
| 452 | "sort_on": "created", |
||
| 453 | "sort_order": "descending", |
||
| 454 | }, |
||
| 455 | "transitions": [], |
||
| 456 | "custom_transitions": [print_stickers], |
||
| 457 | "columns": self.columns.keys(), |
||
| 458 | }, { |
||
| 459 | "id": "rejected", |
||
| 460 | "title": _("Rejected"), |
||
| 461 | "contentFilter": { |
||
| 462 | "review_state": "rejected", |
||
| 463 | "sort_on": "created", |
||
| 464 | "sort_order": "descending", |
||
| 465 | }, |
||
| 466 | "transitions": [], |
||
| 467 | "custom_transitions": [ |
||
| 468 | { |
||
| 469 | "id": "print_stickers", |
||
| 470 | "title": _("Print stickers"), |
||
| 471 | "url": "workflow_action?action=print_stickers"}, |
||
| 472 | ], |
||
| 473 | "columns": self.columns.keys(), |
||
| 474 | }, { |
||
| 475 | "id": "assigned", |
||
| 476 | "title": get_image("assigned.png", |
||
| 477 | title=t(_("Assigned"))), |
||
| 478 | "contentFilter": { |
||
| 479 | "assigned_state": "assigned", |
||
| 480 | "cancellation_state": "active", |
||
| 481 | "review_state": ("sample_received", |
||
| 482 | "attachment_due",), |
||
| 483 | "sort_on": "created", |
||
| 484 | "sort_order": "descending", |
||
| 485 | }, |
||
| 486 | "transitions": [ |
||
| 487 | {"id": "receive"}, |
||
| 488 | {"id": "retract"}, |
||
| 489 | {"id": "prepublish"}, |
||
| 490 | {"id": "cancel"}, |
||
| 491 | ], |
||
| 492 | "custom_transitions": [print_stickers], |
||
| 493 | "columns": self.columns.keys(), |
||
| 494 | }, { |
||
| 495 | "id": "unassigned", |
||
| 496 | "title": get_image("unassigned.png", |
||
| 497 | title=t(_("Unsassigned"))), |
||
| 498 | "contentFilter": { |
||
| 499 | "assigned_state": "unassigned", |
||
| 500 | "cancellation_state": "active", |
||
| 501 | "review_state": ( |
||
| 502 | "sample_received", |
||
| 503 | "attachment_due", |
||
| 504 | ), |
||
| 505 | "sort_on": "created", |
||
| 506 | "sort_order": "descending", |
||
| 507 | }, |
||
| 508 | "transitions": [ |
||
| 509 | {"id": "receive"}, |
||
| 510 | {"id": "retract"}, |
||
| 511 | {"id": "prepublish"}, |
||
| 512 | {"id": "cancel"}, |
||
| 513 | ], |
||
| 514 | "custom_transitions": [print_stickers], |
||
| 515 | "columns": self.columns.keys(), |
||
| 516 | }, { |
||
| 517 | "id": "late", |
||
| 518 | "title": get_image("late.png", |
||
| 519 | title=t(_("Late"))), |
||
| 520 | "contentFilter": { |
||
| 521 | "cancellation_state": "active", |
||
| 522 | # Query only for unpublished ARs that are late |
||
| 523 | "review_state": ( |
||
| 524 | "sample_received", |
||
| 525 | "attachment_due", |
||
| 526 | "to_be_verified", |
||
| 527 | "verified", |
||
| 528 | ), |
||
| 529 | "getDueDate": { |
||
| 530 | "query": DateTime(), |
||
| 531 | "range": "max", |
||
| 532 | }, |
||
| 533 | "sort_on": "created", |
||
| 534 | "sort_order": "descending", |
||
| 535 | }, |
||
| 536 | "custom_transitions": [print_stickers], |
||
| 537 | "columns": self.columns.keys(), |
||
| 538 | } |
||
| 929 |