planet list on the frontpage and the community page.
admin.site.register(Version)
admin.site.register(OrganisationType)
admin.site.register(Organisation, OrganisationAdmin)
+admin.site.register(ImportedRSSFeed)
+admin.site.register(ImportedRSSItem)
class Meta:
ordering = ('name',)
+
+# Basic classes for importing external RSS feeds, such as planet
+class ImportedRSSFeed(models.Model):
+ internalname = models.CharField(max_length=32, null=False, blank=False, unique=True)
+ url = models.URLField(null=False, blank=False)
+
+ def __unicode__(self):
+ return self.internalname
+
+class ImportedRSSItem(models.Model):
+ feed = models.ForeignKey(ImportedRSSFeed)
+ title = models.CharField(max_length=100, null=False, blank=False)
+ url = models.URLField(null=False, blank=False)
+ posttime = models.DateTimeField(null=False, blank=False)
+
+ def __unicode__(self):
+ return self.title
+
+ @property
+ def date(self):
+ return self.posttime.strftime("%Y-%m-%d")
+
from news.models import NewsArticle
from events.models import Event
from quotes.models import Quote
-from models import Version
+from models import Version, ImportedRSSFeed, ImportedRSSItem
# models needed for the pieces on the community page
from survey.models import Survey
events = Event.objects.select_related('country').filter(approved=True).filter(training=False)[:3]
quote = Quote.objects.filter(approved=True).order_by('?')[0]
versions = Version.objects.all()
+ planet = ImportedRSSItem.objects.filter(feed__internalname="planet").order_by("-posttime")[:5]
return render_to_response('index.html', {
'title': 'The world\'s most advanced open source database',
'events': events,
'quote': quote,
'versions': versions,
+ 'planet': planet,
})
# Community main page (contains surveys and potentially more)
s = s[0]
except:
s = None
+ planet = ImportedRSSItem.objects.filter(feed__internalname="planet").order_by("-posttime")[:7]
return render_to_response('core/community.html', {
'survey': s,
+ 'planet': planet,
}, NavContext(request, 'community'))
# Generic fallback view for static pages
</div>
{%endif%}
-<p>FIXME</p>
-<!-- BEGIN planet_block -->
<div id="pgPlanetWrap">
<div id="pgPlanet">
<dl>
<dt>Planet PostgreSQL</dt>
<dd><ul>
- <!-- BEGIN planet_loop -->
- <li><a href="{link}">{title}</a></li>
- <!-- END planet_loop -->
+ {%for post in planet%}
+ <li><a href="{{post.url}}">{{post.title}}</a></li>
+ {%endfor%}
</ul></dd>
<dd><a href="http://planet.postgresql.org">More</a></dd>
</dl>
</div>
</div>
-<!-- END planet_block -->
{%endblock%}
<img src="/media/img/hdr/hdr_planetpg.png" width="140" height="10" alt="Planet PostgreSQL" />
</a>
<div id="pgFrontPlanetWrap">
- <!-- BEGIN planet_loop -->
+ {%for post in planet%}
<p>
- <span class="txtDate">{date}</span><br />
- <a href="{link}">{title}</a>
+ <span class="txtDate">{{post.date}}</span><br />
+ <a href="{{post.url}}">{{post.title}}</a>
</p>
- <!-- END planet_loop -->
+ {%endfor%}
<div>
<img class="pgArrowImage" src="/layout/images/blt_blu_arrow.png" width="6" height="5" alt="" />
<ul class="pgRSSBottomList">
--- /dev/null
+#!/usr/bin/env python
+
+import feedparser
+import psycopg2
+import socket
+
+
+# Set timeout for loading RSS feeds
+socket.setdefaulttimeout(20)
+
+
+db = psycopg2.connect('host=/tmp dbname=pgweb')
+curs = db.cursor()
+curs.execute("SELECT id,internalname,url FROM core_importedrssfeed")
+for id,internalname,url in curs.fetchall():
+ try:
+ feed = feedparser.parse(url)
+
+ if not hasattr(feed, 'status'):
+ # bozo_excpetion can seemingly be set when there is no error as well,
+ # so make sure we only check if we didn't get a status.
+ if hasattr(feed,'bozo_exception'):
+ raise Exception('Feed load error %s' % feed.bozo_exception)
+ raise Exception('Feed load error with no exception!')
+ if feed.status != 200:
+ raise Exception('Feed returned status %s' % feed.status)
+ for entry in feed.entries:
+ curs.execute("""INSERT INTO core_importedrssitem (feed_id, title, url, posttime)
+SELECT %(feed)s, %(title)s, %(url)s, %(posttime)s
+WHERE NOT EXISTS (SELECT * FROM core_importedrssitem c2 WHERE c2.feed_id=%(feed)s AND c2.url=%(url)s)""", {
+ 'feed': id,
+ 'title': entry.title,
+ 'url': entry.link,
+ 'posttime': entry.date,
+ })
+ except Exception, e:
+ print "Failed to load %s: %s" % (internalname, e)
+
+db.commit()
+