コード例 #1
0
ファイル: choicelists.py プロジェクト: gary-ops/lino
    def field(cls, *args, **kw):
        """
        Create and return a database field that points to one value of this
        choicelist.

        The returned field is an instance of :class:`ChoiceListField`.
        Returns a `DummyField` if the plugin which defines this
        choicelist is not installed.
        """
        if settings.SITE.is_installed(cls.app_label):
            fld = ChoiceListField(cls, *args, **kw)
            # cls.setup_field(fld)
            cls._fields.append(fld)
            return fld
        return fields.DummyField()
コード例 #2
0
class ProjectRelated(model.Model):
    """
    Mixin for models that are related to a "project". This adds a
    field named `project` and related default behaviour.

    A project in this context means what the users consider "the
    central most important model that is used to classify most other
    things".  For example in :ref:`avanti` the "project" is a Client
    while in :ref:`tera` it is a therapy.  The application's project
    model is specified in :attr:`lino.core.site.Site.project_model`.


    .. attribute:: project

        Pointer to the project to which this object is related.

        If the application's :attr:`project_model
        <lino.core.site.Site.project_model>` is empty, the
        :attr:`project` field will be a :class:`DummyField
        <lino.core.fields.DummyField>`.
    """
    class Meta(object):
        abstract = True

    if settings.SITE.project_model:
        project = fields.ForeignKey(
            settings.SITE.project_model,
            blank=True,
            null=True,
            related_name="%(app_label)s_%(class)s_set_by_project",
        )
    else:
        project = fields.DummyField('project')

    def get_related_project(self):
        if settings.SITE.project_model:
            return self.project

    def summary_row(self, ar, **kw):
        s = [ar.obj2html(self)]
        if settings.SITE.project_model:
            # if self.project and not dd.has_fk(rr,'project'):
            if self.project:
                # s += " (" + ui.obj2html(self.project) + ")"
                s += [" (", ar.obj2html(self.project), ")"]
        return s

    def update_owned_instance(self, controllable):
        """
        When a :class:`project-related <ProjectRelated>` object controls
        another project-related object, then the controlled
        automatically inherits the `project` of its controller.
        """
        if isinstance(controllable, ProjectRelated):
            controllable.project = self.project
        super(ProjectRelated, self).update_owned_instance(controllable)

    def get_mailable_recipients(self):
        if isinstance(self.project, settings.SITE.models.contacts.Partner):
            if self.project.email:
                yield ('to', self.project)
        for r in super(ProjectRelated, self).get_mailable_recipients():
            yield r

    def get_postable_recipients(self):
        if isinstance(self.project, settings.SITE.models.contacts.Partner):
            yield self.project
        for p in super(ProjectRelated, self).get_postable_recipients():
            yield p
コード例 #3
0
class ProjectRelated(model.Model):
    """Mixin for Models that are automatically related to a "project".  A
    project means here "the central most important thing that is used
    to classify most other things".  

    Whether an application has such a concept of "project",
    and which model has this privileged status,
    is set in :attr:`lino.core.site.Site.project_model`.

    For example in :ref:`welfare` the "project" is a Client.

    """
    class Meta(object):
        abstract = True

    if settings.SITE.project_model:
        project = models.ForeignKey(
            settings.SITE.project_model,
            blank=True,
            null=True,
            related_name="%(app_label)s_%(class)s_set_by_project",
        )
    else:
        project = fields.DummyField()

    def get_related_project(self):
        if settings.SITE.project_model:
            return self.project

    def summary_row(self, ar, **kw):
        s = [ar.obj2html(self)]
        if settings.SITE.project_model:
            # if self.project and not dd.has_fk(rr,'project'):
            if self.project:
                # s += " (" + ui.obj2html(self.project) + ")"
                s += [" (", ar.obj2html(self.project), ")"]
        return s

    def update_owned_instance(self, controllable):
        """
        When a :class:`project-related <ProjectRelated>`
        object controls another project-related object,
        then the controlled automatically inherits
        the `project` of its controller.
        """
        if isinstance(controllable, ProjectRelated):
            controllable.project = self.project
        super(ProjectRelated, self).update_owned_instance(controllable)

    def get_mailable_recipients(self):
        if isinstance(self.project, settings.SITE.modules.contacts.Partner):
            if self.project.email:
                yield ('to', self.project)
        for r in super(ProjectRelated, self).get_mailable_recipients():
            yield r

    def get_postable_recipients(self):
        if isinstance(self.project, settings.SITE.modules.contacts.Partner):
            yield self.project
        for p in super(ProjectRelated, self).get_postable_recipients():
            yield p