2 # -*- conding: utf-8 -*-
4 __date__ ="$2009-09-08 14:31:26$"
6 from django.core.management.base import BaseCommand
7 from django.utils import simplejson as json
8 from django.test.client import Client
9 from django.core.urlresolvers import reverse
11 from optparse import make_option
13 class Command(BaseCommand):
15 option_list = BaseCommand.option_list + (
16 make_option('-u', '--user', action='store', dest='username'),
17 make_option('-p', '--password', action='store', dest='password'),
18 make_option('-d', '--dublin-core', action='store_true', dest='dc'),
21 def handle(self, *args, **options):
23 if not options['username'] or not options['password']:
24 raise CommandError("You must provide login data")
26 client.login(username=options['username'], \
27 password=options['password'])
29 print options['username'], options['password']
34 print "Uploading '%s' as document '%s'" % (filename, bookname)
35 print "Wth DC template" if options['dc'] else ""
37 print client.post( reverse("document_list_view"),\
40 'ocr_file': open(filename),
41 'generate_dc': options['dc'] } )