[Hejes-devel] [914] - blog/manage: no right sidebar for easier usage

hejes-devel at nytud.hu hejes-devel at nytud.hu
Wed Aug 28 18:36:39 CEST 2013


Revision: 914
Author:   mihaltz
Date:     2013-08-28 18:36:39 +0200 (Wed, 28 Aug 2013)
Log Message:
-----------
- blog/manage: no right sidebar for easier usage
- blog/index: show only 1st paragraph of body for each post; format using MARKMIN
- blog/show: categories and tags formatted like on index page
- blog/show+index: link on main image to index
- blog/index: show status message if a tag or a category was selected
- blog/index: pager (TODO: don't show all page numbers if npages > 5 or so, e.g. << 1 | 2 | 3 ... 5 | 6 >>)

Modified Paths:
--------------
    trunk/web2py/applications/helyesiras_webdev/controllers/blog.py
    trunk/web2py/applications/helyesiras_webdev/databases/storage.sqlite
    trunk/web2py/applications/helyesiras_webdev/progress.log
    trunk/web2py/applications/helyesiras_webdev/views/blog/index.html
    trunk/web2py/applications/helyesiras_webdev/views/blog/show.html
    trunk/web2py/applications/helyesiras_webdev/views/layout.html

Modified: trunk/web2py/applications/helyesiras_webdev/controllers/blog.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/controllers/blog.py	2013-08-28 11:00:33 UTC (rev 913)
+++ trunk/web2py/applications/helyesiras_webdev/controllers/blog.py	2013-08-28 16:36:39 UTC (rev 914)
@@ -5,20 +5,25 @@
 @author MM
 """
 
+from util import safeint
 
+
 def index():
   """Starting page for the blog.
      returns following keys:
      posts: Rows object with most recent 5 blog posts
      categories: Rows object with all category names and ids (for sidebar)
      tags: Rows object with all tag names and ids (for sidebar)
+     ntotal: total number of posts available
+     page: page number (1...) for pagination
+     perpage: number of posts per page
      TODO:
      check GET vars (category, tag(s?)) and filter posts accordingly
   """
   # all categories & tags for sidebar
   cats = dbblog().select(dbblog.categories.ALL, orderby=dbblog.categories.id)
   tags = dbblog().select(dbblog.tags.ALL, orderby=dbblog.tags.name)
-  # assemble query: last 5 posts, filtered by category or tag specified via args
+  # assemble query:  posts filtered by category or tag specified via args
   query = dbblog.posts.category == dbblog.categories.id
   usercat = request.vars.get('category')
   if usercat:
@@ -26,9 +31,18 @@
   usertag = request.vars.get('tag')
   if usertag:
     query &= (dbblog.posts.tags.contains(usertag))
-  # execute query
-  posts = dbblog(query).select(orderby=~dbblog.posts.created_on, limitby=(0, 5))
-  return dict(categories=cats, tags=tags, posts=posts)
+  # prepare pagination
+  rset = dbblog(query)
+  ntotal = rset.count()
+  perpage = 5
+  npages = (ntotal / perpage) + (1 if ntotal % perpage > 0 else 0)
+  tmp = safeint(request.vars.get('page'))
+  page = tmp if tmp != None and tmp > 0 and tmp <= npages else 1
+  offset = (page - 1) * perpage
+  limitby = (offset, offset + perpage)  
+  # fetch desired rows
+  posts = rset.select(orderby=~dbblog.posts.created_on, limitby=limitby)
+  return dict(categories=cats, tags=tags, posts=posts, ntotal=ntotal, page=page, perpage=perpage)
 
 
 def show():
@@ -60,5 +74,3 @@
   """
   grid = SQLFORM.grid(dbblog.posts)
   return dict(grid=grid)
-  
-  

Modified: trunk/web2py/applications/helyesiras_webdev/databases/storage.sqlite
===================================================================
(Binary files differ)

Modified: trunk/web2py/applications/helyesiras_webdev/progress.log
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/progress.log	2013-08-28 11:00:33 UTC (rev 913)
+++ trunk/web2py/applications/helyesiras_webdev/progress.log	2013-08-28 16:36:39 UTC (rev 914)
@@ -663,3 +663,80 @@
 [2013-08-09 15:47:13] EDIT helyesiras_webdev/views/layout.html: 0
 [2013-08-14 10:37:02] EDIT helyesiras_webdev/views/default/suggest.html: 0
 [2013-08-14 10:37:32] EDIT helyesiras_webdev/views/default/suggest.html: 0
+[2013-08-28 16:02:15] EDIT helyesiras_webdev/views/layout.html: 2
+[2013-08-28 16:10:36] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 16:11:04] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 16:25:38] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 16:28:12] EDIT helyesiras_webdev/views/blog/show.html: 0
+[2013-08-28 16:28:23] EDIT helyesiras_webdev/views/blog/show.html: 0
+[2013-08-28 16:29:39] EDIT helyesiras_webdev/views/blog/show.html: 2
+[2013-08-28 16:30:57] EDIT helyesiras_webdev/views/blog/show.html: 2
+[2013-08-28 16:31:11] EDIT helyesiras_webdev/views/blog/show.html: 0
+[2013-08-28 16:31:18] EDIT helyesiras_webdev/views/blog/show.html: 0
+[2013-08-28 16:36:13] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 16:37:18] EDIT helyesiras_webdev/views/blog/show.html: 0
+[2013-08-28 17:01:20] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 17:12:30] EDIT helyesiras_webdev/views/blog/index.html: 3
+[2013-08-28 17:13:37] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 17:15:11] EDIT helyesiras_webdev/views/blog/index.html: 2
+[2013-08-28 17:15:35] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 17:17:34] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 17:41:54] EDIT helyesiras_webdev/controllers/blog.py: 10
+[2013-08-28 17:41:58] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-08-28 17:42:38] EDIT helyesiras_webdev/controllers/blog.py: 1
+[2013-08-28 17:43:23] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-08-28 17:44:23] EDIT helyesiras_webdev/controllers/blog.py: -1
+[2013-08-28 17:45:04] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-08-28 17:47:21] EDIT helyesiras_webdev/controllers/blog.py: 3
+[2013-08-28 17:47:34] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-08-28 17:48:52] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-08-28 17:49:14] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-08-28 17:49:27] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-08-28 17:49:47] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-08-28 17:53:17] EDIT helyesiras_webdev/views/blog/index.html: 11
+[2013-08-28 18:03:24] EDIT helyesiras_webdev/views/blog/index.html: 13
+[2013-08-28 18:03:39] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:03:58] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:04:06] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:04:36] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:07:49] EDIT helyesiras_webdev/views/blog/index.html: -9
+[2013-08-28 18:08:37] EDIT helyesiras_webdev/views/blog/index.html: 2
+[2013-08-28 18:09:12] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:10:52] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:11:31] EDIT helyesiras_webdev/views/blog/index.html: 2
+[2013-08-28 18:12:17] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:12:46] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:13:47] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:14:23] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:15:39] EDIT helyesiras_webdev/views/blog/index.html: 1
+[2013-08-28 18:15:48] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:16:03] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:16:30] EDIT helyesiras_webdev/views/blog/index.html: 3
+[2013-08-28 18:17:16] EDIT helyesiras_webdev/views/blog/index.html: -7
+[2013-08-28 18:18:47] EDIT helyesiras_webdev/views/blog/index.html: 2
+[2013-08-28 18:20:44] EDIT helyesiras_webdev/views/blog/index.html: 4
+[2013-08-28 18:20:59] EDIT helyesiras_webdev/views/blog/index.html: -3
+[2013-08-28 18:21:47] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:21:50] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:22:55] EDIT helyesiras_webdev/views/blog/index.html: -3
+[2013-08-28 18:23:25] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:23:57] EDIT helyesiras_webdev/views/blog/index.html: -3
+[2013-08-28 18:24:10] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:24:59] EDIT helyesiras_webdev/views/blog/index.html: 3
+[2013-08-28 18:25:02] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:25:30] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:26:01] EDIT helyesiras_webdev/views/blog/index.html: 2
+[2013-08-28 18:26:19] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:26:49] EDIT helyesiras_webdev/views/blog/index.html: -1
+[2013-08-28 18:26:57] EDIT helyesiras_webdev/views/blog/index.html: -1
+[2013-08-28 18:27:11] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:27:37] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:28:26] EDIT helyesiras_webdev/views/blog/index.html: 3
+[2013-08-28 18:28:41] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:29:10] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:29:28] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:30:28] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:32:25] EDIT helyesiras_webdev/views/blog/index.html: -1
+[2013-08-28 18:32:48] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:32:59] EDIT helyesiras_webdev/views/blog/index.html: 0
+[2013-08-28 18:33:00] EDIT helyesiras_webdev/views/blog/index.html: 0

