示例#1
0
def add_meta_data(request, pid):
    prod = Product.objects.get(id=pid)
    ct = ContentType.objects.get_for_model(prod)
    if request.method == 'POST':
        form = ProductMetaDataForm(request.POST)
        if form.is_valid():
            cf, created = CustomField.objects.get_or_create(name=form.cleaned_data['name'],
                                                   content_type=ct,
                                                   field_type='a')
            cf.save()
            cfv, created = CustomFieldValue.objects.get_or_create(field=cf,
                                                         object_id=prod.id)
            cfv.value = form.cleaned_data['value']
            cfv.clean()
            cfv.save()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Metadata added successfully.',
                                 extra_tags='alert-success')
            if 'add_another' in request.POST:
                return HttpResponseRedirect(reverse('add_meta_data', args=(pid,)))
            else:
                return HttpResponseRedirect(reverse('view_product', args=(pid,)))
    else:
        form = ProductMetaDataForm(initial={'content_type': prod})

    add_breadcrumb(parent=prod, title="Add Metadata", top_level=False, request=request)

    return render(request,
                  'dojo/add_product_meta_data.html',
                  {'form': form,
                   'product': prod,
                   })
示例#2
0
def add_meta_data(request, pid):
    prod = Product.objects.get(id=pid)
    ct = ContentType.objects.get_for_model(prod)
    if request.method == 'POST':
        form = ProductMetaDataForm(request.POST)
        if form.is_valid():
            cf, created = CustomField.objects.get_or_create(name=form.cleaned_data['name'],
                                                   content_type=ct,
                                                   field_type='a')
            cf.save()
            cfv, created = CustomFieldValue.objects.get_or_create(field=cf,
                                                         object_id=prod.id)
            cfv.value = form.cleaned_data['value']
            cfv.clean()
            cfv.save()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Metadata added successfully.',
                                 extra_tags='alert-success')
            if 'add_another' in request.POST:
                return HttpResponseRedirect(reverse('add_meta_data', args=(pid,)))
            else:
                return HttpResponseRedirect(reverse('view_product', args=(pid,)))
    else:
        form = ProductMetaDataForm(initial={'content_type': prod})

    add_breadcrumb(parent=prod, title="Add Metadata", top_level=False, request=request)

    return render(request,
                  'dojo/add_product_meta_data.html',
                  {'form': form,
                   'product': prod,
                   })