Merge pull request #815 from Gluejar/ku2

bugfix
pull/94/head
eshellman 2018-11-05 20:28:20 -05:00 committed by GitHub
commit 8dcfcfe6fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -8,6 +8,7 @@ from regluit.core.validation import (
validate_date, validate_date,
) )
from regluit.core.bookloader import add_from_bookdatas from regluit.core.bookloader import add_from_bookdatas
from regluit.core.models import EbookFile
from .multiscrape import BaseMultiScraper, multiscrape from .multiscrape import BaseMultiScraper, multiscrape
from .utils import ids_from_urls from .utils import ids_from_urls
@ -89,7 +90,7 @@ class KUMultiScraper(BaseMultiScraper):
def get_authors(self): def get_authors(self):
def fullname(auth): def fullname(auth):
firstname = auth.FirstName.text firstname = auth.FirstName.text
lastname = auth.FirstName.text lastname = auth.LastName.text
return u'{} {}'.format(firstname, lastname) return u'{} {}'.format(firstname, lastname)
authors = self.doc.find_all('Author') authors = self.doc.find_all('Author')
creator_list = [] creator_list = []
@ -154,3 +155,13 @@ def load_ku(ku_round=None):
editions.extend(add_from_bookdatas(scrapers)) editions.extend(add_from_bookdatas(scrapers))
return editions return editions
def activate_ku_ebooks():
to_activate = EbookFile.objects.filter(
source__startswith='https://app.knowledgeunlatched.org/uploads/',
ebook__active=False,
)
num_to_activate = to_activate.count()
for ebf in to_activate:
ebf.ebook.activate()
return num_to_activate

View File

@ -1,6 +1,6 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from regluit.core.loaders.ku import load_ku from regluit.core.loaders.ku import load_ku, activate_ku_ebooks
class Command(BaseCommand): class Command(BaseCommand):
help = "load books from knowledge unlatched" help = "load books from knowledge unlatched"
@ -12,3 +12,6 @@ class Command(BaseCommand):
def handle(self, round, **options): def handle(self, round, **options):
books = load_ku(round) books = load_ku(round)
self.stdout.write("loaded {} books".format(len(books))) self.stdout.write("loaded {} books".format(len(books)))
activated = activate_ku_ebooks()
self.stdout.write("activated {} ebooks".format(activated))