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