Example #1
0
def li_with_permission_for_proposal(data):
    context = data['context']
    permission = data['permission_function']
    url = data['url']
    message = data['message']
    url_id = data['url_id']
    load_modal = data.get('load_modal', False)
    data_target = data.get('data_target', '')
    js_script = data.get('js_script', '')
    obj = data['obj']

    proposal = context['proposal']

    permission_denied_message, disabled = is_valid_proposal(context)

    if not disabled:
        if not is_year_editable(proposal.learning_unit_year,
                                raise_exception=False):
            disabled = "disabled"
            permission_denied_message = "{}.  {}".format(
                _("You can't modify learning unit under year : %(year)d") %
                {"year": settings.YEAR_LIMIT_LUE_MODIFICATION + 1},
                _("Modifications should be made in EPC for year %(year)d") %
                {"year": proposal.learning_unit_year.academic_year.year},
            )
        else:
            permission_denied_message, disabled = _get_permission_proposal(
                context, permission, obj)

    if not disabled:
        href = url
    else:
        href = "#"
        load_modal = False
        data_target = ''

    return {
        "class_li": disabled,
        "load_modal": load_modal,
        "url": href,
        "id_li": url_id,
        "title": permission_denied_message,
        "text": message,
        "js_script": js_script,
        "data_target": data_target
    }
Example #2
0
def li_with_permission_for_proposal(data):
    context = data['context']
    permission = data['permission_function']
    url = data['url']
    message = data['message']
    url_id = data['url_id']
    load_modal = data.get('load_modal', False)
    js_script = data.get('js_script', '')
    obj = data['obj']

    proposal = context['proposal']
    person = find_by_user(context.get('user'))

    permission_denied_message, disabled = is_valid_proposal(context)

    if not disabled:
        if not is_year_editable(
                proposal.learning_unit_year, person, raise_exception=False):
            disabled = "disabled"
            permission_denied_message = "{}" \
                .format(_("You can't modify proposition which are related to a learning unit year under"))
        else:
            permission_denied_message, disabled = _get_permission_proposal(
                context, permission, obj)

    if not disabled:
        href = url
    else:
        href = "#"
        load_modal = False

    return {
        "class_li": disabled,
        "load_modal": load_modal,
        "url": href,
        "id_li": url_id,
        "title": permission_denied_message,
        "text": message,
        "js_script": js_script,
    }