Conditions | 3 |
Total Lines | 63 |
Code Lines | 51 |
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 -*- |
||
34 | def __init__(self, context, request): |
||
35 | super(AccreditationView, self).__init__(context, request) |
||
36 | self.contentFilter = { |
||
37 | 'portal_type': 'AnalysisService', |
||
38 | 'sort_on': 'sortable_title', |
||
39 | 'is_active': True} |
||
40 | self.context_actions = {} |
||
41 | self.title = self.context.translate(_("Accreditation")) |
||
42 | self.icon = self.portal_url + \ |
||
43 | "/++resource++bika.lims.images/accredited_big.png" |
||
44 | |||
45 | lab = context.bika_setup.laboratory |
||
46 | accredited = lab.getLaboratoryAccredited() |
||
47 | self.mapping = { |
||
48 | 'lab_is_accredited': |
||
49 | accredited, |
||
50 | 'lab_name': |
||
51 | safe_unicode(lab.getName()), |
||
52 | 'lab_country': |
||
53 | safe_unicode(lab.getPhysicalAddress().get('country', '')), |
||
54 | 'confidence': |
||
55 | safe_unicode(lab.getConfidence()), |
||
56 | 'accreditation_body_abbr': |
||
57 | safe_unicode(lab.getAccreditationBody()), |
||
58 | 'accreditation_body_name': |
||
59 | safe_unicode(lab.getAccreditationBodyURL()), |
||
60 | 'accreditation_standard': |
||
61 | safe_unicode(lab.getAccreditation()), |
||
62 | 'accreditation_reference': |
||
63 | safe_unicode(lab.getAccreditationReference()) |
||
64 | } |
||
65 | if accredited: |
||
66 | self.description = t(_( |
||
67 | safe_unicode(lab.getAccreditationPageHeader()), |
||
68 | mapping=self.mapping |
||
69 | )) |
||
70 | else: |
||
71 | self.description = t(_( |
||
72 | "The lab is not accredited, or accreditation has not been " |
||
73 | "configured. " |
||
74 | )) |
||
75 | msg = t(_("All Accredited analysis services are listed here.")) |
||
76 | self.description = "%s<p><br/>%s</p>" % (self.description, msg) |
||
77 | |||
78 | self.show_select_column = False |
||
79 | request.set('disable_border', 1) |
||
80 | |||
81 | self.review_states = [ |
||
82 | {'id': 'default', |
||
83 | 'title': _('All'), |
||
84 | 'contentFilter': {}, |
||
85 | 'transitions': [{'id': 'empty'}, ], # none |
||
86 | 'columns': ['Title', |
||
87 | 'Keyword', |
||
88 | 'Price', |
||
89 | 'MaxTimeAllowed', |
||
90 | 'DuplicateVariation', |
||
91 | ], |
||
92 | }, |
||
93 | ] |
||
94 | |||
95 | if not self.context.bika_setup.getShowPrices(): |
||
96 | self.review_states[0]['columns'].remove('Price') |
||
97 | |||
120 |