def thing_attr(self, thing, attr): """ For the benefit of subclasses, to lookup attributes which may require more work than a simple getattr (for example, 'author' which has to be gotten from the author_id attribute on most things). """ if attr == "author": return thing.author.name if attr == "author_flair_text": if thing.author.flair_enabled_in_sr(thing.subreddit._id): return getattr(thing.author, 'flair_%s_text' % (thing.subreddit._id), None) else: return None if attr == "author_flair_css_class": if thing.author.flair_enabled_in_sr(thing.subreddit._id): return getattr(thing.author, 'flair_%s_css_class' % (thing.subreddit._id), None) else: return None elif attr == "created": return time.mktime(thing._date.timetuple()) elif attr == "created_utc": return (time.mktime(thing._date.astimezone(pytz.UTC).timetuple()) - time.timezone) elif attr == "child": return CachedVariable("childlisting") return getattr(thing, attr, None)
def thing_attr(self, thing, attr): """ For the benefit of subclasses, to lookup attributes which may require more work than a simple getattr (for example, 'author' which has to be gotten from the author_id attribute on most things). """ if attr == "author": if thing.author._deleted: return "[deleted]" return thing.author.name if attr == "author_flair_text": if thing.author._deleted: return None if thing.author.flair_enabled_in_sr(thing.subreddit._id): return getattr(thing.author, 'flair_%s_text' % (thing.subreddit._id), None) else: return None if attr == "author_flair_css_class": if thing.author._deleted: return None if thing.author.flair_enabled_in_sr(thing.subreddit._id): return getattr(thing.author, 'flair_%s_css_class' % (thing.subreddit._id), None) else: return None elif attr == "created": return time.mktime(thing._date.timetuple()) elif attr == "created_utc": return (time.mktime(thing._date.astimezone(pytz.UTC).timetuple()) - time.timezone) elif attr == "child": return CachedVariable("childlisting") elif attr == "upvotes": return thing.score elif attr == "downvotes": return 0 if attr == 'distinguished': distinguished = getattr(thing, attr, 'no') if distinguished == 'no': return None return distinguished if attr in ["num_reports", "banned_by", "approved_by"]: if c.user_is_loggedin and thing.subreddit.is_moderator(c.user): if attr == "num_reports": return thing.reported ban_info = getattr(thing, "ban_info", {}) if attr == "banned_by": banner = (ban_info.get("banner") if ban_info.get('moderator_banned') else True) return banner if thing._spam else None elif attr == "approved_by": return ban_info.get( "unbanner") if not thing._spam else None return getattr(thing, attr, None)
def thing_attr(self, thing, attr): """ For the benefit of subclasses, to lookup attributes which may require more work than a simple getattr (for example, 'author' which has to be gotten from the author_id attribute on most things). """ if attr == "author": return thing.author.name elif attr == "created": return time.mktime(thing._date.timetuple()) elif attr == "created_utc": return (time.mktime(thing._date.astimezone(pytz.UTC).timetuple()) - time.timezone) elif attr == "child": return CachedVariable("childlisting") return getattr(thing, attr, None)