class GroupDataGrid(DataGrid): """A datagrid showing a list of review groups accessible by the user.""" star = ReviewGroupStarColumn() name = Column(_('Group ID'), link=True, sortable=True) displayname = Column(_('Group Name'), field_name='display_name', link=True, expand=True) pending_count = PendingCountColumn(_('Open Review Requests'), field_name='review_requests', link=True, shrink=True) member_count = GroupMemberCountColumn(_('Members'), field_name='members', shrink=True) def __init__(self, request, title=_('All groups'), *args, **kwargs): local_site = kwargs.pop('local_site', None) queryset = Group.objects.accessible(request.user, local_site=local_site) super(GroupDataGrid, self).__init__(request, queryset=queryset, title=title, *args, **kwargs) self.profile_sort_field = 'sort_group_columns' self.profile_columns_field = 'group_columns' self.default_sort = ['name'] self.default_columns = ['star', 'name', 'displayname', 'pending_count'] @staticmethod def link_to_object(state, obj, value): return obj.get_absolute_url()
class UsersDataGrid(DataGrid): """A datagrid showing a list of users registered on Review Board.""" username = Column(_('Username'), link=True, sortable=True) fullname = Column(_('Full Name'), field_name='get_full_name', link=True, expand=True) pending_count = PendingCountColumn(_('Open Review Requests'), field_name='directed_review_requests', shrink=True) def __init__(self, request, queryset=User.objects.filter(is_active=True), title=_('All users'), local_site=None): if local_site: qs = queryset.filter(local_site=local_site) else: qs = queryset super(UsersDataGrid, self).__init__(request, qs, title) self.default_sort = ['username'] self.profile_sort_field = 'sort_submitter_columns' self.profile_columns_field = 'submitter_columns' self.default_columns = ['username', 'fullname', 'pending_count'] def link_to_object(self, state, obj, value): return local_site_reverse('user', request=self.request, args=[obj.username])
class UsersDataGrid(AlphanumericDataGrid): """A datagrid showing a list of users registered on Review Board.""" username = UsernameColumn(label=_('Username')) fullname = FullNameColumn(label=_('Full Name'), link=True, expand=True) pending_count = PendingCountColumn(_('Open Review Requests'), field_name='directed_review_requests', shrink=True) def __init__(self, request, queryset=User.objects.all(), title=_('All users'), local_site=None): """Initialize the datagrid.""" if local_site: qs = queryset.filter(local_site=local_site) else: qs = queryset super(UsersDataGrid, self).__init__(request, qs, title=title, sortable_column='username', extra_regex='^[0-9_\-\.].*') self.listview_template = 'datagrids/user_listview.html' self.default_sort = ['username'] self.profile_sort_field = 'sort_submitter_columns' self.profile_columns_field = 'submitter_columns' self.default_columns = ['username', 'fullname', 'pending_count'] self.show_inactive = False def link_to_object(self, state, obj, value): """Return a link to the given object.""" return local_site_reverse('user', request=self.request, args=[obj.username]) def load_extra_state(self, profile): """Load extra state for the datagrid. This handles hiding or showing inactive users. Args: profile (reviewboard.accounts.models.Profile): The user profile which contains some basic configurable settings. Returns: bool: Always returns False. """ show_inactive = self.request.GET.get('show-inactive', 0) try: self.show_inactive = int(show_inactive) except ValueError: pass if not self.show_inactive: self.queryset = self.queryset.filter(is_active=True) return False