<s> from __future__ import absolute_import <EOL> from xml . etree import ElementTree <EOL> from casexml . apps . phone . xml import get_data_element <EOL> class UserGroupsFixtureProvider ( object ) : <EOL> """<STR_LIT>""" <EOL> id = '<STR_LIT>' <EOL> def __call__ ( self , user , version , last_sync = None , app = None ) : <EOL> """<STR_LIT>""" <EOL> fixture = self . get_group_fixture ( user , last_sync ) <EOL> if len ( fixture ) : <EOL> return [ fixture ] <EOL> else : <EOL> return [ ] <EOL> def get_group_fixture ( self , user , last_sync = None ) : <EOL> groups = user . get_case_sharing_groups ( ) <EOL> return self . group_fixture ( groups , user ) <EOL> def group_fixture ( self , groups , user ) : <EOL> """<STR_LIT>""" <EOL> xFixture = ElementTree . Element ( '<STR_LIT>' , attrib = { '<STR_LIT:id>' : self . id , '<STR_LIT>' : user . user_id } ) <EOL> xGroups = ElementTree . SubElement ( xFixture , '<STR_LIT>' ) <EOL> for group in groups : <EOL> xGroup = ElementTree . SubElement ( xGroups , '<STR_LIT>' , attrib = { '<STR_LIT:id>' : group . get_id } ) <EOL> xName = ElementTree . SubElement ( xGroup , '<STR_LIT:name>' ) <EOL> xName . text = group . name <EOL> if group . metadata : <EOL> xGroup . append ( get_data_element ( '<STR_LIT>' , group . metadata ) ) <EOL> return xFixture <EOL> user_groups = UserGroupsFixtureProvider ( ) </s>
