1 # -*- coding: utf-8 -*-
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from librarian import RDFNS, WLURI, ValidationError
7 from librarian.dcparser import BookInfo
8 from catalogue.management import XmlUpdater
9 from catalogue.management.commands import XmlUpdaterCommand
12 class FixDC(XmlUpdater):
13 commit_desc = "auto-fixing DC"
14 retain_publishable = True
15 only_first_chunk = True
17 def fix_wluri(elem, change, verbose):
19 WLURI.strict(elem.text)
20 except ValidationError:
21 correct_field = unicode(WLURI.from_slug(WLURI(elem.text).slug))
23 print "Changing %s from %s to %s" % (
24 elem.tag, elem.text, correct_field
26 elem.text = correct_field
28 for field in BookInfo.FIELDS:
29 if field.validator == WLURI:
30 XmlUpdater.fixes_elements('.//' + field.uri)(fix_wluri)
32 @XmlUpdater.fixes_elements(".//" + RDFNS("Description"))
33 def fix_rdfabout(elem, change, verbose):
34 correct_about = change.tree.book.correct_about()
35 attr_name = RDFNS("about")
36 current_about = elem.get(attr_name)
37 if current_about != correct_about:
39 print "Changing rdf:about from %s to %s" % (
40 current_about, correct_about
42 elem.set(attr_name, correct_about)
46 class Command(XmlUpdaterCommand):
48 help = 'Fixes obvious errors in DC: rdf:about and WLURI format.'