Skip to content

Commit 541e96e

Browse files
committed
BK-2085 Add support for Django 1.11 LTS
1 parent 0a101be commit 541e96e

20 files changed

Lines changed: 285 additions & 914 deletions

File tree

lib/booki/editor/common.py

Lines changed: 0 additions & 492 deletions
This file was deleted.

lib/booki/editor/management/commands/bookexport.py

Lines changed: 0 additions & 79 deletions
This file was deleted.

lib/booki/editor/management/commands/bookrename.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,52 @@
1515
# along with Booktype. If not, see <http://www.gnu.org/licenses/>.
1616

1717
from django.core.management.base import BaseCommand, CommandError
18-
from optparse import make_option
1918
from django.contrib.auth.models import User
2019

2120
from booki.editor import models
21+
from booktype.utils.book import rename_book
22+
2223

2324
class Command(BaseCommand):
24-
args = "<book name>"
2525
help = "Rename book."
26+
requires_model_validation = False
27+
BOOK_NAME = '<book name>'
2628

27-
option_list = BaseCommand.option_list + (
28-
make_option('--owner',
29-
action='store',
30-
dest='owner',
31-
default=None,
32-
help='Set new owner of the book.'),
33-
34-
make_option('--new-book-title',
35-
action='store',
36-
dest='new_book_title',
37-
default=None,
38-
help='Set new book title.'),
29+
def add_arguments(self, parser):
30+
parser.add_argument(self.BOOK_NAME, nargs=1, type=str)
31+
parser.add_argument('--owner',
32+
action='store',
33+
dest='owner',
34+
default=None,
35+
help='Set new owner of the book.')
3936

40-
make_option('--new-book-url',
41-
action='store',
42-
dest='new_book_url',
43-
default=None,
44-
help='Set new book url name.'),
37+
parser.add_argument('--new-book-title',
38+
action='store',
39+
dest='new_book_title',
40+
default=None,
41+
help='Set new book title.')
4542

46-
)
47-
48-
requires_model_validation = False
43+
parser.add_argument('--new-book-url',
44+
action='store',
45+
dest='new_book_url',
46+
default=None,
47+
help='Set new book url name.')
4948

5049
def handle(self, *args, **options):
51-
if len(args) != 1:
50+
book_name = options[self.BOOK_NAME][0]
51+
52+
if not book_name:
5253
raise CommandError("You must specify book name.")
5354

5455
try:
55-
book = models.Book.objects.get(url_title__iexact=args[0])
56+
book = models.Book.objects.get(url_title__iexact=book_name)
5657
except models.Book.DoesNotExist:
57-
raise CommandError('Book "%s" does not exist.' % args[0])
58+
raise CommandError('Book "%s" does not exist.' % book_name)
5859

5960
if options['new_book_title']:
6061
book.title = options['new_book_title']
6162

6263
if options['new_book_url']:
63-
from booktype.utils.book import rename_book
6464
rename_book(book, book.title, options['new_book_url'])
6565

6666
if options['owner']:

lib/booki/editor/management/commands/brokenlinks.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@
1414
# You should have received a copy of the GNU Affero General Public License
1515
# along with Booktype. If not, see <http://www.gnu.org/licenses/>.
1616

17-
from django.core.management.base import BaseCommand, CommandError
18-
from optparse import make_option
19-
import os.path
17+
import os
2018
import urllib2
21-
22-
from booki.editor import models
2319
from lxml import etree, html
2420

2521
from django.test import Client
26-
22+
from django.core.management.base import BaseCommand, CommandError
23+
from booki.editor import models
2724

2825
cacheLinks = {}
2926

27+
3028
class HeadRequest(urllib2.Request):
3129
def get_method(self):
3230
return "HEAD"
@@ -59,13 +57,14 @@ def checkLink(options, chapter, urlLink):
5957

6058
if not options['no_cache']:
6159
cacheLinks[urlLink] = returnCode
62-
60+
6361
print ' [%s]' % returnCode
6462
else:
6563
if options['no_local']: return
6664

6765
c = Client()
68-
newUrl = os.path.normpath('/%s/_v/%s/%s/%s' % (chapter.version.book.url_title, chapter.version.getVersion(), chapter.url_title, urlLink))
66+
newUrl = os.path.normpath('/%s/_v/%s/%s/%s' % (
67+
chapter.version.book.url_title, chapter.version.getVersion(), chapter.url_title, urlLink))
6968

7069
print ' >> ', newUrl,
7170
response = c.get(newUrl)
@@ -74,60 +73,61 @@ def checkLink(options, chapter, urlLink):
7473

7574

7675
class Command(BaseCommand):
77-
args = '<book name> [, <book name>, ...]'
76+
BOOK_NAMES = '<book name> [, <book name>, ...]'
7877
help = 'Check links in books.'
7978

