Ejemplo n.º 1
0
    def create_doctor_choice(self, text):
        """The :meth:`create_FOO_choice
        <lino.core.model.Model.create_FOO_choice>` method which turns
        :attr:`doctor` into a learning combobox.

        This is called when an unknown doctor name was given in order
        to auto-create a new doctor.

        The text is expected to be the doctor's name, formatted
        "first_name last_name" without title.

        Doctors are stored as :class:`contacts.Person
        <lino_xl.lib.contacts.models.Person>`.

        The :attr:`title` field of the new doctor will be "Dr." (this
        is currently not configurable).

        The user can enter title, phone number and more by clicking on
        the pointer arrow when the confirmation has been created.

        """
        if not self.doctor_type_id:
            raise ValidationError(_("Cannot auto-create without doctor type"))
        Person = rt.modules.contacts.Person
        kw = parse_name(text)
        if len(kw) != 2:
            raise ValidationError(
                "Cannot find first and last names in %r to \
                auto-create doctor", text)
        kw.update(client_contact_type=self.doctor_type)
        kw.update(title=_("Dr."))
        p = Person(**kw)
        p.full_clean()
        p.save()
        return p
Ejemplo n.º 2
0
 def create_pupil_choice(self, text):
     """
     Called when an unknown pupil name was given.
     Try to auto-create it.
     """
     Pupil = dd.resolve_model(pupil_model)
     kw = parse_name(text)
     if len(kw) != 2:
         raise ValidationError(
             "Cannot find first and last names in %r to \
             auto-create pupil", text)
     p = Pupil(**kw)
     p.full_clean()
     p.save()
     return p
Ejemplo n.º 3
0
 def create_pupil_choice(self, text):
     """
     Called when an unknown pupil name was given.
     Try to auto-create it.
     """
     Pupil = dd.resolve_model(pupil_model)
     kw = parse_name(text)
     if len(kw) != 2:
         raise ValidationError(
             "Cannot find first and last names in %r to \
             auto-create pupil", text)
     p = Pupil(**kw)
     p.full_clean()
     p.save()
     return p
Ejemplo n.º 4
0
 def parse_to_dict(cls, text):
     return parse_name(text)
Ejemplo n.º 5
0
 def choice_text_to_dict(cls, text):
     return parse_name(text)