Exemplo n.º 1
0
    def custom_msg_render(resource, data, meta_data, format=None):
        """
            Custom Method to pre-render the contents for the message template

            @param resource: the S3Resource
            @param data: the data returned from S3Resource.select
            @param meta_data: the meta data for the notification
            @param format: the contents format ("text" or "html")
        """

        from s3 import s3_utc
        created_on_selector = resource.prefix_selector("created_on")
        created_on_colname = None
        notify_on = meta_data["notify_on"]
        last_check_time = meta_data["last_check_time"]
        rows = data["rows"]
        rfields = data["rfields"]
        output = {}
        new, upd = [], []
        if format == "text":
            # Standard text format
            labels = []
            append = labels.append

            for rfield in rfields:
                if rfield.selector == created_on_selector:
                    created_on_colname = rfield.colname
                elif rfield.ftype != "id":
                    append((rfield.colname, rfield.label))

            for row in rows:
                append_record = upd.append
                if created_on_colname:
                    try:
                        created_on = row["_row"][created_on_colname]
                    except KeyError, AttributeError:
                        pass
                    else:
                        if s3_utc(created_on) >= last_check_time:
                            append_record = new.append

                record = []
                append_column = record.append
                for colname, label in labels:
                    append_column((label, row[colname]))
                append_record(record)

            if "new" in notify_on and len(new):
                output["new"] = len(new)
                output["new_records"] = new
            else:
                output["new"] = None
            if "upd" in notify_on and len(upd):
                output["upd"] = len(upd)
                output["upd_records"] = upd
            else:
                output["upd"] = None
Exemplo n.º 2
0
    def custom_msg_render(resource, data, meta_data, format=None):
        """
            Custom Method to pre-render the contents for the message template

            @param resource: the S3Resource
            @param data: the data returned from S3Resource.select
            @param meta_data: the meta data for the notification
            @param format: the contents format ("text" or "html")
        """

        from s3 import s3_utc
        created_on_selector = resource.prefix_selector("created_on")
        created_on_colname = None
        notify_on = meta_data["notify_on"]
        last_check_time = meta_data["last_check_time"]
        rows = data["rows"]
        rfields = data["rfields"]
        output = {}
        new, upd = [], []
        if format == "text":
            # For SMS
            labels = []
            append = labels.append

            for rfield in rfields:
                if rfield.selector == created_on_selector:
                    created_on_colname = rfield.colname
                elif rfield.ftype != "id":
                    append((rfield.colname, rfield.label))

            for row in rows:
                append_record = upd.append
                if created_on_colname:
                    try:
                        created_on = row["_row"][created_on_colname]
                    except KeyError, AttributeError:
                        pass
                    else:
                        if s3_utc(created_on) >= last_check_time:
                            append_record = new.append

                record = []
                append_column = record.append
                for colname, label in labels:
                    append_column((label, row[colname]))
                append_record(record)

            if "new" in notify_on and len(new):
                output["new"] = len(new)
                output["new_records"] = new
            else:
                output["new"] = None
            if "upd" in notify_on and len(upd):
                output["upd"] = len(upd)
                output["upd_records"] = upd
            else:
                output["upd"] = None
Exemplo n.º 3
0
    def custom_msg_notify_subject(resource, data, meta_data):
        """
            Custom Method to subject for the email
            @param resource: the S3Resource
            @param data: the data returned from S3Resource.select
            @param meta_data: the meta data for the notification
        """

        rows = data["rows"]
        subject = "%s $s %s" % (T("SAHANA"), T("Alert Notification"))
        if len(rows) == 1:
            # Since if there are more than one row, the single email has content
            # for all rows
            from s3 import s3_utc
            last_check_time = meta_data["last_check_time"]
            db = current.db
            atable = current.s3db.cap_alert
            row_ = db(atable.id == rows[0]["cap_alert.id"]).select(atable.approved_on,
                                                                   limitby=(0, 1)).first()
            if row_ and row_.approved_on is not None:
                if s3_utc(row_.approved_on) >= last_check_time:
                    subject = get_email_subject(rows[0])

        return subject
