示例#1
0
    def rows(self):
        startdate = json_format_datetime(self.datespan.startdate_utc)
        enddate = json_format_datetime(self.datespan.enddate_utc)
        data = SMSLog.by_domain_date(self.domain, startdate, enddate)
        result = []

        username_map = {
        }  # Store the results of username lookups for faster loading

        direction_map = {
            INCOMING: _("Incoming"),
            OUTGOING: _("Outgoing"),
        }

        # Retrieve message log options
        message_log_options = getattr(settings, "MESSAGE_LOG_OPTIONS", {})
        abbreviated_phone_number_domains = message_log_options.get(
            "abbreviated_phone_number_domains", [])
        abbreviate_phone_number = (self.domain
                                   in abbreviated_phone_number_domains)

        for message in data:
            if message.direction == OUTGOING and not message.processed:
                continue
            recipient_id = message.couch_recipient
            if recipient_id in [None, ""]:
                username = "******"
            elif recipient_id in username_map:
                username = username_map.get(recipient_id)
            else:
                username = "******"
                try:
                    if message.couch_recipient_doc_type == "CommCareCase":
                        username = CommCareCase.get(recipient_id).name
                    else:
                        username = CouchUser.get_by_user_id(
                            recipient_id).username
                except Exception:
                    pass

                username_map[recipient_id] = username

            phone_number = message.phone_number
            if abbreviate_phone_number and phone_number is not None:
                phone_number = phone_number[0:7] if phone_number[
                    0:1] == "+" else phone_number[0:6]

            timestamp = tz_utils.adjust_datetime_to_timezone(
                message.date, pytz.utc.zone, self.timezone.zone)
            result.append([
                self._fmt_timestamp(timestamp),
                self._fmt(username),
                self._fmt(phone_number),
                self._fmt(direction_map.get(message.direction, "-")),
                self._fmt(message.text),
            ])

        return result
示例#2
0
    def rows(self):
        startdate = json_format_datetime(self.datespan.startdate_utc)
        enddate = json_format_datetime(self.datespan.enddate_utc)
        data = SMSLog.by_domain_date(self.domain, startdate, enddate)
        result = []

        direction_map = {
            INCOMING: _("Incoming"),
            OUTGOING: _("Outgoing"),
        }

        # Retrieve message log options
        message_log_options = getattr(settings, "MESSAGE_LOG_OPTIONS", {})
        abbreviated_phone_number_domains = message_log_options.get(
            "abbreviated_phone_number_domains", [])
        abbreviate_phone_number = (self.domain
                                   in abbreviated_phone_number_domains)

        contact_cache = {}

        for message in data:
            if message.direction == OUTGOING and not message.processed:
                continue
            recipient_id = message.couch_recipient
            doc = None
            if recipient_id not in [None, ""]:
                try:
                    if message.couch_recipient_doc_type == "CommCareCase":
                        doc = CommCareCase.get(recipient_id)
                    else:
                        doc = CouchUser.get_by_user_id(recipient_id)
                except Exception:
                    pass

            if doc:
                doc_info = get_doc_info(doc.to_json(), self.domain,
                                        contact_cache)
            else:
                doc_info = None

            phone_number = message.phone_number
            if abbreviate_phone_number and phone_number is not None:
                phone_number = phone_number[0:7] if phone_number[
                    0:1] == "+" else phone_number[0:6]

            timestamp = tz_utils.adjust_datetime_to_timezone(
                message.date, pytz.utc.zone, self.timezone.zone)
            result.append([
                self._fmt_timestamp(timestamp),
                self._fmt_contact_link(message, doc_info),
                self._fmt(phone_number),
                self._fmt(direction_map.get(message.direction, "-")),
                self._fmt(message.text),
            ])

        return result
示例#3
0
    def rows(self):
        data = SMSLog.by_domain_date(self.config["domain"])
        messages = []
        location_id = self.config["location_id"]
        for message in data:
            if message.location_id != location_id:
                continue

            timestamp = ServerTime(message.date).user_time(self.config["timezone"]).done()
            messages.append([_fmt_timestamp(timestamp), _fmt(message.direction), _fmt(message.text)])
        return sorted(messages, key=lambda x: x[0]["sort_key"]) if messages else messages
