예제 #1
0
파일: models.py 프로젝트: tuxella/pydici
    def relationData(self):
        """Compute relational data in json format usable by Dagre / D3 library"""
        nodes = GNodes()
        edges = GEdges()
        leadColor = "#8AA7FF"
        directColor= "#82D887"
        missionColor = "#E4C160"

        try:
            me = GNode(unicode(self.id), unicode(self), color="#EEE")
            nodes.add(me)
            # Mission relations
            for missionContact in self.missioncontact_set.all():
                for mission in missionContact.mission_set.all():
                    missionNode = GNode("mission-%s" % mission.id, """<span class='glyphicon-svg glyphicon-cog'></span>
                                                                      <span class='graph-tooltip' title='%s'><a href='%s'>&nbsp;%s&nbsp;</a></span>""" % (mission.short_name(),
                                                                                                                                                          mission.get_absolute_url(),
                                                                                                                                                          mission.mission_id()))
                    nodes.add(missionNode)
                    edges.append(GEdge(me, missionNode, color=missionColor))
                    for consultant in mission.consultants():
                        consultantNode = GNode("consultant-%s" % consultant.id, unicode(consultant))
                        nodes.add(consultantNode)
                        edges.append(GEdge(missionNode, consultantNode, color=missionColor))
            # Business / Lead relations
            for client in self.client_set.all():
                if client.lead_set.count() < 5 :
                    for lead in client.lead_set.all():
                        leadNode = GNode("lead-%s" % lead.id, """<span class="glyphicon-svg glyphicon-euro"></span>
                                                                 <span class='graph-tooltip' title='%s'><a href='%s'>%s&nbsp;</a></span>""" % (unicode(lead),
                                                                                                                                               lead.get_absolute_url(),
                                                                                                                                               lead.deal_id))
                        nodes.add(leadNode)
                        edges.append(GEdge(me,leadNode, color=leadColor))
                        if lead.responsible:
                            consultantNode = GNode("consultant-%s" % lead.responsible.id, unicode(lead.responsible))
                            nodes.add(consultantNode)
                            edges.append(GEdge(leadNode, consultantNode, color=leadColor))
                else:
                    # Group link for highly linked contact
                    leads = []
                    responsibles = []
                    for lead in client.lead_set.all():
                        leads.append(lead)
                        if lead.responsible:
                            responsibles.append(lead.responsible)
                    leadsId = "-".join([unicode(l.id) for l in leads])
                    leadsTitle = unicode(client.organisation)
                    leadsLabel = _("%s leads" % len(leads))
                    leadsNode = GNode("leads-%s" % leadsId, """<span class='glyphicon-svg glyphicon-euro'></span>
                                                               <span class='graph-tooltip' title='%s'>&nbsp;%s&nbsp;</span>""" % (leadsTitle, leadsLabel))
                    nodes.add(leadsNode)
                    edges.append(GEdge(me,leadsNode, color=leadColor))
                    for responsible in responsibles:
                        consultantNode = GNode("consultant-%s" % responsible.id, unicode(responsible))
                        nodes.add(consultantNode)
                        edges.append(GEdge(leadsNode, consultantNode, color=leadColor))

            # Direct contact relation
            for consultant in self.contact_points.all():
                consultantNode = GNode("consultant-%s" % consultant.id, unicode(consultant))
                nodes.add(consultantNode)
                edges.append(GEdge(me, consultantNode, color=directColor))

            return """var nodes=%s; var edges=%s;""" % (nodes.dump(), edges.dump())

        except Exception, e:
            print e
예제 #2
0
    def relationData(self):
        """Compute relational data in json format usable by Dagre / D3 library"""
        nodes = GNodes()
        edges = GEdges()
        leadColor = "#8AA7FF"
        directColor = "#82D887"
        missionColor = "#E4C160"

        try:
            me = GNode(str(self.id), str(self), color="#EEE")
            nodes.add(me)
            # Mission relations
            for missionContact in self.missioncontact_set.all():
                for mission in missionContact.mission_set.all():
                    missionNode = GNode(
                        "mission-%s" % mission.id,
                        """<span class='glyphicon-svg glyphicon-cog'></span>
                                                                      <span class='graph-tooltip' title='%s'><a href='%s'>&nbsp;%s&nbsp;</a></span>"""
                        % (mission.short_name(), mission.get_absolute_url(),
                           mission.mission_id()))
                    nodes.add(missionNode)
                    edges.append(GEdge(me, missionNode, color=missionColor))
                    for consultant in mission.consultants():
                        consultantNode = GNode("consultant-%s" % consultant.id,
                                               str(consultant))
                        nodes.add(consultantNode)
                        edges.append(
                            GEdge(missionNode,
                                  consultantNode,
                                  color=missionColor))
            # Business / Lead relations
            for client in self.client_set.all():
                if client.lead_set.count() < 5:
                    for lead in client.lead_set.all():
                        leadNode = GNode(
                            "lead-%s" % lead.id,
                            """<span class="glyphicon-svg glyphicon-euro"></span>
                                                                 <span class='graph-tooltip' title='%s'><a href='%s'>%s&nbsp;</a></span>"""
                            %
                            (str(lead), lead.get_absolute_url(), lead.deal_id))
                        nodes.add(leadNode)
                        edges.append(GEdge(me, leadNode, color=leadColor))
                        if lead.responsible:
                            consultantNode = GNode(
                                "consultant-%s" % lead.responsible.id,
                                str(lead.responsible))
                            nodes.add(consultantNode)
                            edges.append(
                                GEdge(leadNode,
                                      consultantNode,
                                      color=leadColor))
                else:
                    # Group link for highly linked contact
                    leads = []
                    responsibles = []
                    for lead in client.lead_set.all():
                        leads.append(lead)
                        if lead.responsible:
                            responsibles.append(lead.responsible)
                    leadsId = "-".join([str(l.id) for l in leads])
                    leadsTitle = str(client.organisation)
                    leadsLabel = _("%s leads" % len(leads))
                    leadsNode = GNode(
                        "leads-%s" % leadsId,
                        """<span class='glyphicon-svg glyphicon-euro'></span>
                                                               <span class='graph-tooltip' title='%s'>&nbsp;%s&nbsp;</span>"""
                        % (leadsTitle, leadsLabel))
                    nodes.add(leadsNode)
                    edges.append(GEdge(me, leadsNode, color=leadColor))
                    for responsible in responsibles:
                        consultantNode = GNode(
                            "consultant-%s" % responsible.id, str(responsible))
                        nodes.add(consultantNode)
                        edges.append(
                            GEdge(leadsNode, consultantNode, color=leadColor))

            # Direct contact relation
            for consultant in self.contact_points.all():
                consultantNode = GNode("consultant-%s" % consultant.id,
                                       str(consultant))
                nodes.add(consultantNode)
                edges.append(GEdge(me, consultantNode, color=directColor))

            return """var nodes=%s; var edges=%s;""" % (nodes.dump(),
                                                        edges.dump())

        except Exception as e:
            print(e)