PromotedLinks can be selfposts.

This commit is contained in:
Brian Simpson
2013-07-16 07:27:12 -04:00
parent ed18fc5b21
commit bf0fd5dc24
7 changed files with 80 additions and 11 deletions

View File

@@ -80,6 +80,7 @@ from r2.lib.validator import (
VOneOf,
VPromoCampaign,
VRatelimit,
VSelfText,
VShamedDomain,
VSponsor,
VSponsorAdmin,
@@ -391,6 +392,8 @@ class PromoteController(ListingController):
l=VLink('link_id'),
title=VTitle('title'),
url=VUrl('url', allow_self=False, lookup=False),
selftext=VSelfText('text'),
kind=VOneOf('kind', ['link', 'self']),
ip=ValidIP(),
disable_comments=VBoolean("disable_comments"),
media_width=VInt("media-width", min=0),
@@ -399,7 +402,7 @@ class PromoteController(ListingController):
media_override=VBoolean("media-override"),
domain_override=VLength("domain", 100)
)
def POST_edit_promo(self, form, jquery, ip, l, title, url,
def POST_edit_promo(self, form, jquery, ip, l, title, url, selftext, kind,
disable_comments,
media_height, media_width, media_embed,
media_override, domain_override):
@@ -426,17 +429,29 @@ class PromoteController(ListingController):
# want the URL
url = url[0].url
if kind == 'link':
if form.has_errors('url', errors.NO_URL, errors.BAD_URL):
return
# users can change the disable_comments on promoted links
if ((not l or not promote.is_promoted(l)) and
(form.has_errors('title', errors.NO_TEXT,
errors.TOO_LONG) or
form.has_errors('url', errors.NO_URL, errors.BAD_URL) or
jquery.has_errors('ratelimit', errors.RATELIMIT))):
(form.has_errors('title', errors.NO_TEXT, errors.TOO_LONG) or
jquery.has_errors('ratelimit', errors.RATELIMIT))):
return
if not l:
l = promote.new_promotion(title, url, c.user, ip)
l = promote.new_promotion(title, url if kind == 'link' else 'self',
selftext if kind == 'self' else '',
c.user, ip)
elif promote.is_promo(l):
# changing link type is not allowed
if ((l.is_self and kind == 'link') or
(not l.is_self and kind == 'self')):
c.errors.add(errors.NO_CHANGE_KIND, field="kind")
form.set_error(errors.NO_CHANGE_KIND, "kind")
return
changed = False
# live items can only be changed by a sponsor, and also
# pay the cost of de-approving the link
@@ -445,7 +460,8 @@ class PromoteController(ListingController):
if title and title != l.title:
l.title = title
changed = not trusted
if url and url != l.url:
if kind == 'link' and url and url != l.url:
l.url = url
changed = not trusted
@@ -455,6 +471,10 @@ class PromoteController(ListingController):
if trusted and promote.is_unapproved(l):
promote.accept_promotion(l)
# selftext can be changed at any time
if kind == 'self':
l.selftext = selftext
# comment disabling is free to be changed any time.
l.disable_comments = disable_comments
if c.user_is_sponsor or c.user.trusted_sponsor:

View File

@@ -131,6 +131,7 @@ error_list = dict((
('JSON_PARSE_ERROR', _('unable to parse JSON data')),
('JSON_INVALID', _('unexpected JSON structure')),
('JSON_MISSING_KEY', _('JSON missing key: "%(key)s"')),
('NO_CHANGE_KIND', _("can't change post type")),
))
errors = Storage([(e, e) for e in error_list.keys()])

View File

