Mercurial > libervia-backend
comparison src/plugins/plugin_misc_invitations.py @ 2241:f87b673c7d17
plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 May 2017 12:37:54 +0200 |
parents | ebc0c1701811 |
children | ba613d32ca60 |
comparison
equal
deleted
inserted
replaced
2240:4b66f070cfbb | 2241:f87b673c7d17 |
---|---|
292 def modify(self, id_, new_extra, replace=False): | 292 def modify(self, id_, new_extra, replace=False): |
293 """Modify invitation data | 293 """Modify invitation data |
294 | 294 |
295 @param id_(unicode): UUID linked to an invitation | 295 @param id_(unicode): UUID linked to an invitation |
296 @param new_extra(dict[unicode, unicode]): data to update | 296 @param new_extra(dict[unicode, unicode]): data to update |
297 empty values will be deleted if replace is True | |
297 @param replace(bool): if True replace the data | 298 @param replace(bool): if True replace the data |
298 else update them | 299 else update them |
299 @raise KeyError: there is not invitation with this id_ | 300 @raise KeyError: there is not invitation with this id_ |
300 """ | 301 """ |
301 self.checkExtra(new_extra) | 302 self.checkExtra(new_extra) |
308 except KeyError: | 309 except KeyError: |
309 continue | 310 continue |
310 else: | 311 else: |
311 new_data = current_data | 312 new_data = current_data |
312 for k,v in new_extra.iteritems(): | 313 for k,v in new_extra.iteritems(): |
313 new_data[k] = v | 314 if k in EXTRA_RESERVED: |
315 log.warning(_(u"Skipping reserved key {key}".format(k))) | |
316 continue | |
317 if v: | |
318 new_data[k] = v | |
319 else: | |
320 try: | |
321 del new_data[k] | |
322 except KeyError: | |
323 pass | |
314 | 324 |
315 self.invitations[id_] = new_data | 325 self.invitations[id_] = new_data |
316 | 326 |
317 d = self.invitations[id_] | 327 d = self.invitations[id_] |
318 d.addCallback(gotCurrentData) | 328 d.addCallback(gotCurrentData) |