Ejemplo n.º 1
0
    def getHTML(self, info, selfInfo, event):
        super(CommonRenderer, self).getHTML(info, selfInfo, event)

        # build html for company name
        comp = u""
        if info["company_name"]:
            if "company_detail_url" in info and info["company_detail_url"]:
                comp += "<a href='%s'>%s</a>" % (
                    cgi.escape(mr(info["company_detail_url"])),
                    cgi.escape(mr(info["company_name"])),
                )
            else:
                comp += cgi.escape(mr(info["company_name"]))

        # build html for contact name
        cont = u""
        if info["contact_name"]:
            if "contact_detail_url" in info and info["contact_detail_url"]:
                cont += "<a href='%s'>%s</a>" % (
                    cgi.escape(mr(info["contact_detail_url"])),
                    cgi.escape(mr(info["contact_name"])),
                )
            else:
                cont += cgi.escape(mr(info["contact_name"]))

        # build actual html section
        html = u"<b>%s:</b>\n" % cgi.escape(_("Attendee"))
        if cont:
            html += cont
            if comp:
                html += " (" + comp + ")"
        elif comp:
            html += comp

        if "Duration" in event:
            duration = int(float(event["Duration"]))
            html += "\n\n<b>%s:</b> " % cgi.escape(_("Duration"))
            html += "%d'%02d\"\n" % (duration / 60, duration % 60)

        return html
Ejemplo n.º 2
0
    def getHTML(self, particiantInfo, selfInfo, event):
        super(GOForgeRenderer, self).getHTML(particiantInfo, selfInfo, event)

        if not "company_id" in particiantInfo:
            return ""

        company_id = particiantInfo["company_id"]
        if not company_id:
            return ""

        # prepare result
        result = []
        html = ""

        # Connect to GOforge db
        sess = self.env.getDatabaseSession("fetcher-goforge")

        # obtain GOforge internal customer id
        res = sess.execute(
            select(
                ["customer_id"], Column(String(), name="customer_unique_ldap_attribute").__eq__(company_id), "customer"
            )
        )

        if res.rowcount == 1:
            row = res.fetchone()

            # fetch tickets from database
            m = MetaData()
            bug = Table(
                "bug",
                m,
                Column("bug_id", Integer),
                Column("summary", String),
                Column("group_id", String),
                Column("status_id", Integer),
                Column("assigned_to", Integer),
                Column("customer_id", Integer),
            )
            user = Table("user", m, Column("user_name", String), Column("user_id", Integer))
            rows = sess.execute(
                select(
                    [bug.c.bug_id, bug.c.summary, bug.c.group_id, user.c.user_name],
                    and_(bug.c.status_id == 1, bug.c.assigned_to == user.c.user_id, bug.c.customer_id == row[0]),
                    [bug, user],
                ).limit(29)
            ).fetchall()

            # put results into dictionary
            for row in rows:
                result.append({"id": row[0], "summary": row[1], "group_id": row[2], "assigned": row[3]})

            if len(result) == 0:
                sess.close()
                return ""

            html = u"<b>%s</b>" % _("GOForge tickets")

            for row in result:
                html += u"\n<a href='%s'>%s</a> %s" % (
                    self.forge_url
                    + "/bugs/?func=detailbug"
                    + "&bug_id="
                    + str(row["id"])
                    + "&group_id="
                    + str(row["group_id"]),
                    row["id"],
                    cgi.escape(mr(row["summary"])),
                )

        sess.close()
        return html
Ejemplo n.º 3
0
    def getHTML(self, particiantInfo, selfInfo, event):
        super(DoingReportRenderer, self).getHTML(particiantInfo, selfInfo, event)

        if event['Type'] != "CallEnded":
            return ""
        if not "Duration" in event:
            return ""

        ldap_uid = selfInfo['ldap_uid'] if 'ldap_uid' in selfInfo else None
        if not ldap_uid:
            return ""

        # Filter out white listed users
        if self.whitelisted_users and not ldap_uid in self.whitelisted_users:
            return ""

        company_id = particiantInfo['company_id'] if 'company_id' in particiantInfo else None
        contact_name = particiantInfo['contact_name'] if 'contact_name' in particiantInfo else None
        contact_phone = particiantInfo['contact_phone'] if 'contact_phone' in particiantInfo else None
        company_name = particiantInfo['company_name'] if 'company_name' in particiantInfo else None
        company_phone = particiantInfo['company_phone'] if 'company_phone' in particiantInfo else None

        if not (contact_name or company_name or company_phone or contact_phone):
            return ""

        # Connect to GOforge db
        sess = self.env.getDatabaseSession("fetcher-goforge")

        # Lookup GOforge user_id from ldap_uid
        res = sess.execute(select(['user_id'], Column(String(), name='user_name').__eq__(ldap_uid), 'user')).fetchone()
        if not res:
            sess.close()
            return ""

        user_id = int(res[0])

        # Lookup GOforge customer ID from sugar company_id
        customer_id = None
        if company_id:
            res = sess.execute(select(['customer_id'], Column(String(),
                name='customer_unique_ldap_attribute').__eq__(company_id), 'customer')).fetchone()

            if res:
                customer_id = int(res[0])

        # Assemble new entry for TB
        date = datetime.strftime(datetime.utcnow(), "%Y.%m.%d")
        minutes = int(math.ceil(float(event["Duration"]) / 60))
        details = "Please amend"
        comment = "Phone call with %s" % contact_name or contact_phone or company_name or company_phone

        if customer_id:
            sess.execute("""
                INSERT INTO doingreport (user_id, customer_id, date, minutes, details, comments, flag)
                VALUES (:user_id, :customer_id, :date, :minutes, :details, :comments, '?')""",
                dict(
                    user_id=user_id,
                    customer_id=customer_id,
                    date=date,
                    minutes=minutes,
                    details=mr(details).encode('ascii', 'xmlcharrefreplace'),
                    comment=mr(comment).encode('ascii', 'xmlcharrefreplace')))
        else:
            sess.execute("""
                INSERT INTO doingreport (user_id, date, minutes, details, comments, flag)
                VALUES (:user_id, :date, :minutes, :details, :comments, '?')""",
                dict(
                    user_id=user_id,
                    date=date,
                    minutes=minutes,
                    details=mr(details).encode('ascii', 'xmlcharrefreplace'),
                    comments=mr(comment).encode('ascii', 'xmlcharrefreplace')))

        # Eventually we need to create an entry in doing_account in order
        # to make the TB editable.
        res = sess.execute(select(['id'], and_(
            Column(String(), name='date').__eq__(date),
            Column(String(), name='user_id').__eq__(user_id)),
            'doing_account')).fetchone()
        if not res:
            sess.execute("""
                INSERT INTO doing_account (date, user_id, account_user, account_billing)
                VALUES(:date, :user_id, 'no', 'no');
            """, dict(date=date, user_id=user_id))

        sess.close()
        return ""