예제 #1
0
def make_feedstory_dict(feeds):
    d = {}
    for feed in feeds:
        try:
            d[feed] = feed.current_story.latest(field_name='date_pulled')
        except ObjectDoesNotExist:
            pull.generate_new_story(feed)
            try:
                d[feed] = feed.current_story.latest(field_name='date_pulled')
            except ObjectDoesNotExist:
                d[feed] = {'story_title':"",'story_contents':'No Story yet! Hit Refresh!'}
    return d
예제 #2
0
def show_feeds(request):
    '''
    Show existing feeds (with 'edit' button for each feed)
    and each associated current story (with 'refresh' button)
    '''
    context = {}
    if request.method == 'POST':
        if request.POST['update']:
            pull.update_stories()

    #this could probably be ajaxified in the future...
    if request.GET.__contains__('refresh_id'):
        try:
            feed = Feed.objects.get(pk=request.GET['refresh_id'])
            pull.generate_new_story(feed)
            messages.info(request, 'Updated Feed %s' % feed)
        except ObjectDoesNotExist:
            messages.error(request, 'Could not find an object with that ID! Nothing to update')
            #Actualy story refresh errors (from pull.py) fail silently for now.
        except AttributeError:
            messages.error(request, 'Could not update feed "%s".  Problem downloading feed.' % feed )
    if request.GET.__contains__('delete_id'):
        try:
            f = Feed.objects.get(pk=request.GET['delete_id'])
            f.delete()
            messages.info(request,'Feed deleted succesfully!')
        except ObjectDoesNotExist:
            messages.error(request,'Could not find an object with that ID! Nothing to delete.')

    feeds = Feed.objects.all()

    context['feeds_with_stories']= make_feedstory_dict(feeds)
    for k in make_feedstory_dict(feeds):
        print k
    
    return render_to_response('rss/show_feeds.html', context, RequestContext(request))