コード例 #1
0
ファイル: seed.py プロジェクト: marknorgren/stacks
    def handle_noargs(self, **options):
        books = []
        book = Book()
        book.uuid = "aaa"
        book.title = "Learning Web Design: A Beginner's Guide to HTML, CSS, JavaScript, and Web Graphics"
        book.author_lastname = "Robbins"
        book.author_firstname = "Jennifer"
        book.description = """
        Do you want to build web pages, but have no previous experience? This friendly guide is the perfect place to start. You'll begin at square one, learning how the Web and web pages work, and then steadily build from there. By the end of the book, you'll have the skills to create a simple site with multi-column pages that adapt for mobile devices.
        
        Learn how to use the latest techniques, best practices, and current web standards--including HTML5 and CSS3. Each chapter provides exercises to help you to learn various techniques, and short quizzes to make sure you understand key concepts.
        
        This thoroughly revised edition is ideal for students and professionals of all backgrounds and skill levels, whether you're a beginner or brushing up on existing skills.
        """
        book.isbn10 = "1449319270"
        book.publisher = "O'reilly"
        books.append(book)

        book = Book()
        book.uuid = "aab"
        book.title = "HTML and CSS: Design and Build Websites"
        book.author_lastname = "Duckett"
        book.author_firstname = "Jon"
        book.description = """
        Every day, more and more people want to learn some HTML and CSS. Joining the professional web designers and programmers are new audiences who need to know a little bit of code at work (update a content management system or e-commerce store) and those who want to make their personal blogs more attractive. Many books teaching HTML and CSS are dry and only written for those who want to become programmers, which is why this book takes an entirely new approach.

        Introduces HTML and CSS in a way that makes them accessible to everyone--hobbyists, students, and professionals--and it's full-color throughout
        Utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging
        Boasts a unique structure that allows you to progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure
        """
        book.isbn10 = "1118008189"
        book.publisher = "Wiley"
        books.append(book)

        book = Book()
        book.uuid = "aac"
        book.title = "JavaScript & jQuery: The Missing Manual"
        book.author_lastname = "McFarland"
        book.author_firstname = "David"
        book.description = """
        JavaScript lets you supercharge your HTML with animation, interactivity, and visual effects--but many web designers find the language hard to learn. This jargon-free guide covers JavaScript basics and shows you how to save time and effort with the jQuery library of prewritten JavaScript code. You'll soon be building web pages that feel and act like desktop programs, without having to do much programming.
        """
        book.isbn10 = "1449399029"
        book.publisher = "O'reilly"
        books.append(book)

        # add all the books that don't exist yet
        for book in books:
            try:
                Book.objects.get(uuid=book.uuid)
            except Book.DoesNotExist:
                book.save()
コード例 #2
0
ファイル: seed.py プロジェクト: fawcett/stacks
    def handle_noargs(self, **options):
        books = []
        book = Book()
        book.uuid = "aaa"
        book.title = "Learning Web Design: A Beginner's Guide to HTML, CSS, JavaScript, and Web Graphics"
        book.author_lastname = "Robbins"
        book.author_firstname = "Jennifer"
        book.description = """
        Do you want to build web pages, but have no previous experience? This friendly guide is the perfect place to start. You'll begin at square one, learning how the Web and web pages work, and then steadily build from there. By the end of the book, you'll have the skills to create a simple site with multi-column pages that adapt for mobile devices.
        
        Learn how to use the latest techniques, best practices, and current web standards--including HTML5 and CSS3. Each chapter provides exercises to help you to learn various techniques, and short quizzes to make sure you understand key concepts.
        
        This thoroughly revised edition is ideal for students and professionals of all backgrounds and skill levels, whether you're a beginner or brushing up on existing skills.
        """
        book.isbn10 = "1449319270"
        book.publisher = "O'reilly"
        books.append(book)

        book = Book()
        book.uuid = "aab"
        book.title = "HTML and CSS: Design and Build Websites"
        book.author_lastname = "Duckett"
        book.author_firstname = "Jon"
        book.description = """
        Every day, more and more people want to learn some HTML and CSS. Joining the professional web designers and programmers are new audiences who need to know a little bit of code at work (update a content management system or e-commerce store) and those who want to make their personal blogs more attractive. Many books teaching HTML and CSS are dry and only written for those who want to become programmers, which is why this book takes an entirely new approach.

        Introduces HTML and CSS in a way that makes them accessible to everyone--hobbyists, students, and professionals--and it's full-color throughout
        Utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging
        Boasts a unique structure that allows you to progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure
        """
        book.isbn10 = "1118008189"
        book.publisher = "Wiley"
        books.append(book)
        
        book = Book()
        book.uuid = "aac"
        book.title = "JavaScript & jQuery: The Missing Manual"
        book.author_lastname = "McFarland"
        book.author_firstname = "David"
        book.description = """
        JavaScript lets you supercharge your HTML with animation, interactivity, and visual effects--but many web designers find the language hard to learn. This jargon-free guide covers JavaScript basics and shows you how to save time and effort with the jQuery library of prewritten JavaScript code. You'll soon be building web pages that feel and act like desktop programs, without having to do much programming.
        """
        book.isbn10 = "1449399029"
        book.publisher = "O'reilly"
        books.append(book)

        # add all the books that don't exist yet
        for book in books:
            try:
                Book.objects.get(uuid=book.uuid)
            except Book.DoesNotExist:
                book.save()
