def __init__(self, thing, delete = True, report = True): # is the current user the author? is_author = thing.is_author # do we show the report button? show_report = not is_author and report and thing.can_reply # do we show the delete button? show_delete = is_author and delete and not thing._deleted show_distinguish = (is_author and (thing.can_ban or # Moderator distinguish c.user.employee or # Admin distinguish c.user_special_distinguish)) show_givegold = thing.can_gild PrintableButtons.__init__(self, "commentbuttons", thing, can_save=thing.can_save, is_author = is_author, profilepage = c.profilepage, permalink = thing.permalink, saved = thing.saved, ignore_reports = thing.ignore_reports, full_comment_path = thing.full_comment_path, full_comment_count = thing.full_comment_count, deleted = thing.deleted, parent_permalink = thing.parent_permalink, can_reply = thing.can_reply, show_report = show_report, report_reasons = Report.get_reasons(thing), show_distinguish = show_distinguish, show_delete = show_delete, show_givegold=show_givegold, )
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", "report_reasons", "banned_by", "approved_by"]: if c.user_is_loggedin and thing.subreddit.is_moderator(c.user): if attr == "num_reports": return thing.reported elif attr == "report_reasons": return Report.get_reasons(thing) 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 __init__(self, thing, delete=True, report=True): # is the current user the author? is_author = thing.is_author # do we show the report button? show_report = not is_author and report and thing.can_reply # do we show the delete button? show_delete = is_author and delete and not thing._deleted show_distinguish = ( is_author and (thing.can_ban or # Moderator distinguish c.user.employee or # Admin distinguish c.user_special_distinguish)) show_givegold = thing.can_gild PrintableButtons.__init__( self, "commentbuttons", thing, can_save=thing.can_save, is_author=is_author, profilepage=c.profilepage, permalink=thing.permalink, saved=thing.saved, ignore_reports=thing.ignore_reports, full_comment_path=thing.full_comment_path, full_comment_count=thing.full_comment_count, deleted=thing.deleted, parent_permalink=thing.parent_permalink, can_reply=thing.can_reply, show_report=show_report, report_reasons=Report.get_reasons(thing), show_distinguish=show_distinguish, show_delete=show_delete, show_givegold=show_givegold, )
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", "report_reasons", "banned_by", "approved_by" ]: if c.user_is_loggedin and thing.subreddit.is_moderator(c.user): if attr == "num_reports": return thing.reported elif attr == "report_reasons": return Report.get_reasons(thing) 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 __init__(self, thing, comments=True, delete=True, report=True): # is the current user the author? is_author = (c.user_is_loggedin and thing.author and c.user.name == thing.author.name) # do we show the report button? show_report = not is_author and report if c.user_is_admin and thing.promoted is None: show_report = False show_marknsfw = show_unmarknsfw = False show_rescrape = False if thing.can_ban or is_author or (thing.promoted and c.user_is_sponsor): if not thing.nsfw: show_marknsfw = True elif thing.nsfw and not thing.nsfw_str: show_unmarknsfw = True if (not thing.is_self and not (thing.has_thumbnail or thing.media_object)): show_rescrape = True show_givegold = thing.can_gild and (c.permalink_page or c.profilepage) # do we show the delete button? show_delete = is_author and delete and not thing._deleted # disable the delete button for live sponsored links if (is_promoted(thing) and not c.user_is_sponsor): show_delete = False # do we show the distinguish button? among other things, # we never want it to appear on link listings -- only # comments pages show_distinguish = ( is_author and (thing.can_ban or # Moderator distinguish c.user.employee or # Admin distinguish c.user_special_distinguish) and getattr(thing, "expand_children", False)) kw = {} if thing.promoted is not None: now = datetime.now(g.tz) kw = dict(promo_url=promo_edit_url(thing), promote_status=getattr(thing, "promote_status", 0), user_is_sponsor=c.user_is_sponsor, traffic_url=promo_traffic_url(thing), is_author=thing.is_author) PrintableButtons.__init__( self, 'linkbuttons', thing, # user existence and preferences is_loggedin=c.user_is_loggedin, # comment link params comment_label=thing.comment_label, commentcls=thing.commentcls, permalink=thing.permalink, # button visibility saved=thing.saved, editable=thing.editable, hidden=thing.hidden, ignore_reports=thing.ignore_reports, show_delete=show_delete, show_report=show_report and c.user_is_loggedin, report_reasons=Report.get_reasons(thing), show_distinguish=show_distinguish, show_marknsfw=show_marknsfw, show_unmarknsfw=show_unmarknsfw, show_flair=thing.can_flair, show_rescrape=show_rescrape, show_givegold=show_givegold, show_comments=comments, # promotion promoted=thing.promoted, is_link=True, **kw)
def __init__(self, thing, comments = True, delete = True, report = True): # is the current user the author? is_author = (c.user_is_loggedin and thing.author and c.user.name == thing.author.name) # do we show the report button? show_report = not is_author and report if c.user_is_admin and thing.promoted is None: show_report = False show_marknsfw = show_unmarknsfw = False show_rescrape = False if thing.can_ban or is_author or (thing.promoted and c.user_is_sponsor): if not thing.nsfw: show_marknsfw = True elif thing.nsfw and not thing.nsfw_str: show_unmarknsfw = True if (not thing.is_self and not (thing.has_thumbnail or thing.media_object)): show_rescrape = True show_givegold = thing.can_gild and (c.permalink_page or c.profilepage) # do we show the delete button? show_delete = is_author and delete and not thing._deleted # disable the delete button for live sponsored links if (is_promoted(thing) and not c.user_is_sponsor): show_delete = False # do we show the distinguish button? among other things, # we never want it to appear on link listings -- only # comments pages show_distinguish = (is_author and (thing.can_ban or # Moderator distinguish c.user.employee or # Admin distinguish c.user_special_distinguish) and getattr(thing, "expand_children", False)) kw = {} if thing.promoted is not None: now = datetime.now(g.tz) kw = dict(promo_url = promo_edit_url(thing), promote_status = getattr(thing, "promote_status", 0), user_is_sponsor = c.user_is_sponsor, traffic_url = promo_traffic_url(thing), is_author = thing.is_author) PrintableButtons.__init__(self, 'linkbuttons', thing, # user existence and preferences is_loggedin = c.user_is_loggedin, # comment link params comment_label = thing.comment_label, commentcls = thing.commentcls, permalink = thing.permalink, # button visibility saved = thing.saved, editable = thing.editable, hidden = thing.hidden, ignore_reports = thing.ignore_reports, show_delete = show_delete, show_report = show_report and c.user_is_loggedin, report_reasons = Report.get_reasons(thing), show_distinguish = show_distinguish, show_marknsfw = show_marknsfw, show_unmarknsfw = show_unmarknsfw, show_flair = thing.can_flair, show_rescrape=show_rescrape, show_givegold=show_givegold, show_comments = comments, # promotion promoted = thing.promoted, is_link = True, **kw)