Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

UC Berkeley Open Source group - now are we done? #269

Closed
wants to merge 39 commits into from

6 participants

@jmuhlfel

Esteemed admins of Reddit,

Now that our semester is nearly over we are submitting our working code for the custom subreddit menu project. Please take a look and let us know if there are any issues - we've tried to break our code in numerous ways, but all our attempts thus far have failed :) Our group email is cs198reddit@googlegroups.com if you want to contact us all at once.

Thanks again, especially to Chromakode for sitting down with us to iron out the details! We look forward to hearing back from you, and we ESPECIALLY look forward to seeing our contributions in the main trunk!

-the Cal CS198 Reddit group

(addendum: we think we've fixed all the trivial issues with our recent commits, hopefully real code reviewing can now begin)

jmuhlfel and others added some commits
@jmuhlfel jmuhlfel Added custom menus box in subreddit settings page 851fa2f
@jmuhlfel jmuhlfel Removed example.ini from git tracking, use your own damn configuration bec64e5
@jmuhlfel jmuhlfel Readded example.ini cfafdb0
@jmuhlfel jmuhlfel Readded example.ini c11086b
@edwu edwu Merge branch 'master' of git://github.com/jmuhlfel/reddit b674afe
@jmuhlfel jmuhlfel custom menus panel (frontend) now supports adding and removing additi…
…onal text boxes
1effa25
@edwu edwu Merge branch 'master' of git://github.com/jmuhlfel/reddit 7734d34
@edwu edwu hardcoded 5 links for submenu 062eb17
@jmuhlfel jmuhlfel we can put a static link on each subreddit page! look at line 61 of r…
…edditheader.html
1898b3e
@jmuhlfel jmuhlfel basic custom menu functionality (links only, no titles) 0659fcc
@edwu edwu made titles work df23e3a
@edwu edwu removed hardcoded links, now can dynamically add them up to a specifi…
…ed amount, need to validate presence of titles when adding links, and need to figure out how to delete links
6a9b4d8
@edwu edwu removed verification of existence for now, wrapped links in <li> e79221b
@edwu edwu fixed links 6bfef3c
user fixed validator so it won't break login 0e86eea
@edwu edwu better naming a43b038
@astraelly astraelly Fix for issue #245 b36305d
@jmuhlfel jmuhlfel fixed frontend javascript. we're almost there! :) 92915bd
@edwu edwu Merge branch 'master' of https://github.com/jmuhlfel/reddit 7952f77
@astraelly astraelly Fixed <3 on RTL layouts d0b9ea0
@astraelly astraelly Merge remote-tracking branch 'upstream/master' f624585
@jmuhlfel jmuhlfel added name tag to each input box d985053
@edwu edwu Merge branch 'master' of https://github.com/jmuhlfel/reddit 5b17050
@edwu edwu Merge branch 'master' of https://github.com/jmuhlfel/reddit a251d58
@edwu edwu backend validation works 5d811a9
@jmuhlfel jmuhlfel nice button styles. still uses absolute positioning, but it looks bet…
…ter than it did last time...
b3732a5
@edwu edwu cleaned up backend code 54d56a6
@edwu edwu front end works? cb2271c
@jmuhlfel jmuhlfel minor CSS fix 275e89f
@jmuhlfel jmuhlfel pre-merge with main Reddit code b44e023
@jmuhlfel jmuhlfel Merge remote-tracking branch 'upstream/master' 20e926b
@jmuhlfel jmuhlfel final fix (hopefully) 54e502b
@jmuhlfel jmuhlfel cleanup random project files b18e20a
@jmuhlfel jmuhlfel more cleanup in subreddit.py ad2912a
@jmuhlfel jmuhlfel css cleanup 35d94d2
@jmuhlfel jmuhlfel removed unnecessary files a90c490
@jmuhlfel jmuhlfel Revert "css cleanup"
This reverts commit 35d94d2.
e189caa
@jmuhlfel jmuhlfel readd needed files a6e5f62
@jmuhlfel jmuhlfel pre-pull request fixes 8a3555f
@et
et commented

Come on Cal, squash your commits! :bomb:

@chromakode chromakode was assigned
@spladug
Owner

Thanks for the patches, but I'm going to close this because it's way too old to merge now (and not really in a mergeable state anyway.)

@spladug spladug closed this
@jmuhlfel

Agreed on both points. Thanks anyway @spladug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 19, 2011
  1. @jmuhlfel
Commits on Oct 21, 2011
  1. @jmuhlfel
  2. @jmuhlfel

    Readded example.ini

    jmuhlfel authored
  3. @jmuhlfel

    Readded example.ini

    jmuhlfel authored
Commits on Oct 29, 2011
  1. @edwu
Commits on Nov 1, 2011
  1. @jmuhlfel
Commits on Nov 8, 2011
  1. @edwu
Commits on Nov 9, 2011
  1. @edwu

    hardcoded 5 links for submenu

    edwu authored
Commits on Nov 11, 2011
  1. @jmuhlfel
Commits on Nov 16, 2011
  1. @jmuhlfel
  2. @edwu

    made titles work

    edwu authored
Commits on Nov 28, 2011
  1. @edwu

    removed hardcoded links, now can dynamically add them up to a specifi…

    edwu authored
    …ed amount, need to validate presence of titles when adding links, and need to figure out how to delete links
  2. @edwu
  3. @edwu

    fixed links

    edwu authored
Commits on Nov 29, 2011
  1. fixed validator so it won't break login

    user authored
  2. @edwu

    better naming

    edwu authored
Commits on Nov 30, 2011
  1. @astraelly

    Fix for issue #245

    astraelly authored
  2. @jmuhlfel
  3. @edwu
  4. @astraelly

    Fixed <3 on RTL layouts

    astraelly authored
  5. @astraelly
  6. @jmuhlfel
  7. @edwu
  8. @edwu
  9. @edwu

    backend validation works

    edwu authored
  10. @jmuhlfel

    nice button styles. still uses absolute positioning, but it looks bet…

    jmuhlfel authored
    …ter than it did last time...
Commits on Dec 1, 2011
  1. @edwu

    cleaned up backend code

    edwu authored
  2. @edwu

    front end works?

    edwu authored
  3. @jmuhlfel

    minor CSS fix

    jmuhlfel authored
Commits on Dec 2, 2011
  1. @jmuhlfel
  2. @jmuhlfel
  3. @jmuhlfel

    final fix (hopefully)

    jmuhlfel authored
  4. @jmuhlfel

    cleanup random project files

    jmuhlfel authored
  5. @jmuhlfel

    more cleanup in subreddit.py

    jmuhlfel authored
  6. @jmuhlfel

    css cleanup

    jmuhlfel authored
  7. @jmuhlfel

    removed unnecessary files

    jmuhlfel authored
  8. @jmuhlfel

    Revert "css cleanup"

    jmuhlfel authored
    This reverts commit 35d94d2.
  9. @jmuhlfel

    readd needed files

    jmuhlfel authored
  10. @jmuhlfel

    pre-pull request fixes

    jmuhlfel authored
This page is out of date. Refresh to see the latest.
View
1  r2/example.ini
@@ -431,4 +431,3 @@ beaker.session_secret = somesecret
# execute malicious code after an exception is raised.
#set debug = false
-
View
31 r2/r2/controllers/api.py
@@ -60,6 +60,7 @@
from md5 import md5
import urllib
import urllib2
+import logging
def reject_vote(thing):
voteword = request.params.get('dir')
@@ -1217,8 +1218,21 @@ def POST_upload_sr_img(self, file, header, sponsor, name, form_id, img_type):
c.site._commit()
return UploadedImage(_('saved'), new_url, name,
errors=errors, form_id=form_id).render()
-
-
+
+ #checks for mismatched fields, empty fields and removes them
+ def customMenu(self, kw):
+ if 'link_urls' in kw and 'link_urls_titles' in kw:
+ link_urls = kw['link_urls']
+ link_urls_titles = kw['link_urls_titles']
+ for i in range(len(link_urls)):
+ if not (link_urls[i] and link_urls_titles[i]):
+ kw['link_urls'][i] = None
+ kw['link_urls_titles'][i] = None
+ temp = filter(lambda x: x, link_urls)
+ kw['link_urls'] = temp
+ temp2 = filter(lambda x: x, link_urls_titles)
+ kw['link_urls_titles'] = temp2
+
@validatedForm(VUser(),
VModhash(),
VRatelimit(rate_user = True,
@@ -1242,19 +1256,21 @@ def POST_upload_sr_img(self, file, header, sponsor, name, form_id, img_type):
sponsor_name =VLength('sponsorship-name', max_length = 64),
sponsor_url = VLength('sponsorship-url', max_length = 500),
css_on_cname = VBoolean("css_on_cname"),
+ link_urls = VCustomMenu(['link-url-0','link-url-1', 'link-url-2', 'link-url-3', 'link-url-4', 'link-url-5', 'link-url-6'], max_length = 100), #add up to 7 links
+ link_urls_titles = VCustomMenu(['link-url-title-0','link-url-title-1', 'link-url-title-2', 'link-url-title-3', 'link-url-title-4', 'link-url-title-5', 'link-url-title-6'], max_length = 100),
)
+
def POST_site_admin(self, form, jquery, name, ip, sr,
sponsor_text, sponsor_url, sponsor_name, **kw):
# the status button is outside the form -- have to reset by hand
form.parent().set_html('.status', "")
-
redir = False
kw = dict((k, v) for k, v in kw.iteritems()
if k in ('name', 'title', 'domain', 'description', 'over_18',
'show_media', 'show_cname_sidebar', 'type', 'link_type', 'lang',
"css_on_cname", "header_title",
- 'allow_top'))
-
+ 'allow_top', 'link_urls', 'link_urls_titles',))
+ self.customMenu(kw)
#if a user is banned, return rate-limit errors
if c.user._spam:
time = timeuntil(datetime.now(g.tz) + timedelta(seconds=600))
@@ -1306,10 +1322,9 @@ def POST_site_admin(self, form, jquery, name, ip, sr,
sr.sponsorship_text = sponsor_text or ""
sr.sponsorship_url = sponsor_url or None
sr.sponsorship_name = sponsor_name or None
-
+
#assume sr existed, or was just built
- old_domain = sr.domain
-
+ old_domain = sr.domain
if not sr.domain:
del kw['css_on_cname']
for k, v in kw.iteritems():
View
22 r2/r2/controllers/validator/validator.py
@@ -101,7 +101,6 @@ def __call__(self, url):
a.append(val)
return self.run(*a)
-
def build_arg_list(fn, env):
"""given a fn and and environment the builds a keyword argument list
for fn"""
@@ -422,6 +421,27 @@ def run(self, text, text2 = ''):
self.set_error(self.length_error, {'max_length': self.max_length})
else:
return text
+
+class VCustomMenu(Validator):
+ only_whitespace = re.compile(r"\A\s*\Z", re.UNICODE)
+
+ def __init__(self, param, max_length,
+ empty_error = errors.NO_TEXT,
+ length_error = errors.TOO_LONG,
+ **kw):
+ Validator.__init__(self, param, **kw)
+ self.max_length = max_length
+ self.length_error = length_error
+ self.empty_error = empty_error
+
+ def run(self, link1, link2, link3, link4, link5, link6, link7):
+ text = [link1,link2,link3,link4,link5,link6,link7]
+ for t in text:
+ if self.empty_error and (not t or self.only_whitespace.match(t)):
+ self.set_error(self.empty_error)
+ elif len(t) > self.max_length:
+ self.set_error(self.length_error, {'max_length': self.max_length})
+ return text
class VPrintable(VLength):
def run(self, text, text2 = ''):
View
13 r2/r2/models/subreddit.py
@@ -72,6 +72,8 @@ class Subreddit(Thing, Printable):
sponsorship_url = None,
sponsorship_img = None,
sponsorship_name = None,
+ link_urls = [],
+ link_urls_titles = [],
# do we allow self-posts, links only, or any?
link_type = 'any', # one of ('link', 'self', 'any')
flair_enabled = True,
@@ -197,6 +199,14 @@ def subscribers(self):
def flair(self):
return self.flair_ids()
+ @property
+ def link_urls(self):
+ return self._base.link_urls if self.base else []
+
+ @property
+ def link_urls_titles(self):
+ return self._base.link_urls_titles if self.base else []
+
def spammy(self):
return self._spam
@@ -843,8 +853,7 @@ def sponsorship_text(self):
@property
def sponsorship_img(self):
return self._base.sponsorship_img if self._base else ""
-
-
+
class MultiReddit(_DefaultSR):
name = 'multi'
View
41 r2/r2/public/static/css/reddit.css
@@ -75,6 +75,10 @@ input[type=checkbox], input[type=radio] { margin-top: .4em; }
/* forms */
+#menu-links input[type="text"]{
+ width: 200px;
+}
+
label.disabled { color: gray; }
.wrong {color: red; font-weight: normal}
.attention {
@@ -367,6 +371,26 @@ ul.flat-vert {text-align: left;}
z-index: 100;
}
+.custom_menu {
+ position: absolute;
+ bottom: 29px;
+ left: 188px;
+ display: inline-block;
+ list-style-type: none;
+ white-space: nowrap;
+}
+
+.custom_menu li {
+ display: inline;
+ font-weight: bold;
+ padding: 4px 3px 0px;
+}
+
+.custom_menu li a {
+ padding: 1px 6px 2px 6px;
+ background-color: #eff7ff;
+ }
+
.tabpane-content { border: 1px solid #5f99cf; padding: 4px 4px 4px 4px; }
#search input[type=text] {
@@ -448,6 +472,21 @@ ul.flat-vert {text-align: left;}
background-image: url(../gradient-nub-hover.png); /* SPRITE */
}
+.morelink .nub-rtl {
+ position: absolute;
+ top: -1px;
+ right: -1px;
+ height: 31px;
+ width: 24px;
+ background: white none no-repeat scroll center left;
+ background-image: url(/static/gradient-nub-rtl.png); /* SPRITE */
+}
+
+.morelink:hover .nub-rtl, .mlhn {
+ background-image: url(/static/gradient-nub-hover-rtl.png); /* SPRITE */
+}
+
+
/* raised box */
.raisedbox {
@@ -2937,6 +2976,8 @@ ul#image-preview-list .description pre {
text-transform: uppercase;
border-bottom: 1px solid gray;
font-size: 90%;
+ position: relative;
+ z-index: 1;
}
#sr-header-area .selected a {
View
63 r2/r2/templates/createsubreddit.html
@@ -240,6 +240,69 @@
</ul>
</%utils:line_field>
+ <%utils:line_field title="${_('custom menus')}">
+ <ul class="upload" id="menu-links">
+ <li><span class="gray">(${_("all links must start with http://")})</span></li>
+ <script language="javascript">
+ function add() {
+ var li = document.createElement("li");
+ li.setAttribute("id", "menu-item-" + i);
+
+ var list = document.getElementById("menu-links");
+
+ li.innerHTML = "<input type=\"text\" id=\"link-url-"+i+"\" name=\"link-url-"+i+"\" placeholder=\"link URL\" /> " +
+ "<input type=\"text\" id=\"link-url-title-"+i+"\" name=\"link-url-title-"+i+"\" placeholder=\"link title\" />";
+
+ list.appendChild(li);
+ i++;
+ if(i >= 1){
+ document.getElementById("remove-button").style.visibility = "visible";
+ }
+ if(i >= 7){
+ document.getElementById("add-button").style.visibility = "hidden";
+ }
+
+ }
+
+ function remove() {
+ var d = document.getElementById("menu-links");
+
+ var olddiv = document.getElementById("menu-item-" + --i);
+
+ d.removeChild(olddiv);
+ if(i < 1){
+ document.getElementById("remove-button").style.visibility = "hidden";
+ }
+ }
+
+ $(window).load(function(){
+ i=${len(thing.site.link_urls)};
+ if(i < 1){
+ document.getElementById("remove-button").style.visibility = "hidden";
+ }
+ });
+ </script>
+ %for i in range(len(thing.site.link_urls)):
+ <li id="${'menu-item-' + str(i)}">
+ <input type="text" name="${'link-url-' + str(i)}" placeholder="link URL" id="${'link-url-' + str(i)}"
+ value="${thing.site.link_urls[i]}"
+ />
+
+ <input type="text" name="${'link-url-title-' + str(i)}" placeholder="link title" id="${'link-url-title-' + str(i)}"
+ value="${thing.site.link_urls_titles[i]}"
+ />
+ </li>
+ %endfor
+
+ </ul>
+
+ <button type="button" id="add-button" onclick="add()">Add link</button>
+ <button type="button" id="remove-button" onclick="remove()">Remove link</button>
+
+ <div class="clear"></div>
+
+ </%utils:line_field>
+
%if c.user_is_admin:
<%utils:line_field title="${_('sponsorship')}">
<ul class="upload">
View
13 r2/r2/templates/redditheader.html
@@ -58,8 +58,18 @@
%for toolbar in thing.toolbars:
${toolbar}
%endfor
- </div>
+ ##custom menu for subreddits
+ %if not isinstance(c.site, FakeSubreddit):
+ <ul class="custom_menu">
+ %for i in range(len(c.site.link_urls)):
+ <li><a href="${c.site.link_urls[i]}" title="${c.site.link_urls_titles[i]}">${c.site.link_urls_titles[i]}</a></li>
+ %endfor
+ </ul>
+ %endif
+
+ </div>
+
<div id="header-bottom-${'left' if c.lang_rtl else 'right'}">
%if not c.user_is_loggedin:
%if thing.enable_login_cover and not g.read_only_mode:
@@ -119,3 +129,4 @@
%endif
</div>
</div>
+
View
1  r2/r2/templates/sidebox.html
@@ -39,3 +39,4 @@
</div>
%endif
</div>
+
Something went wrong with that request. Please try again.