Commit a611dc25 authored by Shelepnev Dmitry's avatar Shelepnev Dmitry
Browse files

Попал в архитектурную проблему с лентой SelectSeriesFeed...Видимо нужно делать редизайн лент

parent 6dd08647
Loading
Loading
Loading
Loading
+87 −6
Original line number Diff line number Diff line
@@ -336,26 +336,43 @@ class SearchBooksFeed(AuthFeed):
    def title(self, obj):
        return "%s | %s"%(settings.TITLE,_("Books found"))    

    def get_object(self, request, searchterms, searchtype, page=1):
    def get_object(self, request, searchterms, searchterms0, searchtype, page=1):
        if not isinstance(page, int):
            page = int(page)
        
        # Поиск книг по подсроке
        if  searchtype == 'books':
            books = Book.objects.extra(where=["upper(title) like %s"], params=["%%%s%%"%searchterms.upper()])
        # Поиск книг по начальной подстроке
        elif searchtype == 'sbooks':
            books = Book.objects.extra(where=["upper(title) like %s"], params=["%s%%"%searchterms.upper()])
        # Поиск книг по автору
        elif searchtype == 'abooks':
            try:
                author_id = int(searchterms)
            except:
                author_id = 0
            books = Book.objects.filter(authors=author_id)
        # Поиск книг по серии
        elif searchtype == 'rbooks':
            try:
                ser_id = int(searchterms)
            except:
                ser_id = 0
            books = Book.objects.filter(series=ser_id)    
        # Поиск книг по автору и серии
        elif searchtype == 'vbooks':
            try:
                ser_id = int(searchterms0)
            except:
                ser_id = 0
            try:
                author_id = int(searchterms)
            except:
                author_id = 0  

            books = Book.objects.filter(author=author_id, series=ser_id)
       
        return {"books":books, "searchterms":searchterms, "searchtype":searchtype, "page":page}

    def link(self, obj):
@@ -413,6 +430,61 @@ class SearchBooksFeed(AuthFeed):
        return {'authors':item.authors.all(),
                'genres':item.genres.all()}        

class SelectSeriesFeed(AuthFeed):
    feed_type = opdsFeed
    subtitle = settings.SUBTITLE
    
    def title(self, obj):
        return "%s | %s"%(settings.TITLE,_("Series by authors select")) 

    def get_object(self, request, searchtype, searchterms):
        try:
            author_id=int(searchterms)
        except:
            author_id = 0
        return author_id
    
    def link(self, obj):
        return reverse("opds_catalog:searchbooks",kwargs={'searchtype':'asbooks','searchterms':obj})

    def feed_extra_kwargs(self, obj):
        return {
                "searchTerm_url":"/opds/search/{searchTerms}/",
                "start_url":reverse("opds_catalog:main"),
                "description_mime_type":"text",
        }

    def items(self, obj):
        return [
                    {"id":1, "title":_("Books by series"), "author":obj, "descr": _("Books by author and series")},
                    {"id":2, "title":_("Books outside series"), "author":obj, "descr": _("Books by author outside series")},
                    {"id":3, "title":_("Books by alphabet"), "author":obj, "descr": _("Books by author alphabetical order")},
        ]

    def item_link(self, item):
        if item["id"] == 1:
           return reverse("opds_catalog:searchseries", kwargs={"searchtype":'aseries', "searchterms":item["author"]})
        elif item["id"] == 2:
           return reverse("opds_catalog:searchbooks", kwargs={"searchtype":'abooks', "searchterms":item["author"]})
        elif item["id"] == 3:
           return reverse("opds_catalog:searchbooks", kwargs={"searchtype":'abooks', "searchterms":item["author"]})
             
    def item_title(self, item):
        return item['title']

    def item_description(self, item):
        return item['descr']

    def item_guid(self, item):
        return "as:%s"%item["id"]

    def item_updateddate(self):
        return timezone.now()

    def item_enclosures(self, item):
        return (opdsEnclosure(self.item_link(item),"application/atom+xml;profile=opds-catalog;kind=navigation", "subsection"),)

            
class SearchAuthorsFeed(AuthFeed):
    feed_type = opdsFeed
    subtitle = settings.SUBTITLE
@@ -473,7 +545,7 @@ class SearchAuthorsFeed(AuthFeed):
        return "a:%s"%(item.id)

    def item_link(self, item):
        return reverse("opds_catalog:searchbooks", kwargs={"searchtype":'abooks', "searchterms":item.id}) 
        return reverse("opds_catalog:searchbooks", kwargs={"searchtype":'asbooks', "searchterms":item.id}) 

    def item_enclosures(self, item):
        return (opdsEnclosure(self.item_link(item),"application/atom+xml;profile=opds-catalog;kind=navigation", "subsection"),)
@@ -493,6 +565,14 @@ class SearchSeriesFeed(AuthFeed):
            series = Series.objects.extra(where=["upper(ser) like %s"], params=["%%%s%%"%searchterms.upper()])
        elif searchtype == 'sseries':
            series = Series.objects.extra(where=["upper(ser) like %s"], params=["%s%%"%searchterms.upper()]) 
        elif searchtype == 'aseries':
            try:
                author_id = int(searchterms)
                books = Book.objects.filter(authors=author_id)
            except:
                books = None
              
            series = Series.objects.filter(book__in=books)                 

        return {"series":series, "searchterms":searchterms, "searchtype":searchtype, "page":page}

@@ -588,6 +668,7 @@ class LangFeed(AuthFeed):
    def item_enclosures(self, item):
        return (opdsEnclosure(self.item_link(item),"application/atom+xml;profile=opds-catalog;kind=navigation", "subsection"),)


class BooksFeed(AuthFeed):
    feed_type = opdsFeed
    subtitle = settings.SUBTITLE
+3 −0
Original line number Diff line number Diff line
@@ -26,8 +26,11 @@ urlpatterns = [
    url(r'^bookshelf/',feeds.MainFeed(), name='bookshelf'),
    url(r'^search/$',feeds.OpenSearch, name='opensearch'),

    url(r'^search/(?P<searchtype>asbooks)/(?P<searchterms>.+)/',feeds.SelectSeriesFeed(), name='searchbooks'), 
    url(r'^search/(?P<searchtype>.*books)/(?P<searchterms>.+)/(?P<page>\d+)/',feeds.SearchBooksFeed(), name='searchbooks'),
    url(r'^search/(?P<searchtype>.*books)/(?P<searchterms>.+)/',feeds.SearchBooksFeed(), name='searchbooks'),    
    url(r'^search/(?P<searchtype>.*books)/(?P<searchterms>.+)/(?P<searchterms0>.+)/(?P<page>\d+)/',feeds.SearchBooksFeed(), name='searchbooks'),
    url(r'^search/(?P<searchtype>.*books)/(?P<searchterms>.+)/(?P<searchterms0>.+)/',feeds.SearchBooksFeed(), name='searchbooks'),
    
    url(r'^search/(?P<searchtype>.*authors)/(?P<searchterms>.+)/(?P<page>\d+)/',feeds.SearchAuthorsFeed(), name='searchauthors'),
    url(r'^search/(?P<searchtype>.*authors)/(?P<searchterms>.+)/',feeds.SearchAuthorsFeed(), name='searchauthors'),