Display gold expiration for users

If users have the 'show gold expiration' preference checked, then how much
gold they have remaining will be shown on their userpage to the public.
This commit is contained in:
MelissaCole
2015-04-22 18:11:50 -07:00
parent fc48bb602c
commit 55c22f96ca
5 changed files with 46 additions and 31 deletions

View File

@@ -2119,25 +2119,30 @@ class SidebarModList(Templated):
class ProfileBar(Templated):
"""Draws a right box for info about the user (karma, etc)"""
def __init__(self, user):
Templated.__init__(self, user = user)
self.viewing_self = False
self.show_private_info = False
Templated.__init__(self, user=user)
if c.user_is_loggedin:
self.viewing_self = user._id == c.user._id
self.show_private_info = self.viewing_self or c.user_is_admin
else:
self.viewing_self = False
self.show_private_info = False
self.show_users_gold_expiration = (self.show_private_info or
user.pref_show_gold_expiration)
if user.gold and self.show_users_gold_expiration:
gold_days_left = (user.gold_expiration -
datetime.datetime.now(g.tz)).days
if gold_days_left < 1:
self.gold_remaining = _("less than a day")
else:
# Round remaining gold to number of days
precision = 60 * 60 * 24
self.gold_remaining = timeuntil(user.gold_expiration,
precision)
if c.user_is_loggedin:
if user.gold and self.show_private_info:
gold_days_left = (user.gold_expiration -
datetime.datetime.now(g.tz)).days
if gold_days_left < 1:
self.gold_remaining = _("less than a day")
else:
# Round remaining gold to number of days
precision = 60 * 60 * 24
self.gold_remaining = timeuntil(user.gold_expiration,
precision)
if user.has_paypal_subscription:
self.paypal_subscr_id = user.gold_subscr_id
self.paypal_url = paypal_subscription_url()

View File

@@ -75,6 +75,7 @@ PREFS_VALIDATORS = dict(
pref_hide_ads=VBoolean("hide_ads"),
pref_show_trending=VBoolean("show_trending"),
pref_highlight_new_comments=VBoolean("highlight_new_comments"),
pref_show_gold_expiration=VBoolean("show_gold_expiration"),
pref_monitor_mentions=VBoolean("monitor_mentions"),
pref_hide_locationbar=VBoolean("hide_locationbar"),
pref_use_global_defaults=VBoolean("use_global_defaults"),
@@ -126,6 +127,7 @@ def filter_prefs(prefs, user):
# don't update the hide_ads pref if they don't have gold
if not user.gold:
del prefs['pref_hide_ads']
del prefs['pref_show_gold_expiration']
if not (user.gold or user.is_moderator_somewhere):
prefs['pref_highlight_new_comments'] = True

View File

@@ -141,6 +141,7 @@ class Account(Thing):
pref_show_snoovatar=False,
gild_reveal_username=False,
selfserve_cpm_override_pennies=None,
pref_show_gold_expiration=False,
)
_preference_attrs = tuple(k for k in _defaults.keys()
if k.startswith("pref_"))

View File

@@ -350,6 +350,11 @@
(${_("we'll remember your visits for 48 hours and show you which comments you haven't seen yet")})
</span>
<br>
${checkbox(_("show gold expiration"), "show_gold_expiration")}
&#32;<span class="details">
(${_("show how much gold you have remaining on your userpage")})
</span>
<br>
<% creddit_link = unsafe('&#32;<a href="/creddits">creddit</a>&#32;') %>
${checkbox(_wsf("use a %(creddit_link)s to automatically renew my gold if it expires", creddit_link=creddit_link), "creddit_autorenew")}
</td>

View File

@@ -103,7 +103,7 @@
%endif
%endif
%if thing.show_private_info and (thing.user.gold or thing.user.gold_creddits > 0):
%if thing.show_users_gold_expiration and (thing.user.gold or thing.user.gold_creddits > 0):
<div class="rounded gold-accent gold-expiration-info">
%if hasattr(thing, "gold_remaining"):
<div class="gold-remaining" title="${thing.user.gold_expiration.strftime('%Y-%m-%d')}">
@@ -115,22 +115,24 @@
<br>
<a href="/gold/about">${_("view gold features/benefits")}</a>
</div>
%if hasattr(thing, "paypal_subscr_id"):
<div>
<a href=${thing.paypal_url}>
${_("Recurring Paypal subscription")}
</a>
&#32;
${thing.paypal_subscr_id}
</div>
%endif
%if thing.show_private_info:
%if hasattr(thing, "paypal_subscr_id"):
<div>
<a href="${thing.paypal_url}">
${_("Recurring Paypal subscription")}
</a>
&#32;
${thing.paypal_subscr_id}
</div>
%endif
%if hasattr(thing, "stripe_customer_id"):
<div>
<a href="/gold/subscription">
${_("manage recurring subscription")}
</a>
</div>
%if hasattr(thing, "stripe_customer_id"):
<div>
<a href="/gold/subscription">
${_("manage recurring subscription")}
</a>
</div>
%endif
%endif
%endif
%if hasattr(thing, "gold_creddit_message"):