Commit 1732096b authored by mitshel's avatar mitshel
Browse files

Development sopdswrap.py, sopdstempl.py modules, Intermediate commit.

parent 68082b74
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -222,19 +222,31 @@ class opdsClient():
    def entry_authors(self,book_id,link_show=False):
        return self.Wrapper.entry_authors(self.opdsdb.getauthors(book_id))

    def get_authors(self,book_id):
        return self.Wrapper.get_authors(self.opdsdb.getauthors(book_id))

    def entry_doubles(self,book_id):
        self.Wrapper.entry_doubles(book_id,self.opdsdb.getdoublecount(book_id))

    def entry_genres(self,book_id):
        return self.Wrapper.entry_genres(self.opdsdb.getgenres(book_id))

    def get_genres(self,book_id):
        return self.Wrapper.get_genres(self.opdsdb.getgenres(book_id))

    def entry_series(self,book_id):
        return self.Wrapper.entry_series(self.opdsdb.getseries(book_id))

    def get_series(self,book_id):
        return self.Wrapper.get_series(self.opdsdb.getseries(book_id))

    def entry_covers(self,cover,cover_type,book_id):
        if self.cfg.COVER_SHOW!=0:
           self.Wrapper.entry_covers(book_id)

    def entry_acquisition(self,acq_data):
        self.Wrapper.entry_acquisition(acq_data)

    def entry_content(self,e_content):
        self.Wrapper.entry_content(e_content)

@@ -269,12 +281,19 @@ class opdsClient():
               self.entry_link_subsection(id, item_title, reg_date, 'item:%s'%(item_id))
            if item_type==2:
               id='90'+str(item_id)
               self.entry_link_book(item_id,format,item_title, reg_date, 'item:%s'%(item_id))
               self.entry_covers(cover,cover_type,item_id)
               authors=self.entry_authors(item_id,True)
               genres=self.entry_genres(item_id)
               series=self.entry_series(item_id)
               self.entry_content2(annotation,item_title,authors,genres,item_name,fsize,docdate,series)
