I am trying to add a new column 'article_customer_number' to an existing datagrid field:
class IArticlesListRowSchema(Interface):
dexteritytextindexer.searchable('article_number')
articles_color_size_list = schema.Choice(title=_(u'Artikel Farbton / Gebinde'), vocabulary='mdb_theme.ArticlesVocabulary', required=True)
article_number = schema.TextLine(title=_(u'Artikelnummer'), required=True, min_length=5, max_length=5)
article_customer_number = schema.TextLine(title=_(u'Kunden-Artikelnummer'), required=False, default=u'')
In the edit forms of my existing dexterity content, the datagrid displays the string <NO_VALUE>
in each row. To avoid inadvertently saving that string when an editor makes other changes to their content, I want to update my existing content by adding a default value.
In the past, I have successfully updated existing values using the article.update(column_name=value)
line below. This does not work for new fields. What am I doing wrong here?
def set_default_customer_article_number(context):
""" add key/value 'article_customer_number':u'' in articles_list fields.
remove obsolete 'plentymarkets_variant_id', 'ean_code', 'article_plentymarkets_price'
"""
catalog = api.portal.get_tool('portal_catalog')
brains = catalog(portal_type=['produkte'])
product_count = 0
article_count = 0
keys_to_remove = ['plentymarkets_variant_id', 'ean_code', 'article_plentymarkets_price']
key_to_add = {'article_customer_number': u''}
for brain in brains:
obj = brain.getObject()
articles_list = obj.articles_list
product_count += 1
if articles_list:
for article in articles_list:
for key in keys_to_remove:
if key in article.keys():
del article[key]
article.update(key_to_add)
article_count += 1
log.info(article)
obj.reindexObject()
log.info('%s %s products updated' % (get_linenumber(), product_count))
log.info('%s articles updated.' % article_count)