mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-25 23:08:22 -05:00
Rename STATUS to PROMOTE_STATUS and move to r2.models.promo.
This commit is contained in:
@@ -62,7 +62,7 @@ def visible_promo(article):
|
||||
return (c.user_is_sponsor or
|
||||
is_author or
|
||||
(not article.disable_comments and
|
||||
article.promote_status >= promote.STATUS.promoted))
|
||||
article.promote_status >= PROMOTE_STATUS.promoted))
|
||||
# not a promo, therefore it is visible
|
||||
return True
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ from r2.lib.utils import fetch_things2, tup, UniqueIterator, set_last_modified
|
||||
from r2.lib import utils
|
||||
from r2.lib import amqp, sup, filters
|
||||
from r2.lib.comment_tree import add_comments, update_comment_votes
|
||||
from r2.models.promo import PROMOTE_STATUS
|
||||
from r2.models.query_cache import (cached_query, merged_cached_query,
|
||||
CachedQuery, CachedQueryMutator,
|
||||
MergedCachedQuery)
|
||||
@@ -669,7 +670,6 @@ def get_user_reported(user_id):
|
||||
|
||||
|
||||
def set_promote_status(link, promote_status):
|
||||
from r2.lib.promote import STATUS
|
||||
all_queries = [promote_query(link.author_id) for promote_query in
|
||||
(get_unpaid_links, get_unapproved_links,
|
||||
get_rejected_links, get_live_links, get_accepted_links)]
|
||||
@@ -677,16 +677,17 @@ def set_promote_status(link, promote_status):
|
||||
get_all_rejected_links(), get_all_live_links(),
|
||||
get_all_accepted_links()])
|
||||
|
||||
if promote_status == STATUS.unpaid:
|
||||
if promote_status == PROMOTE_STATUS.unpaid:
|
||||
inserts = [get_unpaid_links(link.author_id), get_all_unpaid_links()]
|
||||
elif promote_status == STATUS.unseen:
|
||||
elif promote_status == PROMOTE_STATUS.unseen:
|
||||
inserts = [get_unapproved_links(link.author_id),
|
||||
get_all_unapproved_links()]
|
||||
elif promote_status == STATUS.rejected:
|
||||
elif promote_status == PROMOTE_STATUS.rejected:
|
||||
inserts = [get_rejected_links(link.author_id), get_all_rejected_links()]
|
||||
elif promote_status == STATUS.promoted:
|
||||
elif promote_status == PROMOTE_STATUS.promoted:
|
||||
inserts = [get_live_links(link.author_id), get_all_live_links()]
|
||||
elif promote_status in (STATUS.accepted, STATUS.pending, STATUS.finished):
|
||||
elif promote_status in (PROMOTE_STATUS.accepted, PROMOTE_STATUS.pending,
|
||||
PROMOTE_STATUS.finished):
|
||||
inserts = [get_accepted_links(link.author_id), get_all_accepted_links()]
|
||||
|
||||
deletes = list(set(all_queries) - set(inserts))
|
||||
@@ -701,14 +702,15 @@ def set_promote_status(link, promote_status):
|
||||
|
||||
|
||||
def _promoted_link_query(user_id, status):
|
||||
from r2.lib.promote import STATUS, get_promote_srid
|
||||
from r2.lib.promote import get_promote_srid
|
||||
|
||||
STATUS_CODES = {'unpaid': STATUS.unpaid,
|
||||
'unapproved': STATUS.unseen,
|
||||
'rejected': STATUS.rejected,
|
||||
'live': STATUS.promoted,
|
||||
'accepted': (STATUS.accepted, STATUS.pending,
|
||||
STATUS.finished)}
|
||||
STATUS_CODES = {'unpaid': PROMOTE_STATUS.unpaid,
|
||||
'unapproved': PROMOTE_STATUS.unseen,
|
||||
'rejected': PROMOTE_STATUS.rejected,
|
||||
'live': PROMOTE_STATUS.promoted,
|
||||
'accepted': (PROMOTE_STATUS.accepted,
|
||||
PROMOTE_STATUS.pending,
|
||||
PROMOTE_STATUS.finished)}
|
||||
|
||||
q = Link._query(Link.c.sr_id == get_promote_srid(),
|
||||
Link.c._spam == (True, False),
|
||||
|
||||
@@ -45,10 +45,6 @@ import random
|
||||
from uuid import uuid1
|
||||
|
||||
|
||||
STATUS = Enum("unpaid", "unseen", "accepted", "rejected",
|
||||
"pending", "promoted", "finished")
|
||||
|
||||
|
||||
UPDATE_QUEUE = 'update_promos_q'
|
||||
QUEUE_ALL = 'all'
|
||||
|
||||
@@ -107,20 +103,21 @@ def is_promo(link):
|
||||
and hasattr(link, "promote_status"))
|
||||
|
||||
def is_accepted(link):
|
||||
return is_promo(link) and (link.promote_status != STATUS.rejected and
|
||||
link.promote_status >= STATUS.accepted)
|
||||
return (is_promo(link) and
|
||||
link.promote_status != PROMOTE_STATUS.rejected and
|
||||
link.promote_status >= PROMOTE_STATUS.accepted)
|
||||
|
||||
def is_unpaid(link):
|
||||
return is_promo(link) and link.promote_status == STATUS.unpaid
|
||||
return is_promo(link) and link.promote_status == PROMOTE_STATUS.unpaid
|
||||
|
||||
def is_unapproved(link):
|
||||
return is_promo(link) and link.promote_status <= STATUS.unseen
|
||||
return is_promo(link) and link.promote_status <= PROMOTE_STATUS.unseen
|
||||
|
||||
def is_rejected(link):
|
||||
return is_promo(link) and link.promote_status == STATUS.rejected
|
||||
return is_promo(link) and link.promote_status == PROMOTE_STATUS.rejected
|
||||
|
||||
def is_promoted(link):
|
||||
return is_promo(link) and link.promote_status == STATUS.promoted
|
||||
return is_promo(link) and link.promote_status == PROMOTE_STATUS.promoted
|
||||
|
||||
def is_live_on_sr(link, srname):
|
||||
if not is_promoted(link):
|
||||
@@ -289,9 +286,9 @@ def new_promotion(title, url, user, ip):
|
||||
|
||||
# set the status of the link, populating the query queue
|
||||
if c.user_is_sponsor or user.trusted_sponsor:
|
||||
set_promote_status(l, STATUS.accepted)
|
||||
set_promote_status(l, PROMOTE_STATUS.accepted)
|
||||
else:
|
||||
set_promote_status(l, STATUS.unpaid)
|
||||
set_promote_status(l, PROMOTE_STATUS.unpaid)
|
||||
|
||||
# the user has posted a promotion, so enable the promote menu unless
|
||||
# they have already opted out
|
||||
@@ -425,9 +422,11 @@ def auth_campaign(link, campaign, user, pay_id):
|
||||
if trans_id < 0:
|
||||
PromotionLog.add(link, 'FREEBIE (campaign: %s)' % campaign._id)
|
||||
|
||||
set_promote_status(link,
|
||||
max(STATUS.unseen if trans_id else STATUS.unpaid,
|
||||
link.promote_status))
|
||||
if trans_id:
|
||||
new_status = max(PROMOTE_STATUS.unseen, link.promote_status)
|
||||
else:
|
||||
new_status = max(PROMOTE_STATUS.unpaid, link.promote_status)
|
||||
set_promote_status(link, new_status)
|
||||
# notify of campaign creation
|
||||
# update the query queue
|
||||
if user and (user._id == link.author_id) and trans_id > 0:
|
||||
@@ -468,7 +467,7 @@ def accept_promotion(link):
|
||||
PromotionLog.add(link, 'status update: accepted')
|
||||
# update the query queue
|
||||
|
||||
set_promote_status(link, STATUS.accepted)
|
||||
set_promote_status(link, PROMOTE_STATUS.accepted)
|
||||
now = promo_datetime_now(0)
|
||||
if link._fullname in set(l.thing_name for l in
|
||||
PromotionWeights.get_campaigns(now)):
|
||||
@@ -486,7 +485,7 @@ def reject_promotion(link, reason = None):
|
||||
# Since status is updated first,
|
||||
# if make_daily_promotions happens to run
|
||||
# while we're doing work here, it will correctly exclude it
|
||||
set_promote_status(link, STATUS.rejected)
|
||||
set_promote_status(link, PROMOTE_STATUS.rejected)
|
||||
|
||||
links, = get_live_promotions([SponsorBoxWeightings.ALL_ADS_ID])[0]
|
||||
if link._fullname in links:
|
||||
@@ -502,7 +501,7 @@ def reject_promotion(link, reason = None):
|
||||
def unapprove_promotion(link):
|
||||
PromotionLog.add(link, 'status update: unapproved')
|
||||
# update the query queue
|
||||
set_promote_status(link, STATUS.unseen)
|
||||
set_promote_status(link, PROMOTE_STATUS.unseen)
|
||||
|
||||
def accepted_campaigns(offset=0):
|
||||
now = promo_datetime_now(offset=offset)
|
||||
@@ -565,7 +564,7 @@ def charge_pending(offset=1):
|
||||
if is_promoted(l):
|
||||
emailer.queue_promo(l, camp.bid, camp.trans_id)
|
||||
else:
|
||||
set_promote_status(l, STATUS.pending)
|
||||
set_promote_status(l, PROMOTE_STATUS.pending)
|
||||
emailer.queue_promo(l, camp.bid, camp.trans_id)
|
||||
text = ('auth charge for campaign %s, trans_id: %d' %
|
||||
(camp._id, camp.trans_id))
|
||||
@@ -727,7 +726,7 @@ def make_daily_promotions(offset = 0, test = False):
|
||||
print "unpromote", l
|
||||
else:
|
||||
# update the query queue
|
||||
set_promote_status(links[l], STATUS.finished)
|
||||
set_promote_status(links[l], PROMOTE_STATUS.finished)
|
||||
emailer.finished_promo(links[l])
|
||||
|
||||
for l in new_links:
|
||||
@@ -736,7 +735,7 @@ def make_daily_promotions(offset = 0, test = False):
|
||||
print "promote2", l
|
||||
else:
|
||||
# update the query queue
|
||||
set_promote_status(links[l], STATUS.promoted)
|
||||
set_promote_status(links[l], PROMOTE_STATUS.promoted)
|
||||
emailer.live_promo(links[l])
|
||||
|
||||
# convert the weighted dict to use sr_ids which are more useful
|
||||
|
||||
@@ -37,6 +37,7 @@ from mako.filters import url_escape
|
||||
from r2.lib.strings import strings, Score
|
||||
from r2.lib.db import tdb_cassandra
|
||||
from r2.models.subreddit import MultiReddit
|
||||
from r2.models.promo import PROMOTE_STATUS
|
||||
|
||||
from pylons import c, g, request
|
||||
from pylons.i18n import ungettext, _
|
||||
@@ -610,19 +611,17 @@ class PromotedLink(Link):
|
||||
|
||||
@classmethod
|
||||
def add_props(cls, user, wrapped):
|
||||
# prevents cyclic dependencies
|
||||
from r2.lib import promote
|
||||
Link.add_props(user, wrapped)
|
||||
user_is_sponsor = c.user_is_sponsor
|
||||
|
||||
status_dict = dict((v, k) for k, v in promote.STATUS.iteritems())
|
||||
status_dict = dict((v, k) for k, v in PROMOTE_STATUS.iteritems())
|
||||
for item in wrapped:
|
||||
# these are potentially paid for placement
|
||||
item.nofollow = True
|
||||
item.user_is_sponsor = user_is_sponsor
|
||||
status = getattr(item, "promote_status", -1)
|
||||
if item.is_author or c.user_is_sponsor:
|
||||
item.rowstyle = "link " + promote.STATUS.name[status].lower()
|
||||
item.rowstyle = "link " + PROMOTE_STATUS.name[status].lower()
|
||||
else:
|
||||
item.rowstyle = "link promoted"
|
||||
# Run this last
|
||||
|
||||
@@ -28,6 +28,11 @@ from r2.lib.db.thing import Thing, NotFound
|
||||
from r2.lib.utils import Enum
|
||||
from r2.models import Link
|
||||
|
||||
|
||||
PROMOTE_STATUS = Enum("unpaid", "unseen", "accepted", "rejected",
|
||||
"pending", "promoted", "finished")
|
||||
|
||||
|
||||
NO_TRANSACTION = 0
|
||||
|
||||
class PromoCampaign(Thing):
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
<%!
|
||||
from r2.lib.strings import strings
|
||||
from r2.lib.promote import STATUS
|
||||
from r2.models.promo import PROMOTE_STATUS
|
||||
%>
|
||||
|
||||
<%def name="banbuttons()">
|
||||
@@ -227,7 +227,7 @@
|
||||
_("reject"), _("cancel"), \
|
||||
"reject_promo", "cancel_reject_promo")}
|
||||
</li>
|
||||
%if thing.promote_status in (STATUS.unseen, STATUS.rejected):
|
||||
%if thing.promote_status in (PROMOTE_STATUS.unseen, PROMOTE_STATUS.rejected):
|
||||
<li>
|
||||
${ynbutton(_("accept"), _("accepted"), "promote")}
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user