<s> from __future__ import unicode_literals <EOL> import pytz <EOL> from django . contrib . auth . models import User <EOL> from django . http import Http404 <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from djblets . datagrid . grids import ( <EOL> Column , <EOL> DateTimeColumn , <EOL> DataGrid as DjbletsDataGrid , <EOL> AlphanumericDataGrid as DjbletsAlphanumericDataGrid ) <EOL> from djblets . util . templatetags . djblets_utils import ageid <EOL> from reviewboard . accounts . models import ( LocalSiteProfile , Profile , <EOL> ReviewRequestVisit ) <EOL> from reviewboard . datagrids . columns import ( BugsColumn , <EOL> DateTimeSinceColumn , <EOL> DiffSizeColumn , <EOL> DiffUpdatedColumn , <EOL> DiffUpdatedSinceColumn , <EOL> GroupMemberCountColumn , <EOL> GroupsColumn , <EOL> MyCommentsColumn , <EOL> NewUpdatesColumn , <EOL> PendingCountColumn , <EOL> PeopleColumn , <EOL> RepositoryColumn , <EOL> ReviewCountColumn , <EOL> ReviewGroupStarColumn , <EOL> ReviewRequestCheckboxColumn , <EOL> ReviewRequestIDColumn , <EOL> ReviewRequestStarColumn , <EOL> ReviewSubmitterColumn , <EOL> ReviewSummaryColumn , <EOL> ShipItColumn , <EOL> SubmitterColumn , <EOL> SummaryColumn , <EOL> ToMeColumn ) <EOL> from reviewboard . datagrids . sidebar import Sidebar , DataGridSidebarMixin <EOL> from reviewboard . datagrids . builtin_items import ( IncomingSection , <EOL> OutgoingSection , <EOL> UserGroupsItem , <EOL> UserProfileItem ) <EOL> from reviewboard . reviews . models import Group , ReviewRequest , Review <EOL> from reviewboard . site . urlresolvers import local_site_reverse <EOL> class ShowClosedReviewRequestsMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def load_extra_state ( self , profile , allow_hide_closed = True ) : <EOL> """<STR_LIT>""" <EOL> if profile : <EOL> self . show_closed = profile . show_closed <EOL> try : <EOL> self . show_closed = ( <EOL> int ( self . request . GET . get ( '<STR_LIT>' , <EOL> self . show_closed ) ) != <NUM_LIT:0> ) <EOL> except ValueError : <EOL> pass <EOL> if allow_hide_closed and not self . show_closed : <EOL> self . queryset = self . queryset . filter ( ** { <EOL> self . status_query_field : '<STR_LIT:P>' , <EOL> } ) <EOL> self . queryset = self . queryset . filter ( ** { <EOL> self . site_query_field : self . local_site , <EOL> } ) <EOL> if profile and self . show_closed != profile . show_closed : <EOL> profile . show_closed = self . show_closed <EOL> return True <EOL> return False <EOL> class DataGridJSMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> css_bundle_names = [ ] <EOL> js_bundle_names = [ ] <EOL> js_model_class = '<STR_LIT>' <EOL> js_view_class = '<STR_LIT>' <EOL> periodic_reload = False <EOL> extra_js_model_data = None <EOL> class DataGrid ( DataGridJSMixin , DjbletsDataGrid ) : <EOL> """<STR_LIT>""" <EOL> class AlphanumericDataGrid ( DataGridJSMixin , DjbletsAlphanumericDataGrid ) : <EOL> """<STR_LIT>""" <EOL> class ReviewRequestDataGrid ( ShowClosedReviewRequestsMixin , DataGrid ) : <EOL> """<STR_LIT>""" <EOL> my_comments = MyCommentsColumn ( ) <EOL> star = ReviewRequestStarColumn ( ) <EOL> ship_it = ShipItColumn ( ) <EOL> summary = SummaryColumn ( ) <EOL> submitter = SubmitterColumn ( ) <EOL> branch = Column ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> db_field = '<STR_LIT>' , <EOL> shrink = True , <EOL> sortable = True , <EOL> link = False ) <EOL> bugs_closed = BugsColumn ( ) <EOL> repository = RepositoryColumn ( ) <EOL> time_added = DateTimeColumn ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> detailed_label = _ ( '<STR_LIT>' ) , <EOL> format = '<STR_LIT>' , <EOL> shrink = True , <EOL> css_class = lambda r : ageid ( r . time_added ) ) <EOL> last_updated = DateTimeColumn ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> format = '<STR_LIT>' , <EOL> shrink = True , <EOL> db_field = '<STR_LIT>' , <EOL> field_name = '<STR_LIT>' , <EOL> css_class = lambda r : ageid ( r . last_updated ) ) <EOL> diff_updated = DiffUpdatedColumn ( <EOL> format = '<STR_LIT>' , <EOL> shrink = True , <EOL> css_class = lambda r : ageid ( r . diffset_history . last_diff_updated ) ) <EOL> time_added_since = DateTimeSinceColumn ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> detailed_label = _ ( '<STR_LIT>' ) , <EOL> field_name = '<STR_LIT>' , shrink = True , <EOL> css_class = lambda r : ageid ( r . time_added ) ) <EOL> last_updated_since = DateTimeSinceColumn ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> detailed_label = _ ( '<STR_LIT>' ) , shrink = True , <EOL> db_field = '<STR_LIT>' , <EOL> field_name = '<STR_LIT>' , <EOL> css_class = lambda r : ageid ( r . last_updated ) ) <EOL> diff_updated_since = DiffUpdatedSinceColumn ( <EOL> detailed_label = _ ( '<STR_LIT>' ) , <EOL> shrink = True , <EOL> css_class = lambda r : ageid ( r . diffset_history . last_diff_updated ) ) <EOL> diff_size = DiffSizeColumn ( ) <EOL> review_count = ReviewCountColumn ( ) <EOL> target_groups = GroupsColumn ( ) <EOL> target_people = PeopleColumn ( ) <EOL> to_me = ToMeColumn ( ) <EOL> review_id = ReviewRequestIDColumn ( ) <EOL> status_query_field = '<STR_LIT:status>' <EOL> site_query_field = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . local_site = kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( ReviewRequestDataGrid , self ) . __init__ ( * args , ** kwargs ) <EOL> self . listview_template = '<STR_LIT>' <EOL> self . profile_sort_field = '<STR_LIT>' <EOL> self . profile_columns_field = '<STR_LIT>' <EOL> self . show_closed = True <EOL> self . submitter_url_name = '<STR_LIT:user>' <EOL> self . default_sort = [ '<STR_LIT>' ] <EOL> self . default_columns = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> user = self . request . user <EOL> if user . is_authenticated ( ) : <EOL> profile , is_new = Profile . objects . get_or_create ( user = user ) <EOL> self . timezone = pytz . timezone ( profile . timezone ) <EOL> self . time_added . timezone = self . timezone <EOL> self . last_updated . timezone = self . timezone <EOL> self . diff_updated . timezone = self . timezone <EOL> def load_extra_state ( self , profile , allow_hide_closed = True ) : <EOL> """<STR_LIT>""" <EOL> return super ( ReviewRequestDataGrid , self ) . load_extra_state ( <EOL> profile , allow_hide_closed ) <EOL> def post_process_queryset ( self , queryset ) : <EOL> """<STR_LIT>""" <EOL> q = queryset . with_counts ( self . request . user ) <EOL> return super ( ReviewRequestDataGrid , self ) . post_process_queryset ( q ) <EOL> def link_to_object ( self , state , obj , value ) : <EOL> """<STR_LIT>""" <EOL> if value and isinstance ( value , User ) : <EOL> return local_site_reverse ( '<STR_LIT:user>' , request = self . request , <EOL> args = [ value ] ) <EOL> return obj . get_absolute_url ( ) <EOL> class ReviewDataGrid ( ShowClosedReviewRequestsMixin , DataGrid ) : <EOL> """<STR_LIT>""" <EOL> timestamp = DateTimeColumn ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> format = '<STR_LIT>' , <EOL> shrink = True ) <EOL> submitter = ReviewSubmitterColumn ( ) <EOL> review_summary = ReviewSummaryColumn ( ) <EOL> status_query_field = '<STR_LIT>' <EOL> site_query_field = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . local_site = kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( ReviewDataGrid , self ) . __init__ ( * args , ** kwargs ) <EOL> self . listview_template = '<STR_LIT>' <EOL> self . profile_columns_field = '<STR_LIT>' <EOL> self . show_closed = True <EOL> self . default_sort = [ '<STR_LIT>' ] <EOL> self . default_columns = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> user = self . request . user <EOL> if user . is_authenticated ( ) : <EOL> profile , is_new = Profile . objects . get_or_create ( user = user ) <EOL> self . timezone = pytz . timezone ( profile . timezone ) <EOL> self . timestamp . timezone = self . timezone <EOL> class DashboardDataGrid ( DataGridSidebarMixin , ReviewRequestDataGrid ) : <EOL> """<STR_LIT>""" <EOL> new_updates = NewUpdatesColumn ( ) <EOL> my_comments = MyCommentsColumn ( ) <EOL> selected = ReviewRequestCheckboxColumn ( ) <EOL> sidebar = Sidebar ( <EOL> [ <EOL> OutgoingSection , <EOL> IncomingSection , <EOL> ] , <EOL> default_view_id = '<STR_LIT>' ) <EOL> js_model_class = '<STR_LIT>' <EOL> js_view_class = '<STR_LIT>' <EOL> periodic_reload = True <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> local_site = kwargs . get ( '<STR_LIT>' , None ) <EOL> super ( DashboardDataGrid , self ) . __init__ ( * args , ** kwargs ) <EOL> self . listview_template = '<STR_LIT>' <EOL> self . profile_sort_field = '<STR_LIT>' <EOL> self . profile_columns_field = '<STR_LIT>' <EOL> self . default_view = '<STR_LIT>' <EOL> self . show_closed = False <EOL> self . show_archived = False <EOL> self . default_sort = [ '<STR_LIT>' ] <EOL> self . default_columns = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> self . extra_js_model_data = { <EOL> '<STR_LIT>' : self . show_archived , <EOL> } <EOL> self . local_site = local_site <EOL> self . user = self . request . user <EOL> self . profile = Profile . objects . get_or_create ( user = self . user ) [ <NUM_LIT:0> ] <EOL> self . site_profile = LocalSiteProfile . objects . get_or_create ( <EOL> user = self . user , <EOL> local_site = local_site , <EOL> profile = self . profile ) [ <NUM_LIT:0> ] <EOL> def load_extra_state ( self , profile ) : <EOL> """<STR_LIT>""" <EOL> group_name = self . request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> view = self . request . GET . get ( '<STR_LIT>' , self . default_view ) <EOL> user = self . request . user <EOL> if view == '<STR_LIT>' : <EOL> self . queryset = ReviewRequest . objects . from_user ( <EOL> user , user , local_site = self . local_site ) <EOL> self . title = _ ( '<STR_LIT>' ) <EOL> elif view == '<STR_LIT>' : <EOL> self . queryset = ReviewRequest . objects . from_user ( <EOL> user , user , None , local_site = self . local_site ) <EOL> self . title = _ ( '<STR_LIT>' ) <EOL> elif view == '<STR_LIT>' : <EOL> self . queryset = ReviewRequest . objects . to_user_directly ( <EOL> user , user , local_site = self . local_site ) <EOL> self . title = _ ( '<STR_LIT>' ) <EOL> elif view in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if group_name : <EOL> try : <EOL> group = Group . objects . get ( name = group_name , <EOL> local_site = self . local_site ) <EOL> if not group . is_accessible_by ( user ) : <EOL> raise Http404 <EOL> except Group . DoesNotExist : <EOL> raise Http404 <EOL> self . queryset = ReviewRequest . objects . to_group ( <EOL> group_name , self . local_site , user ) <EOL> self . title = _ ( '<STR_LIT>' ) % group_name <EOL> else : <EOL> self . queryset = ReviewRequest . objects . to_user_groups ( <EOL> user , user , local_site = self . local_site ) <EOL> self . title = _ ( '<STR_LIT>' ) <EOL> elif view == '<STR_LIT>' : <EOL> self . queryset = self . profile . starred_review_requests . public ( <EOL> user = user , local_site = self . local_site , status = None ) <EOL> self . title = _ ( '<STR_LIT>' ) <EOL> elif view == '<STR_LIT>' : <EOL> self . queryset = ReviewRequest . objects . to_user ( <EOL> user , user , local_site = self . local_site ) <EOL> self . title = _ ( '<STR_LIT>' ) <EOL> else : <EOL> raise Http404 <EOL> if profile and '<STR_LIT>' in profile . extra_data : <EOL> self . show_archived = profile . extra_data [ '<STR_LIT>' ] <EOL> try : <EOL> show = self . request . GET . get ( '<STR_LIT>' , self . show_archived ) <EOL> self . show_archived = int ( show ) != <NUM_LIT:0> <EOL> except ValueError : <EOL> pass <EOL> if not self . show_archived : <EOL> hidden_q = ReviewRequestVisit . objects . filter ( <EOL> user = user ) . exclude ( visibility = ReviewRequestVisit . VISIBLE ) <EOL> hidden_q = hidden_q . values_list ( '<STR_LIT>' , flat = True ) <EOL> self . queryset = self . queryset . exclude ( pk__in = hidden_q ) <EOL> if ( profile and <EOL> self . show_archived != profile . extra_data . get ( '<STR_LIT>' ) ) : <EOL> profile . extra_data [ '<STR_LIT>' ] = self . show_archived <EOL> profile_changed = True <EOL> else : <EOL> profile_changed = False <EOL> self . extra_js_model_data [ '<STR_LIT>' ] = self . show_archived <EOL> parent_profile_changed = super ( DashboardDataGrid , self ) . load_extra_state ( <EOL> profile , allow_hide_closed = False ) <EOL> return profile_changed or parent_profile_changed <EOL> class UsersDataGrid ( AlphanumericDataGrid ) : <EOL> """<STR_LIT>""" <EOL> username = Column ( _ ( '<STR_LIT>' ) , link = True , sortable = True ) <EOL> fullname = Column ( _ ( '<STR_LIT>' ) , field_name = '<STR_LIT>' , <EOL> link = True , expand = True ) <EOL> pending_count = PendingCountColumn ( _ ( '<STR_LIT>' ) , <EOL> field_name = '<STR_LIT>' , <EOL> shrink = True ) <EOL> def __init__ ( self , request , <EOL> queryset = User . objects . filter ( is_active = True ) , <EOL> title = _ ( '<STR_LIT>' ) , <EOL> local_site = None ) : <EOL> """<STR_LIT>""" <EOL> if local_site : <EOL> qs = queryset . filter ( local_site = local_site ) <EOL> else : <EOL> qs = queryset <EOL> super ( UsersDataGrid , self ) . __init__ ( request , qs , title = title , <EOL> sortable_column = '<STR_LIT:username>' , <EOL> extra_regex = '<STR_LIT>' ) <EOL> self . default_sort = [ '<STR_LIT:username>' ] <EOL> self . profile_sort_field = '<STR_LIT>' <EOL> self . profile_columns_field = '<STR_LIT>' <EOL> self . default_columns = [ <EOL> '<STR_LIT:username>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> def link_to_object ( self , state , obj , value ) : <EOL> """<STR_LIT>""" <EOL> return local_site_reverse ( '<STR_LIT:user>' , request = self . request , <EOL> args = [ obj . username ] ) <EOL> class GroupDataGrid ( DataGrid ) : <EOL> """<STR_LIT>""" <EOL> star = ReviewGroupStarColumn ( ) <EOL> name = Column ( _ ( '<STR_LIT>' ) , link = True , sortable = True ) <EOL> displayname = Column ( _ ( '<STR_LIT>' ) , field_name = '<STR_LIT>' , <EOL> link = True , expand = True ) <EOL> pending_count = PendingCountColumn ( _ ( '<STR_LIT>' ) , <EOL> field_name = '<STR_LIT>' , <EOL> link = True , <EOL> shrink = True ) <EOL> member_count = GroupMemberCountColumn ( _ ( '<STR_LIT>' ) , <EOL> field_name = '<STR_LIT>' , <EOL> shrink = True ) <EOL> def __init__ ( self , request , title = _ ( '<STR_LIT>' ) , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> local_site = kwargs . pop ( '<STR_LIT>' , None ) <EOL> queryset = Group . objects . accessible ( request . user , <EOL> local_site = local_site ) <EOL> super ( GroupDataGrid , self ) . __init__ ( request , queryset = queryset , <EOL> title = title , * args , ** kwargs ) <EOL> self . profile_sort_field = '<STR_LIT>' <EOL> self . profile_columns_field = '<STR_LIT>' <EOL> self . default_sort = [ '<STR_LIT:name>' ] <EOL> self . default_columns = [ <EOL> '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> @ staticmethod <EOL> def link_to_object ( state , obj , value ) : <EOL> """<STR_LIT>""" <EOL> return obj . get_absolute_url ( ) <EOL> class UserPageDataGridMixin ( DataGridSidebarMixin ) : <EOL> """<STR_LIT>""" <EOL> sidebar = Sidebar ( [ <EOL> UserProfileItem , <EOL> UserGroupsItem , <EOL> ] ) <EOL> class UserPageReviewRequestDataGrid ( UserPageDataGridMixin , <EOL> ReviewRequestDataGrid ) : <EOL> """<STR_LIT>""" <EOL> tab_title = _ ( '<STR_LIT>' ) <EOL> def __init__ ( self , request , user , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> queryset = ReviewRequest . objects . from_user ( <EOL> user . username , <EOL> user = request . user , <EOL> status = None , <EOL> with_counts = True , <EOL> local_site = kwargs . get ( '<STR_LIT>' ) , <EOL> filter_private = True , <EOL> show_inactive = True ) <EOL> super ( UserPageReviewRequestDataGrid , self ) . __init__ ( <EOL> request , <EOL> queryset = queryset , <EOL> title = _ ( "<STR_LIT>" ) % user . username , <EOL> * args , ** kwargs ) <EOL> self . groups = user . review_groups . accessible ( request . user ) <EOL> self . user = user <EOL> class UserPageReviewsDataGrid ( UserPageDataGridMixin , ReviewDataGrid ) : <EOL> """<STR_LIT>""" <EOL> tab_title = _ ( '<STR_LIT>' ) <EOL> def __init__ ( self , request , user , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> queryset = Review . objects . from_user ( <EOL> user . username , <EOL> user = request . user , <EOL> public = True , <EOL> filter_private = True , <EOL> status = None , <EOL> local_site = kwargs . get ( '<STR_LIT>' ) ) <EOL> super ( UserPageReviewsDataGrid , self ) . __init__ ( <EOL> request , <EOL> queryset = queryset , <EOL> title = _ ( "<STR_LIT>" ) % user . username , <EOL> * args , ** kwargs ) <EOL> self . groups = user . review_groups . accessible ( request . user ) <EOL> self . user = user </s>
