[Hejes-devel] [934] right sidebar: nyest.hu/rss/hirek top 5 posts loads with Ajax :)
hejes-devel at nytud.hu
hejes-devel at nytud.hu
Wed Sep 11 18:35:23 CEST 2013
Revision: 934
Author: mihaltz
Date: 2013-09-11 18:35:23 +0200 (Wed, 11 Sep 2013)
Log Message:
-----------
right sidebar: nyest.hu/rss/hirek top 5 posts loads with Ajax :)
Modified Paths:
--------------
trunk/web2py/applications/helyesiras_webdev/controllers/blog.py
trunk/web2py/applications/helyesiras_webdev/views/right_sidebar.html
Added Paths:
-----------
trunk/web2py/applications/helyesiras_webdev/views/blog/nyest_hirek.load
Modified: trunk/web2py/applications/helyesiras_webdev/controllers/blog.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/controllers/blog.py 2013-09-11 15:02:19 UTC (rev 933)
+++ trunk/web2py/applications/helyesiras_webdev/controllers/blog.py 2013-09-11 16:35:23 UTC (rev 934)
@@ -5,9 +5,11 @@
@author MM
"""
+
from util import safeint
from blogutil import get_feed
+
EXCEPTIONMSG = 'Elnézést kérünk, váratlan hiba történt. Kérjük, próbálkozzon újra később.'
"""Flashed when an exception is caught in any controller. If emtpy string, no flashing."""
@@ -81,8 +83,8 @@
@auth.requires_login()
def manage():
- """Show an SQLFORM.smartgrid to manage dbblog.posts or .categories.
- With no arguments, posts is the default, otherwise generate smartgrid for table args[0].
+ """Show an SQLFORM.smartgrid to manage dbblog.posts or dbblog.categories.
+ With no arguments, table posts is the default, otherwise generate smartgrid for table args[0].
"""
if len(request.args) == 0:
request.args.append('posts')
@@ -98,7 +100,7 @@
def feed():
"""Return a dict that can be rendered by views/blog/feed.rss as the RSS feed of the blog. URL is http://<host_name>/<application_name>/blog/feed.rss.
- Note: the builtin views/generic.rss could be used instead the custom views/blog/feed.rss, but at this time there's a (python) bug preventing it, see https://groups.google.com/forum/#!msg/web2py/8ZwVMKS69Sg/2ijXe2eKGBgJ
+ Note: the builtin views/generic.rss could be used instead of the custom views/blog/feed.rss, but at this time there's a (python) bug preventing it, see https://groups.google.com/forum/#!msg/web2py/8ZwVMKS69Sg/2ijXe2eKGBgJ
See modules/blogutil.get_feed().
"""
data = get_feed(dbblog, URL(c='blog', f='index', host=True, extension=''),
@@ -112,3 +114,23 @@
redirect(URL(c='blog', f='feed', extension='rss'))
+def nyest_hirek():
+ """This is (the controller of) a component that we want to call via Ajax with the LOAD() helper (see right_sidebar.html).
+ - Use case 1 (uncomment the "return dict(....)" line and comment the other return line):
+ Returns a dict containing top 5 posts from http://www.nyest.hu/rss/hirek.
+ Associated view is views/blog/nyest_hirek.load.
+ Usage: in any view: {{=LOAD(c='blog', f='nyest_hirek.load', ajax=True, content='Betöltés...')}}
+ - Use case 2 (uncomment the "return DIV(....)" line and comment the other return line):
+ Returns a DIV helper containing the rendered HTML containing top 5 posts from http://www.nyest.hu/rss/hirek.
+ Usage: in any view: {{=LOAD(c='blog', f='nyest_hirek', ajax=True, content='Betöltés...')}}
+ In this case, no view is called (faster?)
+ """
+ import gluon.contrib.feedparser as feedparser
+ items = []
+ d = feedparser.parse("http://www.nyest.hu/rss/hirek")
+ for i in range(0, min(5, len(d.entries))):
+ items.append(dict(title=d.entries[i].get('title', '(notitle)'), link=d.entries[i].get('link', 'http://nyest.hu')))
+ #return dict(feed=items) # uncomment for use case 1
+ return DIV( *[P( A( x['title'], _href=x['link'], _target='_blank')) for x in items] ) # uncomment for use case 2
+
+
Added: trunk/web2py/applications/helyesiras_webdev/views/blog/nyest_hirek.load
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/views/blog/nyest_hirek.load (rev 0)
+++ trunk/web2py/applications/helyesiras_webdev/views/blog/nyest_hirek.load 2013-09-11 16:35:23 UTC (rev 934)
@@ -0,0 +1,5 @@
+{{
+for item in feed:
+ = P( A( item['title'], _href=item['link'], _target='_blank'))
+pass
+}}
Modified: trunk/web2py/applications/helyesiras_webdev/views/right_sidebar.html
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/views/right_sidebar.html 2013-09-11 15:02:19 UTC (rev 933)
+++ trunk/web2py/applications/helyesiras_webdev/views/right_sidebar.html 2013-09-11 16:35:23 UTC (rev 934)
@@ -29,9 +29,12 @@
<dt>
<img src="http://htp-devel.nytud.hu/helyesiras_webdev/static/widget/w2_head_top2.png">
- <h2>Nyest</h2>
+ <h2>Nyest.hu hírek</h2>
</dt>
- <dd><div class="helyesiras-widget-2-dd-inner"><div class="helyesiras-widget-2-dd-inner-top"></div></div></dd>
+ <dd class="init-open active"><div class="helyesiras-widget-2-dd-inner"><div class="helyesiras-widget-2-dd-inner-top">
+{{=LOAD(c='blog', f='nyest_hirek', ajax=True, content='Betöltés...')}}
+ </div></div></dd>
+
<dt>
<img src="http://htp-devel.nytud.hu/helyesiras_webdev/static/widget/w2_head_top2.png">
<h2>Ketsoros cimsor is elferjen ha kell</h2>
More information about the Hejes-devel
mailing list