예제 #1
0
 def validate(self, value):
     # setting parent, for that we check if there are a Add- or a Editform
     super(ReferenceNumberPrefixValidator, self).validate(value)
     if IAddForm.providedBy(self.view.parentForm):
         if not PrefixAdapter(self.context).is_valid_number(value):
             raise schema.interfaces.ConstraintNotSatisfied()
     else:
         parent = aq_parent(aq_inner(self.context))
         if not PrefixAdapter(parent).is_valid_number(value, self.context):
             raise schema.interfaces.ConstraintNotSatisfied()
예제 #2
0
    def __iter__(self):
        for item in self.previous:

            obj = self.context.unrestrictedTraverse(
                item['_path'].lstrip('/'), None)

            if item.get('reference_number_prefix'):
                parent = aq_parent(aq_inner(obj))

                if PrefixAdapter(parent).get_number(obj) != item.get(
                        'reference_number_prefix'):

                    PrefixAdapter(parent).get_child_mapping().pop(
                        PrefixAdapter(parent).get_number(obj))

            yield item
예제 #3
0
def reference_number_prefix_default(context):
    """Determine the default for the reference number prefix.

    context: Usually the container where a new object is created (i.e.
    default factory is called during content creation), unless the factory
    is called from an edit or display action (which shouldn't happen).
    """
    return PrefixAdapter(context).get_next_number()
def reference_number_prefix_default(context):
    """Determine the default for the reference number prefix.

    context: Usually the container where a new object is created (i.e.
    default factory is called during content creation), unless the factory
    is called from an edit or display action (which shouldn't happen).
    """
    if not context:
        # We don't have any context if using the /@types endpoint from the
        # plone rest-api.
        # See https://github.com/4teamwork/opengever.core/issues/5283
        return u''
    return PrefixAdapter(context).get_next_number()
예제 #5
0
def saveReferenceNumberPrefix(obj, event):
    """When an object providing IReferenceNumberPrefixMarker (repository
    folders) gets added or has been modified, make sure it has
    a unique reference number prefix.

    If necessary, set_number() creates a collision free prefix.
    """
    parent = aq_parent(aq_inner(obj))

    # Mark the reference number as issued in the parent's annotations
    number = PrefixAdapter(parent).set_number(
        obj,
        IReferenceNumberPrefix(obj).reference_number_prefix)

    # Store the number on the actual object
    IReferenceNumberPrefix(obj).reference_number_prefix = number
예제 #6
0
def reference_number_default_value(data):
    return PrefixAdapter(data.context).get_next_number()