X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/37dab8f9ef681bfba763ee4f279c9babd49de783..a802a933f53625f732e9d3807b4162e770c8aaf1:/apps/catalogue/management/commands/fixdc.py diff --git a/apps/catalogue/management/commands/fixdc.py b/apps/catalogue/management/commands/fixdc.py index 3f997d0c..564773e9 100644 --- a/apps/catalogue/management/commands/fixdc.py +++ b/apps/catalogue/management/commands/fixdc.py @@ -9,32 +9,35 @@ from catalogue.management import XmlUpdater from catalogue.management.commands import XmlUpdaterCommand +def fix_wluri(elem, change, verbose): + try: + WLURI.strict(elem.text) + except ValidationError: + correct_field = unicode(WLURI.from_slug( + WLURI(elem.text.strip()).slug)) + try: + WLURI.strict(correct_field) + except ValidationError: + # Can't make a valid WLURI out of it, leave as is. + return False + if verbose: + print "Changing %s from %s to %s" % ( + elem.tag, elem.text, correct_field + ) + elem.text = correct_field + return True + + class FixDC(XmlUpdater): commit_desc = "auto-fixing DC" retain_publishable = True only_first_chunk = True - def fix_wluri(elem, change, verbose): - try: - WLURI.strict(elem.text) - except ValidationError: - correct_field = unicode(WLURI.from_slug( - WLURI(elem.text.strip()).slug)) - try: - WLURI.strict(correct_field) - except ValidationError: - # Can't make a valid WLURI out of it, leave as is. - return False - if verbose: - print "Changing %s from %s to %s" % ( - elem.tag, elem.text, correct_field - ) - elem.text = correct_field - return True for field in BookInfo.FIELDS: if field.validator == WLURI: XmlUpdater.fixes_elements('.//' + field.uri)(fix_wluri) + # unused @XmlUpdater.fixes_elements(".//" + RDFNS("Description")) def fix_rdfabout(elem, change, verbose): correct_about = change.tree.book.correct_about()