From: Marcin Koziej Date: Mon, 9 Sep 2013 16:15:25 +0000 (+0200) Subject: import script X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/60fb768e247f66ddd18b8cac2101fdc3996ba67b?hp=b61e4fa32bc8fb7c64910520eb9008e73ac47edf import script --- diff --git a/scripts/image.xml b/scripts/image.xml new file mode 100644 index 00000000..72760158 --- /dev/null +++ b/scripts/image.xml @@ -0,0 +1,28 @@ + + + + + + Fundacja Nowoczesna Polska + Sekuła, Aleksandra + Sławiec, Urszula + Kucharska-Hornung, Katarzyna + + Obraz + Publikacja zrealizowana w ramach projektu Wolne Lektury (http://wolnelektury.pl). Reprodukcja cyfrowa wykonana przez Bibliotekę Narodową z egzemplarza pochodzącego ze zbiorów BN. + + + + + + Domena publiczna + + Image + image/png + + + + pol + + + diff --git a/scripts/import_image.py b/scripts/import_image.py new file mode 100755 index 00000000..30ca8c09 --- /dev/null +++ b/scripts/import_image.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +import sys +sys.path.append('.') +sys.path.append('./apps') +sys.path.append('./lib') + +from django.core.management import setup_environ +from redakcja import settings +from redakcja import localsettings + +setup_environ(settings) +settings.CATALOGUE_REPO_PATH = localsettings.CATALOGUE_REPO_PATH +settings.CATALOGUE_IMAGE_REPO_PATH = localsettings.CATALOGUE_IMAGE_REPO_PATH +settings.MEDIA_ROOT = localsettings.MEDIA_ROOT +settings.STATIC_ROOT = localsettings.STATIC_ROOT + + +from catalogue.models import Image +from django.core.files import File +import re +from os import path +from django.contrib.auth.models import User +from django.conf import settings + + + +user = { + 'obj': User.objects.get(username='marcinkoziej'), + 'name': 'Marcin Koziej', + 'email': 'marcinkoziej@nowoczesnapolska.org.pl' + } + +files = sys.argv[1:] + +xml = open(path.dirname(__file__)+"/image.xml").read().decode('utf-8') + +for filename in files: + dfile = File(open(filename)) + img = Image() + name = path.splitext(path.basename(filename))[0] + print filename, name + try: + old = Image.objects.get(slug=name) + print "deleting old %s" % name + old.delete() + except: + pass + + + img.slug = name + img.title = name + img.image.save(filename, dfile) + + img.save() + img.commit(xml, author=user['obj'], author_name=user['name'], author_email=user['email']) + + +