mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-25 23:08:22 -05:00
Add new tab for link flair templates.
This commit is contained in:
@@ -2304,10 +2304,12 @@ class ApiController(RedditController):
|
||||
flair_template = VFlairTemplateByID('flair_template_id'),
|
||||
text = VFlairText('text'),
|
||||
css_class = VFlairCss('css_class'),
|
||||
text_editable = VBoolean('text_editable'))
|
||||
text_editable = VBoolean('text_editable'),
|
||||
flair_type = VOneOf('flair_type', (USER_FLAIR, LINK_FLAIR),
|
||||
default=USER_FLAIR))
|
||||
@api_doc(api_section.flair)
|
||||
def POST_flairtemplate(self, form, jquery, flair_template, text,
|
||||
css_class, text_editable):
|
||||
css_class, text_editable, flair_type):
|
||||
if text is None:
|
||||
text = ''
|
||||
if css_class is None:
|
||||
@@ -2332,7 +2334,8 @@ class ApiController(RedditController):
|
||||
try:
|
||||
flair_template = FlairTemplateBySubredditIndex.create_template(
|
||||
c.site._id, text=text, css_class=css_class,
|
||||
text_editable=text_editable)
|
||||
text_editable=text_editable,
|
||||
flair_type=flair_type)
|
||||
except OverflowError:
|
||||
form.set_html(".status:first", _('max flair templates reached'))
|
||||
return
|
||||
@@ -2342,15 +2345,18 @@ class ApiController(RedditController):
|
||||
# Push changes back to client.
|
||||
if new:
|
||||
jquery('#empty-flair-template').before(
|
||||
FlairTemplateEditor(flair_template).render(style='html'))
|
||||
FlairTemplateEditor(flair_template, flair_type)
|
||||
.render(style='html'))
|
||||
empty_template = FlairTemplate()
|
||||
empty_template._committed = True # to disable unnecessary warning
|
||||
jquery('#empty-flair-template').html(
|
||||
FlairTemplateEditor(empty_template).render(style='html'))
|
||||
FlairTemplateEditor(empty_template, flair_type)
|
||||
.render(style='html'))
|
||||
form.set_html('.status', _('saved'))
|
||||
else:
|
||||
jquery('#%s' % flair_template._id).html(
|
||||
FlairTemplateEditor(flair_template).render(style='html'))
|
||||
FlairTemplateEditor(flair_template, flair_type)
|
||||
.render(style='html'))
|
||||
form.set_html('.status', _('saved'))
|
||||
jquery('input[name="text"]').data('saved', text)
|
||||
jquery('input[name="css_class"]').data('saved', css_class)
|
||||
|
||||
@@ -25,6 +25,7 @@ from r2.models import FakeSubreddit, Subreddit, Ad, AdSR
|
||||
from r2.models import Friends, All, Sub, NotFound, DomainSR, Random, Mod, RandomNSFW, MultiReddit, ModSR
|
||||
from r2.models import Link, Printable, Trophy, bidding, PromotionWeights, Comment
|
||||
from r2.models import Flair, FlairTemplate, FlairTemplateBySubredditIndex
|
||||
from r2.models import USER_FLAIR, LINK_FLAIR
|
||||
from r2.models.oauth2 import OAuth2Client
|
||||
from r2.models import ModAction
|
||||
from r2.models import Thing
|
||||
@@ -2497,7 +2498,10 @@ class FlairPane(Templated):
|
||||
tabs = [
|
||||
('grant', _('grant flair'), FlairList(num, after, reverse, name,
|
||||
user)),
|
||||
('templates', _('edit flair templates'), FlairTemplateList()),
|
||||
('templates', _('user flair templates'),
|
||||
FlairTemplateList(USER_FLAIR)),
|
||||
('link_templates', _('link flair templates'),
|
||||
FlairTemplateList(LINK_FLAIR)),
|
||||
]
|
||||
|
||||
Templated.__init__(
|
||||
@@ -2590,21 +2594,27 @@ class FlairCsv(Templated):
|
||||
return self.results_by_line[-1]
|
||||
|
||||
class FlairTemplateList(Templated):
|
||||
def __init__(self, flair_type):
|
||||
Templated.__init__(self, flair_type=flair_type)
|
||||
|
||||
@property
|
||||
def templates(self):
|
||||
ids = FlairTemplateBySubredditIndex.get_template_ids(c.site._id)
|
||||
ids = FlairTemplateBySubredditIndex.get_template_ids(
|
||||
c.site._id, flair_type=self.flair_type)
|
||||
fts = FlairTemplate._byID(ids)
|
||||
return [FlairTemplateEditor(fts[i]) for i in ids]
|
||||
return [FlairTemplateEditor(fts[i], self.flair_type) for i in ids]
|
||||
|
||||
class FlairTemplateEditor(Templated):
|
||||
def __init__(self, flair_template):
|
||||
def __init__(self, flair_template, flair_type):
|
||||
Templated.__init__(self,
|
||||
id=flair_template._id,
|
||||
text=flair_template.text,
|
||||
css_class=flair_template.css_class,
|
||||
text_editable=flair_template.text_editable,
|
||||
sample=FlairTemplateSample(flair_template),
|
||||
position=getattr(c.site, 'flair_position', 'right'))
|
||||
sample=FlairTemplateSample(flair_template,
|
||||
flair_type),
|
||||
position=getattr(c.site, 'flair_position', 'right'),
|
||||
flair_type=flair_type)
|
||||
|
||||
def render(self, *a, **kw):
|
||||
res = Templated.render(self, *a, **kw)
|
||||
@@ -2614,11 +2624,16 @@ class FlairTemplateEditor(Templated):
|
||||
|
||||
class FlairTemplateSample(Templated):
|
||||
"""Like a read-only version of FlairTemplateEditor."""
|
||||
def __init__(self, flair_template):
|
||||
wrapped_user = WrappedUser(c.user, subreddit=c.site, force_show_flair=True,
|
||||
flair_template=flair_template)
|
||||
def __init__(self, flair_template, flair_type):
|
||||
if flair_type is USER_FLAIR:
|
||||
wrapped_user = WrappedUser(c.user, subreddit=c.site,
|
||||
force_show_flair=True,
|
||||
flair_template=flair_template)
|
||||
else:
|
||||
wrapped_user = Link(flair_text=flair_template.text,
|
||||
flair_css_class=flair_template.css_class)
|
||||
Templated.__init__(self, flair_template_id=flair_template._id,
|
||||
wrapped_user=wrapped_user)
|
||||
wrapped_user=wrapped_user, flair_type=flair_type)
|
||||
|
||||
class FlairPrefs(CachedTemplate):
|
||||
def __init__(self):
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
%if thing.id:
|
||||
<input type="hidden" name="flair_template_id" value="${thing.id}" />
|
||||
%endif
|
||||
<input type="hidden" name="flair_type" value="${thing.flair_type}" />
|
||||
<span class="flaircell flairsample-${thing.position} tagline">
|
||||
%if thing.text or thing.css_class:
|
||||
${unsafe(thing.sample.render())}
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
${flair_template}
|
||||
%endfor
|
||||
<div id="empty-flair-template">
|
||||
${FlairTemplateEditor(empty_template)}
|
||||
${FlairTemplateEditor(empty_template, thing.flair_type)}
|
||||
</div>
|
||||
</div>
|
||||
<form class="clearflairtemplates"
|
||||
|
||||
@@ -20,4 +20,14 @@
|
||||
## CondeNet, Inc. All Rights Reserved.
|
||||
################################################################################
|
||||
|
||||
${thing.wrapped_user}
|
||||
<%namespace file="link.html" import="entry" />
|
||||
|
||||
<%
|
||||
from r2.models import USER_FLAIR, LINK_FLAIR
|
||||
%>
|
||||
|
||||
%if thing.flair_type is USER_FLAIR:
|
||||
${thing.wrapped_user}
|
||||
%elif thing.flair_type is LINK_FLAIR:
|
||||
${entry(thing.wrapped_user)}
|
||||
%endif
|
||||
|
||||
Reference in New Issue
Block a user