def validate_start_date_equals_end_date(action, data, context, container):
    """ Check that the start date is inside the restrictictions.
    It must not start before the contextParents start date or end
    after the contextsParents end date"""
    errors = []
    if data.get("start_date", None) and data.get("end_date", None):
        start = ui_date.get_date(data["end_date"])
        end = ui_date.get_date(data["start_date"])
        if start != end:
            errors.append(interface.Invalid(_(u"End date must be equal to start date"), "end_date"))
    return errors
Exemple #2
0
def validate_start_date_equals_end_date(action, data, context, container):
    """ Check that the start date is inside the restrictictions.
    It must not start before the contextParents start date or end
    after the contextsParents end date"""
    errors = []
    if data.get('start_date', None) and data.get('end_date', None):
        start = ui_date.get_date(data['end_date'])
        end = ui_date.get_date(data['start_date'])
        if start != end:
            errors.append(
                interface.Invalid(_(u"End date must be equal to start date"),
                                  "end_date"))
    return errors
def validate_start_date_within_parent(parent, data):
    """ Check that the start date is inside the restrictictions.
    It must not start before the contextParents start date or end
    after the contextsParents end date"""
    errors = []
    if data.get("start_date", None):
        start = ui_date.get_date(data["start_date"])
        if getattr(parent, "start_date", None):
            pstart = ui_date.get_date(parent.start_date)
            if start < pstart:
                errors.append(interface.Invalid(_(u"Start date must be after (%s)") % pstart, "start_date"))
        if getattr(parent, "end_date", None):
            pend = ui_date.get_date(parent.end_date)
            if start > pend:
                errors.append(interface.Invalid(_(u"Start date must be prior to (%s)") % pend, "start_date"))
    return errors
def validate_start_date_within_parent( parent, data ):
    """ Check that the start date is inside the restrictictions.
    It must not start before the contextParents start date or end
    after the contextsParents end date"""
    errors =[]
    if data.get('start_date',None):
        start = ui_date.get_date(data['start_date'])
        if getattr(parent, 'start_date', None):
            pstart = ui_date.get_date(parent.start_date)
            if start < pstart:
                errors.append( interface.Invalid( 
                _(u"Start date must be after (%s)") % pstart, 
                "start_date" ))
        if getattr(parent, 'end_date', None):
            pend = ui_date.get_date(parent.end_date)
            if start > pend:
                errors.append( interface.Invalid( 
                _(u"Start date must be prior to (%s)") % pend, 
                "start_date" ))
    return errors
def validate_end_date_within_parent( parent, data ):
    """
    Check that the end date is inside the restrictictions.
    It must not end before the context.Parents start date or end
    after the context.Parents end date
    """
    errors =[]
    if data.get( 'end_date', None):
        end = ui_date.get_date(data['end_date'])
        if getattr(parent, 'start_date', None):
            pstart = ui_date.get_date(parent.start_date)
            if end < pstart:
                errors.append( interface.Invalid( 
                _(u"End date must be after (%s)")  % pstart, 
                "end_date" ))
        if getattr(parent, 'end_date', None):
            pend = ui_date.get_date(parent.end_date)
            if end > pend:
                errors.append( interface.Invalid( 
                _(u"End date must be prior to (%s)") % pend, 
                "end_date" ))
    return errors