Modified: trunk/web2py/applications/helyesiras_webdev/views/blog/index.html
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/views/blog/index.html	2013-08-28 11:00:33 UTC (rev 913)
+++ trunk/web2py/applications/helyesiras_webdev/views/blog/index.html	2013-08-28 16:36:39 UTC (rev 914)
@@ -2,6 +2,22 @@
 
 {{from util import pretty_hu_date}}
 
+{{def page_url(p):
+  # return URL string of p`th page with current category or tag filtering
+  v = dict()
+  cat = request.vars.get('category')
+  if cat:
+    v['category'] = cat
+  pass
+  tag = request.vars.get('tag')
+  if tag:
+    v['tag'] = tag
+  pass
+  v['page'] = str(p)
+  return URL(c='blog', f='index', vars=v)
+}}
+
+
 {{block blog_sidebar-first}}
   <h4 class="sidebar-title">Rovatok</h4>
     <div class="sidebar-cats">
@@ -29,8 +45,14 @@
 <div id="blog-container">
 
 {{#=response.toolbar()}}
-    <img src="http://htp-devel.nytud.hu/helyesiras_webdev/static/images/blog_h.png">
+<a href="{{=URL(c='blog', f='index')}}"> <img src="http://htp-devel.nytud.hu/helyesiras_webdev/static/images/blog_h.png"> </a>
 
+{{if request.vars.get('tag'):}}
+  <div class="status-msg">A következő címkéjű bejegyzések láthatók: <b>{{=request.vars.get('tag')}}</b>. <a href="{{=URL(c='blog', f='index')}}">Összes bejegyzés megjelenítése</a></div>
+{{elif request.vars.get('category'):}}
+  <div class="status-msg">A következő kategóriába tartozó bejegyzések láthatók: <b>{{=request.vars.get('category')}}</b>. <a href="{{=URL(c='blog', f='index')}}">Összes bejegyzés megjelenítése</a></div>
+{{pass}}
+
 {{for i, row in enumerate(posts):}}
   <div class="blog-list{{if i == 0:}} first{{pass}}{{if i == len(posts)-1:}} last{{pass}}">
     <img src="{{=row.posts.image_url}}" width=100 height=100></img>
@@ -38,7 +60,7 @@
         <div class="blog-cat-name"><span>{{=row.categories.name}}</span></div>
     	<h2>{{=A(row.posts.title, _href=URL(c='blog', f='show', args=[row.posts.slug]))}}</h2>
    	 	<div class="blog-date">{{=pretty_hu_date(row.posts.created_on).encode('utf8')}}</div>
-   	 	<div class="blog-body">{{=row.posts.body}}</div>
+   	 	<div class="blog-body">{{=MARKMIN(row.posts.body.split('\n')[0])}}</div>
     	<div class="blog-read-more">{{=A('Tovább', _href=URL(c='blog', f='show', args=[row.posts.slug]))}}</div>
     </div>
     </div>
@@ -46,13 +68,18 @@
   {{pass}}
 {{pass}}
 
-{{ # pager: TODO }}
 <div class="pager">
-<span>◂</span>
-<span>1</span>
-<span>|</span>
-<span><a href="{{=URL(c='blog', f='index')}}">2</a></span>
-<span><a href="{{=URL(c='blog', f='index')}}">▸</a></span>
-</div>
+  {{npages = (ntotal / perpage) + (1 if ntotal % perpage > 0 else 0)}}
+  <span>{{ = XML('◂') if page == 1 else A(XML('◂'), _href=page_url(page - 1))}}</span>
+  {{ # TODO: don't list all page numbers if npages > 5, e.g. << 1 | 2 | 3 ... 5 | 6 >> }}
+  {{for i in range(1, npages + 1):}}
+    <span>{{= i if i == page else A(i, _href=page_url(i))}}</span>
+    {{if i < npages:}}
+      <span>{{= '|'}}</span>
+    {{pass}}
+  {{pass}}
+  <span>{{ = XML('▸') if page == npages else A(XML('▸'), _href=page_url(page + 1))}}</span>  
+</div> <!-- <div class="pager"> -->
 
+
 </div> <!-- <div id="blog-container"> -->

Modified: trunk/web2py/applications/helyesiras_webdev/views/blog/show.html
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/views/blog/show.html	2013-08-28 11:00:33 UTC (rev 913)
+++ trunk/web2py/applications/helyesiras_webdev/views/blog/show.html	2013-08-28 16:36:39 UTC (rev 914)
@@ -3,21 +3,27 @@
 {{from util import pretty_hu_date}}
 
 {{block blog_sidebar-first}}
-  <div>Rovatok</div>
-  {{for row in categories:}}
-    <div>{{=A(row.name, _href=URL(c='blog', f='index', vars={'category': row.name}))}}</div>
-  {{pass}}
-  <div>Címkék</div>
-  {{for row in tags:}}
-    <div>{{=A(row.name, _href=URL(c='blog', f='index', vars={'tag': row.name}))}} ({{=len(row.posts)}})</div>
-  {{pass}}
+  <h4 class="sidebar-title">Rovatok</h4>
+  <div class="sidebar-cats">
+    {{for row in categories:}}
+      {{=A(row.name, _href=URL(c='blog', f='index', vars={'category': row.name}))}}
+    {{pass}}
+  </div>
+  <h4 class="sidebar-title">Címkék</h4>
+  <div class="sidebar-tags">
+    {{for row in tags:}}
+      {{=A(row.name, _href=URL(c='blog', f='index', vars={'tag': row.name}))}} ({{=len(row.posts)}})
+    {{pass}}
+  </div>
 {{end}}
 
 
 <div id="blog-container">
 
 {{#=response.toolbar()}}
-    <img src="http://htp-devel.nytud.hu/helyesiras_webdev/static/images/blog_h.png">
+<a href="{{=URL(c='blog', f='index')}}"> <img src="http://htp-devel.nytud.hu/helyesiras_webdev/static/images/blog_h.png"> </a>
+    
+    
 <div class="blog-head">
 	<h1>{{=post.posts.title}}</h1>
 	<div class="blog-cat-name">{{=post.categories.name}}</div>

Modified: trunk/web2py/applications/helyesiras_webdev/views/layout.html
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/views/layout.html	2013-08-28 11:00:33 UTC (rev 913)
+++ trunk/web2py/applications/helyesiras_webdev/views/layout.html	2013-08-28 16:36:39 UTC (rev 914)
@@ -166,8 +166,10 @@
 	});
     
 	</script>
-	
 
+
+{{ if not (request.controller == 'blog' and request.function == 'manage'): }}
+
 <div id="helyesiras-widget-2">
 	<dl>
 	    <dt>
@@ -194,8 +196,9 @@
 	</dl>
 </div>      
       
+{{ pass }}      
+
       
-      
 {{if not ((request.controller == 'default' and request.function == 'index') or (request.controller == 'blog' and request.function == 'manage')):}}
       <div id="sidebar-first">
 {{if request.controller == 'default' and request.function not in ['akh', 'gyik', 'hqa', 'howitworks']:}}




More information about the Hejes-devel mailing list