Skip to content
This repository
Browse code

Move the saved links listing to the profile page hierarchy.

  • Loading branch information...
commit 6ab11b367c0d1628ed4e1cb83aefea7608fea202 1 parent c9c959d
Neil Williams authored May 02, 2012
3  r2/r2/config/routing.py
@@ -156,10 +156,11 @@ def make_map(global_conf={}, app_conf={}):
156 156
 
157 157
     mc('/', controller='hot', action='listing')
158 158
 
159  
-    listing_controllers = "hot|saved|new|randomrising|comments"
  159
+    listing_controllers = "hot|new|randomrising|comments"
160 160
 
161 161
     mc('/:controller', action='listing',
162 162
        requirements=dict(controller=listing_controllers))
  163
+    mc('/saved', controller='user', action='saved_redirect')
163 164
 
164 165
     mc('/by_id/:names', controller='byId', action='listing')
165 166
 
1  r2/r2/controllers/__init__.py
@@ -21,7 +21,6 @@
21 21
 ################################################################################
22 22
 from listingcontroller import ListingController
23 23
 from listingcontroller import HotController
24  
-from listingcontroller import SavedController
25 24
 from listingcontroller import NewController
26 25
 from listingcontroller import BrowseController
27 26
 from listingcontroller import MessageController
32  r2/r2/controllers/listingcontroller.py
@@ -49,6 +49,7 @@
49 49
 
50 50
 from pylons.i18n import _
51 51
 from pylons import Response
  52
+from pylons.controllers.util import redirect_to
52 53
 
53 54
 import random
54 55
 from functools import partial
@@ -351,19 +352,6 @@ def GET_listing(self, **env):
351 352
         self.infotext = request.get.get('deleted') and strings.user_deleted
352 353
         return ListingController.GET_listing(self, **env)
353 354
 
354  
-class SavedController(ListingController):
355  
-    where = 'saved'
356  
-    skip = False
357  
-    title_text = _('saved')
358  
-
359  
-    def query(self):
360  
-        return queries.get_saved(c.user)
361  
-
362  
-    @validate(VUser())
363  
-    @listing_api_doc(uri='/saved')
364  
-    def GET_listing(self, **env):
365  
-        return ListingController.GET_listing(self, **env)
366  
-
367 355
 class NewController(ListingController):
368 356
     where = 'new'
369 357
     title_text = _('newest submissions')
@@ -527,6 +515,7 @@ def title(self):
527 515
                   'submitted': _("submitted by %(user)s"),
528 516
                   'liked': _("liked by %(user)s"),
529 517
                   'disliked': _("disliked by %(user)s"),
  518
+                  'saved': _("saved by %(user)s"),
530 519
                   'hidden': _("hidden by %(user)s")}
531 520
         title = titles.get(self.where, _('profile for %(user)s')) \
532 521
             % dict(user = self.vuser.name, site = c.site.name)
@@ -548,6 +537,8 @@ def keep(item):
548 537
                     return False
549 538
                 if item.likes is not False and self.where == 'disliked':
550 539
                     return False
  540
+                if self.where == 'saved' and not item.saved:
  541
+                    return False
551 542
             return wouldkeep and (getattr(item, "promoted", None) is None and
552 543
                     (self.where == "deleted" or
553 544
                      not getattr(item, "deleted", False)))
@@ -580,6 +571,9 @@ def query(self):
580 571
         elif self.where == 'hidden':
581 572
             q = queries.get_hidden(self.vuser)
582 573
 
  574
+        elif self.where == 'saved':
  575
+            q = queries.get_saved(self.vuser)
  576
+
583 577
         elif c.user_is_admin:
584 578
             q = admin_profile_query(self.vuser, self.where, desc('_date'))
585 579
 
@@ -594,7 +588,7 @@ def query(self):
594 588
     @listing_api_doc(section=api_section.users, uri='/{username}/{where}',
595 589
                      uri_variants=['/{username}/' + where for where in [
596 590
                                        'overview', 'submitted', 'commented',
597  
-                                       'liked', 'disliked', 'hidden']])
  591
+                                       'liked', 'disliked', 'hidden', 'saved']])
598 592
     def GET_listing(self, where, vuser, sort, time, **env):
599 593
         self.where = where
600 594
         self.sort = sort
@@ -618,6 +612,11 @@ def GET_listing(self, where, vuser, sort, time, **env):
618 612
             and not votes_visible(vuser)):
619 613
             return self.abort403()
620 614
 
  615
+        if where == "saved" and not (c.user_is_loggedin and
  616
+                                     (c.user._id == vuser._id or
  617
+                                      c.user_is_admin)):
  618
+            self.abort403()
  619
+
621 620
         check_cheating('user')
622 621
 
623 622
         self.vuser = vuser
@@ -637,6 +636,11 @@ def GET_about(self, vuser):
637 636
             return self.abort404()
638 637
         return Reddit(content = Wrapped(vuser)).render()
639 638
 
  639
+    def GET_saved_redirect(self):
  640
+        if not c.user_is_loggedin:
  641
+            abort(404)
  642
+        return redirect_to("/user/" + c.user.name + "/saved")
  643
+
640 644
 class MessageController(ListingController):
641 645
     show_nums = False
642 646
     render_cls = MessagePage
3  r2/r2/lib/pages/pages.py
@@ -1227,6 +1227,9 @@ def build_toolbars(self):
1227 1227
                         NamedButton('disliked'),
1228 1228
                         NamedButton('hidden')]
1229 1229
 
  1230
+        if c.user_is_loggedin and (c.user._id == self.user._id or
  1231
+                                   c.user_is_admin):
  1232
+            main_buttons += [NamedButton('saved')]
1230 1233
 
1231 1234
         toolbar = [PageNameNav('nomenu', title = self.user.name),
1232 1235
                    NavMenu(main_buttons, base_path = path, type="tabmenu")]

1 note on commit 6ab11b3

Eddie Kay

I think this commit may have caused issue 442. Could you take a look?

Please sign in to comment.
Something went wrong with that request. Please try again.