示例#1
0
    def test__read_link(self):
        empty = '<span></span>'
        book_id = db.book.insert(
            name='test__read_link',
            reader='slider',
        )
        book = db(db.book.id == book_id).select().first()
        self._objects.append(book)

        # As integer, book_id
        link = read_link(db, book_id)
        # Eg <a data-w2p_disable_with="default" href="/zcomix/books/slider/57">READ</a>
        soup = BeautifulSoup(str(link))
        anchor = soup.find('a')
        self.assertEqual(anchor.string, 'READ')
        self.assertEqual(anchor['href'],
                         '/zcomix/books/slider/{bid}'.format(bid=book_id))

        # As Row, book
        link = read_link(db, book)
        soup = BeautifulSoup(str(link))
        anchor = soup.find('a')
        self.assertEqual(anchor.string, 'READ')
        self.assertEqual(anchor['href'],
                         '/zcomix/books/slider/{bid}'.format(bid=book_id))

        # Invalid id
        link = read_link(db, -1)
        self.assertEqual(str(link), empty)

        # Test reader variation
        book.reader = 'awesome_reader'
        link = read_link(db, book)
        soup = BeautifulSoup(str(link))
        anchor = soup.find('a')
        self.assertEqual(anchor.string, 'READ')
        self.assertEqual(
            anchor['href'],
            '/zcomix/books/awesome_reader/{bid}'.format(bid=book_id))

        # Test attributes
        book.reader = 'slider'
        attributes = dict(
            _href='/path/to/file',
            _class='btn btn-large',
            _type='button',
            _target='_blank',
        )
        link = read_link(db, book, **attributes)
        soup = BeautifulSoup(str(link))
        anchor = soup.find('a')
        self.assertEqual(anchor.string, 'READ')
        self.assertEqual(anchor['href'], '/path/to/file')
        self.assertEqual(anchor['class'], 'btn btn-large')
        self.assertEqual(anchor['type'], 'button')
        self.assertEqual(anchor['target'], '_blank')
示例#2
0
    def test__read_link(self):
        empty = '<span></span>'
        book_id = db.book.insert(
            name='test__read_link',
            reader='slider',
        )
        book = db(db.book.id == book_id).select().first()
        self._objects.append(book)

        # As integer, book_id
        link = read_link(db, book_id)
        # Eg <a data-w2p_disable_with="default" href="/zcomix/books/slider/57">READ</a>
        soup = BeautifulSoup(str(link))
        anchor = soup.find('a')
        self.assertEqual(anchor.string, 'READ')
        self.assertEqual(anchor['href'], '/zcomix/books/slider/{bid}'.format(
            bid=book_id))

        # As Row, book
        link = read_link(db, book)
        soup = BeautifulSoup(str(link))
        anchor = soup.find('a')
        self.assertEqual(anchor.string, 'READ')
        self.assertEqual(anchor['href'], '/zcomix/books/slider/{bid}'.format(
            bid=book_id))

        # Invalid id
        link = read_link(db, -1)
        self.assertEqual(str(link), empty)

        # Test reader variation
        book.reader = 'awesome_reader'
        link = read_link(db, book)
        soup = BeautifulSoup(str(link))
        anchor = soup.find('a')
        self.assertEqual(anchor.string, 'READ')
        self.assertEqual(anchor['href'], '/zcomix/books/awesome_reader/{bid}'.format(
            bid=book_id))

        # Test attributes
        book.reader = 'slider'
        attributes = dict(
            _href='/path/to/file',
            _class='btn btn-large',
            _type='button',
            _target='_blank',
        )
        link = read_link(db, book, **attributes)
        soup = BeautifulSoup(str(link))
        anchor = soup.find('a')
        self.assertEqual(anchor.string, 'READ')
        self.assertEqual(anchor['href'], '/path/to/file')
        self.assertEqual(anchor['class'], 'btn btn-large')
        self.assertEqual(anchor['type'], 'button')
        self.assertEqual(anchor['target'], '_blank')
