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