Move get_promote_srid from r2.lib.promote to r2.models.promo.

This commit is contained in:
bsimpson63
2012-10-31 12:44:36 -04:00
parent b18fffae00
commit dcc73cd52a
5 changed files with 20 additions and 20 deletions

View File

@@ -41,7 +41,7 @@ from r2.lib import organic
import r2.lib.search as search
from r2.lib.utils import iters, check_cheating, timeago
from r2.lib import sup
from r2.lib.promote import randomized_promotion_list, get_promote_srid
from r2.lib.promote import randomized_promotion_list
import socket
from api_docs import api_doc, api_section

View File

@@ -29,7 +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.promo import PROMOTE_STATUS, get_promote_srid
from r2.models.query_cache import (cached_query, merged_cached_query,
CachedQuery, CachedQueryMutator,
MergedCachedQuery)
@@ -702,8 +702,6 @@ def set_promote_status(link, promote_status):
def _promoted_link_query(user_id, status):
from r2.lib.promote import get_promote_srid
STATUS_CODES = {'unpaid': PROMOTE_STATUS.unpaid,
'unapproved': PROMOTE_STATUS.unseen,
'rejected': PROMOTE_STATUS.rejected,

View File

@@ -60,19 +60,6 @@ def health_check():
return time.time() - int(NamedGlobals.get(PROMO_HEALTH_KEY, default=0))
@memoize("get_promote_srid")
def get_promote_srid(name = 'promos'):
try:
sr = Subreddit._by_name(name, stale=True)
except NotFound:
sr = Subreddit._new(name = name,
title = "promoted links",
# negative author_ids make this unlisable
author_id = -1,
type = "public",
ip = '0.0.0.0')
return sr._id
# attrs
def promo_traffic_url(l): # old traffic url

View File

@@ -37,7 +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 r2.models.promo import PROMOTE_STATUS, get_promote_srid
from pylons import c, g, request
from pylons.i18n import ungettext, _
@@ -728,7 +728,6 @@ class Comment(Thing, Printable):
@classmethod
def add_props(cls, user, wrapped):
from r2.lib.template_helpers import add_attr, get_domain
from r2.lib import promote
from r2.lib.wrapped import CachedVariable
from r2.lib.pages import WrappedUser
@@ -757,7 +756,7 @@ class Comment(Thing, Printable):
can_reply_srs = set(s._id for s in subreddits if s.can_comment(user)) \
if c.user_is_loggedin else set()
can_reply_srs.add(promote.get_promote_srid())
can_reply_srs.add(get_promote_srid())
min_score = user.pref_min_comment_score

View File

@@ -25,6 +25,7 @@ from datetime import datetime
from pylons import g
from r2.lib.db.thing import Thing, NotFound
from r2.lib.memoize import memoize
from r2.lib.utils import Enum
from r2.models import Link
@@ -33,6 +34,21 @@ PROMOTE_STATUS = Enum("unpaid", "unseen", "accepted", "rejected",
"pending", "promoted", "finished")
@memoize("get_promote_srid")
def get_promote_srid(name = 'promos'):
from r2.models.subreddit import Subreddit
try:
sr = Subreddit._by_name(name, stale=True)
except NotFound:
sr = Subreddit._new(name = name,
title = "promoted links",
# negative author_ids make this unlisable
author_id = -1,
type = "public",
ip = '0.0.0.0')
return sr._id
NO_TRANSACTION = 0
class PromoCampaign(Thing):