@@ -290,7 +290,7 @@ def traffic_totals():
traffic_data = traffic.zip_timeseries(impressions, clicks)
return [(d.date(), v) for d, v in traffic_data]
def new_promotion(title, url, user, ip):
def new_promotion(title, url, selftext, user, ip):
"""
Creates a new promotion with the provided title, etc, and sets it
status to be 'unpaid'.
@@ -300,6 +300,12 @@ def new_promotion(title, url, user, ip):
l.promoted = True
l.disable_comments = False
PromotionLog.add(l, 'promotion created')
if url == 'self':
l.url = l.make_permalink_slow()
l.is_self = True
l.selftext = selftext
l._commit()
# set the status of the link, populating the query queue

View File

@@ -4274,6 +4274,10 @@ ul.tabmenu.formtab {
width: 100%;
}
#kind-selector label {
padding-right: 20px;
}
.campaign {
border: 1px solid #336699;
background-color: #EFF7FF;

View File

@@ -52,6 +52,12 @@ ${unsafe(taglinetext % dict(date = thing._date.strftime("%Y-%m-%d"),
report = report)}
</%def>
<%def name="domain()">
%if not thing.is_self:
${parent.domain()}
%endif
</%def>
<%def name="entry()">
${parent.entry()}
<p class="sponsored-tagline">

View File

@@ -25,6 +25,7 @@
from r2.lib.media import thumbnail_url
from r2.lib.template_helpers import static
from r2.lib import promote
from r2.lib.pages import UserText
from r2.lib.strings import strings
from r2.models import Account
from r2.lib import js
@@ -86,8 +87,14 @@ ${unsafe(js.use('sponsored'))}
editable = trusted or not promote.is_promoted(thing.link)
%>
<input name="kind" value="${'self' if thing.link.is_self else 'link'}" type="hidden">
${title_field(thing.link, editable=editable)}
${url_field(thing.link, editable=editable, enable_override=c.user_is_sponsor)}
%if thing.link.is_self:
${text_field(thing.link.selftext)}
%else:
${url_field(thing.link, editable=editable, enable_override=c.user_is_sponsor)}
%endif
${error_field("NO_CHANGE_KIND", "kind", "div")}
%if editable:
${image_field(thing.link)}
@@ -129,9 +136,25 @@ ${self.javascript_setup()}
</%utils:line_field>
</%def>
<%def name="kind_selector(link_selected=True)">
<%utils:line_field title="${_('post type')}" id="kind-selector" css_class="rounded">
<div class="linefield-content">
<input id="url_link" class="nomargin"
type="radio" value="link" name="kind"
onclick="$('#text-field').hide(); $('#url-field').show()"
${"checked='checked'" if link_selected else ""}>
<label for="url_link">${_("link")}</label>
<input id="self_link" class="nomargin"
type="radio" value="self" name="kind"
onclick="$('#url-field').hide(); $('#text-field').show()"
${"" if link_selected else "checked='checked'"}>
<label for="self_link">${_("text")}</label>
</div>
</%utils:line_field>
</%def>
<%def name="url_field(link, editable=False, enable_override=False)">
<%utils:line_field title="${_('url')}" id="url-field" css_class="rounded">
<input name="kind" value="link" type="hidden"/>
<input id="url" name="url" type="text"
${"disabled" if not editable else ""}
value="${('self' if link.is_self else link.url) if link else ""}"
@@ -161,6 +184,13 @@ ${self.javascript_setup()}
</%utils:line_field>
</%def>
<%def name="text_field(text='', visible=True)">
<%utils:line_field title="${_('text')}" id="text-field" css_class="rounded"
style="${('' if visible else 'display:none')}">
${UserText(None, text=text, have_form=False, creating=True)}
</%utils:line_field>
</%def>
<%def name="image_field(link)">
<%utils:line_field title="${_('look and feel')}"
description="${_('images will be resized if larger than 70 x 70 pixels')}"

View File

@@ -20,7 +20,7 @@
## reddit Inc. All Rights Reserved.
###############################################################################
<%namespace file="promotelinkform.html" import="title_field, url_field" />
<%namespace file="promotelinkform.html" import="title_field, url_field, text_field, kind_selector" />
<%namespace file="utils.html" import="error_field" />
<%namespace name="utils" file="utils.html"/>
@@ -33,7 +33,9 @@
<div class="pretty-form" id="promo-form">
${title_field(None, editable=True)}
${kind_selector()}
${url_field(None, editable=True, enable_override=c.user_is_sponsor)}
${text_field(visible=False)}
<div class="rules">
By clicking "next" you agree to the&#32;<a href="http://www.reddit.com/wiki/selfservicepromotion">Self Serve Advertising Rules.</a>