WolfgangFahl / pyOnlineSpreadSheetEditing

python Online SpreadSheet Editing tool with configurable enhancer/importer and check phase
Apache License 2.0
2 stars 0 forks source link

allow enhancer Callback #3

Closed WolfgangFahl closed 2 years ago

WolfgangFahl commented 2 years ago

it should be possible to add callback for the enhancer phase of table editing Example

 def fixUrls(self,s:SpreadSheet):
        '''
        fix event homepages in the given spreadsheet
        '''
        events=s.lods["events"]
        for event in events:
            url=event["homepage"]
            if not url.startswith("http"):
                url=f"http://{url}"
                event["homepage"]=url
        pass

    def testEnhancer(self):
        '''
        '''
        lods={
            "series": [ {
                "acronym": "IRCDL",
                "title": "Italian Research Conference on Digital Libraries",
                "dblpSeries": "ircdl",
                "wikiDataId": "Q105693562",
                "wikiCfpSeries": 1655
            }
            ],
            "events": [ {
                "acronym":"IRCDL 2014",
                "series": "IRCDL",
                #|Type=Conference
                #|Field=Digital Library
                #|Start date=2014
                "homepage":"www.dis.uniroma1.it/~ircdl13/",
                #|TibKatId=819300411
                #|City=Padova
                #|State=Italy
                #|presence=presence
                }
            ]
        }
        te=TableEditing(lods)
        te.addEnhancer(self.fixUrls)
        te.enhance()
        self.assertTrue(lods["events"][0]["homepage"].startswith("http:"))