def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. We will make sure that each non None constraint_definition is satisfied (unicity) This Constraint use portal_catalog """ errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit) for attribute_name, expression_criterion_dict in self.constraint_definition.items(): message_id = None mapping = dict(attribute_name=attribute_name) #Evaluate expression_criterion_dict expression = Expression(expression_criterion_dict) from Products.ERP5Type.Utils import createExpressionContext econtext = createExpressionContext(obj) criterion_dict = expression(econtext) from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery # Add uid in criterion keys to avoid fetching current object. criterion_dict['query'] = NegatedQuery(Query(uid=obj.getUid())) portal = obj.getPortalObject() result = portal.portal_catalog.countResults(**criterion_dict)[0][0] if result >= 1: mapping['value'] = criterion_dict.get(attribute_name) message_id = 'message_invalid_attribute_unicity' # Generate error if message_id is not None: errors.append(self._generateError(obj, self._getMessage(message_id), mapping)) return errors
def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. We will make sure that each non None constraint_definition is satisfied (unicity) This Constraint use portal_catalog """ error_list = PropertyExistenceConstraint._checkConsistency(self, obj, fixit=fixit) attribute_name = self.getConstraintProperty() expression_criterion_dict = self.getFilterParameter() message_id = None mapping = dict(attribute_name=attribute_name) #Evaluate expression_criterion_dict expression = Expression(expression_criterion_dict) econtext = createExpressionContext(obj) criterion_dict = expression(econtext) # Add uid in criterion keys to avoid fetching current object. criterion_dict['query'] = NegatedQuery(Query(uid=obj.getUid())) portal = obj.getPortalObject() result = portal.portal_catalog.countResults(**criterion_dict)[0][0] if result >= 1: mapping['value'] = criterion_dict.get(attribute_name) message_id = 'message_invalid_attribute_unicity' # Generate error if message_id is not None: error_list.append(self._generateError(obj, self._getMessage(message_id), mapping)) return error_list
def buildIndex(language=None): from Products.ZSQLCatalog.SQLCatalog import NegatedQuery, Query # Retrieve the different subjects in the catalog subject_list = context.searchResults( select_list=['subject', 'reference'], query=NegatedQuery(Query(subject=None)), language=language or '', sort_on=(('subject', 'ascending'), ('title', 'ascending')), #src__=1, ) #return subject_list #return map(lambda x:(x.subject, x.reference), subject_list) # Convert the result into list # This is not the fastest approach but should be OK for # moderate size subject_list = list(subject_list) subject_count = len( subject_list) # Not the fastest (use countResults instead) # Return immediately if empty if not subject_count: return '<p></p>' # Now build the page result = [] last_subject = None for subject in subject_list: if last_subject != subject.subject: subject_title = subject.subject subject_title = subject_title[0].upper() + subject_title[1:] result.append("<h1>%s</h1>" % subject_title) result.append("""<p><a href="%s/%s/view">%s</a></p>""" % (web_section_url, subject.reference, subject.title)) last_subject = subject.subject return '\n'.join(result)
def getUnreadDocumentUrlList(self, portal_type=None, user_name=None, **kw): """ returns document that needs to be acknowledged : - Acknowledgement (internal email) - Site Message This method will mainly be used by getUnreadAcknowledgementList. Also, because url are used, the result will be easy to cache. """ document_list = [] if user_name is not None: portal = self.getPortalObject() person_value = portal.ERP5Site_getAuthenticatedMemberPersonValue( user_name=user_name) if person_value is not None: now = DateTime() # First look at all event that define the current user as destination all_document_list = [x.getObject() for x in \ self.portal_catalog(portal_type = portal_type, simulation_state = self.getPortalTransitInventoryStateList(), # start_date = {'query':now,'range':'max'}, # stop_date = {'query':now,'range':'min'}, default_destination_uid=person_value.getUid())] # Now we can look directly at acknowledgement document not approved yet # so not in a final state final_state_list = self.getPortalCurrentInventoryStateList() query = NegatedQuery(Query(simulation_state=final_state_list)) for x in self.portal_catalog( portal_type=self._getAcknowledgementTypeList(), query=query, # start_date = {'query':now,'range':'max'}, # stop_date = {'query':now,'range':'min'}, default_destination_uid=person_value.getUid()): x = x.getObject() if x not in all_document_list: all_document_list.append(x) for document in all_document_list: # We filter manually on dates until a good solution is found for # searching by dates on the catalog if (document.getStartDate() < now < (document.getStopDate() + 1)): acknowledged = document.isAcknowledged( user_name=user_name) if not acknowledged: document_list.append(document.getRelativeUrl()) else: raise ValueError('No user name given') return document_list
def isVersionUnique(self): """ Returns true if no other document exists with the same reference, version and language, or if the current document has no reference. """ if not self.getReference(): return True kw = dict(portal_type=self.getPortalDocumentTypeList(), reference=self.getReference(), version=self.getVersion(), language=self.getLanguage(), query=NegatedQuery(Query(validation_state=('cancelled', 'deleted')))) catalog = self.getPortalObject().portal_catalog self_count = catalog.unrestrictedCountResults(uid=self.getUid(), **kw)[0][0] count = catalog.unrestrictedCountResults(**kw)[0][0] # If self is not indexed yet, then if count == 1, version is not unique return count <= self_count
def generateNestedQuery(getQuery, priority_list, criterion_dict, possible_worklist_id_dict=None): """ """ assert possible_worklist_id_dict is None \ or len(possible_worklist_id_dict) != 0 my_priority_list = priority_list[:] my_criterion_id = my_priority_list.pop() query_list = [] append = query_list.append my_criterion_dict = criterion_dict[my_criterion_id] if len(my_priority_list) > 0: for criterion_value, worklist_id_dict in my_criterion_dict.iteritems(): if possible_worklist_id_dict is not None: criterion_worklist_id_dict = worklist_id_dict.copy() # Do not use iterkeys since the dictionary will be modified in the # loop for worklist_id in criterion_worklist_id_dict.keys(): if worklist_id not in possible_worklist_id_dict: del criterion_worklist_id_dict[worklist_id] else: criterion_worklist_id_dict = worklist_id_dict if len(criterion_worklist_id_dict): subcriterion_query = generateNestedQuery( getQuery=getQuery, priority_list=my_priority_list, criterion_dict=criterion_dict, possible_worklist_id_dict=criterion_worklist_id_dict) if subcriterion_query is not None: query = getQuery(comparison_operator='IN', **{my_criterion_id: criterion_value}) if isinstance(criterion_value, ExclusionTuple): query = NegatedQuery(query) query = ComplexQuery( logical_operator='OR', *(query, getQuery(**{my_criterion_id: None}))) append( ComplexQuery(query, subcriterion_query, logical_operator='AND')) else: possible_value_list = tuple() impossible_value_list = tuple() possible = True for criterion_value, criterion_worklist_id_dict \ in my_criterion_dict.iteritems(): if possible_worklist_id_dict is not None: possible = False for worklist_id in criterion_worklist_id_dict.iterkeys(): if worklist_id in possible_worklist_id_dict: possible = True break if possible: if isinstance(criterion_value, ExclusionTuple): impossible_value_list += criterion_value else: possible_value_list += criterion_value value_query_list = [] if len(possible_value_list): query = getQuery(comparison_operator='IN', **{my_criterion_id: possible_value_list}) value_query_list.append(query) if len(impossible_value_list): query = getQuery(comparison_operator='IN', **{my_criterion_id: impossible_value_list}) query = NegatedQuery(query) query = ComplexQuery(logical_operator='OR', *(query, getQuery(**{my_criterion_id: None}))) value_query_list.append(query) append(ComplexQuery(logical_operator='AND', *value_query_list)) if len(query_list): return ComplexQuery(logical_operator='OR', *query_list) return None
def mergeRevision(self): """ Merge the current document with any previous revision or change its version to make sure it is still unique. NOTE: revision support is implemented in the Document class rather than within the ContributionTool because the ingestion process requires to analyse the content of the document first. Hence, it is not possible to do any kind of update operation until the whole ingestion process is completed, since update requires to know reference, version, language, etc. In addition, we have chosen to try to merge revisions after each metadata discovery as a way to make sure that any content added in the system through the ContributionTool (ex. through webdav) will be merged if necessary. It may be posssible though to split disoverMetadata and finishIngestion. """ document = self if self.getReference(): invalid_validation_state_list = ('archived', 'cancelled', 'deleted') catalog = self.getPortalObject().portal_catalog # Find all document with same (reference, version, language) kw = dict( portal_type=self.getPortalType(), reference=self.getReference(), query=NegatedQuery( Query(validation_state=invalid_validation_state_list)), sort_on='creation_date') if self.getVersion(): kw['version'] = self.getVersion() if self.getLanguage(): kw['language'] = self.getLanguage() document_list = catalog.unrestrictedSearchResults(**kw) existing_document = None # Select the first one which is not self and which # shares the same coordinates for o in document_list: if o.getRelativeUrl() != self.getRelativeUrl() and\ o.getVersion() == self.getVersion() and\ o.getLanguage() == self.getLanguage(): existing_document = o.getObject() if existing_document.getValidationState() not in \ invalid_validation_state_list: break else: existing_document = None # We found an existing document to update if existing_document is not None: document = existing_document if not _checkPermission(Permissions.ModifyPortalContent, existing_document): raise Unauthorized( "[DMS] You are not allowed to update the existing document which has the same coordinates (id %s)" % existing_document.getId()) else: update_kw = {} for k in self.propertyIds(): if k not in FIXED_PROPERTY_IDS and self.hasProperty(k): update_kw[k] = self.getProperty(k) existing_document.edit(**update_kw) # Erase self self.getParentValue().manage_delObjects([ self.getId(), ]) return document
def getInventoryQueryDict(self, budget_cell): """ Query dict to pass to simulation query """ query_dict = dict() axis = self.getInventoryAxis() if not axis: return query_dict base_category = self.getProperty('variation_base_category') if not base_category: return query_dict budget_line = budget_cell.getParentValue() context = budget_cell if self.isMemberOf('budget_variation/budget'): context = budget_line.getParentValue() elif self.isMemberOf('budget_variation/budget_line'): context = budget_line if axis == 'movement': axis = 'default_%s' % base_category if axis == 'movement_strict_membership': axis = 'default_strict_%s' % base_category uid_based_axis = False if axis in ('node', 'section', 'payment', 'function', 'project', 'mirror_section', 'mirror_node', 'funding' ): axis = '%s_uid' % axis uid_based_axis = True query = None portal_categories = self.getPortalObject().portal_categories for criterion_category in context.getMembershipCriterionCategoryList(): if '/' not in criterion_category: # safe ... continue criterion_base_category, node_url = criterion_category.split('/', 1) if criterion_base_category == base_category: if node_url == 'budget_special_node/none': # This is the "Nothing" virtual node query = Query(**{axis: None}) elif node_url == 'budget_special_node/all_other': # This is the "All Other" virtual node other_uid_list = [] none_node_selected = False for node in self._getNodeList(budget_line): if '%s/%s' % (base_category, node.getRelativeUrl()) in\ budget_line.getVariationCategoryList(): if node.getRelativeUrl() == 'budget_special_node/none': none_node_selected = True else: if uid_based_axis: other_uid_list.append(node.getUid()) else: other_uid_list.append(node.getRelativeUrl()) if none_node_selected: # in this case we don't want to include NULL in All others query = NegatedQuery(Query(**{axis: other_uid_list})) else: query = ComplexQuery( NegatedQuery(Query(**{axis: other_uid_list})), Query(**{axis: None}), operator="OR") else: value = portal_categories.getCategoryValue(node_url, base_category=criterion_base_category) if uid_based_axis: query_dict.setdefault(axis, []).append(value.getUid()) else: query_dict.setdefault(axis, []).append(value.getRelativeUrl()) if query: if axis in query_dict: query_dict[axis] = ComplexQuery( query, Query(**{axis: query_dict[axis]}), operator='OR') else: query_dict[axis] = query return query_dict
"""Cleanup the data from support request module. So that test are isolated. """ from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery portal = context.getPortalObject() test_project_set = set( (portal.project_module.erp5_officejs_support_request_ui_test_project_001, portal.project_module.erp5_officejs_support_request_ui_test_project_002)) to_delete_list = [] for brain in portal.portal_catalog( portal_type="Support Request", simulation_state=NegatedQuery( Query(simulation_state=("cancelled", )))): support_request = brain.getObject() if support_request.getId().startswith( 'erp5_officejs_support_request_ui_test_'): continue # business template data assert support_request.getSourceProjectValue() in test_project_set, \ "Support request %s have unexpected project." % support_request.absolute_url() to_delete_list.append(support_request.getId()) portal.support_request_module.manage_delObjects(to_delete_list) event_to_delete_id_list = [] for event in portal.event_module.contentValues(): if event.getFollowUp(portal_type='Support Request'): event_to_delete_id_list.append(event.getId()) portal.event_module.manage_delObjects(event_to_delete_id_list) # Clear worklist cache
search_kw['node_uid'] = portal.restrictedTraverse(node).getUid() mirror_section = mirror_section or request.get('mirror_section') if mirror_section: search_kw['mirror_section_uid'] = portal.restrictedTraverse( mirror_section).getUid() ledger = ledger or request.get('ledger') if ledger: search_kw['ledger_uid'] = [ portal.portal_categories.restrictedTraverse(x).getUid() for x in ledger ] if grouping == 'grouping': search_kw['grouping_reference'] = None else: assert grouping == 'ungrouping', grouping search_kw['grouping_reference'] = NegatedQuery( Query(grouping_reference=None)) if title: search_kw['title_query'] = ComplexQuery(Query(title=title), Query(parent_title=title), logical_operator='OR') if delivery_reference: search_kw['parent_reference'] = delivery_reference if debit_price: search_kw['stock.total_price'] = debit_price if credit_price: try: search_kw['stock.total_price'] = -float(credit_price['query']) except ValueError, e: # happens when user entered a complex query (like "> 100 AND < 200") # in that case, there is not much we can do.
report_type = 'purchase' elif doc_portal_type == 'Sale Invoice Transaction': line_portal_type = 'Invoice Line' report_type = 'sale' else: raise ValueError("unknown document portal type for report %s" % doc_portal_type) else: raise ValueError("unknown type for report") selection_columns = [('group_by', "Group by")] if from_date is None: # get the minimum start date in catalog from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery kw = {"delivery.start_date": None, "key": "DefaultKey"} q = NegatedQuery(Query(**kw)) select_expression = "MIN(delivery.start_date)" group_by = "delivery.start_date" from_date = DateTime() result_list = context.portal_catalog(select_expression=select_expression, group_by_expression=group_by, simulation_state=simulation_state, portal_type=doc_portal_type, query=q, limit=1) if result_list: from_date = DateTime(result_list[0][2]) # get period list between given date interval_list_dict = getIntervalListBetweenDates( from_date=from_date,
def createTestResult(self, name, revision, test_name_list, allow_restart, test_title=None, node_title=None, project_title=None): """(temporary) - name (string) - revision (string representation of an integer) - test_name_list (list of strings) - allow_restart (boolean) XXX 'revision' should be a string representing the full revision of the tested code, because some projects are tested with different revisions of ERP5. -> (test_result_path, revision) or None if already completed """ LOG('createTestResult', 0, (name, revision, test_title, project_title)) portal = self.getPortalObject() if test_title is None: test_title = name def createNode(test_result, node_title): if node_title is not None: node = self._getTestResultNode(test_result, node_title) if node is None: # Note: specialise might not be set. This is on purpose, in order # to support cases, when client will call createTestResult # without calling subscribeNode before, and this is required # to find Test Node document returned by # _getTestNodeRelativeUrl. node = test_result.newContent(portal_type='Test Result Node', title=node_title, specialise=self._getTestNodeRelativeUrl( node_title)) node.start() def createTestResultLineList(test_result, test_name_list): test_priority_list = [] previous_test_result_list = portal.test_result_module.searchFolder( title=SimpleQuery(comparison_operator='=', title=test_result.getTitle()), sort_on=[('creation_date','descending')], simulation_state=('stopped', 'public_stopped'), limit=1) if len(previous_test_result_list): previous_test_result = previous_test_result_list[0].getObject() for line in previous_test_result.objectValues(): if line.getSimulationState() in ('stopped', 'public_stopped'): # Execute first the tests that failed on previous run (so that we # can see quickly if a fix was effective) and the slowest tests (to # make sure slow tests are executed in parrallel and prevent # situations where at the end all test nodes are waiting for the # latest to finish). test_priority_list.append( (line.getStringIndex() == 'PASSED', -line.getProperty('duration'), line.getTitle())) sorted_test_list = [x[2] for x in sorted(test_priority_list)] # Sort tests by name to have consistent ids for test result line on a # test suite. for test_name in sorted(test_name_list): index = 0 if sorted_test_list: try: index = sorted_test_list.index(test_name) except ValueError: pass line = test_result.newContent(portal_type='Test Result Line', title=test_name, int_index=index) reference_list_string = None if type(revision) is str and '=' in revision: reference_list_string = revision int_index, reference = None, revision elif type(revision) is str: # backward compatibility int_index, reference = revision, None else: # backward compatibility int_index, reference = revision catalog_kw = {'portal_type': 'Test Result', 'title': SimpleQuery(comparison_operator='=', title=test_title), 'sort_on': (("creation_date","descending"),), 'query': NegatedQuery(SimpleQuery(simulation_state="cancelled")), 'limit': 1} result_list = portal.test_result_module.searchFolder(**catalog_kw) if result_list: test_result = result_list[0].getObject() if test_result is not None: last_state = test_result.getSimulationState() last_revision = str(test_result.getIntIndex()) if last_state == 'started': createNode(test_result, node_title) reference = test_result.getReference() if reference_list_string: last_revision = reference elif reference: last_revision = last_revision, reference result_line_list = test_result.objectValues(portal_type="Test Result Line") result_line_list_len = len(result_line_list) if result_line_list_len == 0 and len(test_name_list): test_result.serialize() # prevent duplicate test result lines createTestResultLineList(test_result, test_name_list) elif result_line_list_len: # Do not process test result if all test result lines are already affected if len([x for x in result_line_list if x.getSimulationState() == 'draft']) == 0: return return test_result.getRelativeUrl(), last_revision if last_state in ('stopped', 'public_stopped'): if not allow_restart: if reference_list_string is not None: if reference_list_string == test_result.getReference(): return if portal.test_result_module.searchFolder( reference=SimpleQuery(comparison_operator='=', reference=reference_list_string), **catalog_kw): return if last_revision == int_index: return test_result = portal.test_result_module.newContent( portal_type='Test Result', title=test_title, reference=reference, is_indexable=False) if int_index is not None: test_result._setIntIndex(int_index) if project_title is not None: project_list = portal.portal_catalog(portal_type='Project', title=SimpleQuery(comparison_operator='=', title=project_title.encode('utf-8'))) if len(project_list) != 1: raise ValueError('found this list of project : %r for title %r' % \ ([x.path for x in project_list], project_title)) test_result._setSourceProjectValue(project_list[0].getObject()) test_result.updateLocalRolesOnSecurityGroups() # XXX test_result.start() del test_result.isIndexable test_result.immediateReindexObject() self.serialize() # prevent duplicate test result # following 2 functions only call 'newContent' on test_result createTestResultLineList(test_result, test_name_list) createNode(test_result, node_title) return test_result.getRelativeUrl(), revision
from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery configuration_dict = { 'portal_type': ["Manufacturing Order", "Manufacturing Execution"] } portal = context.getPortalObject() if context.getPortalType() in portal.getPortalResourceTypeList(): # only show production related to current resource delivery_uid_set = set() for line in portal.portal_catalog( portal_type="Manufacturing Execution Line", query=NegatedQuery( Query(simulation_state=["draft", "cancelled", "delivered"])), default_resource_uid=context.getUid(), select_dict={"parent_uid": None}): delivery_uid_set.add(line.parent_uid) # to make sure to filter even if nothing match delivery_uid_set.add(0) configuration_dict["delivery_uid_list"] = [x for x in delivery_uid_set] return configuration_dict
def createTestResult(self, name, revision, test_name_list, allow_restart, test_title=None, node_title=None, project_title=None): """(temporary) - name (string) - revision (string representation of an integer) - test_name_list (list of strings) - allow_restart (boolean) XXX 'revision' should be a string representing the full revision of the tested code, because some projects are tested with different revisions of ERP5. -> (test_result_path, revision) or None if already completed """ LOG('createTestResult', 0, (name, revision, test_title, project_title)) portal = self.getPortalObject() if test_title is None: test_title = name def createNode(test_result, node_title): if node_title is not None: node = self._getTestResultNode(test_result, node_title) if node is None: node = test_result.newContent( portal_type='Test Result Node', title=node_title) node.start() def createTestResultLineList(test_result, test_name_list): duration_list = [] previous_test_result_list = portal.test_result_module.searchFolder( title=SimpleQuery(comparison_operator='=', title=test_result.getTitle()), sort_on=[('creation_date', 'descending')], simulation_state=('stopped', 'public_stopped'), limit=1) if len(previous_test_result_list): previous_test_result = previous_test_result_list[0].getObject() for line in previous_test_result.objectValues(): if line.getSimulationState() in ('stopped', 'public_stopped'): duration_list.append( (line.getTitle(), line.getProperty('duration'))) duration_list.sort(key=lambda x: -x[1]) sorted_test_list = [x[0] for x in duration_list] # Sort tests by name to have consistent numbering of test result line on # a test suite. for test_name in sorted(test_name_list): index = 0 if sorted_test_list: try: index = sorted_test_list.index(test_name) except ValueError: pass line = test_result.newContent(portal_type='Test Result Line', title=test_name, int_index=index) reference_list_string = None if type(revision) is str and '=' in revision: reference_list_string = revision int_index, reference = None, revision elif type(revision) is str: # backward compatibility int_index, reference = revision, None else: # backward compatibility int_index, reference = revision catalog_kw = { 'portal_type': 'Test Result', 'title': SimpleQuery(comparison_operator='=', title=test_title), 'sort_on': (("creation_date", "descending"), ), 'query': NegatedQuery(SimpleQuery(simulation_state="cancelled")), 'limit': 1 } result_list = portal.test_result_module.searchFolder(**catalog_kw) if result_list: test_result = result_list[0].getObject() if test_result is not None: last_state = test_result.getSimulationState() last_revision = str(test_result.getIntIndex()) if last_state == 'started': createNode(test_result, node_title) reference = test_result.getReference() if reference_list_string: last_revision = reference elif reference: last_revision = last_revision, reference result_line_list = test_result.objectValues( portal_type="Test Result Line") result_line_list_len = len(result_line_list) if result_line_list_len == 0 and len(test_name_list): test_result.serialize( ) # prevent duplicate test result lines createTestResultLineList(test_result, test_name_list) elif result_line_list_len: # Do not process test result if all test result lines are already affected if len([ x for x in result_line_list if x.getSimulationState() == 'draft' ]) == 0: return return test_result.getRelativeUrl(), last_revision if last_state in ('stopped', 'public_stopped'): if not allow_restart: if reference_list_string is not None: if reference_list_string == test_result.getReference( ): return if portal.test_result_module.searchFolder( reference=SimpleQuery( comparison_operator='=', reference=reference_list_string), **catalog_kw): return if last_revision == int_index: return test_result = portal.test_result_module.newContent( portal_type='Test Result', title=test_title, reference=reference, is_indexable=False) if int_index is not None: test_result._setIntIndex(int_index) if project_title is not None: project_list = portal.portal_catalog(portal_type='Project', title=SimpleQuery( comparison_operator='=', title=project_title)) if len(project_list) != 1: raise ValueError('found this list of project : %r for title %r' % \ ([x.path for x in project_list], project_title)) test_result._setSourceProjectValue(project_list[0].getObject()) test_result.updateLocalRolesOnSecurityGroups() # XXX test_result.start() del test_result.isIndexable test_result.immediateReindexObject() self.serialize() # prevent duplicate test result # following 2 functions only call 'newContent' on test_result createTestResultLineList(test_result, test_name_list) createNode(test_result, node_title) return test_result.getRelativeUrl(), revision
'simulation_state': ( 'stopped', 'delivered', ), 'portal_type': portal.getPortalAccountingMovementTypeList(), } if not at_date and context.getStopDate(): at_date = context.getStopDate().latestTime() if at_date: kw['at_date'] = at_date kw['reconciliation_query'] = SimpleQuery( aggregate_bank_reconciliation_date=kw['at_date'], comparison_operator="<=") if portal.REQUEST.get('reconciled_uid_list'): # This is to take into account lines we just reconciled. # We sum all reconciled lines execpt those we just reconciled + those we just # reconciled without applying the criterion on reconcilation kw['workaround_catalog_lag_query'] = NegatedQuery( SimpleQuery(uid=portal.REQUEST['reconciled_uid_list'])) previously_reconciled = portal.portal_simulation.getInventory(**kw) kw.pop('workaround_catalog_lag_query') kw.pop('reconciliation_query') kw['uid'] = portal.REQUEST['reconciled_uid_list'] return previously_reconciled + portal.portal_simulation.getInventory(**kw) return context.portal_simulation.getInventory(**kw)
real_key = key[:-7] new_mapping['%s_value_' % real_key] = new_mapping[real_key] new_mapping['%s_usage_' % real_key] = value # TODO: this is a quick and dirty implementation of what should be done by # Query.asSearchTextExpression. Instead of keeping '%s_value_' and '%s_usage_', # we'll simply keep the query. new_mapping[real_key] = '%s %s' % (usage_map[value], new_mapping[real_key]) else: if request.form.get('%s_is_excluded_' % key): # Build a negated query nq_kw = {'strict_%s' % key : value} q_kw = {key : None} left_join_list.append(key) left_join_list.append('strict_%s' % key) query_list.append(ComplexQuery(NegatedQuery(Query(**nq_kw)), Query(**q_kw), logical_operator="OR")) new_mapping[key] = "" new_mapping["dialog_%s" %(key,)] = value new_mapping["dialog_excluded_%s" %(key,)] = True else: if request.form.get('%s_is_strict_' % key): new_mapping['strict_%s' % key] = value new_mapping['dialog_strict_%s' % key] = value else: new_mapping[key] = value new_mapping['dialog_%s' % key] = value new_mapping["query"] = ComplexQuery(query_list) new_mapping['left_join_list'] = left_join_list
new_mapping['%s_value_' % real_key] = new_mapping[real_key] new_mapping['%s_usage_' % real_key] = value # TODO: this is a quick and dirty implementation of what should be done by # Query.asSearchTextExpression. Instead of keeping '%s_value_' and '%s_usage_', # we'll simply keep the query. new_mapping[real_key] = '%s %s' % (value, new_mapping[real_key]) else: if request.form.get('%s_is_excluded_' % key): # Build a negated query nq_kw = {'strict_%s' % key: value} q_kw = {key: None} left_join_list.append(key) left_join_list.append('strict_%s' % key) query_list.append( ComplexQuery(NegatedQuery(Query(**nq_kw)), Query(**q_kw), logical_operator="OR")) new_mapping[key] = "" new_mapping["dialog_%s" % (key, )] = value new_mapping["dialog_excluded_%s" % (key, )] = True else: if request.form.get('%s_is_strict_' % key): new_mapping['strict_%s' % key] = value new_mapping['dialog_strict_%s' % key] = value else: new_mapping[key] = value new_mapping['dialog_%s' % key] = value new_mapping["query"] = ComplexQuery(query_list) new_mapping['left_join_list'] = left_join_list