#               self.entry_link_book(item_id,format,item_title, reg_date, 'item:%s'%(item_id))
#               self.entry_covers(cover,cover_type,item_id)
#               authors=self.entry_authors(item_id,True)
#               genres=self.entry_genres(item_id)
#               series=self.entry_series(item_id)
#               self.entry_content2(annotation,item_title,authors,genres,item_name,fsize,docdate,series)
               (authors, authors_link) = self.get_authors(item_id)
               (genres,  genres_link)  = self.get_genres(item_id)
               (series,  series_link)  = self.get_series(item_id)
               acq_data={'link_id':item_id,'filename':item_name,'e_date':reg_date,'e_title':websym(item_title),'e_id':'item:%s'%(item_id),
                         'annotation':websym(annotation), 'docdate':docdate, 'format':format,'cover':cover,'cover_type':cover_type,'filesize':fsize//1024,
                         'authors':websym(authors),'genres':websym(genres),'series':websym(series),'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link}
               self.entry_acquisition(acq_data)
            self.entry_finish()
        self.page_control(self.page_value,self.id_value)
        self.footer()
+59 −21
Original line number Diff line number Diff line
@@ -100,10 +100,13 @@ class opdsTemplate():
       self.document_entry_authors=('<author><name>%%(last_name)s %%(first_name)s</name></author>'
                               '<link href="%(modulepath)s?id=22%%(author_id)s" rel="related" type="application/atom+xml;profile=opds-catalog" title="Все книги %%(last_name)s %%(first_name)s" />'
                               )%{'modulepath':self.modulepath}
       self.document_link_authors=self.document_entry_authors
       self.document_entry_doubles=('<link href="%(modulepath)s?id=23%%(book_id)s" rel="related" type="application/atom+xml;profile=opds-catalog" title="Дубликаты книги" />'
                               )%{'modulepath':self.modulepath}
       self.document_entry_genres='<category term="%(genre)s" label="%(genre)s" />'
       self.document_link_genres=self.document_entry_genres
       self.document_entry_series='' 
       self.document_link_series=self.document_entry_series
       self.document_entry_covers=('<link href="%(modulepath)s?id=99%%(book_id)s" rel="http://opds-spec.org/image" type="image/jpeg" />'
                               '<link href="%(modulepath)s?id=99%%(book_id)s" rel="x-stanza-cover-image" type="image/jpeg" />'
                               '<link href="%(modulepath)s?id=99%%(book_id)s" rel="http://opds-spec.org/thumbnail"  type="image/jpeg" />'
@@ -153,17 +156,22 @@ class webTemplate(opdsTemplate):
                               .footer {padding-top: 15pt; border-top: 2pt dotted #AAA; margin-top: 20pt; }
                               .navigation_entry {margin-left: 20pt;}
                               .navigation_entry h2 {display: inline-block;margin: 2pt 20pt 6pt -15pt; }
                               .acquisition_entry { width: 100%% }
                               .acq_link { clear: both; width: 100%%; }
                               .acq_cover { float: left; width: 20%%; }
                               .acq_infobook  { float: left; width: 80%%; }
                               .acq_info_container { clear: both; width: 100%%; }
                            </style>
                            '''
       self.document_header=('<html>'
                               '<head>'
                               '<meta charset=%(charset)s>'
                               '<title>%%(title)s</title>'
                               '<title>%%(subtitle)s</title>'
                               '%(style)s'
                               '</head>'
                               '<body>'
                               '<div class=page>'
                               '<h1>%%(subtitle)s</h1>'
                               '<h1>%%(title)s</h1>'
                               )%{'charset':self.charset,'style':self.document_style}
       self.document_footer='</div></body>'
       self.document_mainmenu_std=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=01">По каталогам</a></h2><i>Каталогов: %%(cat_num)s, книг: %%(book_num)s.</i></div>'
@@ -205,34 +213,35 @@ class webTemplate(opdsTemplate):
                               '<id>id:%(e_id)s</id>-->')
       self.document_entry_link_subsection=('<h2><a href="%(modulepath)s?id=%%(link_id)s%%(nl)s">%%(e_title)s</a></h2><i></i>'
                               )%{'modulepath':self.modulepath}
       self.document_entry_book_head=('<h2>%(e_title)s</h2>')
       self.document_entry_book_head=('<h2>%(e_title)s</h2> <i>Скачать в формате: </i>')
       self.document_entry_link_book_alternate=''
       self.document_entry_link_book=('<i><a href="%(modulepath)s?id=%%(id)s%%(link_id)s">%%(format)s</a></i>&nbsp;'
                               )%{'modulepath':self.modulepath}
       self.document_entry_authors=('<author><name>%%(last_name)s %%(first_name)s</name></author>'
                               '<link href="%(modulepath)s?id=22%%(author_id)s" rel="related" type="application/atom+xml;profile=opds-catalog" title="Все книги %%(last_name)s %%(first_name)s" />'
                               )%{'modulepath':self.modulepath}
       self.document_link_authors=('<a href="%(modulepath)s?id=22%%(author_id)s">%%(last_name)s %%(first_name)s</a>'
                               )%{'modulepath':self.modulepath}
       self.document_entry_doubles=('<link href="%(modulepath)s?id=23%%(book_id)s" rel="related" type="application/atom+xml;profile=opds-catalog" title="Дубликаты книги" />'
                               )%{'modulepath':self.modulepath}
       self.document_entry_genres='<category term="%(genre)s" label="%(genre)s" />'
       self.document_entry_genres=''
       self.document_link_genres=''
       self.document_entry_series=''
       self.document_entry_covers=('<link href="%(modulepath)s?id=99%%(book_id)s" rel="http://opds-spec.org/image" type="image/jpeg" />'
                               '<link href="%(modulepath)s?id=99%%(book_id)s" rel="x-stanza-cover-image" type="image/jpeg" />'
                               '<link href="%(modulepath)s?id=99%%(book_id)s" rel="http://opds-spec.org/thumbnail"  type="image/jpeg" />'
                               '<link href="%(modulepath)s?id=99%%(book_id)s" rel="x-stanza-cover-image-thumbnail"  type="image/jpeg" />'
       self.document_link_series=''
       self.document_entry_covers=('<br><img src="%(modulepath)s?id=99%%(book_id)s" type="image/jpeg" width="80">'
                               )%{'modulepath':self.modulepath}
       self.document_entry_content='<content type="text">%(e_content)s</content>'
       self.document_entry_content2_start='<content type="text/html">'
       self.document_entry_content2_title='&lt;b&gt;Название книги:&lt;/b&gt; %(title)s&lt;br/&gt;'
       self.document_entry_content2_authors='&lt;b&gt;Авторы:&lt;/b&gt; %(authors)s&lt;br/&gt;'
       self.document_entry_content2_genres='&lt;b&gt;Жанры:&lt;/b&gt; %(genres)s&lt;br/&gt;'
       self.document_entry_content2_series='&lt;b&gt;Серии:&lt;/b&gt; %(series)s&lt;br/&gt;'
       self.document_entry_content2_filename='&lt;b&gt;Файл:&lt;/b&gt; %(filename)s&lt;br/&gt;'
       self.document_entry_content2_filename='&lt;b&gt;Файл:&lt;/b&gt; %(filename)s&lt;br/&gt;'
       self.document_entry_content2_filesize='&lt;b&gt;Размер файла:&lt;/b&gt; %(filesize)sКб.&lt;br/&gt;'
       self.document_entry_content2_docdate='&lt;b&gt;Дата правки:&lt;/b&gt; %(docdate)s&lt;br/&gt;'
       self.document_entry_content2_annotation='&lt;p class=book&gt; %(annotation)s&lt;/p&gt;'
       self.document_entry_content2_finish='</content>'
       self.document_entry_content='<i>%(e_content)s</i>'
       self.document_entry_content2_start='<div style="content">'
       self.document_entry_content2_title='<b>Название книги:</b> %(title)s<br>'
       self.document_entry_content2_authors='<b>Авторы:</b> %(authors)s<br>'
       self.document_entry_content2_genres='<b>Жанры:</b> %(genres)s<br>'
       self.document_entry_content2_series='<b>Серии:</b> %(series)s<br>'
       self.document_entry_content2_filename='<b>Файл:</b> %(filename)s<br>'
       self.document_entry_content2_filename='<b>Файл:</b> %(filename)s<br>'
       self.document_entry_content2_filesize='<b>Размер файла:</b> %(filesize)sКб.<br>'
       self.document_entry_content2_docdate='<b>Дата правки:</b> %(docdate)s<br>'
       self.document_entry_content2_annotation='<p class="annotation">%(annotation)s</p>'
       self.document_entry_content2_finish='</div>'

       self.document_alphabet_menu=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(iid)s&amp;alpha=1%%(nl)s">А..Я (РУС)</a></h2><i></i></div>'
                                    '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(iid)s&amp;alpha=2%%(nl)s">0..9 (Цифры)</a></h2><i></i></div>'
@@ -246,3 +255,32 @@ class webTemplate(opdsTemplate):
       self.document_page_control_next=('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="next" title="Next Page" href="%(modulepath)s?id=%%(link_id)s&amp;page=%%(page)s" />'
                               )%{'modulepath':self.modulepath}


       self.document_entry_acq_start='<br><div class=acquisition_entry>\n'
       self.document_entry_acq_link_start='<div class=acq_link>'
       self.document_entry_acq_book_title=('<h2>%(e_title)s</h2> <i>Скачать в формате: </i>')
       self.document_entry_acq_book_link_alternate=''
       self.document_entry_acq_book_link=('<i><a href="%(modulepath)s?id=%%(id)s%%(link_id)s">%%(format)s</a></i>&nbsp;'
                               )%{'modulepath':self.modulepath}
       self.document_entry_acq_link_finish='</div>'

       self.document_entry_acq_info_start='<div class=acq_info_container>\n'

       self.document_entry_acq_info_cover=('<div class=acq_cover><img src="%(modulepath)s?id=99%%(link_id)s" type="image/jpeg" width="80"></div>'
                               )%{'modulepath':self.modulepath}

       self.document_entry_acq_infobook_start='<div class=acq_infobook>'
       self.document_entry_acq_infobook_title='<b>Название книги:</b> %(e_title)s<br>'
       self.document_entry_acq_infobook_authors='<b>Авторы:</b> %(authors_link)s<br>'
       self.document_entry_acq_infobook_genres='<b>Жанры:</b> %(genres)s<br>'
       self.document_entry_acq_infobook_series='<b>Серии:</b> %(series)s<br>'
       self.document_entry_acq_infobook_filename='<b>Файл:</b> %(filename)s<br>'
       self.document_entry_acq_infobook_filesize='<b>Размер файла:</b> %(filesize)sКб.<br>'
       self.document_entry_acq_infobook_docdate='<b>Дата правки:</b> %(docdate)s<br>'
       self.document_entry_acq_infobook_annotation='<p class="annotation">%(annotation)s</p>'
       self.document_entry_acq_infobook_finish='</div>'

       self.document_entry_acq_info_finish='</div>'

       self.document_entry_acq_finish='</div>'
+83 −1
Original line number Diff line number Diff line
@@ -110,6 +110,17 @@ class baseWrapper():
            authors+=last_name+' '+first_name
        return authors

    def get_authors(self,tupleAUTHORS):
        authors=""
        authors_link=""
        for (author_id,first_name,last_name) in tupleAUTHORS:
            authors_link+=self.template.document_link_authors%{'author_id':author_id,'last_name':websym(last_name,True),'first_name':websym(first_name,True)}
            if len(authors)>0:
               authors+=', '
            authors+=last_name+' '+first_name
        return (authors, authors_link)


    def entry_doubles(self,book_id,dcount):
        if dcount>0:
           self.add_response_body(self.template.document_entry_doubles%{'book_id':book_id})
@@ -123,6 +134,15 @@ class baseWrapper():
            genres+=genre
        return genres

    def get_genres(self,tupleGENRES):
        genres=""
        genres_link=""
        for (section,genre) in tupleGENRES:
            genres_link+=self.template.document_link_genres%{'genre':genre}
            if len(genres)>0:
                  genres+=', '
            genres+=genre
        return (genres, genres_link)

    def entry_series(self,tupleSERIES):
        series=""
@@ -135,6 +155,18 @@ class baseWrapper():
                  series += ' #' + str(ser_no)
        return series

    def get_series(self,tupleSERIES):
        series=""
        series_link=""
        for (ser,ser_no) in tupleSERIES:
            series_link+=self.template.document_link_series%{'ser':ser,'ser_no':ser_no}
            if len(series)>0:
                  series+=', '
            series+=ser
            if ser_no > 0:
                  series += ' #' + str(ser_no)
        return (series, series_link)

    def entry_covers(self,book_id):
        self.add_response_body(self.template.document_entry_covers%{'book_id':book_id})

@@ -161,10 +193,60 @@ class baseWrapper():
           self.add_response_body(self.template.document_entry_content2_annotation%{'annotation':websym(annotation)})
        self.add_response_body(self.template.document_entry_content2_finish)    


    def entry_finish(self):
        self.add_response_body(self.template.document_entry_finish)

    def entry_acq_link_book(self,acq_data):
        data=acq_data.copy()
        if data['e_date']==None:
           data['e_date']=datetime.datetime(2001,9,9,0,0,0)
        self.add_response_body(self.template.document_entry_acq_book_title%data)
        self.add_response_body(self.template.document_entry_acq_book_link_alternate%data)
        data['id']=91
        self.add_response_body(self.template.document_entry_acq_book_link%data)
        data['id']=92
        data['format']=data['format']+'.zip'
        self.add_response_body(self.template.document_entry_acq_book_link%data)
        if acq_data['format'].lower()=='fb2' and self.cfg.FB2TOEPUB:
           data['id']=93
           data['format']='epub'
           self.add_response_body(self.template.document_entry_acq_book_link%data)
        if acq_data['format'].lower()=='fb2' and self.cfg.FB2TOMOBI:
           data['id']=94
           data['format']='mobi'
           self.add_response_body(self.template.document_entry_acq_book_link%data)

    def entry_acq_info_book(self,acq_data):
        self.add_response_body(self.template.document_entry_acq_infobook_start)
        if acq_data['e_title']!='':
           self.add_response_body(self.template.document_entry_acq_infobook_title%acq_data)
        if acq_data['authors']!='':
           self.add_response_body(self.template.document_entry_acq_infobook_authors%acq_data)
        if acq_data['genres']!='':
           self.add_response_body(self.template.document_entry_acq_infobook_genres%acq_data)
        if acq_data['series']!='':
           self.add_response_body(self.template.document_entry_acq_infobook_series%acq_data)
        if acq_data['filename']!='':
           self.add_response_body(self.template.document_entry_acq_infobook_filename%acq_data)
        if acq_data['filesize']>0:
           self.add_response_body(self.template.document_entry_acq_infobook_filesize%acq_data)
        if acq_data['docdate']!='':
           self.add_response_body(self.template.document_entry_acq_infobook_docdate%acq_data)
        if acq_data['annotation']!='':
           self.add_response_body(self.template.document_entry_acq_infobook_annotation%acq_data)
        self.add_response_body(self.template.document_entry_acq_infobook_finish)

    def entry_acquisition(self,acq_data):
        self.add_response_body(self.template.document_entry_acq_start%acq_data)
        self.add_response_body(self.template.document_entry_acq_link_start%acq_data)
        self.entry_acq_link_book(acq_data)
        self.add_response_body(self.template.document_entry_acq_link_finish%acq_data)
        self.add_response_body(self.template.document_entry_acq_info_start%acq_data)
        self.add_response_body(self.template.document_entry_acq_info_cover%acq_data)
        self.entry_acq_info_book(acq_data)
        self.add_response_body(self.template.document_entry_acq_info_finish%acq_data)
        self.add_response_body(self.template.document_entry_acq_finish%acq_data)

    def page_control_prev(self, page, link_id):
           self.add_response_body(self.template.document_page_control_prev%{'link_id':link_id,'page':page-1})