| Conditions | 8 |
| Total Lines | 311 |
| Code Lines | 273 |
| 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 -*- |
||
| 147 | def setupCatalogs(self, portal): |
||
| 148 | # an item should belong to only one catalog. |
||
| 149 | # that way looking it up means first looking up *the* catalog |
||
| 150 | # in which it is indexed, as well as making it cheaper to index. |
||
| 151 | |||
| 152 | def addIndex(cat, *args): |
||
| 153 | # noinspection PyBroadException |
||
| 154 | try: |
||
| 155 | cat.addIndex(*args) |
||
| 156 | except: |
||
| 157 | pass |
||
| 158 | |||
| 159 | def addColumn(cat, col): |
||
| 160 | # noinspection PyBroadException |
||
| 161 | try: |
||
| 162 | cat.addColumn(col) |
||
| 163 | except: |
||
| 164 | pass |
||
| 165 | |||
| 166 | # create lexicon |
||
| 167 | wordSplitter = Empty() |
||
| 168 | wordSplitter.group = 'Word Splitter' |
||
| 169 | wordSplitter.name = 'Unicode Whitespace splitter' |
||
| 170 | caseNormalizer = Empty() |
||
| 171 | caseNormalizer.group = 'Case Normalizer' |
||
| 172 | caseNormalizer.name = 'Unicode Case Normalizer' |
||
| 173 | stopWords = Empty() |
||
| 174 | stopWords.group = 'Stop Words' |
||
| 175 | stopWords.name = 'Remove listed and single char words' |
||
| 176 | elem = [wordSplitter, caseNormalizer, stopWords] |
||
| 177 | zc_extras = Empty() |
||
| 178 | zc_extras.index_type = 'Okapi BM25 Rank' |
||
| 179 | zc_extras.lexicon_id = 'Lexicon' |
||
| 180 | |||
| 181 | # bika_catalog |
||
| 182 | |||
| 183 | bc = getToolByName(portal, 'bika_catalog', None) |
||
| 184 | if bc is None: |
||
| 185 | logger.warning('Could not find the bika_catalog tool.') |
||
| 186 | return |
||
| 187 | |||
| 188 | # noinspection PyBroadException |
||
| 189 | try: |
||
| 190 | bc.manage_addProduct['ZCTextIndex'].manage_addLexicon( |
||
| 191 | 'Lexicon', 'Lexicon', elem) |
||
| 192 | except: |
||
| 193 | logger.warning('Could not add ZCTextIndex to bika_catalog') |
||
| 194 | pass |
||
| 195 | |||
| 196 | at = getToolByName(portal, 'archetype_tool') |
||
| 197 | at.setCatalogsByType('Batch', ['bika_catalog', 'portal_catalog']) |
||
| 198 | # TODO Remove in >v1.3.0 |
||
| 199 | at.setCatalogsByType('Sample', ['bika_catalog', 'portal_catalog']) |
||
| 200 | # TODO Remove in >v1.3.0 |
||
| 201 | at.setCatalogsByType('SamplePartition', |
||
| 202 | ['bika_catalog', 'portal_catalog']) |
||
| 203 | at.setCatalogsByType('ReferenceSample', |
||
| 204 | ['bika_catalog', 'portal_catalog']) |
||
| 205 | |||
| 206 | addIndex(bc, 'path', 'ExtendedPathIndex', 'getPhysicalPath') |
||
| 207 | addIndex(bc, 'allowedRolesAndUsers', 'KeywordIndex') |
||
| 208 | addIndex(bc, 'UID', 'FieldIndex') |
||
| 209 | addIndex(bc, 'SearchableText', 'ZCTextIndex', zc_extras) |
||
| 210 | addIndex(bc, 'Title', 'ZCTextIndex', zc_extras) |
||
| 211 | addIndex(bc, 'Description', 'ZCTextIndex', zc_extras) |
||
| 212 | addIndex(bc, 'id', 'FieldIndex') |
||
| 213 | addIndex(bc, 'getId', 'FieldIndex') |
||
| 214 | addIndex(bc, 'Type', 'FieldIndex') |
||
| 215 | addIndex(bc, 'portal_type', 'FieldIndex') |
||
| 216 | addIndex(bc, 'created', 'DateIndex') |
||
| 217 | addIndex(bc, 'Creator', 'FieldIndex') |
||
| 218 | addIndex(bc, 'getObjPositionInParent', 'GopipIndex') |
||
| 219 | addIndex(bc, 'title', 'FieldIndex', 'Title') |
||
| 220 | addIndex(bc, 'sortable_title', 'FieldIndex') |
||
| 221 | addIndex(bc, 'description', 'FieldIndex', 'Description') |
||
| 222 | addIndex(bc, 'review_state', 'FieldIndex') |
||
| 223 | addIndex(bc, 'Identifiers', 'KeywordIndex') |
||
| 224 | addIndex(bc, 'is_active', 'BooleanIndex') |
||
| 225 | addIndex(bc, 'BatchDate', 'DateIndex') |
||
| 226 | addIndex(bc, 'getClientTitle', 'FieldIndex') |
||
| 227 | addIndex(bc, 'getClientUID', 'FieldIndex') |
||
| 228 | addIndex(bc, 'getClientID', 'FieldIndex') |
||
| 229 | addIndex(bc, 'getClientBatchID', 'FieldIndex') |
||
| 230 | addIndex(bc, 'getDateReceived', 'DateIndex') |
||
| 231 | addIndex(bc, 'getDateSampled', 'DateIndex') |
||
| 232 | addIndex(bc, 'getDueDate', 'DateIndex') |
||
| 233 | addIndex(bc, 'getExpiryDate', 'DateIndex') |
||
| 234 | addIndex(bc, 'getReferenceDefinitionUID', 'FieldIndex') |
||
| 235 | addIndex(bc, 'getSampleTypeTitle', 'FieldIndex') |
||
| 236 | addIndex(bc, 'getSampleTypeUID', 'FieldIndex') |
||
| 237 | |||
| 238 | # https://github.com/senaite/senaite.core/pull/1091 |
||
| 239 | addIndex(bc, 'getSupportedServices', 'KeywordIndex') |
||
| 240 | addIndex(bc, 'getBlank', 'BooleanIndex') |
||
| 241 | addIndex(bc, 'isValid', 'BooleanIndex') |
||
| 242 | |||
| 243 | addColumn(bc, 'path') |
||
| 244 | addColumn(bc, 'UID') |
||
| 245 | addColumn(bc, 'id') |
||
| 246 | addColumn(bc, 'getId') |
||
| 247 | addColumn(bc, 'Type') |
||
| 248 | addColumn(bc, 'portal_type') |
||
| 249 | addColumn(bc, 'creator') |
||
| 250 | addColumn(bc, 'Created') |
||
| 251 | addColumn(bc, 'Title') |
||
| 252 | addColumn(bc, 'Description') |
||
| 253 | addColumn(bc, 'sortable_title') |
||
| 254 | addColumn(bc, 'getClientTitle') |
||
| 255 | addColumn(bc, 'getClientID') |
||
| 256 | addColumn(bc, 'getClientBatchID') |
||
| 257 | addColumn(bc, 'getSampleTypeTitle') |
||
| 258 | addColumn(bc, 'getDateReceived') |
||
| 259 | addColumn(bc, 'getDateSampled') |
||
| 260 | addColumn(bc, 'review_state') |
||
| 261 | |||
| 262 | # bika_setup_catalog |
||
| 263 | |||
| 264 | bsc = getToolByName(portal, 'bika_setup_catalog', None) |
||
| 265 | if bsc is None: |
||
| 266 | logger.warning('Could not find the setup catalog tool.') |
||
| 267 | return |
||
| 268 | |||
| 269 | # noinspection PyBroadException |
||
| 270 | try: |
||
| 271 | bsc.manage_addProduct['ZCTextIndex'].manage_addLexicon( |
||
| 272 | 'Lexicon', 'Lexicon', elem) |
||
| 273 | except: |
||
| 274 | logger.warning('Could not add ZCTextIndex to bika_setup_catalog') |
||
| 275 | pass |
||
| 276 | |||
| 277 | at = getToolByName(portal, 'archetype_tool') |
||
| 278 | at.setCatalogsByType('Department', |
||
| 279 | ['bika_setup_catalog', "portal_catalog", ]) |
||
| 280 | at.setCatalogsByType('Container', ['bika_setup_catalog', ]) |
||
| 281 | at.setCatalogsByType('ContainerType', ['bika_setup_catalog', ]) |
||
| 282 | at.setCatalogsByType('AnalysisCategory', ['bika_setup_catalog', ]) |
||
| 283 | at.setCatalogsByType('AnalysisService', |
||
| 284 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 285 | at.setCatalogsByType('AnalysisSpec', ['bika_setup_catalog', ]) |
||
| 286 | at.setCatalogsByType('SampleCondition', ['bika_setup_catalog']) |
||
| 287 | at.setCatalogsByType('SampleMatrix', ['bika_setup_catalog', ]) |
||
| 288 | at.setCatalogsByType('SampleType', |
||
| 289 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 290 | at.setCatalogsByType('SamplePoint', |
||
| 291 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 292 | at.setCatalogsByType('StorageLocation', |
||
| 293 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 294 | at.setCatalogsByType('SamplingDeviation', ['bika_setup_catalog', ]) |
||
| 295 | at.setCatalogsByType('IdentifierType', ['bika_setup_catalog', ]) |
||
| 296 | at.setCatalogsByType('Instrument', |
||
| 297 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 298 | at.setCatalogsByType('InstrumentType', |
||
| 299 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 300 | at.setCatalogsByType('InstrumentLocation', |
||
| 301 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 302 | at.setCatalogsByType('Method', ['bika_setup_catalog', 'portal_catalog']) |
||
| 303 | at.setCatalogsByType('Multifile', ['bika_setup_catalog']) |
||
| 304 | at.setCatalogsByType('AttachmentType', ['bika_setup_catalog', ]) |
||
| 305 | at.setCatalogsByType('Attachment', ['portal_catalog']) |
||
| 306 | at.setCatalogsByType('Calculation', |
||
| 307 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 308 | at.setCatalogsByType('AnalysisProfile', |
||
| 309 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 310 | at.setCatalogsByType('ARTemplate', |
||
| 311 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 312 | at.setCatalogsByType('LabProduct', |
||
| 313 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 314 | at.setCatalogsByType('LabContact', |
||
| 315 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 316 | at.setCatalogsByType('Manufacturer', |
||
| 317 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 318 | at.setCatalogsByType('Preservation', ['bika_setup_catalog', ]) |
||
| 319 | at.setCatalogsByType('ReferenceDefinition', |
||
| 320 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 321 | at.setCatalogsByType('SRTemplate', |
||
| 322 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 323 | at.setCatalogsByType('SubGroup', ['bika_setup_catalog', ]) |
||
| 324 | at.setCatalogsByType('Supplier', |
||
| 325 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 326 | at.setCatalogsByType('Unit', ['bika_setup_catalog', ]) |
||
| 327 | at.setCatalogsByType('WorksheetTemplate', |
||
| 328 | ['bika_setup_catalog', 'portal_catalog']) |
||
| 329 | at.setCatalogsByType('BatchLabel', ['bika_setup_catalog', ]) |
||
| 330 | |||
| 331 | addIndex(bsc, 'path', 'ExtendedPathIndex', 'getPhysicalPath') |
||
| 332 | addIndex(bsc, 'allowedRolesAndUsers', 'KeywordIndex') |
||
| 333 | addIndex(bsc, 'UID', 'FieldIndex') |
||
| 334 | addIndex(bsc, 'SearchableText', 'ZCTextIndex', zc_extras) |
||
| 335 | addIndex(bsc, 'Title', 'ZCTextIndex', zc_extras) |
||
| 336 | addIndex(bsc, 'Description', 'ZCTextIndex', zc_extras) |
||
| 337 | addIndex(bsc, 'id', 'FieldIndex') |
||
| 338 | addIndex(bsc, 'getId', 'FieldIndex') |
||
| 339 | addIndex(bsc, 'Type', 'FieldIndex') |
||
| 340 | addIndex(bsc, 'portal_type', 'FieldIndex') |
||
| 341 | addIndex(bsc, 'created', 'DateIndex') |
||
| 342 | addIndex(bsc, 'Creator', 'FieldIndex') |
||
| 343 | addIndex(bsc, 'getObjPositionInParent', 'GopipIndex') |
||
| 344 | addIndex(bc, 'Identifiers', 'KeywordIndex') |
||
| 345 | |||
| 346 | addIndex(bsc, 'title', 'FieldIndex', 'Title') |
||
| 347 | addIndex(bsc, 'sortable_title', 'FieldIndex') |
||
| 348 | addIndex(bsc, 'description', 'FieldIndex', 'Description') |
||
| 349 | |||
| 350 | addIndex(bsc, 'review_state', 'FieldIndex') |
||
| 351 | |||
| 352 | addIndex(bsc, 'getAccredited', 'FieldIndex') |
||
| 353 | addIndex(bsc, 'getAnalyst', 'FieldIndex') |
||
| 354 | addIndex(bsc, 'getBlank', 'FieldIndex') |
||
| 355 | addIndex(bsc, 'getCalculationTitle', 'FieldIndex') |
||
| 356 | addIndex(bsc, 'getCalculationUID', 'FieldIndex') |
||
| 357 | addIndex(bsc, 'getCalibrationExpiryDate', 'FieldIndex') |
||
| 358 | addIndex(bsc, 'getCategoryTitle', 'FieldIndex') |
||
| 359 | addIndex(bsc, 'getCategoryUID', 'FieldIndex') |
||
| 360 | addIndex(bsc, 'getClientUID', 'FieldIndex') |
||
| 361 | addIndex(bsc, 'getDepartmentTitle', 'FieldIndex') |
||
| 362 | addIndex(bsc, 'getDocumentID', 'FieldIndex') |
||
| 363 | addIndex(bsc, 'getDuplicateVariation', 'FieldIndex') |
||
| 364 | addIndex(bsc, 'getFormula', 'FieldIndex') |
||
| 365 | addIndex(bsc, 'getFullname', 'FieldIndex') |
||
| 366 | addIndex(bsc, 'getHazardous', 'FieldIndex') |
||
| 367 | addIndex(bsc, 'getInstrumentLocationName', 'FieldIndex') |
||
| 368 | addIndex(bsc, 'getInstrumentTitle', 'FieldIndex') |
||
| 369 | addIndex(bsc, 'getInstrumentType', 'FieldIndex') |
||
| 370 | addIndex(bsc, 'getInstrumentTypeName', 'FieldIndex') |
||
| 371 | addIndex(bsc, 'getKeyword', 'FieldIndex') |
||
| 372 | addIndex(bsc, 'getManagerEmail', 'FieldIndex') |
||
| 373 | addIndex(bsc, 'getManagerName', 'FieldIndex') |
||
| 374 | addIndex(bsc, 'getManagerPhone', 'FieldIndex') |
||
| 375 | addIndex(bsc, 'getMaxTimeAllowed', 'FieldIndex') |
||
| 376 | addIndex(bsc, 'getMethodID', 'FieldIndex') |
||
| 377 | addIndex(bsc, 'getAvailableMethodUIDs', 'KeywordIndex') |
||
| 378 | addIndex(bsc, 'getModel', 'FieldIndex') |
||
| 379 | addIndex(bsc, 'getName', 'FieldIndex') |
||
| 380 | addIndex(bsc, 'getPointOfCapture', 'FieldIndex') |
||
| 381 | addIndex(bsc, 'getPrice', 'FieldIndex') |
||
| 382 | addIndex(bsc, 'getSamplePointTitle', 'KeywordIndex') |
||
| 383 | addIndex(bsc, 'getSamplePointUID', 'FieldIndex') |
||
| 384 | addIndex(bsc, 'getSampleTypeTitle', 'FieldIndex') |
||
| 385 | addIndex(bsc, 'getSampleTypeTitles', 'KeywordIndex') |
||
| 386 | addIndex(bsc, 'getSampleTypeUID', 'FieldIndex') |
||
| 387 | addIndex(bsc, 'getServiceUID', 'FieldIndex') |
||
| 388 | addIndex(bsc, 'getServiceUIDs', 'KeywordIndex') |
||
| 389 | addIndex(bsc, 'getTotalPrice', 'FieldIndex') |
||
| 390 | addIndex(bsc, 'getUnit', 'FieldIndex') |
||
| 391 | addIndex(bsc, 'getVATAmount', 'FieldIndex') |
||
| 392 | addIndex(bsc, 'getVolume', 'FieldIndex') |
||
| 393 | addIndex(bsc, 'is_active', 'BooleanIndex') |
||
| 394 | |||
| 395 | addColumn(bsc, 'path') |
||
| 396 | addColumn(bsc, 'UID') |
||
| 397 | addColumn(bsc, 'id') |
||
| 398 | addColumn(bsc, 'getId') |
||
| 399 | addColumn(bsc, 'Type') |
||
| 400 | addColumn(bsc, 'portal_type') |
||
| 401 | addColumn(bsc, 'getObjPositionInParent') |
||
| 402 | |||
| 403 | addColumn(bsc, 'Title') |
||
| 404 | addColumn(bsc, 'Description') |
||
| 405 | addColumn(bsc, 'title') |
||
| 406 | addColumn(bsc, 'sortable_title') |
||
| 407 | addColumn(bsc, 'description') |
||
| 408 | addColumn(bsc, 'review_state') |
||
| 409 | addColumn(bsc, 'getAccredited') |
||
| 410 | addColumn(bsc, 'getInstrumentType') |
||
| 411 | addColumn(bsc, 'getInstrumentTypeName') |
||
| 412 | addColumn(bsc, 'getInstrumentLocationName') |
||
| 413 | addColumn(bsc, 'getBlank') |
||
| 414 | addColumn(bsc, 'getCalculationTitle') |
||
| 415 | addColumn(bsc, 'getCalculationUID') |
||
| 416 | addColumn(bsc, 'getCalibrationExpiryDate') |
||
| 417 | addColumn(bsc, 'getCategoryTitle') |
||
| 418 | addColumn(bsc, 'getCategoryUID') |
||
| 419 | addColumn(bsc, 'getClientUID') |
||
| 420 | addColumn(bsc, 'getDepartmentTitle') |
||
| 421 | addColumn(bsc, 'getDuplicateVariation') |
||
| 422 | addColumn(bsc, 'getFormula') |
||
| 423 | addColumn(bsc, 'getFullname') |
||
| 424 | addColumn(bsc, 'getHazardous') |
||
| 425 | addColumn(bsc, 'getInstrumentTitle') |
||
| 426 | addColumn(bsc, 'getKeyword') |
||
| 427 | addColumn(bsc, 'getManagerName') |
||
| 428 | addColumn(bsc, 'getManagerPhone') |
||
| 429 | addColumn(bsc, 'getManagerEmail') |
||
| 430 | addColumn(bsc, 'getMaxTimeAllowed') |
||
| 431 | addColumn(bsc, 'getModel') |
||
| 432 | addColumn(bsc, 'getName') |
||
| 433 | addColumn(bsc, 'getPointOfCapture') |
||
| 434 | addColumn(bsc, 'getPrice') |
||
| 435 | addColumn(bsc, 'getSamplePointTitle') |
||
| 436 | addColumn(bsc, 'getSamplePointUID') |
||
| 437 | addColumn(bsc, 'getSampleTypeTitle') |
||
| 438 | addColumn(bsc, 'getSampleTypeUID') |
||
| 439 | addColumn(bsc, 'getServiceUID') |
||
| 440 | addColumn(bsc, 'getTotalPrice') |
||
| 441 | addColumn(bsc, 'getUnit') |
||
| 442 | addColumn(bsc, 'getVATAmount') |
||
| 443 | addColumn(bsc, 'getVolume') |
||
| 444 | |||
| 445 | # portal_catalog |
||
| 446 | pc = getToolByName(portal, 'portal_catalog', None) |
||
| 447 | if pc is None: |
||
| 448 | logger.warning('Could not find the portal_catalog tool.') |
||
| 449 | return |
||
| 450 | addIndex(pc, 'Analyst', 'FieldIndex') |
||
| 451 | addColumn(pc, 'Analyst') |
||
| 452 | # TODO: Nmrl |
||
| 453 | addColumn(pc, 'getProvince') |
||
| 454 | addColumn(pc, 'getDistrict') |
||
| 455 | |||
| 456 | # Setting up all LIMS catalogs defined in catalog folder |
||
| 457 | setup_catalogs(portal, getCatalogDefinitions()) |
||
| 458 | |||
| 512 |