web/views/actions.py
branchtls-sprint
changeset 707 21a59b468f1a
parent 696 2a5a19185288
child 714 39a2a6673171
equal deleted inserted replaced
706:8be68582abb0 707:21a59b468f1a
    49     """base class for link search actions. By default apply on
    49     """base class for link search actions. By default apply on
    50     any size entity result search it the current state is 'linksearch'
    50     any size entity result search it the current state is 'linksearch'
    51     if accept match.
    51     if accept match.
    52     """
    52     """
    53     id = 'select'
    53     id = 'select'
    54     __selectors__ = (match_search_state('linksearch'),
    54     __select__ = match_search_state('linksearch') & match_searched_etype()
    55                      match_searched_etype)
       
    56     
    55     
    57     title = _('select')
    56     title = _('select')
    58     category = 'mainactions'    
    57     category = 'mainactions'    
    59     order = 0
    58     order = 0
    60     
    59     
    62         return linksearch_select_url(self.req, self.rset)
    61         return linksearch_select_url(self.req, self.rset)
    63 
    62 
    64 
    63 
    65 class CancelSelectAction(Action):
    64 class CancelSelectAction(Action):
    66     id = 'cancel'
    65     id = 'cancel'
    67     __selectors__ = (match_search_state('linksearch'),)
    66     __select__ = match_search_state('linksearch')
    68     
    67     
    69     title = _('cancel select')
    68     title = _('cancel select')
    70     category = 'mainactions'
    69     category = 'mainactions'
    71     order = 10
    70     order = 10
    72     
    71     
    76                               vid='edition', __mode='normal')
    75                               vid='edition', __mode='normal')
    77 
    76 
    78 
    77 
    79 class ViewAction(Action):
    78 class ViewAction(Action):
    80     id = 'view'
    79     id = 'view'
    81     __selectors__ = (match_search_state('normal'),
    80     __select__ = (match_search_state('normal') &
    82                      match_user_groups('users', 'managers'),
    81                   match_user_groups('users', 'managers') &
    83                      view_is_not_default_view,
    82                   view_is_not_default_view() & 
    84                      non_final_entity())
    83                   non_final_entity())
    85     
    84     
    86     title = _('view')
    85     title = _('view')
    87     category = 'mainactions'    
    86     category = 'mainactions'    
    88     order = 0
    87     order = 0
    89     
    88     
    95                               **params)
    94                               **params)
    96 
    95 
    97 
    96 
    98 class ModifyAction(Action):
    97 class ModifyAction(Action):
    99     id = 'edit'
    98     id = 'edit'
   100     __selectors__ = (match_search_state('normal'),
    99     __select__ = (match_search_state('normal') &
   101                      one_line_rset, 
   100                   one_line_rset() & 
   102                      has_permission('update') | has_editable_relation('add'))
   101                   (has_permission('update') | has_editable_relation('add')))
   103     
   102     
   104     title = _('modify')
   103     title = _('modify')
   105     category = 'mainactions'
   104     category = 'mainactions'
   106     order = 10
   105     order = 10
   107 
   106 
   110         return entity.absolute_url(vid='edition')
   109         return entity.absolute_url(vid='edition')
   111         
   110         
   112 
   111 
   113 class MultipleEditAction(Action):
   112 class MultipleEditAction(Action):
   114     id = 'muledit' # XXX get strange conflicts if id='edit'
   113     id = 'muledit' # XXX get strange conflicts if id='edit'
   115     __selectors__ = (match_search_state('normal'),
   114     __select__ = (match_search_state('normal') &
   116                      two_lines_rset, one_etype_rset,
   115                      two_lines_rset(), one_etype_rset() &
   117                      has_permission('update'))
   116                   has_permission('update'))
   118 
   117 
   119     title = _('modify')
   118     title = _('modify')
   120     category = 'mainactions'
   119     category = 'mainactions'
   121     order = 10
   120     order = 10
   122     
   121     
   126 
   125 
   127 # generic secondary actions ###################################################
   126 # generic secondary actions ###################################################
   128 
   127 
   129 class ManagePermissionsAction(Action):
   128 class ManagePermissionsAction(Action):
   130     id = 'addpermission'
   129     id = 'addpermission'
   131     __selectors__ = match_user_groups('managers') 
   130     __select__ = match_user_groups('managers') 
   132 
   131 
   133     title = _('manage permissions')
   132     title = _('manage permissions')
   134     category = 'moreactions'
   133     category = 'moreactions'
   135     order = 100
   134     order = 100
   136 
   135 
       
   136     @classmethod
   137     def registered(cls, vreg):
   137     def registered(cls, vreg):
   138         if 'require_permission' in vreg.schema:
   138         if 'require_permission' in vreg.schema:
   139             cls.__selectors__ |= relation_possible('require_permission', 'subject', 'EPermission',
   139             cls.__select__ |= relation_possible('require_permission', 'subject', 'EPermission',
   140                                                    action='add')
   140                                                 action='add')
   141             
   141         return super(ManagePermissionsAction, cls).registered(vreg)
       
   142     
   142     def url(self):
   143     def url(self):
   143         return self.rset.get_entity(0, 0).absolute_url(vid='security')
   144         return self.rset.get_entity(0, 0).absolute_url(vid='security')
   144 
   145 
   145     
   146     
   146 class DeleteAction(Action):
   147 class DeleteAction(Action):
   147     id = 'delete'
   148     id = 'delete'
   148     __selectors__ = (one_line_rset, has_permission('delete'))
   149     __select__ = one_line_rset() & has_permission('delete')
   149     
   150     
   150     title = _('delete')
   151     title = _('delete')
   151     category = 'moreactions' 
   152     category = 'moreactions' 
   152     order = 20
   153     order = 20
   153     
   154     
   158         return self.build_url(rql=self.rset.printable_rql(), vid='deleteconf')
   159         return self.build_url(rql=self.rset.printable_rql(), vid='deleteconf')
   159     
   160     
   160         
   161         
   161 class CopyAction(Action):
   162 class CopyAction(Action):
   162     id = 'copy'
   163     id = 'copy'
   163     __selectors__ = (one_line_rset, has_permission('add'))
   164     __select__ = one_line_rset() & has_permission('add')
   164     
   165     
   165     title = _('copy')
   166     title = _('copy')
   166     category = 'moreactions'
   167     category = 'moreactions'
   167     order = 30
   168     order = 30
   168     
   169     
   174 class AddNewAction(MultipleEditAction):
   175 class AddNewAction(MultipleEditAction):
   175     """when we're seeing more than one entity with the same type, propose to
   176     """when we're seeing more than one entity with the same type, propose to
   176     add a new one
   177     add a new one
   177     """
   178     """
   178     id = 'addentity'
   179     id = 'addentity'
   179     __selectors__ = (match_search_state('normal'),
   180     __select__ = (match_search_state('normal') &
   180                      (addable_etype_empty_rset
   181                   (addable_etype_empty_rset()
   181                       # XXX has_add_permission in the middle so '&' is available
   182                    | (two_lines_rset() & one_etype_rset &  & has_add_permission()))
   182                       | (two_lines_rset & has_add_permission() & one_etype_rset ))
   183                   )
   183                      )
       
   184 
   184 
   185     category = 'moreactions'
   185     category = 'moreactions'
   186     order = 40
   186     order = 40
   187     
   187     
   188     @property
   188     @property
   201 
   201 
   202 # logged user actions #########################################################
   202 # logged user actions #########################################################
   203 
   203 
   204 class UserPreferencesAction(Action):
   204 class UserPreferencesAction(Action):
   205     id = 'myprefs'
   205     id = 'myprefs'
   206     __selectors__ = (authenticated_user,)
   206     __select__ = authenticated_user()
   207     
   207     
   208     title = _('user preferences')
   208     title = _('user preferences')
   209     category = 'useractions'
   209     category = 'useractions'
   210     order = 10
   210     order = 10
   211 
   211 
   213         return self.build_url(self.id)
   213         return self.build_url(self.id)
   214 
   214 
   215 
   215 
   216 class UserInfoAction(Action):
   216 class UserInfoAction(Action):
   217     id = 'myinfos'
   217     id = 'myinfos'
   218     __selectors__ = (authenticated_user,)
   218     __select__ = authenticated_user()
   219     
   219     
   220     title = _('personnal informations')
   220     title = _('personnal informations')
   221     category = 'useractions'
   221     category = 'useractions'
   222     order = 20
   222     order = 20
   223 
   223 
   225         return self.build_url('euser/%s'%self.req.user.login, vid='edition')
   225         return self.build_url('euser/%s'%self.req.user.login, vid='edition')
   226 
   226 
   227 
   227 
   228 class LogoutAction(Action):
   228 class LogoutAction(Action):
   229     id = 'logout'
   229     id = 'logout'
   230     __selectors__ = (authenticated_user,)
   230     __select__ = authenticated_user()
   231     
   231     
   232     title = _('logout')
   232     title = _('logout')
   233     category = 'useractions'
   233     category = 'useractions'
   234     order = 30
   234     order = 30
   235 
   235 
   239     
   239     
   240 # site actions ################################################################
   240 # site actions ################################################################
   241 
   241 
   242 class ManagersAction(Action):
   242 class ManagersAction(Action):
   243     __abstract__ = True
   243     __abstract__ = True
   244     __selectors__ = (match_user_groups('managers'),)
   244     __select__ = match_user_groups('managers')
   245 
   245 
   246     category = 'siteactions'
   246     category = 'siteactions'
   247 
   247 
   248     def url(self):
   248     def url(self):
   249         return self.build_url(self.id)
   249         return self.build_url(self.id)
   261     order = 20
   261     order = 20
   262 
   262 
   263 
   263 
   264 class ViewSchemaAction(Action):
   264 class ViewSchemaAction(Action):
   265     id = 'schema'
   265     id = 'schema'
   266     __selectors__ = (yes,)
   266     __select__ = yes()
   267     
   267     
   268     title = _("site schema")
   268     title = _("site schema")
   269     category = 'siteactions'
   269     category = 'siteactions'
   270     order = 30
   270     order = 30
   271     
   271