示例#4
0
 def rows(self):
     startdate = json_format_datetime(self.datespan.startdate_utc)
     enddate = json_format_datetime(self.datespan.enddate_utc)
     data = SMSLog.by_domain_date(self.domain, startdate, enddate)
     result = []
     
     username_map = {} # Store the results of username lookups for faster loading
     
     direction_map = {
         INCOMING: _("Incoming"),
         OUTGOING: _("Outgoing"),
     }
     
     # Retrieve message log options
     message_log_options = getattr(settings, "MESSAGE_LOG_OPTIONS", {})
     abbreviated_phone_number_domains = message_log_options.get("abbreviated_phone_number_domains", [])
     abbreviate_phone_number = (self.domain in abbreviated_phone_number_domains)
     
     for message in data:
         if message.direction == OUTGOING and not message.processed:
             continue
         recipient_id = message.couch_recipient
         if recipient_id in [None, ""]:
             username = "******"
         elif recipient_id in username_map:
             username = username_map.get(recipient_id)
         else:
             username = "******"
             try:
                 if message.couch_recipient_doc_type == "CommCareCase":
                     username = CommCareCase.get(recipient_id).name
                 else:
                     username = CouchUser.get_by_user_id(recipient_id).username
             except Exception:
                 pass
            
             username_map[recipient_id] = username
         
         phone_number = message.phone_number
         if abbreviate_phone_number and phone_number is not None:
             phone_number = phone_number[0:7] if phone_number[0:1] == "+" else phone_number[0:6]
         
         timestamp = tz_utils.adjust_datetime_to_timezone(message.date, pytz.utc.zone, self.timezone.zone)
         result.append([
             self._fmt_timestamp(timestamp),
             self._fmt(username),
             self._fmt(phone_number),
             self._fmt(direction_map.get(message.direction,"-")),
             self._fmt(message.text),
         ])
     
     return result
示例#5
0
    def rows(self):
        startdate = json_format_datetime(self.datespan.startdate_utc)
        enddate = json_format_datetime(self.datespan.enddate_utc)
        data = SMSLog.by_domain_date(self.domain, startdate, enddate)
        result = []

        direction_map = {
            INCOMING: _("Incoming"),
            OUTGOING: _("Outgoing"),
        }

        # Retrieve message log options
        message_log_options = getattr(settings, "MESSAGE_LOG_OPTIONS", {})
        abbreviated_phone_number_domains = message_log_options.get("abbreviated_phone_number_domains", [])
        abbreviate_phone_number = (self.domain in abbreviated_phone_number_domains)

        contact_cache = {}

        for message in data:
            if message.direction == OUTGOING and not message.processed:
                continue
            recipient_id = message.couch_recipient
            doc = None
            if recipient_id not in [None, ""]:
                try:
                    if message.couch_recipient_doc_type == "CommCareCase":
                        doc = CommCareCase.get(recipient_id)
                    else:
                        doc = CouchUser.get_by_user_id(recipient_id)
                except Exception:
                    pass

            if doc:
                doc_info = get_doc_info(doc.to_json(), self.domain,
                    contact_cache)
            else:
                doc_info = None

            phone_number = message.phone_number
            if abbreviate_phone_number and phone_number is not None:
                phone_number = phone_number[0:7] if phone_number[0:1] == "+" else phone_number[0:6]

            timestamp = tz_utils.adjust_datetime_to_timezone(message.date, pytz.utc.zone, self.timezone.zone)
            result.append([
                self._fmt_timestamp(timestamp),
                self._fmt_contact_link(message, doc_info),
                self._fmt(phone_number),
                self._fmt(direction_map.get(message.direction,"-")),
                self._fmt(message.text),
            ])

        return result
示例#6
0
文件: sms.py 项目: ekush/commcare-hq
    def rows(self):
        startdate = json_format_datetime(self.datespan.startdate_utc)
        enddate = json_format_datetime(self.datespan.enddate_utc)
        data = SMSLog.by_domain_date(self.domain, startdate, enddate)
        result = []

        reporting_locations_id = self.get_location_filter(
        ) if self.uses_locations else []
        # Retrieve message log options
        message_log_options = getattr(settings, "MESSAGE_LOG_OPTIONS", {})
        abbreviated_phone_number_domains = message_log_options.get(
            "abbreviated_phone_number_domains", [])
        abbreviate_phone_number = (self.domain
                                   in abbreviated_phone_number_domains)

        contact_cache = {}
        message_type_filter = self.get_message_type_filter()

        for message in data:
            if message.direction == OUTGOING and not message.processed:
                continue

            message_types = self._get_message_types(message)
            if not message_type_filter(message_types):
                continue

            if reporting_locations_id and message.location_id not in reporting_locations_id:
                continue

            doc_info = self.get_recipient_info(
                message.couch_recipient_doc_type, message.couch_recipient,
                contact_cache)

            phone_number = message.phone_number
            if abbreviate_phone_number and phone_number is not None:
                phone_number = phone_number[0:7] if phone_number[
                    0:1] == "+" else phone_number[0:6]

            timestamp = ServerTime(message.date).user_time(
                self.timezone).done()
            result.append([
                self._fmt_timestamp(timestamp),
                self._fmt_contact_link(message.couch_recipient, doc_info),
                self._fmt(phone_number),
                self._fmt_direction(message.direction),
                self._fmt(message.text),
                self._fmt(", ".join(message_types)),
            ])

        return result
