<s> import logging <EOL> from django . core . urlresolvers import reverse <EOL> from django . template import defaultfilters <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . translation import ungettext_lazy <EOL> from horizon import tables <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . identity . groups import constants <EOL> from openstack_dashboard import policy <EOL> LOG = logging . getLogger ( __name__ ) <EOL> LOGOUT_URL = '<STR_LIT>' <EOL> STATUS_CHOICES = ( <EOL> ( "<STR_LIT:true>" , True ) , <EOL> ( "<STR_LIT:false>" , False ) <EOL> ) <EOL> class CreateGroupLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = constants . GROUPS_CREATE_URL <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , group ) : <EOL> return api . keystone . keystone_can_edit_group ( ) <EOL> class EditGroupLink ( policy . PolicyTargetMixin , tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = constants . GROUPS_UPDATE_URL <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , group ) : <EOL> return api . keystone . keystone_can_edit_group ( ) <EOL> class DeleteGroupsAction ( policy . PolicyTargetMixin , tables . DeleteAction ) : <EOL> @ staticmethod <EOL> def action_present ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> @ staticmethod <EOL> def action_past ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> name = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , datum ) : <EOL> return api . keystone . keystone_can_edit_group ( ) <EOL> def delete ( self , request , obj_id ) : <EOL> LOG . info ( '<STR_LIT>' % obj_id ) <EOL> api . keystone . group_delete ( request , obj_id ) <EOL> class ManageUsersLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = constants . GROUPS_MANAGE_URL <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , datum ) : <EOL> return api . keystone . keystone_can_edit_group ( ) <EOL> class GroupFilterAction ( tables . FilterAction ) : <EOL> def filter ( self , table , groups , filter_string ) : <EOL> """<STR_LIT>""" <EOL> q = filter_string . lower ( ) <EOL> def comp ( group ) : <EOL> if q in group . name . lower ( ) : <EOL> return True <EOL> return False <EOL> return filter ( comp , groups ) <EOL> class GroupsTable ( tables . DataTable ) : <EOL> name = tables . Column ( '<STR_LIT:name>' , verbose_name = _ ( '<STR_LIT:Name>' ) ) <EOL> description = tables . Column ( lambda obj : getattr ( obj , '<STR_LIT:description>' , None ) , <EOL> verbose_name = _ ( '<STR_LIT>' ) ) <EOL> id = tables . Column ( '<STR_LIT:id>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> class Meta ( object ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> row_actions = ( ManageUsersLink , EditGroupLink , DeleteGroupsAction ) <EOL> table_actions = ( GroupFilterAction , CreateGroupLink , <EOL> DeleteGroupsAction ) <EOL> class UserFilterAction ( tables . FilterAction ) : <EOL> def filter ( self , table , users , filter_string ) : <EOL> """<STR_LIT>""" <EOL> q = filter_string . lower ( ) <EOL> return [ user for user in users <EOL> if q in user . name . lower ( ) <EOL> or q in ( getattr ( user , '<STR_LIT:email>' , None ) or '<STR_LIT>' ) . lower ( ) ] <EOL> class RemoveMembers ( tables . DeleteAction ) : <EOL> @ staticmethod <EOL> def action_present ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> @ staticmethod <EOL> def action_past ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> name = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , user = None ) : <EOL> return api . keystone . keystone_can_edit_group ( ) <EOL> def action ( self , request , obj_id ) : <EOL> user_obj = self . table . get_object_by_id ( obj_id ) <EOL> group_id = self . table . kwargs [ '<STR_LIT>' ] <EOL> LOG . info ( '<STR_LIT>' % ( user_obj . id , <EOL> group_id ) ) <EOL> api . keystone . remove_group_user ( request , <EOL> group_id = group_id , <EOL> user_id = user_obj . id ) <EOL> class AddMembersLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> url = constants . GROUPS_ADD_MEMBER_URL <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , user = None ) : <EOL> return api . keystone . keystone_can_edit_group ( ) <EOL> def get_link_url ( self , datum = None ) : <EOL> return reverse ( self . url , kwargs = self . table . kwargs ) <EOL> class UsersTable ( tables . DataTable ) : <EOL> name = tables . Column ( '<STR_LIT:name>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> email = tables . Column ( '<STR_LIT:email>' , verbose_name = _ ( '<STR_LIT>' ) , <EOL> filters = [ defaultfilters . escape , <EOL> defaultfilters . urlize ] ) <EOL> id = tables . Column ( '<STR_LIT:id>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> enabled = tables . Column ( '<STR_LIT>' , verbose_name = _ ( '<STR_LIT>' ) , <EOL> status = True , <EOL> status_choices = STATUS_CHOICES , <EOL> filters = ( defaultfilters . yesno , <EOL> defaultfilters . capfirst ) , <EOL> empty_value = _ ( '<STR_LIT:False>' ) ) <EOL> class GroupMembersTable ( UsersTable ) : <EOL> class Meta ( object ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> table_actions = ( UserFilterAction , AddMembersLink , RemoveMembers ) <EOL> class AddMembers ( tables . BatchAction ) : <EOL> @ staticmethod <EOL> def action_present ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> @ staticmethod <EOL> def action_past ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> name = "<STR_LIT>" <EOL> icon = "<STR_LIT>" <EOL> requires_input = True <EOL> success_url = constants . GROUPS_MANAGE_URL <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , user = None ) : <EOL> return api . keystone . keystone_can_edit_group ( ) <EOL> def action ( self , request , obj_id ) : <EOL> user_obj = self . table . get_object_by_id ( obj_id ) <EOL> group_id = self . table . kwargs [ '<STR_LIT>' ] <EOL> LOG . info ( '<STR_LIT>' % ( user_obj . id , <EOL> group_id ) ) <EOL> api . keystone . add_group_user ( request , <EOL> group_id = group_id , <EOL> user_id = user_obj . id ) <EOL> def get_success_url ( self , request = None ) : <EOL> group_id = self . table . kwargs . get ( '<STR_LIT>' , None ) <EOL> return reverse ( self . success_url , args = [ group_id ] ) <EOL> class GroupNonMembersTable ( UsersTable ) : <EOL> class Meta ( object ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> table_actions = ( UserFilterAction , AddMembers ) </s>
