Example #1
0
    def query(self):
        q = None
        if self.where == 'overview':
            self.check_modified(self.vuser, 'overview')
            q = queries.get_overview(self.vuser, self.sort, self.time)

        elif self.where == 'comments':
            sup.set_sup_header(self.vuser, 'commented')
            self.check_modified(self.vuser, 'commented')
            q = queries.get_comments(self.vuser, self.sort, self.time)

        elif self.where == 'submitted':
            sup.set_sup_header(self.vuser, 'submitted')
            self.check_modified(self.vuser, 'submitted')
            q = queries.get_submitted(self.vuser, self.sort, self.time)

        elif self.where in ('liked', 'disliked'):
            sup.set_sup_header(self.vuser, self.where)
            self.check_modified(self.vuser, self.where)
            if self.where == 'liked':
                q = queries.get_liked(self.vuser)
            else:
                q = queries.get_disliked(self.vuser)

        elif self.where == 'hidden':
            q = queries.get_hidden(self.vuser)

        elif c.user_is_admin:
            q = admin_profile_query(self.vuser, self.where, desc('_date'))

        if q is None:
            return self.abort404()

        return q
    def query(self):
        q = None
        if self.where == 'overview':
            self.check_modified(self.vuser, 'overview')
            q = queries.get_overview(self.vuser, self.sort, self.time)

        elif self.where == 'comments':
            sup.set_sup_header(self.vuser, 'commented')
            self.check_modified(self.vuser, 'commented')
            q = queries.get_comments(self.vuser, self.sort, self.time)

        elif self.where == 'submitted':
            sup.set_sup_header(self.vuser, 'submitted')
            self.check_modified(self.vuser, 'submitted')
            q = queries.get_submitted(self.vuser, self.sort, self.time)

        elif self.where in ('liked', 'disliked'):
            sup.set_sup_header(self.vuser, self.where)
            self.check_modified(self.vuser, self.where)
            if self.where == 'liked':
                q = queries.get_liked(self.vuser)
            else:
                q = queries.get_disliked(self.vuser)

        elif self.where == 'hidden':
            q = queries.get_hidden(self.vuser)

        elif c.user_is_admin:
            q = admin_profile_query(self.vuser, self.where, desc('_date'))

        if q is None:
            return self.abort404()

        return q
Example #3
0
    def query(self):
        q = None
        if self.where == "overview":
            self.check_modified(self.vuser, "overview")
            q = queries.get_overview(self.vuser, self.sort, self.time)

        elif self.where == "comments":
            sup.set_sup_header(self.vuser, "commented")
            self.check_modified(self.vuser, "commented")
            q = queries.get_comments(self.vuser, self.sort, self.time)

        elif self.where == "submitted":
            sup.set_sup_header(self.vuser, "submitted")
            self.check_modified(self.vuser, "submitted")
            q = queries.get_submitted(self.vuser, self.sort, self.time)

        elif self.where in ("liked", "disliked"):
            sup.set_sup_header(self.vuser, self.where)
            self.check_modified(self.vuser, self.where)
            if self.where == "liked":
                q = queries.get_liked(self.vuser)
            else:
                q = queries.get_disliked(self.vuser)

        elif self.where == "hidden":
            q = queries.get_hidden(self.vuser)

        elif c.user_is_admin:
            q = admin_profile_query(self.vuser, self.where, desc("_date"))

        if q is None:
            return self.abort404()

        return q
    def query(self):
        q = None

        if self.where == 'profile':
            q = object  # dummy value

        if self.where == 'overview':
            self.check_modified(self.vuser, 'overview')
            q = queries.get_overview(self.vuser, 'new', 'all')

        elif self.where == 'comments':
            self.check_modified(self.vuser, 'commented')
            q = queries.get_comments(self.vuser, 'new', 'all')

        elif self.where == 'submitted':
            self.check_modified(self.vuser, 'submitted')
            q = queries.get_submitted(self.vuser, 'new', 'all')

        elif self.where in ('liked', 'disliked'):
            self.check_modified(self.vuser, self.where)
            if self.where == 'liked':
                q = queries.get_liked(self.vuser, not c.user_is_admin)
            else:
                q = queries.get_disliked(self.vuser, not c.user_is_admin)

        elif self.where == 'hidden':
            q = queries.get_hidden(self.vuser, not c.user_is_admin)

        elif self.where == 'drafts':
            q = queries.get_drafts(self.vuser)

        elif c.user_is_admin:
            q = admin_profile_query(self.vuser, self.where, desc('_date'))

        if q is None:
            return self.abort404()

        return q
    def query(self):
        q = None

        if self.where == 'profile':
            q = object  # dummy value

        if self.where == 'overview':
            self.check_modified(self.vuser, 'overview')
            q = queries.get_overview(self.vuser, 'new', 'all')

        elif self.where == 'comments':
            self.check_modified(self.vuser, 'commented')
            q = queries.get_comments(self.vuser, 'new', 'all')

        elif self.where == 'submitted':
            self.check_modified(self.vuser, 'submitted')
            q = queries.get_submitted(self.vuser, 'new', 'all')

        elif self.where in ('liked', 'disliked'):
            self.check_modified(self.vuser, self.where)
            if self.where == 'liked':
                q = queries.get_liked(self.vuser, not c.user_is_admin)
            else:
                q = queries.get_disliked(self.vuser, not c.user_is_admin)

        elif self.where == 'hidden':
            q = queries.get_hidden(self.vuser, not c.user_is_admin)

        elif self.where == 'drafts':
            q = queries.get_drafts(self.vuser)

        elif c.user_is_admin:
            q = admin_profile_query(self.vuser, self.where, desc('_date'))

        if q is None:
            return self.abort404()

        return q
