From: Radek Czajka Date: Wed, 18 Apr 2012 08:33:21 +0000 (+0200) Subject: basic integrity check, X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/1a6cd382132f5fceb9894b34ea923539b67c80bc?ds=sidebyside basic integrity check, newtagging fix for django 1.4: no ADMIN_MEDIA_PREFIX --- diff --git a/apps/catalogue/management/commands/checkintegrity.py b/apps/catalogue/management/commands/checkintegrity.py new file mode 100644 index 000000000..0892a7815 --- /dev/null +++ b/apps/catalogue/management/commands/checkintegrity.py @@ -0,0 +1,64 @@ +# -*- 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. +# +from optparse import make_option +from django.core.management.base import BaseCommand + +from catalogue.models import Book + + +class Command(BaseCommand): + option_list = BaseCommand.option_list + ( + make_option('-q', '--quiet', action='store_false', dest='verbose', default=True, + help='Suppress output'), + make_option('-d', '--dry-run', action='store_true', dest='dry_run', default=False, + help="Just check for problems, don't fix them"), + ) + help = 'Checks integrity of catalogue data.' + + def handle(self, **options): + from django.db import transaction + + verbose = options['verbose'] + + with transaction.commit_on_success(): + for book in Book.objects.all().iterator(): + try: + info = book.wldocument().book_info + except: + if verbose: + print "ERROR! Bad XML for book:", book.slug + print "To resolve: republish." + print + else: + should_be = [p.slug for p in info.parts] + is_now = [p.slug for p in book.children.all().order_by('parent_number')] + if should_be != is_now: + if verbose: + print "ERROR! Wrong children for book:", book.slug + print "Is: ", is_now + print "Should be:", should_be + print "To resolve: republish parent book." + print + + # Check for parent l-tags. + parents = [] + parent = book.parent + while parent: + parents.append(parent) + parent = parent.parent + ltags = [b.book_tag() for b in parents] + if set(ltags) != set(book.tags.filter(category='book')): + if options['verbose']: + print "Wrong book tags for book:", book + print "Is: ", ", ".join(sorted(t.slug for t in book.tags.filter(category='book'))) + print "Should be:", ", ".join(sorted(t.slug for t in ltags)) + if not options['dry_run']: + book.tags = ltags + list(book.tags.exclude(category='book')) + if options['verbose']: + print "Fixed." + if options['verbose']: + print + + # TODO: check metadata tags, reset counters diff --git a/apps/newtagging/admin.py b/apps/newtagging/admin.py index 8ddfd0347..57a76d5d4 100644 --- a/apps/newtagging/admin.py +++ b/apps/newtagging/admin.py @@ -15,7 +15,7 @@ class FilteredSelectMultiple(forms.SelectMultiple): def _media(self): from django.conf import settings js = ['js/SelectBox.js' , 'js/SelectFilter2.js'] - return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js]) + return forms.Media(js=['%sadmin/%s' % (settings.STATIC_URL, url) for url in js]) media = property(_media) def __init__(self, verbose_name, is_stacked, attrs=None, choices=()): @@ -30,7 +30,7 @@ class FilteredSelectMultiple(forms.SelectMultiple): # TODO: "id_" is hard-coded here. This should instead use the correct # API to determine the ID dynamically. output.append(u'SelectFilter.init("id_%s", "%s", %s, "%s"); });\n' % \ - (name, self.verbose_name.replace('"', '\\"'), int(self.is_stacked), settings.ADMIN_MEDIA_PREFIX)) + (name, self.verbose_name.replace('"', '\\"'), int(self.is_stacked), settings.STATIC_URL + "admin/")) return mark_safe(u''.join(output))