def get_folder_content(folder, user, add_query=None, sort_on='release_date', reverse=True, **args): _filters = deepcopy(getattr(folder, 'filters', [])) # retrieve classifications queries classifications = [ CLASSIFICATIONS[fid] for fid in getattr(folder, 'classifications', []) ] query = None if classifications: for classification in classifications: classification_query = classification().get_query(**args) query = and_op(query, classification_query) query = and_op(query, add_query) objects = find_entities(user=user, add_query=query, sort_on=sort_on, reverse=reverse, filters=_filters, include_site=True, filter_op='or', **args) return objects
def __call__(self): site = get_site_folder(True, self.request) if not getattr(site, 'activate_improve', False): return {'improve': None} resources = deepcopy(getattr( self.request, 'resources', {'js_links': [], 'css_links': []})) result = {'css_links': [], 'js_links': []} root = self.request.root actions = getBusinessAction( context=root, request=self.request, process_id='lacviewmanager', node_id='improve') result['improve'] = None if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['improve'] = actions_result[3][0] result['css_links'] = [c for c in actions_result[2].get('css_links', []) if c not in resources['css_links']] result['js_links'] = [c for c in actions_result[2].get('js_links', []) if c not in resources['js_links']] update_resources(self.request, result) return result
def deserialize(self, cstruct=colander.null): appstruct = super(CalendarSearchSchema, self).deserialize(cstruct) thematics = appstruct.get('thematics', []) dates = appstruct.get('dates', 0) appstruct = { 'metadata_filter': { 'content_types': {'cultural_event'}, 'states': ['published'], 'tree': deepcopy(DEFAULT_TREE) }, 'text_filter': { 'text_to_search': appstruct.pop('text_to_search', '') }, 'contribution_filter': { 'artists_ids': appstruct.pop('artists_ids', []) }, 'geographic_filter': { 'city': appstruct.pop('city', []) }, 'temporal_filter': { 'start_end_dates': DEFAULT_DATES[dates][1]() } } for thematic in thematics: appstruct['metadata_filter']['tree'][ROOT_TREE][thematic] = {} return appstruct
def __call__(self): site = get_site_folder(True, self.request) if not getattr(site, 'activate_improve', False): return {'improve': None} resources = deepcopy( getattr(self.request, 'resources', { 'js_links': [], 'css_links': [] })) result = {'css_links': [], 'js_links': []} root = self.request.root actions = getBusinessAction(context=root, request=self.request, process_id='lacviewmanager', node_id='improve') result['improve'] = None if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['improve'] = actions_result[3][0] result['css_links'] = [ c for c in actions_result[2].get('css_links', []) if c not in resources['css_links'] ] result['js_links'] = [ c for c in actions_result[2].get('js_links', []) if c not in resources['js_links'] ] update_resources(self.request, result) return result
def __call__(self): root = getSite() options = {} options['locations'] = {} options['show_all'] = True resources = deepcopy(getattr( self.request, 'resources', {'js_links': [], 'css_links': []})) search_view_instance = GeoSearchForm(self.context, self.request) search_view_result = search_view_instance() search_body = '' result = {'css_links': [], 'js_links': []} if isinstance(search_view_result, dict) and \ 'coordinates' in search_view_result: search_body = search_view_result['coordinates'][search_view_instance.coordinates][0]['body'] result['css_links'] = [c for c in search_view_result['css_links'] if c not in resources['css_links']] result['js_links'] = [c for c in search_view_result['js_links'] if c not in resources['js_links']] result['search_body'] = search_body result['options'] = json.dumps(options) result['url'] = self.request.resource_url( root, '@@creationculturelapi', query={'op': 'find_geo_cultural_event'}) update_resources(self.request, result) return result
def hash_venue_data(self): result = self.title result += self.description result += str(getattr(self, 'handicapped_accessibility', False) or False) result += str(getattr(self, 'capacity', '') or '') result += ''.join(sorted(getattr(self, 'kind', []) or [])) addresses = [self.address_str(a) for a in getattr(self, 'addresses', [])] addresses = sorted(addresses) contacts = deepcopy(getattr(self, 'contacts', []) or []) for contact in contacts: phone = contact.get('phone', None) if isinstance(phone, dict): contact['phone'] = phone.get('number', '') + \ phone.get('country', '') fax = contact.get('fax', None) if isinstance(fax, dict): contact['fax'] = fax.get('number', '') + \ fax.get('country', '') contacts = [sorted(a.items(), key=lambda e: e[0]) for a in contacts] contacts = sorted( contacts, key=lambda a: dict(a).get('title', '')) result += str(contacts) result += str(addresses) result = result.replace(' ', '').strip() m = hashlib.md5() m.update(result.encode()) self.hash_venue = m.digest()
def get_visibility_filter(self): registry = get_current_registry() return { 'metadata_filter': { 'tree': deepcopy(self.tree), 'content_types': [registry.content.typeof(self)], 'states': list(getattr(self, 'state', [])) } }
def test_deepcopy(self): list1 = [1, 2, 3] my_dict1 = {'d1': list1} my_dict = {'a': my_dict1} self.assertIs(my_dict['a'], my_dict1) self.assertIs(my_dict['a']['d1'], list1) result = utils.deepcopy(my_dict) self.assertIsNot(result['a'], my_dict1) self.assertIsNot(result['a']['d1'], list1)
def get_analyzed_data(node, source, validated): result = {} for child in node.children: if hasattr(child, 'analyzer'): validated_ = deepcopy(validated) result_child = child.analyzer(child, source, validated_) if result_child is not None: result.update(result_child) return result
def site_folder_tree_evolve(root, registry): from lac.views.filter import find_entities from lac.content.interface import ISiteFolder from lac.utilities.utils import deepcopy root = getSite() sites = find_entities(interfaces=[ISiteFolder]) for site in sites: site.tree = deepcopy(root.tree) log.info('Site tree evolved.')
def get_filter_nodes_to_omit(node, filter_): result_node = [] for child in node.children: if hasattr(child, 'filter_analyzer'): filter_cp = deepcopy(filter_) result_child = child.filter_analyzer(filter_cp) if result_child: nodes_to_omit = [n for n in result_child.keys() if result_child[n]['is_unique']] result_node.append((child.name, nodes_to_omit)) return result_node
def merge_with_filter_view(view, args): """Merge view.filter_instance.validated with args (kwargs really) Give priority to the filter in validated if a filter of the same name exists in args. """ validated = None if view and getattr(view, 'filter_instance', None): validated = view.filter_instance.validated if not validated: return deepcopy(args) if not args: return deepcopy(validated) result = deepcopy(validated) for arg in args: if arg not in validated: result[arg] = args[arg] return result
def get_filter_nodes_to_omit(node, filter_): result_node = [] for child in node.children: if hasattr(child, 'filter_analyzer'): filter_cp = deepcopy(filter_) result_child = child.filter_analyzer(filter_cp) if result_child: nodes_to_omit = [ n for n in result_child.keys() if result_child[n]['is_unique'] ] result_node.append((child.name, nodes_to_omit)) return result_node
def __call__(self): user = get_current(self.request) resources = deepcopy( getattr(self.request, 'resources', { 'js_links': [], 'css_links': [] })) search_view_instance = SearchView(self.context, self.request) search_view_result = search_view_instance() search_body = '' result = {'css_links': [], 'js_links': []} if isinstance(search_view_result, dict) and \ 'coordinates' in search_view_result: search_body = search_view_result['coordinates'][ search_view_instance.coordinates][0]['body'] result['css_links'] = [ c for c in search_view_result['css_links'] if c not in resources['css_links'] ] result['js_links'] = [ c for c in search_view_result['js_links'] if c not in resources['js_links'] ] result['search_body'] = search_body result['view'] = self result['alerts'] = [] if hasattr(user, 'get_alerts'): site = get_site_folder(True, self.request) result['alerts'] = user.get_alerts(site=site) result['login_action'] = None if self.request.user is None: root = self.request.root actions = getBusinessAction(context=root, request=self.request, process_id='usermanagement', node_id='login') if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['login_action'] = actions_result[3][0] update_resources(self.request, result) return result
def __call__(self): site = get_site_folder(True, self.request) if self.request.view_name in ('@@resetpassword', '@@registration', 'login', '@@login') or \ not getattr(site, 'activate_questionnaire', False): return {'questionnaire': None} user = get_current() email = getattr(user, 'email', '') if email: db = arango_server.db("lac") collection = create_collection(db, CURRENT_QUEST) doc = collection.get_first_example({"email": email}) if doc: return {'questionnaire': None} resources = deepcopy( getattr(self.request, 'resources', { 'js_links': [], 'css_links': [] })) result = {'css_links': [], 'js_links': []} root = self.request.root actions = getBusinessAction(context=root, request=self.request, process_id='lacviewmanager', node_id='questionnaire') result['questionnaire'] = None result['current_questionnaire'] = CURRENT_QUEST if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['questionnaire'] = actions_result[3][0] result['css_links'] = [ c for c in actions_result[2].get('css_links', []) if c not in resources['css_links'] ] result['js_links'] = [ c for c in actions_result[2].get('js_links', []) if c not in resources['js_links'] ] update_resources(self.request, result) return result
def evolve_filter(filter_): default_tree = deepcopy(DEFAULT_TREE) country = filter_.get('country', []) result = { 'metadata_filter': { 'negation': False, 'content_types': filter_.get('content_types', []), 'states': filter_.get('states', []), 'tree': filter_.get('tree', default_tree), }, 'temporal_filter': { 'negation': False, 'start_end_dates': filter_.get('start_end_dates', { 'start_date': None, 'end_date': None }), 'created_date': filter_.get('created_date', { 'created_after': None, 'created_before': None }) }, 'geographic_filter': { 'negation': filter_.get('zipcode', {}).get('negation', False), 'city': filter_.get('city', []), 'country': country[0] if len(country) > 0 else '', 'zipcode': filter_.get('zipcode', {}).get('zipcode', []) }, 'contribution_filter': { 'negation': False, 'authors': filter_.get('authors', []), 'artist_ids': filter_.get('artist_ids', []) }, 'text_filter': { 'negation': False, 'text_to_search': filter_.get('text_to_search', ''), }, 'other_filter': { 'negation': False, 'sources': filter_.get('sources', []), } } return result
def __call__(self): site = get_site_folder(True, self.request) if self.request.view_name in ('@@resetpassword', '@@registration', 'login', '@@login') or \ not getattr(site, 'activate_questionnaire', False): return {'questionnaire': None} user = get_current() email = getattr(user, 'email', '') if email: db = arango_server.db("lac") collection = create_collection(db, CURRENT_QUEST) doc = collection.get_first_example({"email": email}) if doc: return {'questionnaire': None} resources = deepcopy(getattr( self.request, 'resources', {'js_links': [], 'css_links': []})) result = {'css_links': [], 'js_links': []} root = self.request.root actions = getBusinessAction( context=root, request=self.request, process_id='lacviewmanager', node_id='questionnaire') result['questionnaire'] = None result['current_questionnaire'] = CURRENT_QUEST if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['questionnaire'] = actions_result[3][0] result['css_links'] = [c for c in actions_result[2].get('css_links', []) if c not in resources['css_links']] result['js_links'] = [c for c in actions_result[2].get('js_links', []) if c not in resources['js_links']] update_resources(self.request, result) return result
def __call__(self): user = get_current(self.request) resources = deepcopy(getattr( self.request, 'resources', {'js_links': [], 'css_links': []})) search_view_instance = SearchView(self.context, self.request) search_view_result = search_view_instance() search_body = '' result = {'css_links': [], 'js_links': []} if isinstance(search_view_result, dict) and \ 'coordinates' in search_view_result: search_body = search_view_result['coordinates'][search_view_instance.coordinates][0]['body'] result['css_links'] = [c for c in search_view_result['css_links'] if c not in resources['css_links']] result['js_links'] = [c for c in search_view_result['js_links'] if c not in resources['js_links']] result['search_body'] = search_body result['view'] = self result['alerts'] = [] if hasattr(user, 'get_alerts'): site = get_site_folder(True, self.request) result['alerts'] = user.get_alerts(site=site) result['login_action'] = None if self.request.user is None: root = self.request.root actions = getBusinessAction( context=root, request=self.request, process_id='usermanagement', node_id='login') if actions: actions_result = update_actions(root, self.request, actions) #actions_result = (action_updated, action_alert_messages, # action_resources, action_informations) if actions_result[3]: result['login_action'] = actions_result[3][0] update_resources(self.request, result) return result
def evolve_filter(filter_): default_tree = deepcopy(DEFAULT_TREE) country = filter_.get('country', []) result = { 'metadata_filter': { 'negation': False, 'content_types': filter_.get('content_types', []), 'states': filter_.get('states', []), 'tree': filter_.get('tree', default_tree), }, 'temporal_filter': { 'negation': False, 'start_end_dates': filter_.get( 'start_end_dates', {'start_date': None, 'end_date': None}), 'created_date': filter_.get( 'created_date', {'created_after': None, 'created_before': None}) }, 'geographic_filter': { 'negation': filter_.get('zipcode', {}).get('negation', False), 'city': filter_.get('city', []), 'country': country[0] if len(country) > 0 else '', 'zipcode': filter_.get('zipcode', {}).get('zipcode', []) }, 'contribution_filter': { 'negation': False, 'authors': filter_.get('authors', []), 'artist_ids': filter_.get('artist_ids', []) }, 'text_filter': { 'negation': False, 'text_to_search': filter_.get('text_to_search', ''), }, 'other_filter': { 'negation': False, 'sources': filter_.get('sources', []), } } return result
def get_folder_content(folder, user, add_query=None, sort_on='release_date', reverse=True, **args): _filters = deepcopy(getattr(folder, 'filters', [])) # retrieve classifications queries classifications = [CLASSIFICATIONS[fid] for fid in getattr(folder, 'classifications', [])] query = None if classifications: for classification in classifications: classification_query = classification().get_query(**args) query = and_op(query, classification_query) query = and_op(query, add_query) objects = find_entities(user=user, add_query=query, sort_on=sort_on, reverse=reverse, filters=_filters, include_site=True, filter_op='or', **args) return objects
def __call__(self): root = getSite() options = {} options['locations'] = {} options['show_all'] = True resources = deepcopy( getattr(self.request, 'resources', { 'js_links': [], 'css_links': [] })) search_view_instance = GeoSearchForm(self.context, self.request) search_view_result = search_view_instance() search_body = '' result = {'css_links': [], 'js_links': []} if isinstance(search_view_result, dict) and \ 'coordinates' in search_view_result: search_body = search_view_result['coordinates'][ search_view_instance.coordinates][0]['body'] result['css_links'] = [ c for c in search_view_result['css_links'] if c not in resources['css_links'] ] result['js_links'] = [ c for c in search_view_result['js_links'] if c not in resources['js_links'] ] result['search_body'] = search_body result['options'] = json.dumps(options) result['url'] = self.request.resource_url( root, '@@creationculturelapi', query={'op': 'find_geo_cultural_event'}) update_resources(self.request, result) return result