80-
option_list = BaseCommand.option_list + (
81-
make_option('--no-remote',
82-
action='store_true',
83-
dest='no_remote',
84-
default=False,
85-
help='Do we check for remote links?'),
86-
87-
make_option('--no-local',
88-
action='store_true',
89-
dest='no_local',
90-
default=False,
91-
help='Do we check for local links?'),
92-
93-
make_option('--no-cache',
94-
action='store_true',
95-
dest='no_cache',
96-
default=False,
97-
help='Do not cache network links.'),
98-
99-
make_option('--ignore-url',
100-
action='append',
101-
dest='ignore_url',
102-
default=[],
103-
help='What hosts to ignore, e.g. http://www.wikipedia.org/'),
104-
105-
)
106-
79+
def add_arguments(self, parser):
80+
parser.add_argument(self.BOOK_NAMES, nargs='+', type=str)
81+
82+
parser.add_argument('--no-remote',
83+
action='store_true',
84+
dest='no_remote',
85+
default=False,
86+
help='Do we check for remote links?')
87+
88+
parser.add_argument('--no-local',
89+
action='store_true',
90+
dest='no_local',
91+
default=False,
92+
help='Do we check for local links?')
93+
94+
parser.add_argument('--no-cache',
95+
action='store_true',
96+
dest='no_cache',
97+
default=False,
98+
help='Do not cache network links.')
99+
100+
parser.add_argument('--ignore-url',
101+
action='append',
102+
dest='ignore_url',
103+
default=[],
104+
help='What hosts to ignore, e.g. http://www.wikipedia.org/')
105+
107106
def handle(self, *args, **options):
108107
global cacheLinks
109108

109+
book_names = options.get(self.BOOK_NAMES, [])
110+
110111
# filter only books we want
111-
if len(args) > 0:
112-
booksList = models.Book.objects.filter(url_title__in=args).order_by('url_title')
112+
if book_names:
113+
booksList = models.Book.objects.filter(url_title__in=book_names).order_by('url_title')
113114
else:
114115
booksList = models.Book.objects.all().order_by('url_title')
115116

116-
117117
for book in booksList:
118118
print '[%s]' % book.url_title
119119

120120
try:
121121
for chapter in models.Chapter.objects.filter(version__book=book):
122122
print ' [%s]' % chapter.url_title,
123-
123+
124124
try:
125125
tree = html.document_fromstring(chapter.content)
126126
print ''
127127
except:
128128
print ' [ERROR PARSING HTML]'
129129
continue
130-
130+
131131
for elem in tree.iter():
132132
src = elem.get('src')
133133
if src:

lib/booki/editor/management/commands/confdel.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,28 @@
1515
# along with Booktype. If not, see <http://www.gnu.org/licenses/>.
1616

1717
from django.core.management.base import BaseCommand, CommandError
18-
from optparse import make_option
1918

2019
from django.conf import settings
2120

2221
from booktype.utils import config
2322

2423
class Command(BaseCommand):
25-
args = "<key>"
2624
help = "Delete configuration variable."
2725
requires_model_validation = False
2826

27+
def add_arguments(self, parser):
28+
parser.add_argument("<key>", nargs=1, type=str)
29+
2930
def handle(self, *args, **options):
3031
if not hasattr(settings, 'BOOKTYPE_CONFIG'):
3132
raise CommandError('Does not have BOOKTYPE_CONFIG in settings.py file.')
3233

33-
if len(args) != 1:
34+
if not options['<key>'][0]:
3435
raise CommandError("You must specify variable name")
3536

36-
if not settings.BOOKTYPE_CONFIG.has_key(args[0]):
37+
if not settings.BOOKTYPE_CONFIG.has_key(options['<key>'][0]):
3738
raise CommandError("There is no such variable.")
3839

39-
del settings.BOOKTYPE_CONFIG[args[0]]
40+
del settings.BOOKTYPE_CONFIG[options['<key>'][0]]
4041

4142
config.save_configuration()

lib/booki/editor/management/commands/confget.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,37 @@
1414
# You should have received a copy of the GNU Affero General Public License
1515
# along with Booktype. If not, see <http://www.gnu.org/licenses/>.
1616

17-
from django.core.management.base import BaseCommand, CommandError
18-
from optparse import make_option
17+
import json
1918

19+
from django.core.management.base import BaseCommand, CommandError
2020
from django.conf import settings
2121

22-
from booktype.utils import config
23-
import json
2422

2523
class Command(BaseCommand):
26-
args = "<key>"
2724
help = "Get value for configuration variable."
28-
29-
option_list = BaseCommand.option_list + (
30-
make_option('--as_json',
31-
action='store_true',
32-
dest='as_json',
33-
default=False,
34-
help='Value is defined as JSON encoded string.'),
35-
)
36-
3725
requires_model_validation = False
3826

27+
def add_arguments(self, parser):
28+
parser.add_argument("<key>", nargs=1, type=str)
29+
parser.add_argument('--as_json',
30+
action='store_true',
31+
dest='as_json',
32+
default=False,
33+
help='Value is defined as JSON encoded string.')
34+
3935
def handle(self, *args, **options):
4036
if not hasattr(settings, 'BOOKTYPE_CONFIG'):
4137
raise CommandError('Does not have BOOKTYPE_CONFIG in settings.py file.')
4238

43-
if len(args) != 1:
39+
if not options["<key>"][0]:
4440
raise CommandError("You must specify variable name")
4541

46-
if not settings.BOOKTYPE_CONFIG.has_key(args[0]):
42+
if not settings.BOOKTYPE_CONFIG.has_key(options["<key>"][0]):
4743
raise CommandError("There is no such variable.")
4844

49-
value = settings.BOOKTYPE_CONFIG[args[0]]
45+
value = settings.BOOKTYPE_CONFIG[options["<key>"][0]]
5046

5147
if options['as_json']:
5248
value = json.dumps(value)
5349

54-
self.stdout.write(str(value)+"\n")
50+
self.stdout.write(str(value) + "\n")

0 commit comments

Comments
 (0)