示例#3
0
文件: books.py 项目: zsw/zcomix.com
def book():
    """Book page controller

    request.args(0): id of book
    """
    if not request.args(0):
        redirect(URL(c='default', f='index'))

    book_record = db(db.book.id == request.args(0)).select(db.book.ALL).first()
    if not book_record:
        redirect(URL(c='default', f='index'))

    creator = db(db.creator.id == book_record.creator_id).select(
        db.creator.ALL).first()
    auth_user = db(db.auth_user.id == creator.auth_user_id).select(
        db.auth_user.ALL).first()

    read_button = read_link(db, book_record,
                            **dict(
                                _class='btn btn-default',
                                _type='button',
                            ))

    pre_links = []
    if creator.tumblr:
        pre_links.append(A('tumblr', _href=creator.tumblr, _target='_blank'))
    if creator.wikipedia:
        pre_links.append(
            A('wikipedia', _href=creator.wikipedia, _target='_blank'))

    return dict(
        auth_user=auth_user,
        book=book_record,
        cover_image=cover_image(db,
                                book_record.id,
                                size='original',
                                img_attributes={'_class': 'img-responsive'}),
        creator=creator,
        creator_links=CustomLinks(db.creator,
                                  creator.id).represent(pre_links=pre_links),
        links=CustomLinks(db.book, book_record.id).represent(),
        page_count=db(db.book_page.book_id == book_record.id).count(),
        read_button=read_button,
    )
示例#4
0
文件: books.py 项目: zsw/zcomix.com
def book():
    """Book page controller

    request.args(0): id of book
    """
    if not request.args(0):
        redirect(URL(c='default', f='index'))

    book_record = db(db.book.id == request.args(0)).select(
            db.book.ALL).first()
    if not book_record:
        redirect(URL(c='default', f='index'))

    creator = db(db.creator.id == book_record.creator_id).select(
            db.creator.ALL).first()
    auth_user = db(db.auth_user.id == creator.auth_user_id).select(
            db.auth_user.ALL).first()

    read_button = read_link(
        db,
        book_record,
        **dict(
            _class='btn btn-default',
            _type='button',
        )
    )

    pre_links = []
    if creator.tumblr:
        pre_links.append(A('tumblr', _href=creator.tumblr, _target='_blank'))
    if creator.wikipedia:
        pre_links.append(A('wikipedia', _href=creator.wikipedia, _target='_blank'))

    return dict(
        auth_user=auth_user,
        book=book_record,
        cover_image=cover_image(db, book_record.id, size='original', img_attributes={'_class': 'img-responsive'}),
        creator=creator,
        creator_links=CustomLinks(db.creator, creator.id).represent(pre_links=pre_links),
        links=CustomLinks(db.book, book_record.id).represent(),
        page_count=db(db.book_page.book_id == book_record.id).count(),
        read_button=read_button,
    )
示例#5
0
文件: profile.py 项目: zsw/zcomix.com
def book_pages():
    """Creator profile book pages component. (Multiple file upload.)

    request.args(0): integer, id of book.
    """
    # Verify user is legit
    creator_record = db(db.creator.auth_user_id == auth.user_id).select(
        db.creator.ALL
    ).first()
    if not creator_record:
        redirect(URL('books'))

    book_record = None
    if request.args(0):
        query = (db.book.id == request.args(0))
        book_record = db(query).select(db.book.ALL).first()
    if not book_record or book_record.creator_id != creator_record.id:
        redirect(URL('books'))

    response.files.append(
        URL('static', 'blueimp/jQuery-File-Upload/css/jquery.fileupload.css')
    )
    response.files.append(
        URL(
            'static',
            'blueimp/jQuery-File-Upload/css/jquery.fileupload-ui.css'
        )
    )

    read_button = read_link(
        db,
        book_record,
        **dict(
            _class='btn btn-default btn-lg',
            _type='button',
            _target='_blank',
        )
    )

    return dict(
        book=book_record,
        read_button=read_button,
    )
示例#6
0
文件: profile.py 项目: zsw/zcomix.com
def book_pages():
    """Creator profile book pages component. (Multiple file upload.)

    request.args(0): integer, id of book.
    """
    # Verify user is legit
    creator_record = db(db.creator.auth_user_id == auth.user_id).select(
        db.creator.ALL).first()
    if not creator_record:
        redirect(URL('books'))

    book_record = None
    if request.args(0):
        query = (db.book.id == request.args(0))
        book_record = db(query).select(db.book.ALL).first()
    if not book_record or book_record.creator_id != creator_record.id:
        redirect(URL('books'))

    response.files.append(
        URL('static', 'blueimp/jQuery-File-Upload/css/jquery.fileupload.css'))
    response.files.append(
        URL('static',
            'blueimp/jQuery-File-Upload/css/jquery.fileupload-ui.css'))

    read_button = read_link(
        db, book_record,
        **dict(
            _class='btn btn-default btn-lg',
            _type='button',
            _target='_blank',
        ))

    return dict(
        book=book_record,
        read_button=read_button,
    )
