source: WAeUP_SRP/trunk/skins/waeup_pins/scratch_card_batch_create_do.py

Last change on this file was 5179, checked in by Henrik Bettermann, 14 years ago

continue numbering of pin batches instead of filling gaps

  • Property svn:keywords set to Id
File size: 1.0 KB
Line 
1##parameters=type_name, datamodel
2# $Id: scratch_card_batch_create_do.py 5179 2010-04-30 06:39:44Z henrik $
3"""
4Create an empty object in the context according to the datamodel.
5
6Datamodel may be examined to create a suitable id.
7"""
8from Products.CMFCore.utils import getToolByName
9
10#try:
11#    from Products.zdb import set_trace
12#except:
13#    def set_trace():
14#        pass
15
16
17prefix = datamodel.get('prefix').upper()
18datamodel.set('prefix',prefix)
19bl = context.portal_catalog({'meta_type': "ScratchCardBatch",})
20b_ids = []
21
22for b in bl:
23    b_ids.append(b.getId)
24
25p_ids = [p_id for p_id in b_ids if p_id.startswith(prefix)]
26if p_ids:
27    max_bno = max([int(bno.split('_')[1]) for bno in p_ids])
28    next = max_bno+1
29else:
30    next = 1
31
32#next = 1
33#while b_ids and "%s_%d" % (prefix,next) in b_ids:
34#    next += 1
35
36id = "%s_%d" % (prefix,next)
37
38datamodel.set('batch_no',next)
39new_id = context.invokeFactory(type_name, id, datamodel=datamodel,
40                               )
41if new_id is not None:
42    id = new_id
43
44ob = getattr(context, id)
45ob.getContent().edit(mapping=datamodel)
46
47return ob
Note: See TracBrowser for help on using the repository browser.