예제 #1
0
def generate_nav_catalog(subsections, is_root=False):
    links = []

    if is_root:
        links.append({
            'type': 'application/atom+xml',
            'rel': 'self',
            'href': reverse('pathagar.books.views.root')
        })

    links.append({
        'title': 'Home',
        'type': 'application/atom+xml',
        'rel': 'start',
        'href': reverse('pathagar.books.views.root')
    })

    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = ATTRS, hide_generator=True, links=links)

    for subsec in subsections:
        feed.add_item(subsec['id'],
                      subsec['title'],
                      subsec['updated'],
                      links=subsec['links'])

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
예제 #2
0
파일: opds.py 프로젝트: Shizzz/pathagar
def generate_nav_catalog(subsections, is_root=False):
    links = []

    if is_root:
        links.append({'type': 'application/atom+xml',
                      'rel': 'self',
                      'href': reverse('pathagar.books.views.root')})

    links.append({'title': 'Home', 'type': 'application/atom+xml',
                  'rel': 'start',
                  'href': reverse('pathagar.books.views.root')})

    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = ATTRS, hide_generator=True, links=links)


    for subsec in subsections:
        feed.add_item(subsec['id'], subsec['title'],
                      subsec['updated'], links=subsec['links'])

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
예제 #3
0
파일: opds.py 프로젝트: XSCE/xscd
def generate_catalog(request, page_obj):
    attrs = {}
    attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/'
    attrs[u'xmlns:opds'] = u'http://opds-spec.org/'
    attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/'
    attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/'
    
    links = []
    
    if page_obj.has_previous():
        previous_page = page_obj.previous_page_number()
        links.append({'title': 'Previous results', 'type': 'application/atom+xml',
                      'rel': 'previous',
                      'href': page_qstring(request, previous_page)})
    
    if page_obj.has_next():
        next_page = page_obj.next_page_number()
        links.append({'title': 'Next results', 'type': 'application/atom+xml',
                      'rel': 'next',
                      'href': page_qstring(request, next_page)})
    
    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = attrs, hide_generator=True, links=links)

    for book in page_obj.object_list:
        if book.cover_img:
            linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    reverse('pathagar.books.views.download_book',
                            kwargs=dict(book_id=book.pk)),
                    'type': __get_mimetype(book)}, {'rel': \
                    'http://opds-spec.org/cover', 'href': \
                    book.cover_img.url }]
        else:
           linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    reverse('pathagar.books.views.download_book',
                            kwargs=dict(book_id=book.pk)),
                    'type': __get_mimetype(book)}]
        
        add_kwargs = {
            'content': book.a_summary,
            'links': linklist,
            'authors': [{'name' : book.a_author}],
            'dc_publisher': book.dc_publisher,
            'dc_issued': book.dc_issued,
            'dc_identifier': book.dc_identifier,
        }
           
        if book.dc_language is not None:
            add_kwargs['dc_language'] = book.dc_language.code

        feed.add_item(book.a_id, book.a_title, book.a_updated, **add_kwargs)

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
예제 #4
0
def generate_catalog(books, q=None):
    attrs = {}
    attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/'
    attrs[u'xmlns:opds'] = u'http://opds-spec.org/'
    attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/'
    attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/'

    links = []

    if books.has_previous():
        if q:
            links.append({'title':'Previous results', 'type':'application/atom+xml', \
            'rel':'previous','href':'?page=' + str(books.previous_page_number()) + '&q=' + q })
        else:
            links.append({'title':'Previous results', 'type':'application/atom+xml', \
            'rel':'previous','href':'?page=' + str(books.previous_page_number())})


    if books.has_next():
        if q:
            links.append({'title':'Next results', 'type':'application/atom+xml', \
            'rel':'next','href':'?page=' + str(books.next_page_number()) + '&q=' + q })
        else:
            links.append({'title':'Next results', 'type':'application/atom+xml', \
            'rel':'next','href':'?page=' + str(books.next_page_number())})




    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = attrs, hide_generator=True, links=links)


    for book in books.object_list:
        if book.cover_img:
            linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    book.file.url, 'type': __get_mimetype(book)}, {'rel': \
                    'http://opds-spec.org/cover', 'href': \
                    book.cover_img.url }]
        else:
           linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    book.file.url, 'type': __get_mimetype(book)}]

        feed.add_item(book.a_id, book.a_title, book.a_updated, \
            content=book.a_summary, links = linklist, \
            authors = [{'name' : book.a_author}], \
            dc_language=book.dc_language.code, dc_publisher=book.dc_publisher, \
            dc_issued=book.dc_issued, dc_identifier=book.dc_identifier)

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
예제 #5
0
def generate_catalog(request, page_obj):
    links = []
    links.append({'title': 'Home', 'type': 'application/atom+xml',
                  'rel': 'start',
                  'href': reverse('root_feed')})

    if page_obj.has_previous():
        previous_page = page_obj.previous_page_number()
        links.append(
            {'title': 'Previous results', 'type': 'application/atom+xml',
             'rel': 'previous',
             'href': page_qstring(request, previous_page)})

    if page_obj.has_next():
        next_page = page_obj.next_page_number()
        links.append({'title': 'Next results', 'type': 'application/atom+xml',
                      'rel': 'next',
                      'href': page_qstring(request, next_page)})

    feed = AtomFeed(title='Pathagar Bookserver OPDS feed',
                    atom_id='pathagar:full-catalog',
                    subtitle='OPDS catalog for the Pathagar book server',
                    extra_attrs=ATTRS, hide_generator=True, links=links)

    for book in page_obj.object_list:
        if book.cover_img:
            linklist = [{'rel': 'http://opds-spec.org/acquisition',
                         'href': reverse('book_download',
                                         kwargs=dict(book_id=book.pk)),
                         'type': __get_mimetype(book)},
                        {'rel': 'http://opds-spec.org/cover', 'href':
                            book.cover_img.url}]
        else:
            linklist = [{'rel': 'http://opds-spec.org/acquisition',
                         'href': reverse('book_download',
                                         kwargs=dict(book_id=book.pk)),
                         'type': __get_mimetype(book)}]

        add_kwargs = {
            'content': book.summary,
            'links': linklist,
            'authors': [{'name': a.name} for a in book.authors.all()],
            'dc_publisher': [p.name for p in book.publishers.all()],
            'dc_issued': book.dc_issued,
            'dc_identifier': book.dc_identifier,
        }

        if book.dc_language is not None:
            add_kwargs['dc_language'] = book.dc_language.code

        feed.add_item(book.a_id, book.title, book.a_updated, **add_kwargs)

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
예제 #6
0
def generate_nav_catalog(subsections, is_root=False, links=None):
    
    if links is None:
        links = []
    
    if is_root:
        links.append({'type': 'application/atom+xml;profile=opds-catalog;kind=navigation',
                      'rel': 'self',
                      'href': reverse('pathagar.books.views.root')})
        links.append({'type': 'application/opensearchdescription+xml',
                      'rel': 'search',
                      'href': reverse('opensearch_description') })
    
    links.append({'title': 'Home', 'type': 'application/atom+xml;profile=opds-catalog;kind=navigation',
                  'rel': 'start',
                  'href': reverse('root_feed')})
    
    icon = None;
    if is_root:
        icon = FEED_ICON_LOCATION
    
    feed = AtomFeed(title = FEED_TITLE,
                    atom_id = 'pathagar:full-catalog',
                    subtitle = FEED_DESCRIPTION,
                    extra_attrs = ATTRS,
                    hide_generator=True,
                    links=links,
                    icon=icon)
    
    for subsec in subsections:
        content = None
        if 'content' in subsec:
            content = subsec['content']
        feed.add_item(  subsec['id'],
                        subsec['title'],
                        subsec['updated'],
                        content=content,
                        links=subsec['links'],
                     )

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
예제 #7
0
def generate_catalog(request, page_obj):
    links = []
    links.append({'title': 'Home', 'type': 'application/atom+xml;profile=opds-catalog;kind=navigation',
                  'rel': 'start',
                  'href': reverse('pathagar.books.views.root')})

    if page_obj.has_previous():
        previous_page = page_obj.previous_page_number()
        links.append({'title': 'Previous results', 'type': 'application/atom+xml;profile=opds-catalog;kind=acquisition',
                      'rel': 'previous',
                      'href': request.path + page_qstring(request, previous_page)})
    
    if page_obj.has_next():
        next_page = page_obj.next_page_number()
        links.append({'title': 'Next results', 'type': 'application/atom+xml;profile=opds-catalog;kind=acquisition',
                      'rel': 'next',
                      'href': request.path + page_qstring(request, next_page)})
    
    feed = AtomFeed(title = FEED_TITLE,
                    atom_id = 'pathagar:full-catalog',
                    subtitle = FEED_DESCRIPTION,
                    extra_attrs = ATTRS,
                    hide_generator=True,
                    links=links,
                    openSearch_totalResults=page_obj.paginator.count,
                    openSearch_itemsPerPage=page_obj.paginator.num_pages,
                    )
    
    bbparser = fimfic_bbcode.Parser()
    for book in page_obj.object_list:
        
        linklist = [
                        {
                            'rel': 'http://opds-spec.org/acquisition',
                            'href': reverse('pathagar.books.views.download_book',
                                            kwargs=dict(book_id=book.pk, filename=book.a_title+".epub" )),
                            'type': 'application/epub+zip'
                        },
                        {
                            'rel': 'http://opds-spec.org/acquisition',
                            'href': reverse('pathagar.books.views.download_book',
                                            kwargs=dict(book_id=book.pk, filename=book.a_title+".mobi" )),
                            'type': 'application/x-mobipocket-ebook'
                        },
                        {
                            'href': book.getOnlineViewingUrl(),
                        },
                   ]
        
        if book.getCoverImageUrl():
            # We are stripping everything past the question mark. guess_type fails in some cases otherwise.
            mimetype, encoding = mimetypes.guess_type( book.getCoverImageUrl().split('?')[0], strict=False )
            if mimetype is None:
                mimetype = 'image/*'
            linklist.append(
                {
                    'rel': 'http://opds-spec.org/image',
                    'type': mimetype,
                    'href': book.getCoverImageUrl()
                },
            )
        
        if book.getThumbnailUrl():
            # We are stripping everything past the question mark. guess_type fails in some cases otherwise.
            mimetype, encoding = mimetypes.guess_type( book.getThumbnailUrl().split('?')[0], strict=False )
            if mimetype is None:
                mimetype = 'image/*'
            linklist.append(
                {
                    'rel': 'http://opds-spec.org/image/thumbnail',
                    'type': mimetype,
                    'href': book.getThumbnailUrl()
                },
            )
        
        authors = []
        for author in book.a_authors.all():
            authors.append(
                {
                    'name':author.name,
                    'uri':author.getLink(),
                })
        
        categories = []
        for category in book.a_categories.all():
            categories.append(category.category)
        
        add_kwargs = {
            'summary': book.a_summary,
            # The Unicode concatenation forces the output of bbparser to Unicode.
            # bbparser outputs a string instead of Unicode if the input is a empty Unicode/string object
            'content': ( {'type':'html'}, u"" + bbparser.format(book.a_content) ),
            'links': linklist,
            'authors': authors,
            'categories': categories,
            'published': book.a_published,
            'dc_publisher': book.dc_publisher,
            'dc_issued': str(book.dc_issued),
            'dc_identifier': book.dc_identifier,
        }
        
        if book.dc_language is not None:
            add_kwargs['dc_language'] = book.dc_language.code

        feed.add_item(
                book.getUUID(),
                book.a_title,
                book.updated,   # A items atom:updated should refer to the time the item was update on THIS server.
                **add_kwargs
                )

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()
예제 #8
0
파일: opds.py 프로젝트: mapmeld/pathagar
def generate_catalog(request, page_obj):
    attrs = {}
    attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/'
    attrs[u'xmlns:opds'] = u'http://opds-spec.org/'
    attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/'
    attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/'

    links = []

    if page_obj.has_previous():
        previous_page = page_obj.previous_page_number()
        links.append({
            'title': 'Previous results',
            'type': 'application/atom+xml',
            'rel': 'previous',
            'href': page_qstring(request, previous_page)
        })

    if page_obj.has_next():
        next_page = page_obj.next_page_number()
        links.append({
            'title': 'Next results',
            'type': 'application/atom+xml',
            'rel': 'next',
            'href': page_qstring(request, next_page)
        })

    feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \
        atom_id = 'pathagar:full-catalog', subtitle = \
        'OPDS catalog for the Pathagar book server', \
        extra_attrs = attrs, hide_generator=True, links=links)

    for book in page_obj.object_list:
        if book.cover_img:
            linklist = [{'rel': \
                    'http://opds-spec.org/acquisition', 'href': \
                    reverse('pathagar.books.views.download_book',
                            kwargs=dict(book_id=book.pk)),
                    'type': __get_mimetype(book)}, {'rel': \
                    'http://opds-spec.org/cover', 'href': \
                    book.cover_img.url }]
        else:
            linklist = [{'rel': \
                     'http://opds-spec.org/acquisition', 'href': \
                     reverse('pathagar.books.views.download_book',
                             kwargs=dict(book_id=book.pk)),
                     'type': __get_mimetype(book)}]

        add_kwargs = {
            'content': book.a_summary,
            'links': linklist,
            'authors': [{
                'name': book.a_author
            }],
            'dc_publisher': book.dc_publisher,
            'dc_issued': book.dc_issued,
            'dc_identifier': book.dc_identifier,
        }

        if book.dc_language is not None:
            add_kwargs['dc_language'] = book.dc_language.code

        feed.add_item(book.a_id, book.a_title, book.a_updated, **add_kwargs)

    s = StringIO()
    feed.write(s, 'UTF-8')
    return s.getvalue()