mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-26 15:28:37 -05:00
Move PromotionLog to r2.models.promo from r2.lib.promote.
This commit is contained in:
@@ -144,7 +144,7 @@ class PromoteController(ListingController):
|
||||
note = nop("note"))
|
||||
def POST_promote_note(self, form, jquery, link, note):
|
||||
if promote.is_promo(link):
|
||||
text = promote.PromotionLog.add(link, note)
|
||||
text = PromotionLog.add(link, note)
|
||||
form.find(".notes").children(":last").after(
|
||||
"<p>" + text + "</p>")
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ from r2.models import Friends, All, Sub, NotFound, DomainSR, Random, Mod, Random
|
||||
from r2.models import Link, Printable, Trophy, bidding, PromoCampaign, PromotionWeights, Comment
|
||||
from r2.models import Flair, FlairTemplate, FlairTemplateBySubredditIndex
|
||||
from r2.models import USER_FLAIR, LINK_FLAIR
|
||||
from r2.models.promo import PromotionLog
|
||||
from r2.models.token import OAuth2Client, OAuth2AccessToken
|
||||
from r2.models import traffic
|
||||
from r2.models import ModAction
|
||||
@@ -3149,7 +3150,7 @@ class PromoteLinkForm(Templated):
|
||||
self.link = promote.wrap_promoted(link)
|
||||
campaigns = PromoCampaign._by_link(link._id)
|
||||
self.campaigns = promote.get_renderable_campaigns(link, campaigns)
|
||||
self.promotion_log = promote.PromotionLog.get(link)
|
||||
self.promotion_log = PromotionLog.get(link)
|
||||
|
||||
if not c.user_is_sponsor:
|
||||
self.now = promote.promo_datetime_now().date()
|
||||
|
||||
@@ -30,7 +30,7 @@ from r2.models.bidding import SponsorBoxWeightings, WeightingRef
|
||||
from r2.models.keyvalue import NamedGlobals
|
||||
from r2.lib.wrapped import Wrapped
|
||||
from r2.lib import authorize
|
||||
from r2.lib import emailer, filters
|
||||
from r2.lib import emailer
|
||||
from r2.lib.template_helpers import get_domain
|
||||
from r2.lib.utils import Enum, UniqueIterator, tup
|
||||
from r2.lib.organic import keep_fresh_links
|
||||
@@ -41,7 +41,6 @@ from r2.lib.db.queries import set_promote_status
|
||||
import itertools
|
||||
|
||||
import random
|
||||
from uuid import uuid1
|
||||
|
||||
|
||||
UPDATE_QUEUE = 'update_promos_q'
|
||||
@@ -897,6 +896,7 @@ def get_total_run(link):
|
||||
return earliest, latest
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
class PromotionLog(tdb_cassandra.View):
|
||||
_use_db = True
|
||||
_connection_pool = 'main'
|
||||
|
||||
@@ -21,9 +21,12 @@
|
||||
###############################################################################
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import uuid1
|
||||
|
||||
from pylons import g
|
||||
from pylons import g, c
|
||||
|
||||
from r2.lib import filters
|
||||
from r2.lib.db import tdb_cassandra
|
||||
from r2.lib.db.thing import Thing, NotFound
|
||||
from r2.lib.memoize import memoize
|
||||
from r2.lib.utils import Enum
|
||||
@@ -102,3 +105,33 @@ class PromoCampaign(Thing):
|
||||
self._deleted = True
|
||||
self._commit()
|
||||
|
||||
class PromotionLog(tdb_cassandra.View):
|
||||
_use_db = True
|
||||
_connection_pool = 'main'
|
||||
_compare_with = tdb_cassandra.TIME_UUID_TYPE
|
||||
|
||||
@classmethod
|
||||
def _rowkey(cls, link):
|
||||
return link._fullname
|
||||
|
||||
@classmethod
|
||||
def add(cls, link, text):
|
||||
name = c.user.name if c.user_is_loggedin else "<AUTOMATED>"
|
||||
now = datetime.now(g.tz).strftime("%Y-%m-%d %H:%M:%S")
|
||||
text = "[%s: %s] %s" % (name, now, text)
|
||||
rowkey = cls._rowkey(link)
|
||||
column = {uuid1(): filters._force_utf8(text)}
|
||||
cls._set_values(rowkey, column)
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def get(cls, link):
|
||||
rowkey = cls._rowkey(link)
|
||||
try:
|
||||
row = cls._byID(rowkey)
|
||||
except tdb_cassandra.NotFound:
|
||||
return []
|
||||
tuples = sorted(row._values().items(), key=lambda t: t[0].time)
|
||||
return [t[1] for t in tuples]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user