コード例 #1
0
ファイル: part.py プロジェクト: pcon-world/pcon_db
def edit_children(request, obj_type, obj_ref, obj_revi):
    """
    View to edit a BOM.

    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/bom-child/edit/`

    .. include:: views_params.txt

    **Template:**

    :file:`parts/bom_edit.html`

    **Context:**

    ``RequestContext``

    ``children_formset``
        a formset to edit the BOM

    ``extra_columns``
        a list of extra columns that are displayed

    ``extra_fields``
        a list of extra fields that are editable

    """
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)

    if not hasattr(obj, "get_children"):
        return HttpResponseBadRequest("object must be a part")
    if request.method == "POST":
        formset = forms.get_children_formset(obj, request.POST)
        if formset.is_valid():
            obj.update_children(formset)
            return HttpResponseRedirect("..")
    else:
        formset = forms.get_children_formset(obj)
    extra_columns = []
    extra_fields = []
    for PCLE in models.get_PCLEs(obj.object):
        fields = PCLE.get_visible_fields()
        if fields:
            extra_columns.extend(
                (f, PCLE._meta.get_field(f).verbose_name) for f in fields)
            prefix = PCLE._meta.module_name
            extra_fields.extend('%s_%s' % (prefix, f) for f in fields)
    ctx.update({
        'current_page': 'BOM-child',
        'extra_columns': extra_columns,
        'extra_fields': extra_fields,
        'children_formset': formset,
    })
    return r2r('parts/bom_edit.html', ctx, request)
コード例 #2
0
ファイル: part.py プロジェクト: amarh/openPLM
def edit_children(request, obj_type, obj_ref, obj_revi):
    """
    View to edit a BOM.

    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/bom-child/edit/`

    .. include:: views_params.txt

    **Template:**

    :file:`parts/bom_edit.html`

    **Context:**

    ``RequestContext``

    ``children_formset``
        a formset to edit the BOM

    ``extra_columns``
        a list of extra columns that are displayed

    ``extra_fields``
        a list of extra fields that are editable

    """
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)

    if not hasattr(obj, "get_children"):
        return HttpResponseBadRequest("object must be a part")
    if request.method == "POST":
        formset = forms.get_children_formset(obj, request.POST)
        if formset.is_valid():
            obj.update_children(formset)
            return HttpResponseRedirect("..")
    else:
        formset = forms.get_children_formset(obj)
    extra_columns = []
    extra_fields = []
    for PCLE in models.get_PCLEs(obj.object):
        fields = PCLE.get_visible_fields()
        if fields:
            extra_columns.extend((f, PCLE._meta.get_field(f).verbose_name)
                    for f in fields)
            prefix = PCLE._meta.module_name
            extra_fields.extend('%s_%s' % (prefix, f) for f in fields)
    ctx.update({'current_page':'BOM-child',
                'extra_columns' : extra_columns,
                'extra_fields' : extra_fields,
                'children_formset': formset, })
    return r2r('parts/bom_edit.html', ctx, request)
コード例 #3
0
ファイル: pcle.py プロジェクト: amarh/openPLM
 def test_bom_edit_post_error_invalid_value(self):
     fname = mockext + "_custom_attribute"
     self.controller.add_child(self.controller2, 10, 15, "-",
             **{mockext:{"custom_attribute":"val1"}})
     self.client.login(username=self.user.username, password="******")
     data = {
         'form-TOTAL_FORMS': u'1',
         'form-INITIAL_FORMS': u'1',
         'form-MAX_NUM_FORMS': u'',
         'form-0-child' :   self.controller2.id,
         'form-0-id'  : self.controller.get_children()[0].link.id,
         'form-0-order'  :  45,
         'form-0-parent' :  self.controller.id,
         'form-0-quantity' :  '45.0',
         'form-0-unit' :  'cm',
         'form-0-%s' % fname : 'new_value' * 10, # too long value
     }
     formset = forms.get_children_formset(self.controller, data)
     response = self.client.post(self.controller.plmobject_url + "BOM-child/edit/",
             data, follow=True)
     link = self.controller.get_children()[0].link
     self.assertEqual(10, link.quantity)
     self.assertEqual(15, link.order)
     self.assertEqual('-', link.unit)
     self.assertEqual("val1", link.extensions[0].custom_attribute)
     self.assertFalse(response.context["children_formset"].is_valid())
コード例 #4
0
ファイル: pcle.py プロジェクト: esimorre/openplm
    def test_children_formset(self):
        fname = mockext + "_custom_attribute"
        self.controller.add_child(self.controller2, 10, 15, "-",
                **{mockext:{"custom_attribute":"val1"}})
        self.controller.add_child(self.controller3, 10, 35, "-")
        # create an initial formset
        formset = forms.get_children_formset(self.controller)
        f1, f2 = formset.forms
        field = f1[fname].field
        self.assertEqual("val1", field.initial)
        self.assertEqual(None, f2[fname].field.initial)
        self.assertRaises(KeyError, lambda: f1[imockext + "_attr1"])
        self.assertRaises(KeyError, lambda: f1[imockext + "_attr2"])
        
        # create a valid formset
        data = {}
        for key, value in formset.management_form.initial.iteritems():
            data["form-" + key] = value or ""
        for i, form in enumerate(formset.forms):
            for field in form:
                value = field.field.initial or form.initial.get(field.name, "")
                if callable(value):
                    value = value()
                data["form-%d-%s" % (i, field.name)] = value 
            data['form-%d-ORDER' % i] = str(i)
        data["form-1-" + fname] = "beer"
        formset = forms.get_children_formset(self.controller, data)
        self.assertTrue(formset.is_valid())

        # update the controller
        self.controller.update_children(formset)
        child1, child2 = self.controller.get_children()
        self.assertEqual(1, child1.link.extensions.count())
        self.assertEqual(1, child2.link.extensions.count())
        self.assertEqual("beer", child2.link.extensions[0].custom_attribute)
        self.assertEqual(3, models.ParentChildLink.objects.count())
        self.assertEqual(2, MockExtension.objects.count())