Stickies: set with a button on comments page

This replaces the need to enter the sticky's permalink on the subreddit
settings page, and adds a new button for stickying/unstickying next to
the contest mode button.
This commit is contained in:
Chad Birch
2013-08-07 12:28:01 -06:00
parent e0889c4ea7
commit 850a07c8cc
7 changed files with 38 additions and 29 deletions

View File

@@ -1134,6 +1134,27 @@ class ApiController(RedditController, OAuth2ResourceController):
thing._commit()
jquery.refresh()
@require_oauth2_scope("modposts")
@validatedForm(VUser(),
VModhash(),
VSrCanBan('id'),
thing=VByName('id'),
state=VBoolean('state'))
def POST_set_subreddit_sticky(self, form, jquery, thing, state):
"""Sets or unsets a self-post as the sticky post in its subreddit."""
if not isinstance(thing, Link) or not thing.is_self:
return
sr = thing.subreddit_slow
if state:
sr.sticky_fullname = thing._fullname
elif not state:
sr.sticky_fullname = None
sr._commit()
jquery.refresh()
@noresponse(VUser(), VModhash(),
thing = VByName('id'))
@api_doc(api_section.links_and_comments)
@@ -1748,7 +1769,6 @@ class ApiController(RedditController, OAuth2ResourceController):
show_cname_sidebar = VBoolean('show_cname_sidebar'),
type = VOneOf('type', ('public', 'private', 'restricted', 'gold_restricted', 'archived')),
link_type = VOneOf('link_type', ('any', 'link', 'self')),
sticky_permalink=VUrl('sticky_permalink'),
submit_link_label=VLength('submit_link_label', max_length=60),
submit_text_label=VLength('submit_text_label', max_length=60),
comment_score_hide_mins=VInt('comment_score_hide_mins',
@@ -1795,7 +1815,7 @@ class ApiController(RedditController, OAuth2ResourceController):
if k in ('name', 'title', 'domain', 'description',
'show_media', 'exclude_banned_modqueue',
'show_cname_sidebar', 'type', 'public_traffic',
'link_type', 'sticky_permalink',
'link_type',
'submit_link_label', 'comment_score_hide_mins',
'submit_text_label', 'lang', 'css_on_cname',
'header_title', 'over_18', 'wikimode', 'wiki_edit_karma',
@@ -1843,17 +1863,6 @@ class ApiController(RedditController, OAuth2ResourceController):
if cname_sr and (not sr or sr != cname_sr):
c.errors.add(errors.USED_CNAME)
sticky_fullname = None
if kw['sticky_permalink']:
sticky_url = UrlParser(kw['sticky_permalink']).path
if sticky_url:
try:
sticky_fullname = Link._by_url(sticky_url, sr)._fullname
except NotFound:
c.errors.add(errors.BAD_URL, field='sticky_permalink')
else:
c.errors.add(errors.BAD_URL, field='sticky_permalink')
can_set_archived = c.user_is_admin or (sr and sr.type == 'archived')
if kw['type'] == 'archived' and not can_set_archived:
c.errors.add(errors.INVALID_OPTION, field='type')
@@ -1882,8 +1891,6 @@ class ApiController(RedditController, OAuth2ResourceController):
elif (form.has_errors(('wiki_edit_karma', 'wiki_edit_age'),
errors.BAD_NUMBER)):
pass
elif form.has_errors('sticky_permalink', errors.BAD_URL):
pass
elif form.has_errors('comment_score_hide_mins', errors.BAD_NUMBER):
pass
#creating a new reddit
@@ -1917,8 +1924,6 @@ class ApiController(RedditController, OAuth2ResourceController):
success = update_wiki_text(sr)
sr.sticky_fullname = sticky_fullname
if not sr.domain:
del kw['css_on_cname']
for k, v in kw.iteritems():

View File

@@ -807,7 +807,6 @@ class SubredditSettingsTemplate(ThingJsonTemplate):
wiki_edit_age = 'site.wiki_edit_age',
domain_sidebar = 'site.show_cname_sidebar',
header_hover_text='site.header_title',
sticky_permalink='site.sticky_permalink',
)
def kind(self, wrapped):

View File

@@ -4094,11 +4094,13 @@ class Goldvertisement(Templated):
class LinkCommentsSettings(Templated):
def __init__(self, link):
Templated.__init__(self)
sr = link.subreddit_slow
self.link = link
self.contest_mode = link.contest_mode
self.stickied = link._fullname == sr.sticky_fullname
self.can_edit = (c.user_is_loggedin
and (c.user_is_admin or
link.subreddit_slow.is_moderator(c.user)))
sr.is_moderator(c.user)))
class ModeratorPermissions(Templated):
def __init__(self, user, permissions_type, permissions,

View File

@@ -206,7 +206,6 @@ class Subreddit(Thing, Printable, BaseSite):
mod_actions=0,
# do we allow self-posts, links only, or any?
link_type='any', # one of ('link', 'self', 'any')
sticky_permalink=None,
sticky_fullname=None,
submit_link_label='',
submit_text_label='',

View File

@@ -1330,6 +1330,8 @@ a.author { margin-right: 0.5em; }
margin: 0 310px 10px 10px;
padding: 0;
color: gray;
form { padding-left: 8px; }
}
.commentarea .menuarea .toggle {

View File

@@ -275,15 +275,6 @@
</ul>
</div>
<div class="usertext-edit">
<div class="delete-field">
<label for="sticky_permalink">${_('Permalink to stickied self-post (blank for none):')}</label>
<input id="sticky_permalink" type="text" name="sticky_permalink"
%if thing.site:
value="${thing.site.sticky_permalink}"
%endif
>
${error_field("BAD_URL", "sticky_permalink")}
</div>
<div class="delete-field">
<label for="comment_score_hide_mins">${_('Minutes to hide comment scores:')}</label>
%if thing.site:

View File

@@ -37,3 +37,14 @@
%if thing.can_edit or thing.contest_mode:
&nbsp;<span class="help-hoverable" title="${_('contest mode randomizes sorting and hides scores. this feature is temporarily available to assist best of 2012 contests.')}">(?)</span>
%endif
%if thing.can_edit and thing.link.is_self:
%if thing.stickied:
${ynbutton(_("unsticky this post"), _("unstickied"), "set_subreddit_sticky",
hidden_data=dict(id=thing.link._fullname, state=False))}
%else:
${ynbutton(_("sticky this post"), _("stickied"), "set_subreddit_sticky",
question=_("sticky this? (any existing sticky will be replaced)"),
hidden_data=dict(id=thing.link._fullname, state=True))}
%endif
%endif