Commit 55d30e15 authored by mitshel's avatar mitshel
Browse files

Завершена выдача поавторам с обработкой серий

parent 79b77cf2
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ def authors_submenu(author_id):
   enc_print('<id>id:31:authors</id></entry>')
   enc_print('<entry>')
   enc_print('<title>Книги вне серий</title>')
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id=32'+str(author_id)+'"/>')
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+cfg.CGI_PATH+'?id=34'+str(author_id)+'"/>')
   enc_print('<id>id:32:authors</id></entry>')
   enc_print('<entry>')
   enc_print('<title>Книги по алфавиту</title>')
@@ -322,6 +322,7 @@ locale.setlocale(locale.LC_ALL,'ru_RU.UTF-8')
type_value=0
slice_value=0
page_value=0
ser_value=0
alpha=0
news=0
np=0
@@ -356,6 +357,10 @@ if 'news' in form:
   news=1
   nl='&amp;news=1'
   np=cfg.NEW_PERIOD
if 'ser' in form:
   ser=form.getvalue("ser","0")
   if ser.isdigit():
      ser_value=int(ser)

opdsdb=sopdsdb.opdsDatabase(cfg.DB_NAME,cfg.DB_USER,cfg.DB_PASS,cfg.DB_HOST,cfg.ROOT_LIB)
opdsdb.openDB()
@@ -686,7 +691,7 @@ if type_value==22 and np==0:
if type_value==31:
   (first_name,last_name)=opdsdb.getauthor_name(slice_value)
   header_authors('Сериии книг автора %s %s'%(last_name,first_name))
   for (ser_id,ser,cnt) in opdsdb.getseriesforauthor(slice_value,cfg.MAXITEMS,page_value):
   for (ser_id,ser,cnt) in opdsdb.getseriesforauthor(slice_value,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW):
       id='34'+str(slice_value)+'&amp;ser='+str(ser_id)
       entry_start()
       entry_head(ser, None, id_value)
@@ -715,6 +720,25 @@ if type_value==33 or (type_value==22 and np!=0):
   page_control(opdsdb,page_value,id_value)
   footer()

#########################################################
# Выдача списка книг по автору по выбранной серии (или вне серий если ser_value==0)
#
if type_value==34:
   header()
   for (book_id,book_name,book_path,reg_date,book_title,annotation,docdate,format,fsize,cover,cover_type) in opdsdb.getbooksforautorser(slice_value,ser_value,cfg.MAXITEMS,page_value,cfg.DUBLICATES_SHOW):
       id='90'+str(book_id)
       entry_start()
       entry_head(book_title, reg_date, id_value)
       entry_link_book(book_id,format)
       entry_covers(cover,cover_type,book_id)
       authors=entry_authors(opdsdb,book_id,True)
       genres=entry_genres(opdsdb,book_id)
       series=entry_series(opdsdb,book_id)
       entry_content2(annotation,book_title,authors,genres,book_name,fsize,docdate,series)
       entry_finish()
   page_control(opdsdb,page_value,id_value)
   footer()

#########################################################
# Выдача списка книг по серии
#
+41 −3
Original line number Diff line number Diff line
@@ -548,16 +548,54 @@ class opdsDatabase:
    cursor.close
    return rows

  def getseriesforauthor(self,author_id,limit=0,page=0):
  def getbooksforautorser(self,author_id,ser_id,limit=0,page=0,doublicates=True):
    if limit==0: limitstr=""
    else: limitstr="limit "+str(limit*page)+","+str(limit)
    if doublicates: dstr=''
    else: dstr=' and a.doublicat=0 '
    if ser_id!=0:
       sql=("select SQL_CALC_FOUND_ROWS a.book_id,a.filename,a.path,a.registerdate,a.title,a.annotation,a.docdate,a.format,a.filesize,a.cover,a.cover_type "
       "from "+TBL_BOOKS+" a "
       "left join "+TBL_BAUTHORS+" b on a.book_id=b.book_id "
       "left join "+TBL_BSERIES +" c on a.book_id=c.book_id "
       "where author_id=%s and ser_id=%s and a.avail!=0 "+dstr+" order by a.title "+limitstr)
       data=(author_id,ser_id)
    else:
       sql=("select SQL_CALC_FOUND_ROWS a.book_id,a.filename,a.path,a.registerdate,a.title,a.annotation,a.docdate,a.format,a.filesize,a.cover,a.cover_type "
       "from "+TBL_BOOKS+" a "
       "left join "+TBL_BAUTHORS+" b on a.book_id=b.book_id "
       "left outer join "+TBL_BSERIES +" c on a.book_id=c.book_id "
       "where author_id=%s and ser_id is NULL and a.avail!=0 "+dstr+" order by a.title "+limitstr)
       data=(author_id,)
       
    cursor=self.cnx.cursor()
    cursor.execute(sql,data)
    rows=cursor.fetchall()

    cursor.execute("SELECT FOUND_ROWS()")
    found_rows=cursor.fetchone()
    if found_rows[0]>limit*page+limit:
       self.next_page=True
    else:
       self.next_page=False

    cursor.close
    return rows

  def getseriesforauthor(self,author_id,limit=0,page=0,doublicates=True):
    if limit==0: limitstr=""
    else: limitstr="limit "+str(limit*page)+","+str(limit)
    if doublicates: dstr=''
    else: dstr=' and doublicat=0 '

    sql=("select SQL_CALC_FOUND_ROWS a.ser_id, a.ser, count(*) from "+TBL_SERIES+" a "
    "left join "+TBL_BSERIES+" b on a.ser_id=b.ser_id "
    "left join "+TBL_BAUTHORS+" c on b.book_id=c.book_id "
    "where author_id="+str(author_id)+" group by 1,2 order by a.ser "+limitstr)
    "left join "+TBL_BOOKS+" d on b.book_id=d.book_id "
    "where author_id=%s and avail!=0 "+dstr+" group by 1,2 order by a.ser "+limitstr)
    data=(author_id,)
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    cursor.execute(sql,data)
    rows=cursor.fetchall()

    cursor.execute("SELECT FOUND_ROWS()")