def latest_article_display(self, obj): """ FILL ME, pep257. """ if obj.closed: return u'—' with django_language(): return naturaltime(obj.latest_article_date_published)
def latest_item_display(self, obj): """ FILL ME, pep257. """ if obj.is_active: with django_language(): return naturaltime(obj.latest_item_date_published) return u'—'
def last_fetch_display(self, obj): """ FILL ME, pep257. """ if obj.closed: return u'—' if obj.last_fetch is None: return _(u'never') with django_language(): return naturaltime(obj.last_fetch)
def date_last_fetch_display(self, obj): """ FILL ME, pep257. """ if obj.is_active: if obj.date_last_fetch is None: return _(u'never') with django_language(): return naturaltime(obj.date_last_fetch) return u'—'
def errors_display(self, obj): """ FILL ME, pep257. """ if obj.errors: errors = obj.errors last3 = [z.rsplit('@@', 1) for z in errors[:3]] with django_language(): return _(u'<span title="Last 3 errors:\n{0}" ' u'style="cursor: pointer">' u'{1} error(s)</span>').format( u'\n'.join( _(u'{0}: {1}').format( naturaltime(dateutil.parser.parse(y)), x) for x, y in last3), len(errors)) return u'—'
def import_google_reader_begin(user_id, access_token): auth = OAuth2Method(settings.GOOGLE_OAUTH2_CLIENT_ID, settings.GOOGLE_OAUTH2_CLIENT_SECRET) auth.authFromAccessToken(access_token) reader = GoogleReader(auth) django_user, mongo_user = get_user_from_dbs(user_id) username = django_user.username try: user_infos = reader.getUserInfo() except TypeError: LOGGER.exception(u'Could not start Google Reader import for user %s.', username) # Don't refresh, it's now done by a dedicated periodic task. # If we failed, it means the problem is quite serious. # import_google_reader_trigger(user_id, refresh=True) return GR_MAX_FEEDS = config.GR_MAX_FEEDS LOGGER.info(u'Starting Google Reader import for user %s.', username) gri = GoogleReaderImport(user_id) # take note of user informations now that we have them. gri.start(user_infos=user_infos) reader.buildSubscriptionList() total_reads, reg_date = reader.totalReadItems(without_date=False) total_starred, star1_date = reader.totalStarredItems(without_date=False) total_feeds = len(reader.feeds) + 1 # +1 for 'starred' gri.reg_date(pytime.mktime(reg_date.timetuple())) gri.star1_date(pytime.mktime(star1_date.timetuple())) gri.total_reads(total_reads) gri.total_starred(total_starred) LOGGER.info( u'Google Reader import for user %s: %s feed(s) and %s read ' u'article(s) to go…', username, total_feeds, total_reads) if total_feeds > GR_MAX_FEEDS and not settings.DEBUG: mail_admins( 'User {0} has more than {1} feeds: {2}!'.format( username, GR_MAX_FEEDS, total_feeds), u"\n\nThe GR import will be incomplete.\n\n" u"Just for you to know…\n\n") # We launch the starred feed import first. Launching it after the # standard feeds makes it being delayed until the world's end. reader.makeSpecialFeeds() starred_feed = reader.getSpecialFeed(ReaderUrl.STARRED_LIST) import_google_reader_starred.apply_async((user_id, username, starred_feed), queue='low') processed_feeds = 1 feeds_to_import = [] for gr_feed in reader.feeds[:GR_MAX_FEEDS]: try: feed = create_feed(gr_feed, mongo_user) except Feed.DoesNotExist: LOGGER.exception( u'Could not create feed “%s” for user %s, ' u'skipped.', gr_feed.title, username) continue processed_feeds += 1 feeds_to_import.append((user_id, username, gr_feed, feed)) LOGGER.info(u'Imported feed “%s” (%s/%s) for user %s…', gr_feed.title, processed_feeds, total_feeds, username) # We need to clamp the total, else task won't finish in # the case where the user has more feeds than allowed. # gri.total_feeds(min(processed_feeds, GR_MAX_FEEDS)) for feed_args in feeds_to_import: import_google_reader_articles.apply_async(feed_args, queue='low') LOGGER.info( u'Imported %s/%s feeds in %s. Articles import already ' u'started with limits: date: %s, %s waves of %s articles, ' u'max articles: %s, reads: %s, starred: %s.', processed_feeds, total_feeds, naturaldelta(now() - gri.start()), naturaltime(max([gri.reg_date(), GR_OLDEST_DATE])), config.GR_WAVE_LIMIT, config.GR_LOAD_LIMIT, config.GR_MAX_ARTICLES, total_reads, total_starred)
def date_added_display(self, obj): """ FILL ME, pep257. """ with django_language(): return naturaltime(obj.date_added)
def date_created_display(self, obj): """ FILL ME, pep257. """ with django_language(): return naturaltime(obj.date_created)