Example #6
0
File: front.py Project: cmak/reddit
    def GET_user(self, num, vuser, sort, time, after, reverse, count, location, **env):
        """user profile pages"""

        # the validator will ensure that vuser is a valid account
        if not vuser:
            return self.abort404()

        # hide spammers profile pages
        if (not c.user_is_loggedin or 
            (c.user._id != vuser._id and not c.user_is_admin)) \
               and vuser._spam:
            return self.abort404()

        check_cheating('user')
        
        content_pane = PaneStack()

        # enable comments displaying with their titles when rendering
        c.profilepage = True
        listing = None

        db_sort = SortMenu.operator(sort)
        db_time = TimeMenu.operator(time)

        # function for extracting the proper thing if query is a relation (see liked)
        prewrap_fn = None

        # default (nonexistent) query to trip an error on if location is unhandles
        query      = None
        
        # build the sort menus for the space above the content
        sortbar = [SortMenu(default = sort), TimeMenu(default = time)]

        # overview page is a merge of comments and links
        if location == 'overview':
            links = Link._query(Link.c.author_id == vuser._id,
                                Link.c._spam == (True, False))
            comments = Comment._query(Comment.c.author_id == vuser._id,
                                      Comment.c._spam == (True, False))
            query = thing.Merge((links, comments), sort = db_sort, data = True)

        elif location == 'comments':
            query = Comment._query(Comment.c.author_id == vuser._id,
                                   Comment.c._spam == (True, False),
                                   sort = db_sort)

        elif location == 'submitted':
            query = Link._query(Link.c.author_id == vuser._id,
                                Link.c._spam == (True, False),
                                sort = db_sort)

        # (dis)liked page: pull votes and extract thing2
        elif ((location == 'liked' or location == 'disliked') and
              votes_visible(vuser)):
            rel = Vote.rel(vuser, Link)
            query = rel._query(rel.c._thing1_id == vuser._id,
                               rel.c._t2_deleted == False)
            query._eager(True, True)
            
            if location == 'liked':
                query._filter(rel.c._name == '1')
            else:
                query._filter(rel.c._name == '-1')
            sortbar = []
            query._sort = desc('_date')
            prewrap_fn = lambda x: x._thing2

        # TODO: this should be handled with '' above once merges work
        elif location == 'hidden' and votes_visible(vuser):
            db_time = None
            query = SaveHide._query(SaveHide.c._thing1_id == vuser._id,
                                    SaveHide.c._name == 'hide',
                                    eager_load = True,
                                    thing_data = True)
            sortbar = []
            query._sort = desc('_date')
            prewrap_fn = lambda x: x._thing2

        # any admin pages live here.
        elif c.user_is_admin:
            db_time = None
            query, prewrap_fn = admin_profile_query(vuser, location, db_sort)

        if query is None:
            return self.abort404()

        if db_time:
            query._filter(db_time)


        builder = QueryBuilder(query, num = num, prewrap_fn = prewrap_fn,
                               after = after, count = count, reverse = reverse,
                               wrap = ListingController.builder_wrapper)
        listing = LinkListing(builder)

        if listing:
            content_pane.append(listing.listing())

        titles = {'':          _("overview for %(user)s on %(site)s"),
                  'comments':  _("comments by %(user)s on %(site)s"),
                  'submitted': _("submitted by %(user)s on %(site)s"),
                  'liked':     _("liked by %(user)s on %(site)s"),
                  'disliked':  _("disliked by %(user)s on %(site)s"),
                  'hidden':    _("hidden by %(user)s on %(site)s")}
        title = titles.get(location, _('profile for %(user)s')) \
               % dict(user = vuser.name, site = c.site.name)

        return ProfilePage(vuser, title = title,
                           nav_menus = sortbar, 
                           content = content_pane).render()