@@ -94,11 +94,13 @@ def getConfigByPortalType(config_map, portal_type):
94
94
variables_map = {
95
95
'sampleId' : context .getSample ().getId (),
96
96
'sample' : context .getSample (),
97
+ 'year' : DateTime ().strftime ("%Y" )[2 :],
97
98
}
98
99
elif portal_type == "SamplePartition" :
99
100
variables_map = {
100
101
'sampleId' : context .aq_parent .getId (),
101
102
'sample' : context .aq_parent ,
103
+ 'year' : DateTime ().strftime ("%Y" )[2 :],
102
104
}
103
105
elif portal_type == "Sample" and parent :
104
106
config = getConfigByPortalType (
@@ -107,6 +109,7 @@ def getConfigByPortalType(config_map, portal_type):
107
109
variables_map = {
108
110
'sampleId' : context .getId (),
109
111
'sample' : context ,
112
+ 'year' : DateTime ().strftime ("%Y" )[2 :],
110
113
}
111
114
elif portal_type == "Sample" :
112
115
sampleDate = None
@@ -128,7 +131,9 @@ def getConfigByPortalType(config_map, portal_type):
128
131
'sequence_type' : 'generated' ,
129
132
'prefix' : '%s' % portal_type .lower (),
130
133
}
131
- variables_map = {}
134
+ variables_map = {
135
+ 'year' : DateTime ().strftime ("%Y" )[2 :],
136
+ }
132
137
133
138
# Actual id construction starts here
134
139
form = config ['form' ]
@@ -137,15 +142,20 @@ def getConfigByPortalType(config_map, portal_type):
137
142
context = variables_map [config ['context' ]],
138
143
config = config )
139
144
elif config ['sequence_type' ] == 'generated' :
140
- if config .get ('split_length' , None ) == 0 :
141
- prefix_config = '-' .join (form .split ('-' )[:- 1 ])
142
- prefix = prefix_config .format (** variables_map )
143
- elif config .get ('split_length' , 0 ) > 0 :
144
- prefix_config = '-' .join (form .split ('-' )[:config ['split_length' ]])
145
- prefix = prefix_config .format (** variables_map )
146
- else :
147
- prefix = config ['prefix' ]
148
- new_seq = number_generator (key = prefix )
145
+ try :
146
+ if config .get ('split_length' , None ) == 0 :
147
+ prefix_config = '-' .join (form .split ('-' )[:- 1 ])
148
+ prefix = prefix_config .format (** variables_map )
149
+ elif config .get ('split_length' , 0 ) > 0 :
150
+ prefix_config = '-' .join (form .split ('-' )[:config ['split_length' ]])
151
+ prefix = prefix_config .format (** variables_map )
152
+ else :
153
+ prefix = config ['prefix' ]
154
+ new_seq = number_generator (key = prefix )
155
+ except KeyError , e :
156
+ msg = "KeyError in GenerateUniqueId on %s: %s" % (
157
+ str (config ), e )
158
+ raise RuntimeError (msg )
149
159
variables_map ['seq' ] = new_seq + 1
150
160
result = form .format (** variables_map )
151
161
return result
0 commit comments