Exemplo n.º 1
0
def smart_link_condition_create(request, smart_link_pk):
    check_permissions(
        request.user,
        [PERMISSION_SMART_LINK_CREATE, PERMISSION_SMART_LINK_EDIT])

    smart_link = get_object_or_404(SmartLink, pk=smart_link_pk)

    if request.method == 'POST':
        form = SmartLinkConditionForm(request.POST)
        if form.is_valid():
            new_smart_link_condition = form.save(commit=False)
            new_smart_link_condition.smart_link = smart_link
            new_smart_link_condition.save()
            messages.success(
                request,
                _(u'Smart link condition: "%s" created successfully.') %
                new_smart_link_condition)
            return HttpResponseRedirect(
                reverse('smart_link_condition_list', args=[smart_link.pk]))
    else:
        form = SmartLinkConditionForm(initial={'smart_link': smart_link})

    return render_to_response(
        'generic_form.html', {
            'form': form,
            'title': _(u'Add new conditions to smart link: "%s"') % smart_link,
            'navigation_object_name': 'smart_link',
            'smart_link': smart_link,
        },
        context_instance=RequestContext(request))
Exemplo n.º 2
0
def smart_link_condition_edit(request, smart_link_condition_pk):
    check_permissions(
        request.user,
        [PERMISSION_SMART_LINK_CREATE, PERMISSION_SMART_LINK_EDIT])

    smart_link_condition = get_object_or_404(SmartLinkCondition,
                                             pk=smart_link_condition_pk)

    next = request.POST.get(
        'next', request.GET.get('next', request.META.get('HTTP_REFERER', '/')))
    previous = request.POST.get(
        'previous',
        request.GET.get('previous', request.META.get('HTTP_REFERER', '/')))

    if request.method == 'POST':
        form = SmartLinkConditionForm(request.POST,
                                      instance=smart_link_condition)
        if form.is_valid():
            new_smart_link_condition = form.save(commit=False)
            new_smart_link_condition.smart_link = smart_link_condition.smart_link
            new_smart_link_condition.save()
            messages.success(
                request,
                _(u'Smart link condition: "%s" edited successfully.') %
                new_smart_link_condition)
            return HttpResponseRedirect(next)
    else:
        form = SmartLinkConditionForm(instance=smart_link_condition)

    return render_to_response('generic_form.html', {
        'form':
        form,
        'title':
        _(u'Edit smart link condition'),
        'next':
        next,
        'previous':
        previous,
        'condition':
        smart_link_condition,
        'smart_link':
        smart_link_condition.smart_link,
        'navigation_object_list': [{
            'object': 'smart_link',
            'name': _(u'smart link')
        }, {
            'object': 'condition',
            'name': _(u'condition')
        }],
    },
                              context_instance=RequestContext(request))