def upload(request): #TODO sort out multi (implement file drop?) params = [] if request.method == 'GET': print "Importing OPML file" filename = request.GET.get('filename') or './opml2.xml' d = listparser.parse(filename) #request.POST['filename'] for f in d.feeds: print f.title feed = Feed(title=f.title) feed.url = f.url feed.user = request.user feed.save() params = {'Messages': ['Your import might have been a success!',]} return response(request, 'mainapp/index.html', params)
def index(request): if request.method == 'POST': # save new feed print "New feed" url = request.POST['url'] d = feedparser.parse(url) try: title = d.feed.title except: title = "New feed" feed = Feed(title=title) feed.url = feed.feed_url = url feed.user = request.user feed.save() return HttpResponseRedirect('/') else: posts = Post.objects.filter(user=request.user) category = request.GET.get('category') or None feed = request.GET.get('feed') or None tag = request.GET.get('tag') or None if category: print "Filtering by category %s" % category posts = posts.filter(feed__in=Feed.objects.filter(category=category)) elif feed: print "Filtering by feed %s" % feed posts = posts.filter(feed=feed) elif tag: # add bayesian mood tags print "Filtering by tag %s" % tag posts = posts.filter(tags__in=Tag.objects.filter(id=tag)) else: # unread items only default read = request.GET.get('read') if read: posts = posts.filter(read=read) else: posts = posts.filter(read=False) posts = posts.exclude(tags__in=Tag.objects.filter(dead=1)) # frontpage params = {'Posts': posts.order_by("-dt_published")[:255]} return response(request, 'mainapp/index.html', params)