1 # -*- coding: utf-8 -*-
3 from django.core.management.base import BaseCommand
4 from django.core.management.color import color_style
5 from catalogue.management.prompt import confirm
6 from catalogue.models import Book
7 from optparse import make_option
8 from datetime import date
10 from slughifi import slughifi
14 'description': u'Publikacja zrealizowana w ramach projektu Cyfrowa Przyszłość (http://edukacjamedialna.edu.pl).',
15 'rights': u'Creative Commons Uznanie autorstwa - Na tych samych warunkach 3.0',
16 'rights_license': u'http://creativecommons.org/licenses/by-sa/3.0/',
20 class Command(BaseCommand):
21 option_list = BaseCommand.option_list + (
22 make_option('-s', '--slug', dest='slug', help="Slug for master module"),
23 make_option('-F', '--file', dest='slugs_file', help="file with child module slugs per line"),
24 make_option('-t', '--title', dest='title', default='', help="title of master module"),
25 make_option('-l', '--level', dest='audience', default='', help='Audience level'),
27 help = 'Create a master module skeleton'
29 def looks_like_synthetic(self, title):
30 if re.match(r"^(gim|lic)_\d[.]? ", title):
34 def gen_xml(self, options, synthetic_modules=[], course_modules=[], project_modules=[]):
39 holder['xml'] += u"%s\n" % t
42 p(u'<dc:%s xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">%s</dc:%s>' % (k, v, k))
45 p(u'<%s>%s</%s>' % (tag, ct, tag))
48 return u"http://edukacjamedialna/%s/" % slug
51 p(u'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">')
52 p(u'<rdf:Description rdf:about="http://redakcja.edukacjamedialna.edu.pl/documents/">')
54 dc(u'title', options['title'])
55 for slug in synthetic_modules:
56 dc(u'relation.hasChild.synthetic', slug_url(slug))
57 for slug in course_modules:
58 dc(u'relation.hasChild.course', slug_url(slug))
59 for slug in project_modules:
60 dc(u'relation.hasChild.project', slug_url(slug))
61 dc(u'publisher', u'Fundacja Nowoczesna Polska')
62 # dc(u'subject.competence', meta.get(u'Wybrana kompetencja z Katalogu', u''))
63 # dc(u'subject.curriculum', meta.get(u'Odniesienie do podstawy programowej', u''))
64 ## for keyword in meta.get(u'Słowa kluczowe', u'').split(u','):
65 ## keyword = keyword.strip()
66 ## dc(u'subject', keyword)
67 dc(u'description', dc_fixed['description'])
68 dc(u'identifier.url', u'http://edukacjamedialna.edu.pl/%s' % options['slug'])
69 dc(u'rights', dc_fixed['rights'])
70 dc(u'rights.license', dc_fixed['rights_license'])
71 dc(u'format', u'synthetic, course, project')
73 dc(u'date', date.strftime(date.today(), "%Y-%m-%d"))
74 dc(u'audience', options['audience'])
75 dc(u'language', u'pol')
76 p(u'</rdf:Description>')
82 def handle(self, *args, **options):
84 "author_name": 'Platforma',
85 "description": 'Automatycznie zaimportowane z EtherPad',
89 slug = options['slug']
91 slug = slughifi(options['title'])
92 existing = Book.objects.filter(slug=slug)
96 overwrite = confirm("%s exists. Overwrite?" % slug, True)
103 master.title = options['title']
107 master.add(slug, options['title'])
109 synthetic_modules = []
111 if 'slugs_file' in options:
112 f = open(options['slugs_file'], 'r')
114 titles = [l.strip() for l in f.readlines()]
119 b = Book.objects.get(title=t)
120 except Book.DoesNotExist:
121 print "Book for title %s does not exist" % t
123 if self.looks_like_synthetic(t):
124 synthetic_modules.append(b.slug)
126 course_modules.append(b.slug)
128 print "Error getting slug list (file %s): %s" % (options['slugs_file'], e)
130 print "synthetic: %s" % synthetic_modules
131 print "course: %s" % course_modules
133 xml = self.gen_xml(options, synthetic_modules, course_modules)
136 if confirm("Commit?", True):
137 c.commit(xml, **commit_args)