- book = Book.create(
- text=form.cleaned_data['text'],
- creator=creator,
- slug=form.cleaned_data['slug'],
- title=form.cleaned_data['title'],
- gallery=form.cleaned_data['gallery'],
+
+ title = form.cleaned_data['title']
+ try:
+ org = request.user.membership_set.get(
+ organization=int(form.cleaned_data['owner_organization'])).organization
+ kwargs = {'owner_organization': org}
+ except:
+ kwargs = {'owner_user': request.user}
+
+ doc = Document.objects.create(**kwargs)
+
+ for tag_form in tag_forms:
+ tag_form.save(instance=doc)
+
+ cover = request.FILES.get('cover')
+ if cover:
+ uppath = 'uploads/%d/' % doc.pk
+ path = settings.MEDIA_ROOT + uppath
+ if not os.path.isdir(path):
+ os.makedirs(path)
+ cover.name = unidecode(cover.name)
+ dest_path = path + cover.name
+ if not os.path.abspath(dest_path).startswith(os.path.abspath(path)):
+ raise Http404
+ with open(dest_path, 'w') as destination:
+ for chunk in cover.chunks():
+ destination.write(chunk)
+ cover_url = 'http://milpeer.eu/media/dynamic/' + uppath + cover.name
+ else:
+ cover_url = ''
+
+ text = '''<section xmlns="http://nowoczesnapolska.org.pl/sst#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <metadata>
+ <dc:publisher>%s</dc:publisher>
+ <dc:description>%s</dc:description>
+ %s
+ <dc:relation.coverImage.url>%s</dc:relation.coverImage.url>
+ </metadata>
+ <header>%s</header>
+ <div class="p"> </div>
+ </section>''' % (
+ escape_xml(form.cleaned_data['publisher']),
+ escape_xml(form.cleaned_data['description']),
+ '\n'.join(tag_form.metadata_rows() for tag_form in tag_forms),
+ escape_xml(cover_url),
+ escape_xml(title))
+
+ doc.commit(
+ text=text,
+ author=creator