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_syntetic(self, slug):
30 if re.match(r"^(gim|lic) \d[.]? ", slug):
34 def gen_xml(self, options, syntetic_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 syntetic_modules:
56 dc(u'relation.hasChild.syntetic', 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'syntetic, 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>')
81 def handle(self, *args, **options):
82 slug = options['slug']
84 slug = slughifi(options['title'])
85 existing = Book.objects.filter(slug=slug)
89 overwrite = confirm("%s exists. Overwrite?" % slug, True)
96 master.title = options['title']
100 master.add(slug, options['title'])
102 syntetic_modules = []
104 if 'slugs_file' in options:
105 f = open(options['slugs_file'], 'r')
107 titles = [l.strip() for l in f.readlines()]
112 b = Book.objects.get(title=t)
113 except Book.DoesNotExist:
114 print "Book for title %s does not exist" % t
116 if self.looks_like_syntetic(t):
117 syntetic_modules.append(b.slug)
119 course_modules.append(b.slug)
121 print "Error getting slug list (file %s): %s" % (options['slugs_file'], e)
123 print "syntetic: %s" % syntetic_modules
124 print "course: %s" % course_modules
126 xml = self.gen_xml(options, syntetic_modules, course_modules)