Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A handful of extra refactoring that the merge between my and Justin's…

… work didn't catch.
  • Loading branch information...
commit be6a0f7159dad719ccbd73d248669d1513f8648e 1 parent 5f66182
@jacobian jacobian authored
View
75 django_website/aggregator/bin/update_feeds.py
@@ -1,75 +0,0 @@
-"""
-Update feeds for Django community page. Requires Mark Pilgrim's excellent
-Universal Feed Parser (http://feedparser.org)
-"""
-
-import os
-import sys
-import time
-import socket
-import optparse
-import datetime
-import feedparser
-
-LOCKFILE = "/tmp/update_feeds.lock"
-def update_feeds(verbose=False):
- from django_website.apps.aggregator.models import Feed, FeedItem
- for feed in Feed.objects.filter(is_defunct=False):
- if verbose:
- print feed
- parsed_feed = feedparser.parse(feed.feed_url)
- for entry in parsed_feed.entries:
- title = entry.title.encode(parsed_feed.encoding, "xmlcharrefreplace")
- guid = entry.get("id", entry.link).encode(parsed_feed.encoding, "xmlcharrefreplace")
- link = entry.link.encode(parsed_feed.encoding, "xmlcharrefreplace")
-
- if not guid:
- guid = link
-
- if hasattr(entry, "summary"):
- content = entry.summary
- elif hasattr(entry, "content"):
- content = entry.content[0].value
- elif hasattr(entry, "description"):
- content = entry.description
- else:
- content = u""
- content = content.encode(parsed_feed.encoding, "xmlcharrefreplace")
-
- try:
- if entry.has_key('modified_parsed'):
- date_modified = datetime.datetime.fromtimestamp(time.mktime(entry.modified_parsed))
- elif parsed_feed.feed.has_key('modified_parsed'):
- date_modified = datetime.datetime.fromtimestamp(time.mktime(parsed_feed.feed.modified_parsed))
- elif parsed_feed.has_key('modified'):
- date_modified = datetime.datetime.fromtimestamp(time.mktime(parsed_feed.modified))
- else:
- date_modified = datetime.datetime.now()
- except TypeError:
- date_modified = datetime.datetime.now()
-
- try:
- feed.feeditem_set.get(guid=guid)
- except FeedItem.DoesNotExist:
- feed.feeditem_set.create(title=title, link=link, summary=content, guid=guid, date_modified=date_modified)
-
-def main(argv):
- socket.setdefaulttimeout(15)
- parser = optparse.OptionParser()
- parser.add_option('--settings')
- parser.add_option('-v', '--verbose', action="store_true")
- options, args = parser.parse_args(argv)
- if options.settings:
- os.environ["DJANGO_SETTINGS_MODULE"] = options.settings
- update_feeds(options.verbose)
-
-if __name__ == '__main__':
- try:
- lockfile = os.open(LOCKFILE, os.O_CREAT | os.O_EXCL)
- except OSError:
- sys.exit(0)
- try:
- sys.exit(main(sys.argv))
- finally:
- os.close(lockfile)
- os.unlink(LOCKFILE)
View
4 django_website/aggregator/forms.py
@@ -1,6 +1,8 @@
+from __future__ import absolute_import
+
from django import forms
from django.forms import widgets
-from apps.aggregator.models import Feed, FeedType
+from .models import Feed, FeedType
class FeedModelForm(forms.ModelForm):
title = forms.CharField(max_length=250, help_text="The name of the resource / blog.")
View
6 django_website/aggregator/views.py
@@ -1,11 +1,13 @@
+from __future__ import absolute_import
+
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views.generic.list_detail import object_list
-from apps.aggregator.models import FeedItem, Feed, FeedType
-from apps.aggregator.forms import FeedModelForm
+from .models import FeedItem, Feed, FeedType
+from .forms import FeedModelForm
def index(request):
feedtype_list = FeedType.objects.all()
View
20 django_website/urls/www.py
@@ -7,10 +7,10 @@
from django.contrib.comments.models import Comment
from django.contrib.sitemaps import views as sitemap_views
from django.views.decorators.cache import cache_page
-from .aggregator.feeds import CommunityAggregatorFeed
-from .aggregator.models import FeedItem
-from .blog.feeds import WeblogEntryFeed
-from .sitemaps import FlatPageSitemap, WeblogSitemap
+from ..aggregator.feeds import CommunityAggregatorFeed
+from ..aggregator.models import FeedItem
+from ..blog.feeds import WeblogEntryFeed
+from ..sitemaps import FlatPageSitemap, WeblogSitemap
comments_info_dict = {
'queryset': Comment.objects.filter(is_public=True).order_by('-submit_date'),
@@ -30,25 +30,25 @@
urlpatterns = patterns('',
url(r'^$', 'django.views.generic.simple.direct_to_template', {'template': 'homepage.html'}, name="homepage"),
- (r'^accounts/', include('django_website.apps.accounts.urls')),
+ (r'^accounts/', include('django_website.accounts.urls')),
(r'^admin/(.*)', admin.site.root),
(r'^comments/$', 'django.views.generic.list_detail.object_list', comments_info_dict),
(r'^comments/', include('django.contrib.comments.urls')),
url(r'^community/add/(?P<feed_type_slug>[-\w]+)/',
- 'django_website.apps.aggregator.views.add_feed',
+ 'django_website.aggregator.views.add_feed',
name='community-add-feed'),
url(r'^community/(?P<feed_type_slug>[-\w]+)/',
- 'django_website.apps.aggregator.views.feed_list',
+ 'django_website.aggregator.views.feed_list',
name="community-feed-list"),
- url(r'^community/', 'django_website.apps.aggregator.views.index', name='community-index'),
- (r'^contact/', include('django_website.apps.contact.urls')),
- (r'^documentation/', include('django_website.legacy.docurls')),
+ url(r'^community/', 'django_website.aggregator.views.index', name='community-index'),
+ (r'^contact/', include('django_website.contact.urls')),
(r'^r/', include('django.conf.urls.shortcut')),
(r'^rss/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
(r'^sitemap\.xml$', cache_page(sitemap_views.sitemap, 60 * 60 * 6), {'sitemaps': sitemaps}),
(r'^weblog/', include('django_website.blog.urls')),
(r'^freenode\.9xJY7YIUWtwn\.html$', 'django.views.generic.simple.direct_to_template', {'template': 'freenode_tmp.html'}),
url(r'^download$', 'django.contrib.flatpages.views.flatpage', {'url': 'download'}, name="download"),
+ (r'', include('django_website.legacy.urls')),
)
if settings.DEVELOPMENT_MODE:
Please sign in to comment.
Something went wrong with that request. Please try again.