Exemplo n.º 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:
         qstr = metarelate.Mapping.sparql_retriever(map_id)
         mapping = fuseki_process.retrieve(qstr)
         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
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     fformat = kwargs.pop('fformat')
     super(Mediator, self).__init__(*args, **kwargs)
     qstr = metocean.Mediator.sparql_retriever(fformat)
     meds = fuseki_process.retrieve(qstr)
     if isinstance(meds, list):
         meds = [(med['mediator'], med['label']) for med in meds]
     else:
         meds = [(meds['mediator'], meds['label'])]
     self.fields['mediator'].choices = meds