Commits

Yang Zhang committed dbd5026

change main page, add get_last_update_books

Comments (0)

Files changed (5)

 #url process and method
 @app.route('/')
 def index():
-    books = Book.get_books()
-    return render_template('index.html', books = books, nav_name='home')
+    hotbooks = Book.get_books(limit = 5)
+    lastbooks = Book.get_last_updatedbooks(limit = 5)
+    return render_template('index.html', hotbooks = hotbooks,lastbooks=lastbooks, nav_name='home')
 
 
 @app.route('/more')
         abort(404)
     label = request.args.get("label",None)
     if(label is None): abort(404)
-    books = Book.get_books_bylabel(label, offset = page -1)
+    if(label ==u'最近更新'):
+        books = Book.get_last_updatedbooks(offset = page -1)
+    else:
+        books = Book.get_books_bylabel(label, offset = page -1)
     if(len(books) == 0): abort(404)
     return render_template('category.html', books = books, nav_name='category', currentlabel =label, cuurentpage = page)
 
     intro           Text,
     cover_image     BLOB,
     last_chapter    VARCHAR,
-    update_date     TIMESTAMP
+    update_date     TIMESTAMP.
+    hot_score       INTEGER DEFAULT 0
 );
 --ALTER TABLE book ADD update_date TIMESTAMP;
-
+--ALTER TABLE book ADD hot_score INTEGER DEFAULT 0;
 CREATE TABLE label(
     name            VARCHAR,
     bookid          INTEGER,
     @staticmethod
     def get_last_updatedbooks(limit = 15, offset = 0):
         c = g.db.cursor()
-        c.execute("SELECT id,name ,last_chapter WHERE update_date is not null\
-                    FROM book ORDER BY id LIMIT :limit OFFSET :offset",{'limit':limit,'offset':limit*offset})
+        c.execute("SELECT id,name ,last_chapter FROM book \
+                        WHERE update_date is not null \
+                        ORDER BY hot_score DESC,update_date DESC LIMIT :limit OFFSET :offset",{'limit':limit,'offset':limit*offset})
         results = c.fetchall()
         tempbooks = []
         if(results is None):

templates/category_select.html

         <div class='span2'>
             <span class='btn span1 {%if "完结" ==currentlabel%} btn-danger{%endif%}' onclick='getCategory(this)'>完结</span>
         </div>
+        <div class='span2'>
+            <span class='btn span1 {%if "最近更新" ==currentlabel%} btn-danger{%endif%}' onclick='getCategory(this)'>最近更新</span>
+        </div>
+        
     </div>
     
     <div class='row category_name'>

templates/index.html

         <div class="divider-arrow"></div>
         <h3  class="color2">热门连载漫画 <a href='/more'><small>查看更多</small></a></h3>
     </div>
-    {%for book in books%}
+    {%for book in hotbooks%}
         <div class="span2">
             <div class="thumbnail">
                 <a href="/showbook?id={{book.id}}"><img src="/static/covers/{{book.id}}.jpg" style='height: 170px;'></a>
     {%endfor%}
     
 </div>
+
+<div class="span11 special-offset" style="margin-top:20px;">
+    <div class="title-divider span11">
+        <div class="divider-arrow"></div>
+        <h3  class="color2">最近更新漫画 <a href='/category?label=最近更新'><small>查看更多</small></a></h3>
+    </div>
+    {%for book in lastbooks%}
+        <div class="span2">
+            <div class="thumbnail">
+                <a href="/showbook?id={{book.id}}"><img src="/static/covers/{{book.id}}.jpg" style='height: 170px;'></a>
+            </div>
+            <div class="vSpace align_center">
+                    <h4 class="ellipsis"><a href="/showbook?id={{book.id}}">{{book.name}}</a></h4>
+                    <p>更新至{{book.last_chapter}}</p>
+            </div>
+        </div>
+    {%endfor%}
+    
+</div>
+
+
 {%endblock%}