Stuck writing an extension

55 views
Skip to first unread message

Marc Bryan

unread,
Jun 16, 2014, 1:55:14 PM6/16/14
to revie...@googlegroups.com
Hi guys,

I'm having trouble writing a dashboard sidebar extension that adds custom filters to the datagrid.

ie. I would like to make a few different links, but an example of one would be 'Needs More Reviews', which would filter the reviews by:
  • less than 2 Ship-its (2 is our internal rule)
  • has no open reviews
  • not yours

Here is what I have currently:

extension.py:

class MySidebarSection(BaseSidebarSection):
    label = 'My Dashboard'

    def get_items(self):
        yield SidebarNavItem(self, 'My Requests to Push', view_id='push')
        yield SidebarNavItem(self, 'My Requests to Fix', view_id='fix')
        yield SidebarNavItem(self, 'Involved Reviews', view_id='involved')
        yield SidebarNavItem(self, 'Needs More Reviews', view_id='outstanding')
        yield SidebarNavItem(self, 'All Requests to Push', view_id='approved')

class MyDashboard(Extension):
    metadata = {
        'Name': 'My Dashboard',
        'Summary': 'Summary here',
    }
    is_configurable = True

    def initialize(self):
        # Your extension initialization is done here.
        DataGridSidebarItemsHook(self, MyDashboardDataGrid, [MySidebarSection])


datagrids.py

class MyDashboardDataGrid(DashboardDataGrid):
    def load_extra_state(self, profile):
        # pass custom queryset and change title
        user = self.request.user
        fullPath = self.request.get_full_path()
        view = self.request.GET.get('view', self.default_view)

        q = Q(repository__name='MyRepo', target_groups__name='internal', status='P')

        if view == 'outstanding':
                q = q & Q(shipit_count__lt=2, issue_open_count=0)  # TODO: make sure the review isn't yours
                self.queryset = ReviewRequest.objects.filter(q)
                self.title = _('Requests That Need Reviews (Reviews with # ship-its < 2, no open issues, not yours)')

        return super(MyDashboardDataGrid, self).load_extra_state(profile)



I assume this is all I need to do, but I keep getting this error when I click on the 'Needs More Reviews' link.

Page not found (404)
Request Method: GET

This 404 is being raised by DashboardDataGrid.load_extra_state().

It seems as if DataGridSidebarItemsHook isn't using MyDashboardDataGrid but instead using DashboardDataGrid.

Is there anything I am missing?

Thanks for your help.

Marc

Christian Hammond

unread,
Jun 17, 2014, 12:35:46 AM6/17/14
to revie...@googlegroups.com
Hi Marc,

The reviewboard-dev list is a better place for these questions, since there’s less traffic there and more people interested in RB-related development.

That said, the problem is that you cannot replace the dashboard. The parameter for the datagrid in DataGridSidebarItemsHook is the class that the sidebar should apply to, but it must be an existing, established datagrid. What you’d have to do there is provide your own URL and view for your this datagrid, render that there, and then link to that URL. That also means you’ll need these hooks in two places, which is going to be a bit annoying.

It’s not ideal, but that’s how it works currently.

Christian

-- 
Christian Hammond - chri...@beanbaginc.com
Review Board - http://www.reviewboard.org
Beanbag, Inc. - http://www.beanbaginc.com
--
Get the Review Board Power Pack at http://www.reviewboard.org/powerpack/
---
Sign up for Review Board hosting at RBCommons: https://rbcommons.com/
---
Happy user? Let us know at http://www.reviewboard.org/users/
---
You received this message because you are subscribed to the Google Groups "reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reviewboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marc Bryan

unread,
Jun 17, 2014, 3:15:54 PM6/17/14
to revie...@googlegroups.com, chri...@beanbaginc.com
Thanks Christian. Makes sense to post to reviewboard-dev. :)

Are there any plans to add another extension point / change the way this works in the future? If I get a chance I can look into making a patch, but time is always the problem :D

Marc

Marc Bryan

unread,
Jun 17, 2014, 3:17:33 PM6/17/14
to revie...@googlegroups.com, chri...@beanbaginc.com
Oops sorry forgot to delete the thread text.

Christian Hammond

unread,
Jun 17, 2014, 3:19:41 PM6/17/14
to revie...@googlegroups.com
Hey Marc,

I can certainly relate. Time’s a problem for me as well. I’d love to add this ability, and think it makes sense, but I can’t give you an ETA right now. Swamped with a large To Do list.

If it were being written, what I’d expect is a hook that DashboardDataGrid’s view directly uses. It would take the ?view= provided to the URL, find the appropriate hook, and either render the queryset it provides through DashboardDataGrid, or render a custom DataGrid. There’s probably a lot to think through, like how the sidebar works, where things integrate, etc.

Christian

-- 
Christian Hammond - chri...@beanbaginc.com
Review Board - http://www.reviewboard.org
Beanbag, Inc. - http://www.beanbaginc.com

Marc Bryan

unread,
Jun 17, 2014, 3:25:08 PM6/17/14
to revie...@googlegroups.com, chri...@beanbaginc.com
Cool! Do you think it is worth filing this as an enhancement ticket?

Christian Hammond

unread,
Jun 17, 2014, 3:43:26 PM6/17/14
to revie...@googlegroups.com
Certainly. Always good to track these :) Might be a good student project in the future.

Thanks,

Christian

-- 
Christian Hammond - chri...@beanbaginc.com
Review Board - http://www.reviewboard.org
Beanbag, Inc. - http://www.beanbaginc.com

Marc Bryan

unread,
Jun 17, 2014, 4:08:53 PM6/17/14
to revie...@googlegroups.com, chri...@beanbaginc.com
Reply all
Reply to author
Forward
0 new messages