コード例 #3
0
def book(request):

    if request.method == "GET":

        books = Book.objects.all()
        data = []
        for book in books:
            data.append({'url': book.url, 'id': book.id})

        response = HttpResponse(json.dumps(data), mimetype="application/json")
        return response
    elif request.method == "POST":
        #extract data and converts to object
        data = json.loads(request.POST.get('data'))

        #extract the file and the filename
        image = request.FILES['image']
        filename = settings.MEDIA_ROOT + image.name

        #write the file to disk
        with open(filename, 'wb+') as destination:
            for chunk in image.chunks():
                destination.write(chunk)

        book = Book()
        if "description" in data: book.description = data["description"]
        if "category" in data: book.category = data["category"]
        data = book.upload(filename)

        response = HttpResponse(json.dumps(data), mimetype="application/json")
        response.status_code = 201
        return response
コード例 #4
0
ファイル: views.py プロジェクト: charliephairoj/backend
def book(request):
    
    if request.method == "GET":
        
        books = Book.objects.all()
        data=[]
        for book in books:
            data.append({'url':book.url, 'id':book.id})
            
        response = HttpResponse(json.dumps(data), mimetype="application/json")
        return response
    elif request.method == "POST":
        #extract data and converts to object
        data = json.loads(request.POST.get('data'))
        
        #extract the file and the filename
        image = request.FILES['image']
        filename = settings.MEDIA_ROOT+image.name
        
        #write the file to disk
        with open(filename, 'wb+' ) as destination:
            for chunk in image.chunks():
                destination.write(chunk)
                
        
        book = Book()
        if "description" in data: book.description = data["description"]
        if "category" in data: book.category = data["category"]
        data = book.upload(filename)
        
        
        
        response = HttpResponse(json.dumps(data), mimetype="application/json")
        response.status_code = 201
        return response
コード例 #5
0
ファイル: parsing.py プロジェクト: klown/clusive
def unpack_epub_file(clusive_user, file, book=None, sort_order=0):
    """
    Process an uploaded EPUB file, returns BookVersion.

    The book will be owned by the given ClusiveUser. If that argument is None, it will be
    created as a public library book.

    If book and sort_order arguments are given, they will be used to locate an existing Book and
    possibly-existing BookVersion objects. For public library books, the title is used to
    look for a matching Book. If there is no matching Book or BookVersion, they will be created.
    If a matching BookVersion already exists it will be overwritten only if
    the modification date in the EPUB metadata is newer.

    This method will:
     * unzip the file into the user media area
     * find metadata
     * create a manifest
     * make a database record

    It does NOT look for glossary words or parse the text content for vocabulary lists,
    call scan_book for that.

    Returns a tuple (bv, changed) of the BookVersion and a boolean value which will
    be true if new book content was found.  If "changed" is False, the bv is an existing
    one that matches the given file and was not updated.

    If there are any errors (such as a non-EPUB file), an exception will be raised.
    """
    with open(file, 'rb') as f, dawn.open(f) as upload:
        book_version = None
        manifest = make_manifest(upload)
        title = get_metadata_item(upload, 'titles') or ''
        author = get_metadata_item(upload, 'creators') or ''
        description = get_metadata_item(upload, 'description') or ''
        language = get_metadata_item(upload, 'language') or ''
        mod_date = upload.meta.get('dates').get('modification') or None

        # Date, if provided should be UTC according to spec.
        if mod_date:
            mod_date = timezone.make_aware(mod_date, timezone=timezone.utc)
        else:
            # Many EPUBs are missing this metadata, unfortunately.
            logger.warning('No mod date found in %s', file)
            mod_date = timezone.now()

        if upload.cover:
            cover = adjust_href(upload, upload.cover.href)
            # For cover path, need to prefix this path with the directory holding this version of the book.
            cover = os.path.join(str(sort_order), cover)
        else:
            cover = None

        # Find or create the BOOK.
        if book:
            # Was supplied as an arg... sanity check.
            if book.title != title:
                logger.warning('DB title: \'%s\', imported title: \'%s\'' % (repr(book.title), repr(title)))
                raise BookMismatch('Does not appear to be a version of the same book, titles differ.')
        else:
            if not clusive_user:
                # For public books, we require a title, and a book with the same title is assumed to be the same book.
                if not title:
                    raise BookMalformed('Malformed EPUB, no title found')
                book = Book.objects.filter(owner=None, title=title).first()
        if not book:
            # Make new Book
            book = Book(owner=clusive_user,
                        title=title,
                        author=author,
                        description=description,
                        cover=cover)
            book.save()
            logger.debug('Created new book for import: %s', book)

        # Find or create the BOOK VERSION
        book_version = BookVersion.objects.filter(book=book, sortOrder=sort_order).first()
        if book_version:
            logger.info('Existing BV was found')
            if mod_date > book_version.mod_date:
                logger.info('Replacing older content of this book version')
                book_version.mod_date = mod_date
                # Also update metadata that's stored on the book, in case it's changed.
                book.author = author
                book.description = description
                book.cover = cover
                book.save()
            else:
                logger.warning('File %s not imported: already exists with same or newer date' % file)
                # Short circuit the import and just return the existing object.
                return book_version, False
        else:
            logger.info('Creating new BV: book=%s, sortOrder=%d' % (book, sort_order))
            book_version = BookVersion(book=book, sortOrder=sort_order, mod_date=mod_date)

        book_version.filename = basename(file)
        if language:
            book_version.language = language
        book_version.save()

        # Unpack the EPUB file
        dir = book_version.storage_dir
        if os.path.isdir(dir):
            logger.debug('Erasing existing content in %s', dir)
            shutil.rmtree(dir)
        os.makedirs(dir)
        with ZipFile(file) as zf:
            zf.extractall(path=dir)
        with open(os.path.join(dir, 'manifest.json'), 'w') as mf:
            mf.write(json.dumps(manifest, indent=4))
        logger.debug("Unpacked epub into %s", dir)
        return book_version, True