示例#7
0
    def rows(self):
        startdate = json_format_datetime(self.datespan.startdate_utc)
        enddate = json_format_datetime(self.datespan.enddate_utc)
        data = SMSLog.by_domain_date(self.domain, startdate, enddate)
        result = []

        direction_map = {
            INCOMING: _("Incoming"),
            OUTGOING: _("Outgoing"),
        }
        reporting_locations_id = self.get_location_filter() if self.locations_enabled else []
        # Retrieve message log options
        message_log_options = getattr(settings, "MESSAGE_LOG_OPTIONS", {})
        abbreviated_phone_number_domains = message_log_options.get("abbreviated_phone_number_domains", [])
        abbreviate_phone_number = (self.domain in abbreviated_phone_number_domains)

        contact_cache = {}
        message_type_filter = self.get_message_type_filter()

        for message in data:
            if message.direction == OUTGOING and not message.processed:
                continue

            message_types = self._get_message_types(message)
            if not message_type_filter(message_types):
                continue

            if reporting_locations_id and message.location_id not in reporting_locations_id:
                continue

            doc_info = self.get_recipient_info(message, contact_cache)

            phone_number = message.phone_number
            if abbreviate_phone_number and phone_number is not None:
                phone_number = phone_number[0:7] if phone_number[0:1] == "+" else phone_number[0:6]

            timestamp = ServerTime(message.date).user_time(self.timezone).done()
            result.append([
                self._fmt_timestamp(timestamp),
                self._fmt_contact_link(message, doc_info),
                self._fmt(phone_number),
                self._fmt(direction_map.get(message.direction,"-")),
                self._fmt(message.text),
                self._fmt(", ".join(message_types)),
            ])

        return result
示例#8
0
    def rows(self):
        data = SMSLog.by_domain_date(self.config['domain'])
        messages = []
        location_id = self.config['location_id']
        for message in data:
            if message.location_id != location_id:
                continue

            timestamp = ServerTime(message.date).user_time(
                self.config['timezone']).done()
            messages.append([
                _fmt_timestamp(timestamp),
                _fmt(message.direction),
                _fmt(message.text),
            ])
        return sorted(messages,
                      key=lambda x: x[0]['sort_key']) if messages else messages
示例#9
0
    def rows(self):
        startdate = json_format_datetime(self.datespan.startdate_utc)
        enddate = json_format_datetime(self.datespan.enddate_utc)
        data = SMSLog.by_domain_date(self.domain, startdate, enddate)
        result = []

        direction_map = {INCOMING: _("Incoming"), OUTGOING: _("Outgoing")}

        # Retrieve message log options
        message_log_options = getattr(settings, "MESSAGE_LOG_OPTIONS", {})
        abbreviated_phone_number_domains = message_log_options.get("abbreviated_phone_number_domains", [])
        abbreviate_phone_number = self.domain in abbreviated_phone_number_domains

        contact_cache = {}

        for message in data:
            if message.direction == OUTGOING and not message.processed:
                continue

            doc_info = self.get_recipient_info(message, contact_cache)

            phone_number = message.phone_number
            if abbreviate_phone_number and phone_number is not None:
                phone_number = phone_number[0:7] if phone_number[0:1] == "+" else phone_number[0:6]

            timestamp = tz_utils.adjust_datetime_to_timezone(message.date, pytz.utc.zone, self.timezone.zone)
            result.append(
                [
                    self._fmt_timestamp(timestamp),
                    self._fmt_contact_link(message, doc_info),
                    self._fmt(phone_number),
                    self._fmt(direction_map.get(message.direction, "-")),
                    self._fmt(message.text),
                ]
            )

        return result