Browse files

Add link flair support to the flair selector.

  • Loading branch information...
1 parent 6d4faa8 commit 1861d7933eaaa66738ac018a52fa25eac9e6fcdf Logan Hanks committed Nov 7, 2011
View
32 r2/r2/controllers/api.py
@@ -2272,10 +2272,11 @@ def POST_setflairenabled(self, form, jquery, flair_enabled):
VModhash(),
flair_enabled = VBoolean("flair_enabled"),
flair_position = VOneOf("flair_position", ("left", "right")),
+ link_flair_position = VOneOf("link_flair_position", ("left", "right")),
flair_self_assign_enabled = VBoolean("flair_self_assign_enabled"))
@api_doc(api_section.flair)
def POST_flairconfig(self, form, jquery, flair_enabled, flair_position,
- flair_self_assign_enabled):
+ link_flair_position, flair_self_assign_enabled):
if c.site.flair_enabled != flair_enabled:
c.site.flair_enabled = flair_enabled
ModAction.create(c.site, c.user, action='editflair',
@@ -2284,6 +2285,10 @@ def POST_flairconfig(self, form, jquery, flair_enabled, flair_position,
c.site.flair_position = flair_position
ModAction.create(c.site, c.user, action='editflair',
details='flair_position')
+ if c.site.link_flair_position != link_flair_position:
+ c.site.link_flair_position = link_flair_position
+ ModAction.create(c.site, c.user, action='editflair',
+ details='link_flair_position')
if c.site.flair_self_assign_enabled != flair_self_assign_enabled:
c.site.flair_self_assign_enabled = flair_self_assign_enabled
ModAction.create(c.site, c.user, action='editflair',
@@ -2387,7 +2392,11 @@ def POST_clearflairtemplates(self, form, jquery):
link = VFlairLink('link'))
def POST_flairselector(self, user, link):
if link:
- return FlairSelector(link=link).render()
+ if hasattr(c.site, '_id') and c.site._id == link.sr_id:
+ site = c.site
+ else:
+ site = Subreddit._byID(link.sr_id, data=True)
+ return FlairSelector(link=link, site=site).render()
if user and not (c.user_is_admin or c.site.is_moderator(c.user)):
# ignore user parameter if c.user is not mod/admin
user = None
@@ -2404,19 +2413,24 @@ def POST_selectflair(self, form, jquery, user, link, flair_template_id,
text):
if link:
flair_type = LINK_FLAIR
+ if hasattr(c.site, '_id') and c.site._id == link.sr_id:
+ site = c.site
+ else:
+ site = Subreddit._byID(link.sr_id, data=True)
else:
flair_type = USER_FLAIR
+ site = c.site
try:
flair_template = FlairTemplateBySubredditIndex.get_template(
- c.site._id, flair_template_id, flair_type=flair_type)
+ site._id, flair_template_id, flair_type=flair_type)
except NotFound:
# TODO: serve error to client
- g.log.debug('invalid flair template for subreddit %s', c.site._id)
+ g.log.debug('invalid flair template for subreddit %s', site._id)
return
- if not c.site.is_moderator(c.user) and not c.user_is_admin:
- if not c.site.flair_self_assign_enabled:
+ if not site.is_moderator(c.user) and not c.user_is_admin:
+ if not site.flair_self_assign_enabled:
# TODO: serve error to client
g.log.debug('flair self-assignment not permitted')
return
@@ -2434,9 +2448,9 @@ def POST_selectflair(self, form, jquery, user, link, flair_template_id,
css_class = flair_template.css_class
if flair_type == USER_FLAIR:
- c.site.add_flair(user)
- setattr(user, 'flair_%s_text' % c.site._id, text)
- setattr(user, 'flair_%s_css_class' % c.site._id, css_class)
+ site.add_flair(user)
+ setattr(user, 'flair_%s_text' % site._id, text)
+ setattr(user, 'flair_%s_css_class' % site._id, css_class)
user._commit()
if ((c.site.is_moderator(c.user) or c.user_is_admin)
View
18 r2/r2/lib/pages/pages.py
@@ -2509,6 +2509,7 @@ def __init__(self, num, after, reverse, name, user):
tabs=TabbedPane(tabs),
flair_enabled=c.site.flair_enabled,
flair_position=c.site.flair_position,
+ link_flair_position=c.site.link_flair_position,
flair_self_assign_enabled=c.site.flair_self_assign_enabled)
class FlairList(Templated):
@@ -2654,7 +2655,7 @@ def __init__(self):
class FlairSelector(CachedTemplate):
"""Provide user with flair options according to subreddit settings."""
- def __init__(self, user=None, link=None):
+ def __init__(self, user=None, link=None, site=None):
if user is None:
user = c.user
if link:
@@ -2665,14 +2666,16 @@ def __init__(self, user=None, link=None):
flair_type = USER_FLAIR
target = user
attr_pattern = 'flair_%s_%%s' % c.site._id
+ if site is None:
+ site = c.site
- position = getattr(c.site, 'flair_position', 'right')
+ position = getattr(site, 'flair_position', 'right')
text = getattr(target, attr_pattern % 'text', '')
css_class = getattr(target, attr_pattern % 'css_class', '')
ids = FlairTemplateBySubredditIndex.get_template_ids(
- c.site._id, flair_type)
+ site._id, flair_type)
template_dict = FlairTemplate._byID(ids)
templates = [template_dict[i] for i in ids]
for template in templates:
@@ -2682,12 +2685,12 @@ def __init__(self, user=None, link=None):
else:
matching_template = None
- admin = bool(c.user_is_admin or c.site.is_moderator(c.user))
+ admin = bool(c.user_is_admin or site.is_moderator(c.user))
- if c.site.flair_self_assign_enabled or admin:
+ if site.flair_self_assign_enabled or admin:
choices = [
WrappedUser(
- user, subreddit=c.site, force_show_flair=True,
+ user, subreddit=site, force_show_flair=True,
flair_template=template,
flair_text_editable=admin or template.text_editable)
for template in templates]
@@ -2701,8 +2704,7 @@ def __init__(self, user=None, link=None):
choice.flair_text = text
break
- wrapped_user = WrappedUser(user, subreddit=c.site,
- force_show_flair=True)
+ wrapped_user = WrappedUser(user, subreddit=site, force_show_flair=True)
Templated.__init__(self, text=text, css_class=css_class,
position=position, choices=choices,
View
1 r2/r2/lib/wrapped.pyx
@@ -464,6 +464,7 @@ class CachedTemplate(Templated):
if c.user and hasattr(c.site, '_id'):
keys.extend([
c.site.flair_enabled, c.site.flair_position,
+ c.site.link_flair_position,
c.user.flair_enabled_in_sr(c.site._id),
c.user.pref_show_flair])
keys = [make_cachable(x, *a) for x in keys]
View
1 r2/r2/models/subreddit.py
@@ -75,6 +75,7 @@ class Subreddit(Thing, Printable):
link_type = 'any', # one of ('link', 'self', 'any')
flair_enabled = True,
flair_position = 'right', # one of ('left', 'right')
+ link_flair_position = 'left', # one of ('left', 'right')
flair_self_assign_enabled = False,
)
_essentials = ('type', 'name', 'lang')
View
10 r2/r2/public/static/css/reddit.css
@@ -681,7 +681,7 @@ a.author { margin-right: 0.5em; }
}
.title .flair {
- font-size: small;
+ font-size: x-small;
}
.link .tagline .flair {
@@ -802,7 +802,13 @@ a.author { margin-right: 0.5em; }
.embededmedia { margin-top: 5px; margin-left: 60px; }
-.thing .title { color: blue; padding: 0px; overflow: hidden; }
+.thing .title {
+ color: blue;
+ margin-right: .4em;
+ padding: 0px;
+ overflow: hidden;
+}
+
.thing .title:visited { color: #551a8b }
.thing .title.click { color: #551a8b }
View
6 r2/r2/public/static/js/flair.js
@@ -165,9 +165,11 @@ $(function() {
($(button).position().left + $(button).width() - 18) + "px")
.css("top", $(button).position().top + "px");
- var target = $(selector).siblings("form").find("input");
var params = {};
- params[target.attr("name")] = target.val();
+ $(selector).siblings("form").find("input").each(
+ function(idx, inp) {
+ params[inp.name] = inp.value;
+ });
$.request("flairselector", params, handleResponse, true, "html");
return false;
}
View
12 r2/r2/templates/flairpane.html
@@ -50,7 +50,7 @@
${_("allow users to assign their own flair")}
</label>
</%utils:line_field>
- <%utils:line_field title="${_('flair position')}">
+ <%utils:line_field title="${_('user flair position')}">
<table class="small-field">
${utils.radio_type('flair_position', "left", _("left"),
_("position flair to the left of the username"),
@@ -60,6 +60,16 @@
thing.flair_position == 'right')}
</table>
</%utils:line_field>
+ <%utils:line_field title="${_('link flair position')}">
+ <table class="small-field">
+ ${utils.radio_type('link_flair_position', "left", _("left"),
+ _("position flair to the left of the link"),
+ thing.link_flair_position == 'left')}
+ ${utils.radio_type('link_flair_position', "right", _("right"),
+ _("position flair to the right of the link"),
+ thing.link_flair_position == 'right')}
+ </table>
+ </%utils:line_field>
<div class="save-button">
<button type="submit">${_("save options")}</button>
</div>
View
7 r2/r2/templates/link.html
@@ -86,10 +86,15 @@
<%def name="entry()">
<p class="title">
- <%call expr="flair()" />
+ %if c.site.link_flair_position == 'left':
+ <%call expr="flair()" />
+ %endif
<%call expr="make_link('title', 'title')">
${thing.title}
</%call>
+ %if c.site.link_flair_position == 'right':
+ <%call expr="flair()" />
+ %endif
%if getattr(thing, "approval_checkmark", None):
<img class="approval-checkmark" title="${thing.approval_checkmark}"
src="${static('green-check.png')}"
View
4 r2/r2/templates/printablebuttons.html
@@ -70,7 +70,9 @@
<li>
<a class="flairselectbtn" href="javascript://">${_('flair')}</a>
<div class="flairselector drop-choices"></div>
- <form><input type="hidden" name="link" value="${thing.thing._fullname}"></form>
+ <form>
+ <input type="hidden" name="link" value="${thing.thing._fullname}">
+ </form>
</li>
%endif
</%def>

0 comments on commit 1861d79

Please sign in to comment.