From: Library Admin Date: Mon, 9 Sep 2013 16:15:40 +0000 (+0200) Subject: Merge branch 'img-playground' of ssh://git.nowoczesnapolska.org.pl:2223/~/repo/redakc... X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/09e8e10bd9c2e35ca5573c60763c1838b8242331?hp=e59fb224da39822620eefe8171d8ecad2c69cda6 Merge branch 'img-playground' of ssh://git.nowoczesnapolska.org.pl:2223/~/repo/redakcja into img-playground --- 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']) + + +