示例#7
0
文件: search.py 项目: zsw/zcomix.com
 def read_link_func(row):
     book_id = link_book_id(row)
     if not book_id:
         return ''
     return read_link(db, book_id, **dict(_class='btn btn-default', _type='button'))
示例#8
0
 def read_link_func(row):
     book_id = link_book_id(row)
     if not book_id:
         return ''
     return read_link(db, book_id,
                      **dict(_class='btn btn-default', _type='button'))
示例#9
0
文件: profile.py 项目: zsw/zcomix.com
def book_release():
    """Release a book controller.

    request.args(0): integer, id of book. Optional, if provided, only
        links associated with that book are listed. Otherwise only books for
        the logged in creator are listed.
    """
    creator_record = db(db.creator.auth_user_id == auth.user_id).select(
        db.creator.ALL
    ).first()
    if not creator_record:
        redirect(URL('books'))

    book_record = None
    if request.args(0):
        book_record = db(db.book.id == request.args(0)).select(
            db.book.ALL
        ).first()
    if not book_record or book_record.creator_id != creator_record.id:
        redirect(URL('books'))

    page_count = db(db.book_page.book_id == book_record.id).count()

    form = SQLFORM.factory(
        Field(
            'cancel',
            default='Cancel',
            widget=InputWidget({
                '_type': 'button',
                '_onclick': 'history.go(-1); return false;'
            }).widget,
        ),
        submit_button='Release',
    )

    if form.accepts(
        request.vars,
        session,
        formname='book_release',
        keepvalues=True
    ):
        book_record.update_record(
            release_date=datetime.datetime.today()
        )
        db.commit()
        # FIXME create torrent
        # FIXME add book to creator torrent
        # FIXME add book to ALL torrent
        session.flash = '{name} released.'.format(
            name=book_record.name
        )
        redirect(URL('books'))
    elif form.errors:
        response.flash = 'Form could not be submitted.' + \
            ' Please make corrections.'

    read_button = read_link(
        db,
        book_record,
        **dict(
            _class='btn btn-default btn-lg',
            _type='button',
            _target='_blank',
        )
    )

    return dict(
        book=book_record,
        creator=creator_record,
        form=form,
        page_count=page_count,
        read_button=read_button,
    )
示例#10
0
文件: profile.py 项目: zsw/zcomix.com
def book_release():
    """Release a book controller.

    request.args(0): integer, id of book. Optional, if provided, only
        links associated with that book are listed. Otherwise only books for
        the logged in creator are listed.
    """
    creator_record = db(db.creator.auth_user_id == auth.user_id).select(
        db.creator.ALL).first()
    if not creator_record:
        redirect(URL('books'))

    book_record = None
    if request.args(0):
        book_record = db(db.book.id == request.args(0)).select(
            db.book.ALL).first()
    if not book_record or book_record.creator_id != creator_record.id:
        redirect(URL('books'))

    page_count = db(db.book_page.book_id == book_record.id).count()

    form = SQLFORM.factory(
        Field(
            'cancel',
            default='Cancel',
            widget=InputWidget({
                '_type': 'button',
                '_onclick': 'history.go(-1); return false;'
            }).widget,
        ),
        submit_button='Release',
    )

    if form.accepts(request.vars,
                    session,
                    formname='book_release',
                    keepvalues=True):
        book_record.update_record(release_date=datetime.datetime.today())
        db.commit()
        # FIXME create torrent
        # FIXME add book to creator torrent
        # FIXME add book to ALL torrent
        session.flash = '{name} released.'.format(name=book_record.name)
        redirect(URL('books'))
    elif form.errors:
        response.flash = 'Form could not be submitted.' + \
            ' Please make corrections.'

    read_button = read_link(
        db, book_record,
        **dict(
            _class='btn btn-default btn-lg',
            _type='button',
            _target='_blank',
        ))

    return dict(
        book=book_record,
        creator=creator_record,
        form=form,
        page_count=page_count,
        read_button=read_button,
    )