)
help = 'Create a master module skeleton'
- def looks_like_syntetic(self, slug):
- if re.match(r"^(gim|lic) \d[.]? ", slug):
+ def looks_like_synthetic(self, title):
+ if re.match(r"^(gim|lic)_\d[.]? ", title):
return True
return False
- def gen_xml(self, options, syntetic_modules=[], course_modules=[], project_modules=[]):
+ def gen_xml(self, options, synthetic_modules=[], course_modules=[], project_modules=[]):
holder = {}
holder['xml'] = u""
p(u'<rdf:Description rdf:about="http://redakcja.edukacjamedialna.edu.pl/documents/">')
dc(u'title', options['title'])
- for slug in syntetic_modules:
- dc(u'relation.hasChild.syntetic', slug_url(slug))
+ for slug in synthetic_modules:
+ dc(u'relation.hasChild.synthetic', slug_url(slug))
for slug in course_modules:
dc(u'relation.hasChild.course', slug_url(slug))
for slug in project_modules:
dc(u'identifier.url', u'http://edukacjamedialna.edu.pl/%s' % options['slug'])
dc(u'rights', dc_fixed['rights'])
dc(u'rights.license', dc_fixed['rights_license'])
- dc(u'format', u'syntetic, course, project')
+ dc(u'format', u'synthetic, course, project')
dc(u'type', u'text')
dc(u'date', date.strftime(date.today(), "%Y-%m-%d"))
dc(u'audience', options['audience'])
dc(u'language', u'pol')
p(u'</rdf:Description>')
p(u'</rdf:RDF>')
+ p(u'</utwor>')
return holder['xml']
def handle(self, *args, **options):
+ commit_args = {
+ "author_name": 'Platforma',
+ "description": 'Automatycznie zaimportowane z EtherPad',
+ "publishable": False,
+ }
+
slug = options['slug']
if not slug:
slug = slughifi(options['title'])
if len(master) == 0:
master.add(slug, options['title'])
- syntetic_modules = []
+ synthetic_modules = []
course_modules = []
if 'slugs_file' in options:
f = open(options['slugs_file'], 'r')
except Book.DoesNotExist:
print "Book for title %s does not exist" % t
continue
- if self.looks_like_syntetic(t):
- syntetic_modules.append(b.slug)
+ if self.looks_like_synthetic(t):
+ synthetic_modules.append(b.slug)
else:
course_modules.append(b.slug)
except Exception, e:
print "Error getting slug list (file %s): %s" % (options['slugs_file'], e)
- print "syntetic: %s" % syntetic_modules
+ print "synthetic: %s" % synthetic_modules
print "course: %s" % course_modules
- xml = self.gen_xml(options, syntetic_modules, course_modules)
-
+ xml = self.gen_xml(options, synthetic_modules, course_modules)
+ c = master[0]
print xml
+ if confirm("Commit?", True):
+ c.commit(xml, **commit_args)
- # master.save()
from django.core.management import setup_environ
from redakcja import settings
+from lxml import etree
setup_environ(settings)
tag_with_name = r"<([^>]+)name=\"([^>]+)>"
def fix(book, author, dry_run=True):
- if len(book) == 0:
- print "%s ==> does not contain chunks" % book.slug
- return
fc = book[0]
txt = fc.materialize()
else:
print "%s ==> i would change this" % book.slug
+def fix_empty_opis(book, author, dry_run=True):
+ fc = book[0]
+ txt = fc.materialize()
+ try:
+ t = etree.fromstring(txt)
+ empty_opis = t.xpath('//opis[not(node())]')
+ empty_cwiczenie = t.xpath('//cwiczenie[not(node())]')
+
+ if empty_opis:
+ print "%s: opis/ x %d" % (book.slug, len(empty_opis))
+
+ if empty_cwiczenie:
+ print "%s: cwiczenie/ x %d" % (book.slug, len(empty_cwiczenie))
+
+ except:
+ print "%s didn't parse" % b.slug
+ return
+
+
import sys
import getopt
if dry_run:
print "This is a dry run, to really fix something, run with --seriously"
for b in Book.objects.all():
- fix(b, me, dry_run)
+ if len(b) == 0:
+ print "%s ==> does not contain chunks" % b.slug
+ continue
+ fix_empty_opis(b, me, dry_run)