diff --git a/r2/example.ini b/r2/example.ini index 00877d8ee..756eed432 100644 --- a/r2/example.ini +++ b/r2/example.ini @@ -608,6 +608,8 @@ frontend_logging = true # use **strong** markup for a larger font, and " \n" (
) to separate lines. goldvertisement_blurbs = "Make reddit better. Try %(reddit_gold)." "This year, give the gift of %(reddit_gold)s.|(and you should probably also give some other, better gifts)" goldvertisement_has_gold_blurbs = "**“Exquisite!”** \nGrab a drink and join us in [the lounge](/r/lounge)." +# daily gold revenue goal (in pennies) for progress bar thing +gold_revenue_goal = 0 # sample multireddits (displayed when a user has no multis) listing_chooser_sample_multis = /user/reddit/m/hello, /user/reddit/m/world # multi of subreddits to share with gold users diff --git a/r2/r2/lib/app_globals.py b/r2/r2/lib/app_globals.py index 80001c7d1..31653335d 100755 --- a/r2/r2/lib/app_globals.py +++ b/r2/r2/lib/app_globals.py @@ -229,6 +229,7 @@ class Globals(object): ConfigValue.float: [ 'spotlight_interest_sub_p', 'spotlight_interest_nosub_p', + 'gold_revenue_goal', ], ConfigValue.tuple: [ 'sr_discovery_links', diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 9a08f1bb5..ed48aa5a6 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -31,7 +31,12 @@ from r2.models import Flair, FlairTemplate, FlairTemplateBySubredditIndex from r2.models import USER_FLAIR, LINK_FLAIR from r2.models import GoldPartnerDealCode from r2.models.bidding import Bid -from r2.models.gold import gold_payments_by_user, gold_received_by_user, days_to_pennies +from r2.models.gold import ( + gold_payments_by_user, + gold_received_by_user, + days_to_pennies, + gold_revenue_on, +) from r2.models.promo import NO_TRANSACTION, PromotionLog, PromotedLinkRoadblock from r2.models.token import OAuth2Client, OAuth2AccessToken from r2.models import traffic @@ -503,7 +508,7 @@ class Reddit(Templated): if no_ads_yet and show_adbox: ps.append(Ads()) - if g.live_config["goldvertisement_blurbs"]: + if g.live_config["gold_revenue_goal"]: ps.append(Goldvertisement()) if c.user.pref_clickgadget and c.recent_clicks: @@ -1733,6 +1738,14 @@ class ServerSecondsBar(Templated): # for simplicity all payment processor fees are $0.30 + 2.9% return pennies * (1 - 0.029) - 30 + @classmethod + def current_value_of_month(cls): + price = g.gold_month_price.pennies + after_fees = cls.subtract_fees(price) + current_rate = cls.get_rate(datetime.datetime.now(g.display_tz)) + delta = datetime.timedelta(seconds=after_fees / current_rate) + return precise_format_timedelta(delta, threshold=5, locale=c.locale) + def make_message(self, seconds, my_message, their_message): if not seconds: return '' @@ -4267,12 +4280,12 @@ class GoldPartnersPage(BoringPage): class Goldvertisement(Templated): def __init__(self): + today = datetime.datetime.now(g.display_tz).date() + revenue_today = gold_revenue_on(today) + revenue_goal = g.live_config["gold_revenue_goal"] + self.percent_filled = int((revenue_today / revenue_goal) * 100) + self.hours_paid = ServerSecondsBar.current_value_of_month() Templated.__init__(self) - if not c.user.gold: - blurbs = g.live_config["goldvertisement_blurbs"] - else: - blurbs = g.live_config["goldvertisement_has_gold_blurbs"] - self.blurb = random.choice(blurbs) class LinkCommentsSettings(Templated): def __init__(self, link): diff --git a/r2/r2/models/gold.py b/r2/r2/models/gold.py index f8948a2e0..44cf8fb90 100644 --- a/r2/r2/models/gold.py +++ b/r2/r2/models/gold.py @@ -33,6 +33,8 @@ from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.schema import Column from sqlalchemy.sql import and_ +from sqlalchemy.sql.expression import select +from sqlalchemy.sql.functions import sum as sa_sum from sqlalchemy.types import DateTime, Integer, String from xml.dom.minidom import Document @@ -48,6 +50,7 @@ from BeautifulSoup import BeautifulStoneSoup from r2.lib.db.tdb_cassandra import NotFound from r2.models.subreddit import Frontpage from r2.models.wiki import WikiPage +from r2.lib.memoize import memoize gold_bonus_cutoff = datetime(2010,7,27,0,0,0,0,g.tz) @@ -515,3 +518,13 @@ def append_random_bottlecap_phrase(message): if bottlecap: message += '\n\n> ' + bottlecap return message + + +@memoize("gold-revenue", time=600) +def gold_revenue_on(date): + NON_REVENUE_STATUSES = ("declined", "chargeback", "fudge") + query = (select([sa_sum(gold_table.c.pennies)]) + .where(~ gold_table.c.status.in_(NON_REVENUE_STATUSES)) + .where(func.date_trunc('day', gold_table.c.date) == date)) + rows = ENGINE.execute(query) + return rows.fetchone()[0] or 0 diff --git a/r2/r2/public/static/css/reddit.less b/r2/r2/public/static/css/reddit.less index d1c53b3ee..15ae73587 100755 --- a/r2/r2/public/static/css/reddit.less +++ b/r2/r2/public/static/css/reddit.less @@ -7363,41 +7363,136 @@ body.post-under-6h-old .gilded-comment-icon { body.gold .buttons li.comment-save-button { display: inline; } .goldvertisement { - height: 50px; - border: 1px solid #c4b487; + @border-color: #c4b487; + @background-shadow: #dad0b3; + + border: 1px solid @border-color; text-align: center; line-height: 1.3em; - box-shadow: 0 0 10px #dad0b3 inset; - color: #333; + box-shadow: 0 0 10px @background-shadow inset; + color: darken(@border-color, 40%); + + .inner { + margin: 1px; + border: 1px solid #dbd1b5; + padding: 6px 8px; + } + + li { + display: inline-block; + margin-right: 2em; + } + + h2 { + margin: 0; + font-weight: normal; + color: inherit; + } + + .progress { + @bar-height: 17px; + padding: 7px 0; + + .bar { + border: 1px solid #dad0b3; + height: @bar-height; + overflow: auto; + + border-radius: 10px; + + span { + display: block; + height: 100%; + background: linear-gradient(to bottom, #fff8ba 0%, #eccf90 100%); + border-radius: (@bar-height/2); + } + } + + p { + float: right; + font-weight: bold; + font-size: 15px; + color: #5a3f1a; + line-height: @bar-height + 2; // +2 to match border on bar + margin-left: 6px; + } + } + + a { + display: inline-block; + margin: 0; + padding: 2px 4px; + border-radius: 3px; + background: lighten(@background-shadow, 20%); + border: 1px solid lighten(@border-color, 10%); + border-bottom-width: 2px; + color: darken(@border-color, 40%); + + &:hover { + background: #fdf4c5; + } + + &:active { + margin-top: 1px; + border-bottom-width: 1px; + } + } } -.goldvertisement .inner { - margin: 1px; - border: 1px solid #dbd1b5; - height: 46px; - line-height: 44px; -} +.gold-bubble { + width: 290px; + border-radius: 4px; + font-size: 125%; + line-height: 1.13; + font-family: "Hoefler Text","Palatino Linotype","Book Antiqua", + Palatino,georgia,garamond,FreeSerif,serif; + border-color: #907c47; + padding: 4px; -.goldvertisement p { - display: inline-block; - vertical-align: middle; - margin: 0 4px; - line-height: 14px; -} + &.anchor-top-centered:before { + border-bottom-color: #907c47; + } -.goldvertisement strong { - font-size: 15px; -} + p + p { + margin-top: 1em; + } -.goldvertisement a { - color: #9a7d2e; - font-weight: bold; - text-decoration: underline; -} + span.gold-branding { + display: inline-block; + vertical-align: bottom; + text-indent: -9999px; + background: transparent url(../gold/goldvertisement-logo.png) top left no-repeat; + width: 79px; + height: 18px; + margin-right: 1px; + } -.goldvertisement i { - font-size: 11px; - font-variant: italic; + p.buy-gold { + background: transparent url(../gold/goldvertisement-gold.png) top left no-repeat; + margin-left: 13px; + padding-left: 67px; + min-height: 45px; + + a { + color: #825b25; + } + } + + p.give-gold { + background: transparent url(../gold/goldvertisement-gild.png) top left no-repeat; + margin-left: 23px; + padding-left: 57px; + min-height: 39px; + } + + p.aside { + color: #777; + font-style: italic; + + a { + color: inherit; + } + } } #stripe-payment th { diff --git a/r2/r2/templates/goldvertisement.html b/r2/r2/templates/goldvertisement.html index 0da8a31b8..2aa927471 100644 --- a/r2/r2/templates/goldvertisement.html +++ b/r2/r2/templates/goldvertisement.html @@ -20,10 +20,40 @@ ## reddit Inc. All Rights Reserved. ############################################################################### -<%namespace file="utils.html" import="text_with_links, md"/> +<%! + from babel.numbers import format_percent +%>
- ${md(thing.blurb)} +

${_("daily reddit gold goal")}

+ +
+

${format_percent(thing.percent_filled / 100.0, locale=c.locale)}

+
+ +
+
+ + ${_("help support reddit")} + +
+

reddit gold gives you extra features + and helps keep our servers running. We believe the more reddit can be + user-supported, the freer we will be to make reddit the best it can + be.

+ +

Buy gold for yourself to gain access to extra features and special benefits. A month of gold pays for + ${thing.hours_paid} of reddit server time!

+ +

Give gold to thank exemplary people and encourage them to post + more.

+ +

This daily goal updates every 10 minutes and is reset at + midnight MST.

+