Example #1
0
 def clean(self):
     """process the form"""
     source = self.data.get('source')
     map_id = self.data.get('mapping')
     # if source:
     #     src_maps = moq.multiple_mappings(fuseki_process, source)
     #     if len(src_maps) > 1:
     #         e = 'mappings already exist for this source'
     #         raise forms.ValidationError(e)
     #  worried about this, prevents updates to deprecate etc
     if map_id:
         mapping = moq.get_mapping_by_id(fuseki_process, map_id)
         if not mapping:
             raise forms.ValidationError('the mapping Id is not valid')
         changed = False
         changes = []
         change_keys = [('source','source'), ('target','target'),
                        ('invertible','invertible'), ('status','status'),
                        ('replaces', 'replaces'), ('comment','note'),
                        ('next_reason', 'reason'), ('editor', 'creator'),
                        ('valueMaps', 'valueMaps')]
         for fkey, mkey in change_keys:
             if self.data.get(fkey) != mapping.get(mkey, ''):
                 changed = True
                 changes.append((mkey,(self.data.get(fkey),
                                       mapping.get(mkey, ''))))
         if not changed:
             raise forms.ValidationError('No update: mapping not changed')
         else:
             print 'changes:', changes
     return self.cleaned_data