Exemplo n.º 1
0
 def test_006_testRelatedKey_with_multiple_join(self):
   # The name of catalog parameter does not matter at all
   # ComplexQuery(ComplexQuery(AutoQuery(RelatedQuery(SimpleQuery())), AutoQuery(RelatedQuery(SimpleQuery()))))
   # 'AutoQuery' doesn't need any ReferenceQuery equivalent.
   self.catalog(ReferenceQuery(ReferenceQuery(
                    ReferenceQuery(RelatedReferenceQuery(ReferenceQuery(operator='=', default='a')), operator='and'),
                    ReferenceQuery(RelatedReferenceQuery(ReferenceQuery(operator='=', default='b')), operator='and')
                  , operator='and'), operator='and'),
                {'query': ComplexQuery(Query(related_default='a'), Query(related_default='b'))})
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
  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
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
    def afterSetUp(self):
        domain_tool = self.getDomainTool()

        # Query to restrict searches to 'interesting' predicates:
        # - ignore simulation rules, which are now predicates
        # - ignore as well constraints, which are predicates
        self.portal_type_query = Query(
            operator='AND',
            portal_type=[
                '!=%s' % x for x in domain_tool.getPortalRuleTypeList() +
                ('Base Domain', 'Contribution Predicate') +
                domain_tool.getPortalConstraintTypeList()
            ])
        super(TestDomainTool, self).afterSetUp()
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    def afterSetUp(self):
        domain_tool = self.getDomainTool()

        # Query to restrict searches to 'interesting' predicates:
        # - ignore simulation rules, which are now predicates
        # - ignore as well constraints, which are predicates
        self.portal_type_query = Query(
            operator='AND',
            portal_type=[
                '!=%s' % x for x in domain_tool.getPortalRuleTypeList() +
                ('Base Domain', 'Contribution Predicate', 'Solver Type',
                 'Trade Model Path', 'Worklist') +
                domain_tool.getPortalDivergenceTesterTypeList() +
                domain_tool.getPortalBusinessProcessTypeList() +
                domain_tool.getPortalBusinessLinkTypeList() +
                domain_tool.getPortalConstraintTypeList()
            ])
        super(TestDomainTool, self).afterSetUp()
Exemplo n.º 8
0
 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 _getEffectiveModel(self, start_date, stop_date):
    """Return the most appropriate model using effective_date, expiration_date
  and version number.
  An effective model is a model which start and stop_date are equal (or
  excluded) to the range of the given start and stop_date and with the
  higher version number (if there is more than one)

  XXX Should we moved this function to a class ? Which one ?
      What about reusing IVersionable ?
  """
    reference = self.getProperty('reference')
    if not reference:
        return self

    query_list = [
        Query(reference=reference),
        Query(portal_type=self.getPortalType()),
        Query(validation_state=('deleted', 'invalidated'), operator='NOT')
    ]
    if start_date is not None:
        query_list.append(
            ComplexQuery(Query(effective_date=None),
                         Query(effective_date=start_date, range='<='),
                         logical_operator='OR'))
    if stop_date is not None:
        query_list.append(
            ComplexQuery(Query(expiration_date=None),
                         Query(expiration_date=stop_date, range='>'),
                         logical_operator='OR'))

    # XXX What to do the catalog returns nothing (either because 'self' was just
    #     created and not yet indexed, or because it was invalidated) ?
    #     For the moment, we return self if self is invalidated and we raise otherwise.
    #     This way, if this happens in activity it may succeed when activity is retried.
    model_list = self.getPortalObject(
    ).portal_catalog.unrestrictedSearchResults(
        query=ComplexQuery(logical_operator='AND', *query_list),
        sort_on=(('version', 'descending'), ))
    if not model_list:
        if self.getValidationState() == 'invalidated':
            return self
        raise KeyError('No %s found with the reference %s between %s and %s' % \
                (self.getPortalType(), reference, start_date, stop_date))
    return model_list[0].getObject()
Exemplo n.º 10
0
# compute sql params, we group and order by date and portal type
if aggregation_level == "year":
  sql_format = "%Y"
elif aggregation_level == "month":
  sql_format = "%Y-%m"
elif aggregation_level == "week":
  sql_format = "%Y-%u"
elif aggregation_level == "day":
  sql_format = "%Y-%m-%d"
if to_date is not None:
  to_date = atTheEndOfPeriod(to_date, period=aggregation_level)
