def byline_list(request): """ A list of all the Authors we have archived. """ object_list = Author.all().order("name") context = { 'object_list': object_list, 'selected': 'byline_list', } return direct_to_template(request, 'byline_list.html', context)
def feed_list(request): """ A list of all the RSS feeds we provide. """ object_list = Author.all().order("name") context = { 'object_list': object_list, 'selected': 'feed_list', } return direct_to_template(request, 'feed_list.html', context)
def byline_scoreboard(request): """ A ranking of the authors by number of bylines """ object_list = Author.all().order("-story_count") context = { 'object_list': object_list, 'selected': 'byline_scoreboard', } return direct_to_template(request, 'byline_scoreboard.html', context)
def update_daily_average_for_all_authors(request): """ Updates the daily average for all Authors. """ logging.info("Updating daily average for all Authors") [taskqueue.add( url = '/_update_daily_average_for_author/', params = {'key' : i.key()}, method='GET' ) for i in Author.all()] return HttpResponse('ok!')
def update_story_count_for_all_authors(request): """ Updates the story count for all Authors. """ logging.info("Updating story count for all Authors") [taskqueue.add( url = '/_update_story_count_for_author/', params = {'key' : i.key()}, method='GET' ) for i in Author.all()] return HttpResponse('ok!')
def byline_detail(request, slug): """ A page with everything written by one of the Authors. """ author = Author.get_by_key_name(slug) if not author: raise Http404 context = { 'author' : author, 'now': datetime.now() - timedelta(hours=5), 'selected': 'byline_list', } return direct_to_template(request, 'byline_detail.html', context)
def get_object(self, bits): if len(bits) != 1: raise FeedDoesNotExist return Author.get_by_key_name(bits[0])
def update_feed(request): """ Fetch a feed and sync each item with the database. """ # Fetch the url url = request.GET['url'] content = fetch(url).content d = feedparser.parse(StringIO.StringIO(content)) # Loop through all the items for entry in d.entries: # See if this link already exists story_query = Story.all() story = story_query.filter('link =', entry.id).get() # And if it doesn't ... if not story: # Create a new Story object story = Story( link = entry.id, title = entry.title, updated_date = datetime.fromtimestamp(time.mktime(entry.updated_parsed)), ) # Prep the authors authors = entry.author.split(',') author_keys = [] # Loop through the authors for author in authors: # Check if the author already exists this_slug = str(slugify(author)) if not this_slug: continue a = Author.get_by_key_name(this_slug) # If it does... if a: # Sync updates if story.updated_date > a.last_updated: a.last_updated = story.updated_date a.put() # Otherwise... else: # Create a new Author obj a = Author( key_name = this_slug, name = author, slug = this_slug, story_count = 1, last_updated = story.updated_date ) a.put() # Add this to the Author key list author_keys.append(a.key()) # Add the author keys to the story object story.bylines = author_keys # Save the story story.put() # Schedule total updates for all the authors [taskqueue.add( url = '/_update_story_count_for_author/', params = {'key' : i}, method='GET' ) for i in author_keys] return HttpResponse('ok!')