Exemplo n.º 4
0
    def custom_msg_render(resource, data, meta_data, format=None):
        """
            Custom Method to pre-render the contents for the message template

            @param resource: the S3Resource
            @param data: the data returned from S3Resource.select
            @param meta_data: the meta data for the notification
            @param format: the contents format ("text" or "html")
        """

        from s3 import s3_utc
        notify_on = meta_data["notify_on"]
        last_check_time = meta_data["last_check_time"]
        rows = data["rows"]
        rfields = data["rfields"]
        output = {}
        new = [] # Alerts are updated by creating new alerts and setting status to update

        db = current.db
        atable = current.s3db.cap_alert
        if format == "text":
            # For SMS
            labels = []
            append = labels.append

            append_record = new.append
            for rfield in rfields:
                if rfield.ftype != "id":
                    append((rfield.colname, rfield.label))

            for row in rows:
                row_ = db(atable.id == row["cap_alert.id"]).select(atable.approved_on,
                                                                   limitby=(0, 1)).first()
                if row_ and row_.approved_on is not None:
                    if s3_utc(row_.approved_on) >= last_check_time:
                        record = []
                        append_column = record.append
                        for colname, label in labels:
                            append_column((label, row[colname]))
                        append_record(record)

            if "new" in notify_on and len(new):
                output["new"] = len(new)
                output["new_records"] = new
            else:
                output["new"] = None
        else:
            # HTML emails
            elements = []
            append = elements.append
            append_record = new.append

            for row in rows:
                row_ = db(atable.id == row["cap_alert.id"]).select(atable.approved_on,
                                                                   limitby=(0, 1)).first()
                if row_ and row_.approved_on is not None:
                    if s3_utc(row_.approved_on) >= last_check_time:
                        content = get_html_email_content(row)
                        container = DIV(DIV(content))
                        append(container)
                        append(BR())
                        append_record(container)
            if "new" in notify_on and len(new):
                output["new"] = len(new)
                output["new_records"] = DIV(*elements)
            else:
                output["new"] = None

        output.update(meta_data)
        return output
Exemplo n.º 5
0
    def custom_msg_render(resource, data, meta_data, format=None):
        """
            Custom Method to pre-render the contents for the message template

            @param resource: the S3Resource
            @param data: the data returned from S3Resource.select
            @param meta_data: the meta data for the notification
            @param format: the contents format ("text" or "html")
        """

        from s3 import s3_utc
        notify_on = meta_data["notify_on"]
        last_check_time = meta_data["last_check_time"]
        rows = data["rows"]
        rfields = data["rfields"]
        output = {}
        new = [
        ]  # Alerts are updated by creating new alerts and setting status to update

        db = current.db
        atable = current.s3db.cap_alert
        if format == "text":
            # For SMS
            labels = []
            append = labels.append

            append_record = new.append
            for rfield in rfields:
                if rfield.ftype != "id":
                    append((rfield.colname, rfield.label))

            for row in rows:
                row_ = db(atable.id == row["cap_alert.id"]).select(
                    atable.approved_on, limitby=(0, 1)).first()
                if row_ and row_.approved_on is not None:
                    if s3_utc(row_.approved_on) >= last_check_time:
                        record = []
                        append_column = record.append
                        for colname, label in labels:
                            append_column((label, row[colname]))
                        append_record(record)

            if "new" in notify_on and len(new):
                output["new"] = len(new)
                output["new_records"] = new
            else:
                output["new"] = None
        else:
            # HTML emails
            elements = []
            append = elements.append
            append_record = new.append

            for row in rows:
                row_ = db(atable.id == row["cap_alert.id"]).select(
                    atable.approved_on, limitby=(0, 1)).first()
                if row_ and row_.approved_on is not None:
                    if s3_utc(row_.approved_on) >= last_check_time:
                        content = get_html_email_content(row)
                        container = DIV(DIV(content))
                        append(container)
                        append(BR())
                        append_record(container)
            if "new" in notify_on and len(new):
                output["new"] = len(new)
                output["new_records"] = DIV(*elements)
            else:
                output["new"] = None

        output.update(meta_data)
        return output
Exemplo n.º 6
0
            # HTML emails
            elements = []
            append = elements.append
            for rfield in rfields:
                if rfield.selector == created_on_selector:
                    created_on_colname = rfield.colname

            for row in rows:
                append_record = upd.append
                if created_on_colname:
                    try:
                        created_on = row["_row"][created_on_colname]
                    except KeyError, AttributeError:
                        pass
                    else:
                        if s3_utc(created_on) >= last_check_time:
                            append_record = new.append
                content = get_html_email_content(row)
                container = DIV(DIV(content))
                append(container)
                append(BR())
                append_record(container)
            if "new" in notify_on and len(new):
                output["new"] = len(new)
                output["new_body"] = DIV(*elements)
            else:
                output["new"] = None
            if "upd" in notify_on and len(upd):
                output["upd"] = len(upd)
                output["upd_body"] = DIV(*elements)
            else:
Exemplo n.º 7
0
            # HTML emails
            elements = []
            append = elements.append
            for rfield in rfields:
                if rfield.selector == created_on_selector:
                    created_on_colname = rfield.colname

            for row in rows:
                append_record = upd.append
                if created_on_colname:
                    try:
                        created_on = row["_row"][created_on_colname]
                    except KeyError, AttributeError:
                        pass
                    else:
                        if s3_utc(created_on) >= last_check_time:
                            append_record = new.append
                content = get_html_email_content(row)
                container = DIV(DIV(content))
                append(container)
                append(BR())
                append_record(container)
            if "new" in notify_on and len(new):
                output["new"] = len(new)
                output["new_body"] = DIV(*elements)
            else:
                output["new"] = None
            if "upd" in notify_on and len(upd):
                output["upd"] = len(upd)
                output["upd_body"] = DIV(*elements)
            else: