def isCommunityDocumentsFolder(self): parent = aq_parent(self.context) if ICommunity.providedBy(parent) \ and self.context.portal_type == 'Folder'\ and self.context.id == 'documents': return True return False
def getEventsForCalendar(self): context = aq_inner(self.context) year = self.year month = self.month portal_state = getMultiAdapter((self.context, self.request), name='plone_portal_state') navigation_root_path = portal_state.navigation_root_path() context = aq_inner(self.context) path = navigation_root_path for obj in aq_chain(context): if ICommunity.providedBy(obj): community = aq_inner(obj) path = '/'.join(community.getPhysicalPath()) weeks = self.calendar.getEventsForCalendar(month, year, path=path) for week in weeks: for day in week: daynumber = day['day'] if daynumber == 0: continue day['is_today'] = self.isToday(daynumber) if day['event']: cur_date = DateTime(year, month, daynumber) localized_date = [self._ts.ulocalized_time(cur_date, context=context, request=self.request)] day['eventstring'] = '\n'.join(localized_date + [' %s' % self.getEventString(e) for e in day['eventslist']]) day['date_string'] = '%s-%s-%s' % (year, month, daynumber) return weeks
def get_next_three_events(self): context = aq_inner(self.context) pc = getToolByName(context, 'portal_catalog') now = localized_now() portal_state = getMultiAdapter((self.context, self.request), name='plone_portal_state') navigation_root_path = portal_state.navigation_root_path() context = aq_inner(self.context) path = navigation_root_path for obj in aq_chain(context): if ICommunity.providedBy(obj): community = aq_inner(obj) path = '/'.join(community.getPhysicalPath()) query = { 'portal_type': 'Event', 'review_state': self.state, 'end': {'query': now, 'range': 'min'}, 'sort_on': 'start', 'path': path, } result = pc(**query) nearest = self.get_nearest_today_event() if nearest: return [event for event in result if event.id != nearest.id][:3] else: return result[:3]
def get_nearest_today_event(self): context = aq_inner(self.context) pc = getToolByName(context, 'portal_catalog') now = localized_now() portal_state = getMultiAdapter((self.context, self.request), name='plone_portal_state') navigation_root_path = portal_state.navigation_root_path() context = aq_inner(self.context) path = navigation_root_path for obj in aq_chain(context): if ICommunity.providedBy(obj): community = aq_inner(obj) path = '/'.join(community.getPhysicalPath()) query = { 'portal_type': 'Event', 'review_state': self.state, 'start': {'query': [now, dt_end_of_day(now)], 'range': 'min:max'}, 'end': {'query': now, 'range': 'min'}, 'sort_on': 'start', 'path': path, 'sort_limit': 1 } result = pc(**query) if result: return result[0] else: return
def community_mode(self): context = aq_inner(self.context) for obj in aq_chain(context): if ICommunity.providedBy(obj): return True return False
def is_community(self): """ Assume that the calendar is only shown on the community itself. """ context = aq_inner(self.context) for obj in aq_chain(context): if ICommunity.providedBy(obj): return True return False
def update(self): try: from plone.protect.interfaces import IDisableCSRFProtection alsoProvides(self.request, IDisableCSRFProtection) except: pass if self.request.environ['REQUEST_METHOD'] == 'POST': pc = api.portal.get_tool('portal_catalog') portal = getSite() absolute_path = '/'.join(portal.getPhysicalPath()) if self.request.form['id'] != '': id_community = absolute_path + '/' + self.request.form['id'] self.context.plone_log( 'Actualitzant Elasticsearch dades comunitat {}'.format( id_community)) community = pc.unrestrictedSearchResults(path=id_community) if community: obj = community[0]._unrestrictedGetObject() try: self.elastic = getUtility(IElasticSearch) self.elastic().search( index=ElasticSharing().get_index_name()) except: self.elastic().indices.create( index=ElasticSharing().get_index_name(), body={ 'mappings': { 'sharing': { 'properties': { 'path': { 'type': 'string' }, 'principal': { 'type': 'string', 'index': 'not_analyzed' }, 'roles': { 'type': 'string' }, 'uuid': { 'type': 'string' } } } } }) for brain in community: obj = brain._unrestrictedGetObject() if not ICommunity.providedBy(obj): elastic_sharing = queryUtility(IElasticSharing) elastic_sharing.modified(obj) self.context.plone_log( 'Actualitzat objecte: {}, de la comunitat: {}'. format(obj, id_community))
def update(self): self.community_hash = '' self.community_gwuuid = '' self.community_url = '' self.community_type = '' for obj in aq_chain(self.context): if ICommunity.providedBy(obj): self.community_hash = sha1(obj.absolute_url()).hexdigest() self.community_gwuuid = IGWUUID(obj).get() self.community_url = obj.absolute_url() self.community_type = obj.community_type
def showEditCommunity(self): pm = getToolByName(self.portal(), 'portal_membership') user = pm.getAuthenticatedMember() if not IPloneSiteRoot.providedBy(self.context) and \ ICommunity.providedBy(self.context) and \ ('Manager' in user.getRoles() or 'WebMaster' in user.getRoles() or 'Site Administrator' in user.getRoles() or 'Owner' in self.context.get_local_roles_for_userid(user.id)): return True
def addActivityPost(content): installed = packages_installed() if 'ulearn.abacus' in installed: if content.portal_type == 'Event': return False for parent in aq_chain(content): if parent.portal_type == 'privateFolder': return False elif ICommunity.providedBy(parent): return True return None
def newevent_url(self): """ Assume that the new event button is only shown on the community itself. """ context = aq_inner(self.context) # Fist, a light guard if ICommunity.providedBy(context): event_folder_id = '' for obj_id in context.objectIds(): if IEventsFolder.providedBy(context[obj_id]): event_folder_id = obj_id return '{}/{}/++add++Event'.format(context.absolute_url(), event_folder_id) else: return ''
def update(self): context = aq_inner(self.context) if IHomePage.providedBy(self.context) or \ IPloneSiteRoot.providedBy(self.context) or \ not IDexterityContent.providedBy(self.context): path = '' else: if ICommunity.providedBy(aq_inner(self.context)): community = aq_inner(self.context) portal = api.portal.get() portal_path = portal.getPhysicalPath() community_path = community.getPhysicalPath() path = '/' + '/'.join(set(community_path) - set(portal_path)) else: path = '' self.search_base = path self.state = ('published', 'intranet') self.username = api.user.get_current().id # self.user_info = get_safe_member_by_id(self.username) self.calendar_url = get_calendar_url(context, self.search_base) self.year, self.month = year, month = self.year_month_display() self.prev_year, self.prev_month = prev_year, prev_month = ( self.get_previous_month(year, month)) self.next_year, self.next_month = next_year, next_month = ( self.get_next_month(year, month)) # TODO: respect current url-query string self.prev_query = '?month=%s&year=%s' % (prev_month, prev_year) self.next_query = '?month=%s&year=%s' % (next_month, next_year) self.cal = calmodule.Calendar(first_weekday()) self._ts = getToolByName(context, 'translation_service') self.month_name = PLMF( self._ts.month_msgid(month), default=self._ts.month_english(month) ) # strftime %w interprets 0 as Sunday unlike the calendar. strftime_wkdays = [ wkday_to_mon1(day) for day in self.cal.iterweekdays() ] self.weekdays = [ PLMF(self._ts.day_msgid(day, format='s'), default=self._ts.weekday_english(day, format='a')) for day in strftime_wkdays ]
def render(self): try: from plone.protect.interfaces import IDisableCSRFProtection alsoProvides(self.request, IDisableCSRFProtection) except: pass pc = api.portal.get_tool('portal_catalog') portal = getSite() absolute_path = '/'.join(portal.getPhysicalPath()) communities = pc.unrestrictedSearchResults(portal_type="ulearn.community") for num, community in enumerate(communities): obj = community._unrestrictedGetObject() id_community = absolute_path + '/' + obj.id self.context.plone_log('Processant {} de {}. Comunitat {}'.format(num, len(communities), obj)) community = pc.unrestrictedSearchResults(path=id_community) try: self.elastic = getUtility(IElasticSearch) self.elastic().search(index=ElasticSharing().get_index_name()) except: self.elastic().indices.create( index=ElasticSharing().get_index_name(), body={ 'mappings': { 'sharing': { 'properties': { 'path': {'type': 'string'}, 'principal': {'type': 'string', 'index': 'not_analyzed'}, 'roles': {'type': 'string'}, 'uuid': {'type': 'string'} } } } } ) for brain in community: obj = brain._unrestrictedGetObject() if not ICommunity.providedBy(obj): elastic_sharing = queryUtility(IElasticSharing) elastic_sharing.modified(obj) self.context.plone_log('Actualitzat objecte: {}, de la comunitat: {}'.format(obj, id_community)) logger.info('Finished update sharing in communities: {}'.format(portal.absolute_url())) self.response.setBody('OK')
def update(self): try: from plone.protect.interfaces import IDisableCSRFProtection alsoProvides(self.request, IDisableCSRFProtection) except: pass if self.request.environ['REQUEST_METHOD'] == 'POST': pc = api.portal.get_tool('portal_catalog') portal = getSite() absolute_path = '/'.join(portal.getPhysicalPath()) if self.request.form['id'] != '': id_community = absolute_path + '/' + self.request.form['id'] self.context.plone_log('Actualitzant Elasticsearch dades comunitat {}'.format(id_community)) community = pc.unrestrictedSearchResults(path=id_community) if community: obj = community[0]._unrestrictedGetObject() try: self.elastic = getUtility(IElasticSearch) self.elastic().search(index=ElasticSharing().get_index_name()) except: self.elastic().indices.create( index=ElasticSharing().get_index_name(), body={ 'mappings': { 'sharing': { 'properties': { 'path': {'type': 'string'}, 'principal': {'type': 'string', 'index': 'not_analyzed'}, 'roles': {'type': 'string'}, 'uuid': {'type': 'string'} } } } } ) for brain in community: obj = brain._unrestrictedGetObject() if not ICommunity.providedBy(obj): elastic_sharing = queryUtility(IElasticSharing) elastic_sharing.modified(obj) self.context.plone_log('Actualitzat objecte: {}, de la comunitat: {}'.format(obj, id_community))
def update(self): context = aq_inner(self.context) self.folder_type = '' for obj in aq_chain(context): if IDocumentFolder.providedBy(obj): self.folder_type = 'documents' break if ILinksFolder.providedBy(obj): self.folder_type = 'links' break if IPhotosFolder.providedBy(obj): self.folder_type = 'photos' break if IEventsFolder.providedBy(obj): self.folder_type = 'events' break if IDiscussionFolder.providedBy(obj): self.folder_type = 'discussion' break if ICommunity.providedBy(obj): self.folder_type = 'community' break
def get_community(self): context = aq_inner(self.context) for obj in aq_chain(context): if ICommunity.providedBy(obj): return obj
def render(self): try: from plone.protect.interfaces import IDisableCSRFProtection alsoProvides(self.request, IDisableCSRFProtection) except: pass pc = api.portal.get_tool('portal_catalog') portal = getSite() absolute_path = '/'.join(portal.getPhysicalPath()) communities = pc.unrestrictedSearchResults( portal_type="ulearn.community") for num, community in enumerate(communities): obj = community._unrestrictedGetObject() id_community = absolute_path + '/' + obj.id self.context.plone_log('Processant {} de {}. Comunitat {}'.format( num, len(communities), obj)) community = pc.unrestrictedSearchResults(path=id_community) try: self.elastic = getUtility(IElasticSearch) self.elastic().search(index=ElasticSharing().get_index_name()) except: self.elastic().indices.create( index=ElasticSharing().get_index_name(), body={ 'mappings': { 'sharing': { 'properties': { 'path': { 'type': 'string' }, 'principal': { 'type': 'string', 'index': 'not_analyzed' }, 'roles': { 'type': 'string' }, 'uuid': { 'type': 'string' } } } } }) for brain in community: obj = brain._unrestrictedGetObject() if not ICommunity.providedBy(obj): elastic_sharing = queryUtility(IElasticSharing) elastic_sharing.modified(obj) self.context.plone_log( 'Actualitzat objecte: {}, de la comunitat: {}'.format( obj, id_community)) logger.info('Finished update sharing in communities: {}'.format( portal.absolute_url())) self.response.setBody('OK')
def searchUsersFunction(context, request, search_string): # noqa portal = getSite() # pm = api.portal.get_tool(name='portal_membership') nonvisibles = api.portal.get_registry_record( name='ulearn.core.controlpanel.IUlearnControlPanelSettings.nonvisibles' ) current_user = api.user.get_current() oauth_token = current_user.getProperty('oauth_token', '') maxclient, settings = getUtility(IMAXClient)() maxclient.setActor(current_user.getId()) maxclient.setToken(oauth_token) # plugins = portal.acl_users.plugins.listPlugins(IPropertiesPlugin) # # We use the most preferent plugin # pplugin = plugins[0][1] # users = pplugin.enumerateUsers() soup = get_soup('user_properties', portal) users = [] if IPloneSiteRoot.providedBy(context): # Search by string (partial) and return a list of Records from the user # catalog if search_string: if isinstance(search_string, str): search_string = search_string.decode('utf-8') normalized_query = unicodedata.normalize( 'NFKD', search_string).encode('ascii', errors='ignore') normalized_query = normalized_query.replace('.', ' ') + '*' users = [ r for r in soup.query(Eq('searchable_text', normalized_query)) ] else: #too_many_users = api.portal.get_tool('portal_properties').site_properties.many_users #if too_many_users: # users = [] #else: # Query for all users in the user_properties, showing only the legit ones users = [r for r in soup.query(Eq('notlegit', False))] if nonvisibles: filtered = [] for user in users: if user is not None: if user.attrs['username'] not in nonvisibles: filtered.append(user) users = filtered elif ICommunity.providedBy(context): if search_string: maxclientrestricted, settings = getUtility(IMAXClient)() maxclientrestricted.setActor(settings.max_restricted_username) maxclientrestricted.setToken(settings.max_restricted_token) max_users = maxclientrestricted.contexts[ context.absolute_url()].subscriptions.get(qs={ 'username': search_string, 'limit': 0 }) if isinstance(search_string, str): search_string = search_string.decode('utf-8') normalized_query = unicodedata.normalize( 'NFKD', search_string).encode('ascii', errors='ignore') normalized_query = normalized_query.replace('.', ' ') + '*' plone_results = [ r for r in soup.query(Eq('searchable_text', normalized_query)) ] if max_users: merged_results = list( set([ plone_user.attrs['username'] for plone_user in plone_results ]) & set([max_user['username'] for max_user in max_users])) users = [] for user in merged_results: users.append([r for r in soup.query(Eq('id', user))][0]) else: merged_results = [] users = [] for plone_user in plone_results: max_results = maxclientrestricted.contexts[ context.absolute_url()].subscriptions.get( qs={ 'username': plone_user.attrs['username'], 'limit': 0 }) merged_results_user = list( set([plone_user.attrs['username']]) & set( [max_user['username'] for max_user in max_results])) if merged_results_user != []: merged_results.append(merged_results_user[0]) if merged_results: for user in merged_results: record = [r for r in soup.query(Eq('id', user))] if record: users.append(record[0]) else: # User subscribed, but no local profile found, append empty profile for display pass else: maxclientrestricted, settings = getUtility(IMAXClient)() maxclientrestricted.setActor(settings.max_restricted_username) maxclientrestricted.setToken(settings.max_restricted_token) max_users = maxclientrestricted.contexts[ context.absolute_url()].subscriptions.get(qs={'limit': 0}) max_users = [user.get('username') for user in max_users] users = [] for user in max_users: record = [r for r in soup.query(Eq('id', user))] if record: users.append(record[0]) else: # User subscribed, but no local profile found, append empty profile for display pass if nonvisibles: filtered = [] for user in users: if user is not None: if user.attrs['username'] not in nonvisibles: filtered.append(user) users = filtered # soluciĆ³n provisional para que no pete cuando estas en la biblioteca o en cualquier carpeta dentro de una comunidad # pendiente decidir cual sera el funcionamiento else: if search_string: if isinstance(search_string, str): search_string = search_string.decode('utf-8') normalized_query = unicodedata.normalize( 'NFKD', search_string).encode('ascii', errors='ignore') normalized_query = normalized_query.replace('.', ' ') + '*' users = [ r for r in soup.query(Eq('searchable_text', normalized_query)) ] else: too_many_users = api.portal.get_tool( 'portal_properties').site_properties.many_users if too_many_users: users = [] else: # Query for all users in the user_properties, showing only the legit ones users = [r for r in soup.query(Eq('notlegit', False))] if nonvisibles: filtered = [] for user in users: if user is not None: if user.attrs['username'] not in nonvisibles: filtered.append(user) users = filtered has_extended_properties = False extender_name = api.portal.get_registry_record( 'genweb.controlpanel.core.IGenwebCoreControlPanelSettings.user_properties_extender' ) if extender_name in [a[0] for a in getUtilitiesFor(ICatalogFactory)]: has_extended_properties = True extended_user_properties_utility = getUtility(ICatalogFactory, name=extender_name) user_properties_utility = getUtility(ICatalogFactory, name='user_properties') users_profile = [] for user in users: if user is not None and user.attrs['username'] != 'admin': if isinstance(user, Record): user_dict = {} for user_property in user_properties_utility.properties: user_dict.update( {user_property: user.attrs.get(user_property, '')}) if has_extended_properties: for user_property in extended_user_properties_utility.properties: user_dict.update( {user_property: user.attrs.get(user_property, '')}) user_dict.update(dict(id=user.attrs['username'])) userImage = '<img src="' + settings.max_server + '/people/' + user.attrs[ 'username'] + '/avatar/large" alt="' + user.attrs[ 'username'] + '" title="' + user.attrs[ 'username'] + '" height="105" width="105" >' # userImage = pm.getPersonalPortrait(user.attrs['username']) # userImage.alt = user.attrs['username'] # userImage.title = user.attrs['username'] # userImage.height = 105 # userImage.width = 105 user_dict.update(dict(foto=str(userImage))) user_dict.update( dict(url=portal.absolute_url() + '/profile/' + user.attrs['username'])) users_profile.append(user_dict) else: # User is NOT an standard Plone user!! is a dict provided by the patched enumerateUsers user_dict = {} for user_property in user_properties_utility.properties: user_dict.update( {user_property: user.get(user_property, '')}) if has_extended_properties: for user_property in extended_user_properties_utility.properties: user_dict.update( {user_property: user.get(user_property, '')}) user_dict.update(dict(id=user.get('id', ''))) userImage = '<img src="' + settings.max_server + '/people/' + user.attrs[ 'username'] + '/avatar/large" alt="' + user.attrs[ 'username'] + '" title="' + user.attrs[ 'username'] + '" height="105" width="105" >' # userImage = pm.getPersonalPortrait(user.attrs['username']) # userImage.alt = user.attrs['username'] # userImage.title = user.attrs['username'] # userImage.height = 105 # userImage.width = 105 user_dict.update(dict(foto=str(userImage))) user_dict.update( dict(url=portal.absolute_url() + '/profile/' + user.get('id', ''))) users_profile.append(user_dict) len_usuaris = len(users_profile) if len_usuaris > 100: escollits = random.sample(range(len(users_profile)), 100) llista = [] for escollit in escollits: llista.append(users_profile[escollit]) return {'content': llista, 'length': len_usuaris, 'big': True} else: users_profile.sort(key=itemgetter('username')) return {'content': users_profile, 'length': len_usuaris, 'big': False}
def get_community(self, path): doc = api.portal.get().unrestrictedTraverse(path) for obj in aq_chain(doc): if ICommunity.providedBy(obj): return obj
def render_viewlet(self): context = aq_inner(self.context) for obj in aq_chain(context): if ICommunity.providedBy(obj): return True return False
def findContainerCommunity(content): for parent in aq_chain(content): if ICommunity.providedBy(parent): return parent return None
def showEditCommunity(self): if not IPloneSiteRoot.providedBy(self.context) and \ ICommunity.providedBy(self.context) and \ checkPermission('cmf.RequestReview', self.context): return True
def searchUsersFunction(context, request, search_string): # noqa portal = getSite() # pm = api.portal.get_tool(name='portal_membership') current_user = api.user.get_current() oauth_token = current_user.getProperty('oauth_token', '') maxclient, settings = getUtility(IMAXClient)() maxclient.setActor(current_user.getId()) maxclient.setToken(oauth_token) # plugins = portal.acl_users.plugins.listPlugins(IPropertiesPlugin) # # We use the most preferent plugin # pplugin = plugins[0][1] # users = pplugin.enumerateUsers() soup = get_soup('user_properties', portal) users = [] if IPloneSiteRoot.providedBy(context): # Search by string (partial) and return a list of Records from the user # catalog if search_string: if isinstance(search_string, str): search_string = search_string.decode('utf-8') normalized_query = unicodedata.normalize('NFKD', search_string).encode('ascii', errors='ignore') normalized_query = normalized_query.replace('.', ' ') + '*' users = [r for r in soup.query(Eq('searchable_text', normalized_query))] else: #too_many_users = api.portal.get_tool('portal_properties').site_properties.many_users #if too_many_users: # users = [] #else: # Query for all users in the user_properties, showing only the legit ones users = [r for r in soup.query(Eq('notlegit', False))] elif ICommunity.providedBy(context): if search_string: maxclientrestricted, settings = getUtility(IMAXClient)() maxclientrestricted.setActor(settings.max_restricted_username) maxclientrestricted.setToken(settings.max_restricted_token) max_users = maxclientrestricted.contexts[context.absolute_url()].subscriptions.get(qs={'username': search_string, 'limit': 0}) if isinstance(search_string, str): search_string = search_string.decode('utf-8') normalized_query = unicodedata.normalize('NFKD', search_string).encode('ascii', errors='ignore') normalized_query = normalized_query.replace('.', ' ') + '*' plone_results = [r for r in soup.query(Eq('searchable_text', normalized_query))] if max_users: merged_results = list(set([plone_user.attrs['username'] for plone_user in plone_results]) & set([max_user['username'] for max_user in max_users])) users = [] for user in merged_results: users.append([r for r in soup.query(Eq('id', user))][0]) else: merged_results = [] users = [] for plone_user in plone_results: max_results = maxclientrestricted.contexts[context.absolute_url()].subscriptions.get(qs={'username': plone_user.attrs['username'], 'limit': 0}) merged_results_user = list(set([plone_user.attrs['username']]) & set([max_user['username'] for max_user in max_results])) if merged_results_user != []: merged_results.append(merged_results_user[0]) if merged_results: for user in merged_results: record = [r for r in soup.query(Eq('id', user))] if record: users.append(record[0]) else: # User subscribed, but no local profile found, append empty profile for display pass else: maxclientrestricted, settings = getUtility(IMAXClient)() maxclientrestricted.setActor(settings.max_restricted_username) maxclientrestricted.setToken(settings.max_restricted_token) max_users = maxclientrestricted.contexts[context.absolute_url()].subscriptions.get(qs={'limit': 0}) max_users = [user.get('username') for user in max_users] users = [] for user in max_users: record = [r for r in soup.query(Eq('id', user))] if record: users.append(record[0]) else: # User subscribed, but no local profile found, append empty profile for display pass # soluciĆ³n provisional para que no pete cuando estas en la biblioteca o en cualquier carpeta dentro de una comunidad # pendiente decidir cual sera el funcionamiento else: if search_string: if isinstance(search_string, str): search_string = search_string.decode('utf-8') normalized_query = unicodedata.normalize('NFKD', search_string).encode('ascii', errors='ignore') normalized_query = normalized_query.replace('.', ' ') + '*' users = [r for r in soup.query(Eq('searchable_text', normalized_query))] else: too_many_users = api.portal.get_tool('portal_properties').site_properties.many_users if too_many_users: users = [] else: # Query for all users in the user_properties, showing only the legit ones users = [r for r in soup.query(Eq('notlegit', False))] has_extended_properties = False extender_name = api.portal.get_registry_record('genweb.controlpanel.core.IGenwebCoreControlPanelSettings.user_properties_extender') if extender_name in [a[0] for a in getUtilitiesFor(ICatalogFactory)]: has_extended_properties = True extended_user_properties_utility = getUtility(ICatalogFactory, name=extender_name) user_properties_utility = getUtility(ICatalogFactory, name='user_properties') users_profile = [] for user in users: if user is not None and user.attrs['username'] != 'admin': if isinstance(user, Record): user_dict = {} for user_property in user_properties_utility.properties: user_dict.update({user_property: user.attrs.get(user_property, '')}) if has_extended_properties: for user_property in extended_user_properties_utility.properties: user_dict.update({user_property: user.attrs.get(user_property, '')}) user_dict.update(dict(id=user.attrs['username'])) userImage = '<img src="' + settings.max_server + '/people/' + user.attrs['username'] + '/avatar/large" alt="' + user.attrs['username'] + '" title="' + user.attrs['username'] + '" height="105" width="105" >' # userImage = pm.getPersonalPortrait(user.attrs['username']) # userImage.alt = user.attrs['username'] # userImage.title = user.attrs['username'] # userImage.height = 105 # userImage.width = 105 user_dict.update(dict(foto=str(userImage))) user_dict.update(dict(url=portal.absolute_url() + '/profile/' + user.attrs['username'])) users_profile.append(user_dict) else: # User is NOT an standard Plone user!! is a dict provided by the patched enumerateUsers user_dict = {} for user_property in user_properties_utility.properties: user_dict.update({user_property: user.get(user_property, '')}) if has_extended_properties: for user_property in extended_user_properties_utility.properties: user_dict.update({user_property: user.get(user_property, '')}) user_dict.update(dict(id=user.get('id', ''))) userImage = '<img src="' + settings.max_server + '/people/' + user.attrs['username'] + '/avatar/large" alt="' + user.attrs['username'] + '" title="' + user.attrs['username'] + '" height="105" width="105" >' # userImage = pm.getPersonalPortrait(user.attrs['username']) # userImage.alt = user.attrs['username'] # userImage.title = user.attrs['username'] # userImage.height = 105 # userImage.width = 105 user_dict.update(dict(foto=str(userImage))) user_dict.update(dict(url=portal.absolute_url() + '/profile/' + user.get('id', ''))) users_profile.append(user_dict) nonvisibles = api.portal.get_registry_record(name='ulearn.core.controlpanel.IUlearnControlPanelSettings.nonvisibles') if nonvisibles: users_profile = [user for user in users_profile if user['id'] not in nonvisibles] len_usuaris = len(users_profile) if len_usuaris > 100: escollits = random.sample(range(len(users_profile)), 100) llista = [] for escollit in escollits: llista.append(users_profile[escollit]) return {'content': llista, 'length': len_usuaris, 'big': True} else: users_profile.sort(key=itemgetter('username')) return {'content': users_profile, 'length': len_usuaris, 'big': False}
def showEditCommunity(self): if not IPloneSiteRoot.providedBy(self.context) and \ ICommunity.providedBy(self.context) and \ 'Owner' in api.user.get_roles(username=self.username, obj=self.context): return True
def get_hash(self): """ Assume that the stats are only shown on the community itself. """ context = aq_inner(self.context) # Light guard if ICommunity.providedBy(context): return sha1(context.absolute_url()).hexdigest()