Exemple #1
0
 def clean(self):
     cleaned_data = self.cleaned_data
     ref = cleaned_data.get("reference", "")
     rev = cleaned_data.get("revision", "")
     auto = cleaned_data.get("auto", False)
     inbulk = getattr(self, "inbulk_cache")
     cls = self.Meta.model
     user = self.user
     if auto and not ref:
         cleaned_data["reference"] = ref = get_new_reference(
             user, cls, self.start, inbulk)
     if not auto and not ref:
         self.errors['reference'] = [
             _("You did not check the Auto box: the reference is required.")
         ]
     if cls.objects.filter(type=cls.__name__, revision=rev,
                           reference=ref).exists():
         if not auto:
             raise ValidationError(
                 _("An object with the same type, reference and revision already exists"
                   ))
         else:
             cleaned_data["reference"] = get_new_reference(
                 user, cls, self.start, inbulk)
     elif cls.objects.filter(type=cls.__name__, reference=ref).exists():
         raise ValidationError(
             _("An object with the same type and reference exists, you may consider to revise it."
               ))
     return cleaned_data
Exemple #2
0
 def clean(self):
     cleaned_data = self.cleaned_data
     ref = cleaned_data.get("reference", "")
     rev = cleaned_data.get("revision", "")
     auto = cleaned_data.get("auto", False)
     inbulk = getattr(self, "inbulk_cache")
     cls = self.Meta.model
     user = self.user
     if auto and not ref:
         cleaned_data["reference"] = ref = get_new_reference(user, cls, self.start, inbulk)
     if not auto and not ref:
         self.errors['reference']=[_("You did not check the Auto box: the reference is required.")]
     if cls.objects.filter(type=cls.__name__, revision=rev, reference=ref).exists():
         if not auto:
             raise ValidationError(_("An object with the same type, reference and revision already exists"))
         else:
             cleaned_data["reference"] = get_new_reference(user, cls, self.start, inbulk)
     elif cls.objects.filter(type=cls.__name__, reference=ref).exists():
         raise ValidationError(_("An object with the same type and reference exists, you may consider to revise it."))
     return cleaned_data
Exemple #3
0
 def _add_doc(self, name):
     data = {
         "lifecycle": self.controller.lifecycle,
         "group": self.controller.group,
         "name": name,
     }
     ref = get_new_reference(self.controller._user, Document3D,
                             len(self.created_docs), self._inbulk_cache)
     doc = Document3DController.create(ref, "Document3D", "a", self.controller._user,
             data, not self._send_mails, True)
     self.created_docs.append(doc)
     # it is not useful to send history mails saying a file has been added
     # ot that a part has been attached
     if self._send_mails:
         doc.block_mails()
     return doc
Exemple #4
0
def get_initial_creation_data(user, cls, start=0, inbulk_cache=None):
    u"""
    Returns initial data to create a new object (from :func:`get_creation_form`).

    :param user: user who will create the object
    :param cls: class of the created object
    :param start: used to generate the reference,  see :func:`.get_new_reference`
    """
    if issubclass(cls, m.PLMObject):
        data = {
            'reference' : get_new_reference(user, cls, start, inbulk_cache),
            'revision' : 'a',
            'lifecycle' : str(m.get_default_lifecycle().pk),
        }
    else:
        data = {}
    return data
Exemple #5
0
def get_initial_creation_data(user, cls, start=0, inbulk_cache=None):
    u"""
    Returns initial data to create a new object (from :func:`get_creation_form`).

    :param user: user who will create the object
    :param cls: class of the created object
    :param start: used to generate the reference,  see :func:`.get_new_reference`
    """
    if issubclass(cls, m.PLMObject):
        data = {
            'reference': get_new_reference(user, cls, start, inbulk_cache),
            'revision': 'a',
            'lifecycle': str(m.get_default_lifecycle().pk),
        }
    else:
        data = {}
    return data
Exemple #6
0
 def _add_part(self, doc, name):
     data = {
         "lifecycle": self.controller.lifecycle,
         "group": self.controller.group,
         "name": name,
     }
     ref = get_new_reference(self.controller._user, Part,
                             len(self.created_parts), self._inbulk_cache)
     part = PartController.create(ref, "Part", "a", self.controller._user, data,
             not self._send_mails, True)
     self._parts[name] = part
     self._parts[part.id] = part
     doc.attach_to_part(part)
     doc.object.PartDecompose = part.object
     doc.object.save()
     self.created_parts.append(part)
     if self._send_mails:
         part.block_mails()
     return part
Exemple #7
0
 def assertNewReference(self, expected, model, start=0):
     ref = get_new_reference(MockUser, model, start=start)
     self.assertEqual(expected, ref)
Exemple #8
0
 def assertNewReference(self, expected, model, start=0):
     ref = get_new_reference(MockUser, model, start=start)
     self.assertEqual(expected, ref)