params = {"creation_date":(from_date, to_date)}
query=None
if from_date is not None and to_date is not None:
  params = {"creation_date":(from_date, to_date)}
  query = Query(range="minmax", **params)
elif from_date is not None:
  params = {"creation_date":from_date}
  query = Query(range="min", **params)
elif to_date is not None:
  params = {"creation_date":to_date}
  query = Query(range="max", **params)
select_expression = {'date' : 'DATE_FORMAT(creation_date, "%s")'%sql_format, 'portal_type' : None}
group_by = ['DATE_FORMAT(creation_date, "%s")' % sql_format, 'portal_type']

# count number of object created by the user for each type of document
reference = kw.get('person_reference_list', context.getReference())
result_list = context.portal_catalog.countResults(select_expression=select_expression,
                                                  portal_type=portal_type_list,limit=None,
                                                  owner=reference,query=query,
                                                  group_by_expression=group_by)
Exemplo n.º 11
0
  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
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.
"""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
Exemplo n.º 14
0
portal_categories = portal.portal_categories

now = DateTime()
effective_date = context.getEffectiveDate()
previous_pay_day = addToDate(effective_date, month=-1)

# Get period dates
result = portal.portal_catalog(portal_type="DSN Monthly Report",
                               simulation_state="validated",
                               sort_on=[("creation_date", "descending")])

from_date = DateTime(effective_date.year(), effective_date.month(), 1)

# We report leave periods which are not over yet ...
result = portal.portal_catalog(portal_type='Leave Request Period',
                               query=Query(expiration_date=None))
leave_period_list = [period.getObject() for period in result]

# ... And leave periods which ended during last period
result = portal.portal_catalog(portal_type='Leave Request Period',
                               expiration_date=">=%s" %
                               from_date.strftime("%Y/%m"))
# We need to filter results, because we can't search in a date interval with
# a smaller grain than a month.
leave_period_list.extend([
    period.getObject() for period in result
    if period.getExpirationDate() > from_date
])


def formatDate(datetime):
Exemplo n.º 15
0
from Products.ZSQLCatalog.SQLCatalog import Query
from erp5.component.module.DateUtils import addToDate
from DateTime import DateTime

portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
  portal_type="Leave Request",
  method_id='LeaveRequest_createRepresentativeRecord',
  creation_date = Query(creation_date=addToDate(DateTime(), to_add={'day': -90}), range="min"),
  activate_kw={'tag': tag},
)
context.activate(after_tag=tag).getId()
Exemplo n.º 16
0
currency = portal.Base_getCurrencyForSection(request['section_category'])
precision = portal.account_module.getQuantityPrecisionFromResource(currency)
request.set('precision', precision)

# There are some disabled fields in Account_viewAccountingTransactionList based on this condition.
request.other['is_accounting_report'] = True

params = dict(
    precision=precision,
    section_uid=section_uid,
    simulation_state=simulation_state,
)
project = request.get('project')
if project:
    if project == 'None':
        params['project_uid'] = Query(project_uid=None)
    else:
        params['project_uid'] = portal.portal_categories.restrictedTraverse(
            project).getUid()

funding_category = request.get('funding')
if funding_category:
    if funding_category == 'None':
        params['funding_uid'] = Query(funding_uid=None)
    else:
        funding_value = portal.restrictedTraverse(funding_category, None)
        if funding_value is not None and funding_value.getPortalType(
        ) != 'Category':
            params['funding_uid'] = funding_value.getUid()
        else:
            params['funding_category'] = funding_category
portal_preferences = portal.portal_preferences

if not portal_preferences.isAuthenticationPolicyEnabled() or \
   not portal_preferences.isPreferredSystemRecoverExpiredPassword():
    # no policy, no sense to file expire at all or symply system do not configured to
    return

user = context.getParentValue()
username = context.getReference()

# Prevent creating new recovery if one was recently created
recovery_list = portal.portal_catalog(
    portal_type="Credential Recovery",
    reference=username,
    default_destination_decision_uid=user.getUid(),
    creation_date=Query(range="min",
                        creation_date=addToDate(DateTime(), {'day': -1})),
    limit=1)
if recovery_list:
    return
tag = 'credential_recovery_%s' % context.getReference()
if portal.portal_activities.countMessageWithTag(tag):
    return

module = portal.getDefaultModule(portal_type='Credential Recovery')
credential_recovery = module.newContent(
    portal_type="Credential Recovery",
    reference=username,
    destination_decision_value=user,
    language=portal.Localizer.get_selected_language(),
    activate_kw={'tag': tag})
context.serialize()
Exemplo n.º 18
0
from zExceptions import NotFound
from Products.ZSQLCatalog.SQLCatalog import ComplexQuery
from Products.ZSQLCatalog.SQLCatalog import Query

now = DateTime()
request = context.REQUEST
portal_catalog = context.portal_catalog

reference = request.get('reference')
data_chunk = request.get('data_chunk')

if data_chunk is not None and reference is not None:
    # here we rely that fluentd will pass to us its tag which we use
    # as reference but we can extract it sometimes from sensor data
    # it thus depends on sensor and the fluentd topography
    query = ComplexQuery(Query(portal_type='Data Supply'),
                         Query(reference=reference),
                         Query(validation_state='validated'),
                         Query(**{
                             'delivery.stop_date': now,
                             'range': 'min'
                         }),
                         Query(**{
                             'delivery.start_date': now,
                             'range': 'max'
                         }),
                         logical_operator="AND")
    data_supply = portal_catalog.getResultValue(query=query)

    #context.log(data_supply)
    # we can have multiple lines for each sensor and we filter out by reference
"""Guess the path of categories, taking as input a mapping {base_category:
category}, where category can be the relative_url, the title or the reference
of the category
"""

from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
portal = context.getPortalObject()
result_dict = {}

for base_category_name, category in category_dict.items():
    category_object = \
      context.getPortalObject().portal_categories[base_category_name]

    category_value = category_object.restrictedTraverse(category, None)
    if category_value is None:
        query = ComplexQuery(
            ComplexQuery(Query(title=category, key='ExactMatch'),
                         Query(reference=category, key='ExactMatch'),
                         logical_operator='OR'),
            ComplexQuery(Query(relative_url='%s/%%' % base_category_name)))
        category_value = portal.portal_catalog.getResultValue(query=query)

    if category_value is not None:
        # remove base category from relative_url
        result_dict[base_category_name] = \
          category_value.getRelativeUrl().split('/', 1)[1]

return result_dict
Exemplo n.º 20
0
  def getInventoryListQueryDict(self, budget_line):
    """Returns the query dict to pass to simulation query for a budget line
    """
    axis = self.getInventoryAxis()
    if not axis:
      return dict()
    base_category = self.getProperty('variation_base_category')
    if not base_category:
      return dict()

    context = budget_line
    if self.isMemberOf('budget_variation/budget'):
      context = budget_line.getParentValue()

    portal_categories = self.getPortalObject().portal_categories
    query_dict = dict()
    uid_based_axis = False
    if axis == 'movement':
      axis = 'default_%s_uid' % base_category
      query_dict['select_list'] = [axis]
      query_dict['group_by'] = [axis]
      uid_based_axis = True
    elif axis == 'movement_strict_membership':
      axis = 'default_strict_%s_uid' % base_category
      query_dict['select_list'] = [axis]
      query_dict['group_by'] = [axis]
      uid_based_axis = True
    else:
      query_dict['group_by_%s' % axis] = True

    if axis in ('node', 'section', 'payment', 'function', 'project',
                'mirror_section', 'mirror_node', 'funding' ):
      axis = '%s_uid' % axis
      uid_based_axis = True

    # if we have a virtual "all others" node, we don't set a criterion here.
    if self.getProperty('include_virtual_other_node'):
      return query_dict

    if self.getProperty('full_consumption_detail'):
      if self.isMemberOf('budget_variation/budget'):
        category_list = [item[1] for item in
          self.getBudgetVariationRangeCategoryList(context)]
      else:
        category_list = [item[1] for item in
          self.getBudgetLineVariationRangeCategoryList(context)]
    else:
      category_list = context.getVariationCategoryList(
        base_category_list=(base_category,))

    found = False
    for node_url in category_list:
      if node_url != '%s/budget_special_node/none' % base_category:
        __traceback_info__ = (node_url, )
        if uid_based_axis:
          query_dict.setdefault(axis, []).append(
                portal_categories.getCategoryValue(node_url,
                      base_category=base_category).getUid())
        else:
          query_dict.setdefault(axis, []).append(
                portal_categories.getCategoryValue(node_url,
                      base_category=base_category).getRelativeUrl())
      found = True
    if found:
      if self.getProperty('include_virtual_none_node'):
        if axis in query_dict:
          query_dict[axis] = ComplexQuery(
                Query(**{axis: None}),
                Query(**{axis: query_dict[axis]}),
                operator="OR")
        else:
          query_dict[axis] = Query(**{axis: None})
      return query_dict
    return dict()
  params['ledger'] = kw['ledger']

category_uid_list = ('payment_uid', 'project_uid', 'funding_uid', 'function_uid',
  'ledger_uid', 'payment_request_uid', 'default_aggregate_uid')
for category_uid in category_uid_list:
  category_uid_value = kw.get(category_uid)
  if category_uid_value:
    if category_uid_value == 'None':
      # XXX Jerome: this code needs some clarification. It is used after a dialog
      # with a list field for project (same for function, payment_request,
      # funding) where the user can select an empty item which means no filter
      # on project, can select a project which means only transactions for
      # that specific project, or select a special value "None" which means
      # transactions that are not related to a project. For that we need a
      # query that will be translated as stock.project_uid IS NULL.      
      params[category_uid] = Query(**{category_uid: None})
    else:
      params[category_uid] = category_uid_value

funding_category = kw.get('funding_category')
if funding_category:
  if funding_category == 'None':
    params['funding_uid'] = Query(funding_uid=None)
  else:
    params['funding_category'] = funding_category
function_category = kw.get('function_category')
if function_category:
  if function_category == 'None':
    params['function_uid'] = Query(function_uid=None)
  else:
    params['function_category'] = function_category
Exemplo n.º 22
0
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery

if document_type == 'Image':
    portal_type = ['Image']
else:
    portal_type = [
        x for x in context.getPortalDocumentTypeList() if x != 'Image'
    ]

return ComplexQuery(Query(portal_type=portal_type),
                    ComplexQuery(Query(
                        validation_state=('published', 'published_alive',
                                          'released', 'released_alive',
                                          'shared', 'shared_alive'),
                        reference='!=None'),
                                 Query(validation_state='embedded',
                                       parent_uid=context.getUid()),
                                 operator='or'),
                    operator='and')
Exemplo n.º 23
0
    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
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
kw.pop('relative_url', None)
kw.pop('follow_up_uid', None)
portal_catalog=context.getPortalObject().portal_catalog
project_object_list = portal_catalog(
           portal_type=portal_type,
           source_project_title=context.getTitle(), **kw)
kw['query'] = Query(relative_url='%s/%%' % context.getRelativeUrl().replace('_', r'\_'))
if project_object_list:
  kw['query'] = ComplexQuery(
    kw['query'],
    Query(uid=[x.getUid() for x in project_object_list]),
    logical_operator='or')
return portal_catalog(portal_type=portal_type, limit=limit, **kw)
Exemplo n.º 25
0
portal_preferences = portal.portal_preferences

blocked_user_login_list = []
all_blocked_user_login_dict = {}

now = DateTime()
one_second = 1 / 24.0 / 60.0 / 60.0
check_duration = portal_preferences.getPreferredAuthenticationFailureCheckDuration(
)
max_authentication_failures = portal_preferences.getPreferredMaxAuthenticationFailure(
)
check_time = now - check_duration * one_second

kw = {
    'portal_type': 'Authentication Event',
    'creation_date': Query(creation_date=check_time, range='min'),
    'validation_state': 'confirmed'
}
failure_list = portal.portal_catalog(**kw)
for failure in failure_list:
    person = failure.getDestinationValue()
    if person not in all_blocked_user_login_dict.keys():
        all_blocked_user_login_dict[person] = []
    all_blocked_user_login_dict[person].append(failure)

# leave only ones that are blocked:
for person, failure_list in all_blocked_user_login_dict.items():
    if len(failure_list) >= max_authentication_failures:
        blocked_user_login_list.append(
            newTempBase(
                portal, person.getTitle(), **{
source_project_uid_list = [
    x.uid for x in context.portal_catalog(relative_url='%s/%%' %
                                          context.getRelativeUrl())
] + [context.getUid()]

from Products.ZSQLCatalog.SQLCatalog import Query

sql_kw = {}
if kw.has_key('from_date') and kw['from_date'] is not None:
    query_kw = {'delivery.start_date': kw['from_date'], 'range': 'min'}
    sql_kw['delivery.start_date'] = Query(**query_kw)
if kw.has_key('at_date') and kw['at_date'] is not None:
    query_kw = {'delivery.stop_date': kw['at_date'], 'range': 'ngt'}
    sql_kw['delivery.stop_date'] = Query(**query_kw)

# Make sure to not include "confirmed tasks" in any case, because in
# this case we must take task reports
if kw.has_key('simulation_state') and len(kw['simulation_state']) > 0:
    task_simulation_state = [
        x for x in kw['simulation_state'] if x != 'confirmed'
    ]
    task_report_simulation_state = kw['simulation_state']
else:
    task_simulation_state = context.getPortalDraftOrderStateList() + \
                            context.getPortalPlannedOrderStateList()
    task_report_simulation_state = ""

task_list = [x.getObject() for x in \
  context.portal_catalog(selection_report=selection_report,
                         portal_type='Task',
                         source_project_uid = source_project_uid_list,
Exemplo n.º 27
0
params = portal.ERP5Site_getAccountingSelectionParameterDict(selection_name)

# this also prevents to be called directly
assert 'node_uid' in kw

total_debit = 0
total_credit = 0
total_debit_price = 0
total_credit_price = 0

at_date = (from_date - 1).latestTime()
inventory_query = {
    'at_date':
    at_date,  # this is not to_date
    'grouping_query':
    ComplexQuery(Query(grouping_reference=None),
                 Query(grouping_date=at_date, range="min"),
                 logical_operator="OR"),
    'simulation_state':
    params['simulation_state'],
    'node_uid':
    kw['node_uid'],
    'portal_type':
    portal.getPortalAccountingMovementTypeList(),
    'section_uid':
    params['section_uid'],
    'sort_on': (
        ('stock.date', 'ASC'),
        ('stock.uid', 'ASC'),
    )
}
Exemplo n.º 28
0
# merchant_registry for merchants.
# the id_group is extended with the group path so that
# each local registry has a different sequence

group = (date.year(), )

new_registry_number = request_eform.portal_ids.generateNewId(
    id_group=group, method=attachLocationYearInfo)

# build a query and search in person module if the person already exists,
# if the person does not exist, create the person and a new assignment for
# the person with function commercant on the organisation if the
# person exist, just add a new assignment for the person with the function
# commercant on organisation
query = ComplexQuery(
    Query(title=request_eform.getTitle()),
    Query(birth_date=request_eform.getStartDate()),
    Query(birthplace_city=request_eform.getDefaultBirthplaceAddressCity()),
    logical_operator="AND")
person_list = [
    person.getObject() for person in person_module.searchFolder(query=query)
]
if request_eform.getBeginning() or request_eform.getOpening():
    if len(person_list) == 0:
        person = person_module.newContent(portal_type='Person')
        person.edit(first_name=request_eform.getFirstName(),
                    last_name=request_eform.getLastName(),
                    default_address_street_address=request_eform.
                    getHeadOfficeAddress(),
                    start_date=request_eform.getStartDate(),
                    default_birthplace_address_city=request_eform.
Exemplo n.º 29
0
    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
Exemplo n.º 30
0
from DateTime import DateTime
from Products.ZSQLCatalog.SQLCatalog import AndQuery, OrQuery, Query, NegatedQuery, SimpleQuery

portal = context.getPortalObject()
portal_catalog = portal.portal_catalog

now = DateTime()

query = AndQuery(
    Query(portal_type=["Data Ingestion Line", "Data Analysis Line"]),
    Query(**{"stock.quantity": "!=0"}),
    Query(resource_portal_type="Data Product"),
    # Should be improved to support mor than one analysis per ingestion
    #SimpleQuery(parent_causality_related_relative_url = None),
    OrQuery(
        Query(simulation_state="stopped",
              use_relative_url="use/big_data/ingestion/batch"),
        AndQuery(Query(simulation_state="started"),
                 Query(use_relative_url="use/big_data/ingestion/stream"))))

for movement in portal_catalog(query):
    if movement.getQuantity() <= 0:
        continue
    if movement.DataIngestionLine_hasMissingRequiredItem():
        raise ValueError("Transformation requires movement to have " +
                         "aggregated data ingestion batch")
    data_ingestion = movement.getParentValue()
    # Get applicable transformation
    for transformation in portal_catalog(
            portal_type="Data Transformation",
            validation_state="validated",