当前位置: 首页>>代码示例>>Python>>正文


Python models.SMS类代码示例

本文整理汇总了Python中corehq.apps.sms.models.SMS的典型用法代码示例。如果您正苦于以下问题:Python SMS类的具体用法?Python SMS怎么用?Python SMS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SMS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_fake_sms

 def _get_fake_sms(self, text):
     msg = SMS(
         domain=self.domain,
         phone_number='+16175555454',
         direction=OUTGOING,
         date=datetime.utcnow(),
         backend_id=self.mobile_backend.couch_id,
         text=text
     )
     msg.save()
     return msg
开发者ID:,项目名称:,代码行数:11,代码来源:

示例2: setUp

 def setUp(self):
     self.domain = Domain(name='mockdomain')
     self.domain.save()
     SMS.by_domain(self.domain.name).delete()
     self.user = 'username-unicel'
     self.password = 'password'
     self.number = 5555551234
     self.couch_user = WebUser.create(self.domain.name, self.user, self.password)
     self.couch_user.add_phone_number(self.number)
     self.couch_user.save()
     self.message_ascii = 'It Works'
     self.message_utf_hex = '0939093F0928094D092609400020091509300924093E00200939094800200907093800200938092E092F00200915093E092E002009390948003F'
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:12,代码来源:test_create_from_request.py

示例3: main_context

    def main_context(self):
        contacts = CommCareUser.by_domain(self.domain, reduce=True)
        web_users = WebUser.by_domain(self.domain)
        web_users_admins = web_users_read_only = 0
        facilities = SQLLocation.objects.filter(domain=self.domain, location_type__name__iexact='FACILITY')
        admin_role_list = UserRole.by_domain_and_name(self.domain, 'Administrator')
        if admin_role_list:
            admin_role = admin_role_list[0]
        else:
            admin_role = None
        for web_user in web_users:
            dm = web_user.get_domain_membership(self.domain)
            if admin_role and dm.role_id == admin_role.get_id:
                web_users_admins += 1
            else:
                web_users_read_only += 1

        main_context = super(GlobalStats, self).main_context
        entities_reported_stock = SQLLocation.objects.filter(
            domain=self.domain,
            location_type__administrative=False
        ).count()

        context = {
            'root_name': self.root_name,
            'country': SQLLocation.objects.filter(domain=self.domain,
                                                  location_type__name__iexact=self.root_name).count(),
            'region': SQLLocation.objects.filter(domain=self.domain, location_type__name__iexact='region').count(),
            'district': SQLLocation.objects.filter(
                domain=self.domain,
                location_type__name__iexact='district'
            ).count(),
            'entities_reported_stock': entities_reported_stock,
            'facilities': len(facilities),
            'contacts': contacts[0]['value'] if contacts else 0,
            'web_users': len(web_users),
            'web_users_admins': web_users_admins,
            'web_users_read_only': web_users_read_only,
            'products': SQLProduct.objects.filter(domain=self.domain, is_archived=False).count(),
            'product_stocks': StockState.objects.filter(sql_product__domain=self.domain).count(),
            'stock_transactions': StockTransaction.objects.filter(report__domain=self.domain).count(),
            'inbound_messages': SMS.count_by_domain(self.domain, direction=INCOMING),
            'outbound_messages': SMS.count_by_domain(self.domain, direction=OUTGOING),
        }

        if self.show_supply_point_types:
            counts = SQLLocation.objects.values('location_type__name').filter(domain=self.domain).annotate(
                Count('location_type')
            ).order_by('location_type__name')
            context['location_types'] = counts
        main_context.update(context)
        return main_context
开发者ID:,项目名称:,代码行数:52,代码来源:

示例4: tearDown

    def tearDown(self):
        SmsBillable.objects.all().delete()
        SmsGatewayFee.objects.all().delete()
        SmsGatewayFeeCriteria.objects.all().delete()
        SmsUsageFee.objects.all().delete()
        SmsUsageFeeCriteria.objects.all().delete()

        self.currency_usd.delete()
        self.other_currency.delete()
        SMS.by_domain(generator.TEST_DOMAIN).delete()

        for api_id, backend_id in self.backend_ids.iteritems():
            SQLMobileBackend.load(backend_id, is_couch_id=True).delete()
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:13,代码来源:test_gateway_fees.py

示例5: remove_from_queue

def remove_from_queue(queued_sms):
    with transaction.atomic():
        sms = SMS()
        for field in sms._meta.fields:
            if field.name != 'id':
                setattr(sms, field.name, getattr(queued_sms, field.name))
        queued_sms.delete()
        sms.save()

    sms.publish_change()

    if sms.direction == OUTGOING and sms.processed and not sms.error:
        create_billable_for_sms(sms)
    elif sms.direction == INCOMING and sms.domain and domain_has_privilege(sms.domain, privileges.INBOUND_SMS):
        create_billable_for_sms(sms)
开发者ID:,项目名称:,代码行数:15,代码来源:

示例6: add_sms_count_info

    def add_sms_count_info(self, result, days):
        end_date = self.domain_now.date()
        start_date = end_date - timedelta(days=days - 1)
        counts = SMS.get_counts_by_date(self.domain, start_date, end_date, self.timezone.zone)

        inbound_counts = {}
        outbound_counts = {}

        for row in counts:
            if row.direction == INCOMING:
                inbound_counts[row.date] = row.sms_count
            elif row.direction == OUTGOING:
                outbound_counts[row.date] = row.sms_count

        inbound_values = []
        outbound_values = []

        for i in range(days):
            dt = start_date + timedelta(days=i)
            inbound_values.append({
                'x': dt.strftime('%Y-%m-%d'),
                'y': inbound_counts.get(dt, 0),
            })
            outbound_values.append({
                'x': dt.strftime('%Y-%m-%d'),
                'y': outbound_counts.get(dt, 0),
            })

        result['sms_count_data'] = [
            {'key': _("Incoming"), 'values': inbound_values},
            {'key': _("Outgoing"), 'values': outbound_values},
        ]
开发者ID:dimagi,项目名称:commcare-hq,代码行数:32,代码来源:views.py

示例7: handle

 def handle(self, domains, **options):
     for domain in domains:
         print("*** Processing Domain %s ***" % domain)
         user_cache = {}
         for msg in SMS.by_domain(domain):
             if msg.couch_recipient:
                 if msg.couch_recipient_doc_type != "CommCareCase":
                     user = None
                     if msg.couch_recipient in user_cache:
                         user = user_cache[msg.couch_recipient]
                     else:
                         try:
                             user = CouchUser.get_by_user_id(msg.couch_recipient)
                         except Exception:
                             user = None
                         if user is None:
                             print("Could not find user %s" % msg.couch_recipient)
                     user_cache[msg.couch_recipient] = user
                     if user and msg.couch_recipient_doc_type != user.doc_type:
                         msg.couch_recipient_doc_type = user.doc_type
                         msg.save()
             else:
                 if msg.couch_recipient_doc_type is not None or msg.couch_recipient is not None:
                     msg.couch_recipient = None
                     msg.couch_recipient_doc_type = None
                     msg.save()
开发者ID:dimagi,项目名称:commcare-hq,代码行数:26,代码来源:fix_smslog_recipient_doc_type.py

示例8: get_participant_messages

 def get_participant_messages(self, case):
     return SMS.by_recipient(
         'CommCareCase',
         case.get_id
     ).filter(
         direction=OUTGOING
     )
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:7,代码来源:reports.py

示例9: handle_domain_specific_delays

def handle_domain_specific_delays(msg, domain_object, utcnow):
    """
    Checks whether or not we need to hold off on sending an outbound message
    due to any restrictions set on the domain, and delays processing of the
    message if necessary.

    Returns True if a delay was made, False if not.
    """
    domain_now = ServerTime(utcnow).user_time(domain_object.get_default_timezone()).done()

    if len(domain_object.restricted_sms_times) > 0:
        if not time_within_windows(domain_now, domain_object.restricted_sms_times):
            delay_processing(msg, settings.SMS_QUEUE_DOMAIN_RESTRICTED_RETRY_INTERVAL)
            return True

    if msg.chat_user_id is None and len(domain_object.sms_conversation_times) > 0:
        if time_within_windows(domain_now, domain_object.sms_conversation_times):
            sms_conversation_length = domain_object.sms_conversation_length
            conversation_start_timestamp = utcnow - timedelta(minutes=sms_conversation_length)
            if SMS.inbound_entry_exists(
                msg.couch_recipient_doc_type,
                msg.couch_recipient,
                conversation_start_timestamp,
                to_timestamp=utcnow
            ):
                delay_processing(msg, 1)
                return True

    return False
开发者ID:,项目名称:,代码行数:29,代码来源:

示例10: get_first_survey_response

    def get_first_survey_response(self, case, dt):
        timestamp_start = datetime.combine(dt, time(20, 45))
        timestamp_start = UserTime(
            timestamp_start, self.timezone).server_time().done()

        timestamp_end = datetime.combine(dt + timedelta(days=1), time(11, 45))
        timestamp_end = UserTime(
            timestamp_end, self.timezone).server_time().done()
        if timestamp_end > datetime.utcnow():
            return RESPONSE_NOT_APPLICABLE

        survey_responses = SMS.by_recipient(
            'CommCareCase',
            case.get_id
        ).filter(
            direction=INCOMING,
            xforms_session_couch_id__isnull=False,
            date__gte=timestamp_start,
            date__lte=timestamp_end
        ).order_by('date')[:1]

        if survey_responses:
            return survey_responses[0]

        return NO_RESPONSE
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:25,代码来源:reports.py

示例11: handle

    def handle(self, *args, **options):
        if len(args) == 0:
            raise CommandError("Usage: python manage.py fix_smslog_recipient_doc_type <domain1 domain2 ...>")

        for domain in args:
            print "*** Processing Domain %s ***" % domain
            user_cache = {}
            for msg in SMS.by_domain(domain):
                if msg.couch_recipient:
                    if msg.couch_recipient_doc_type != "CommCareCase":
                        user = None
                        if msg.couch_recipient in user_cache:
                            user = user_cache[msg.couch_recipient]
                        else:
                            try:
                                user = CouchUser.get_by_user_id(msg.couch_recipient)
                            except Exception:
                                user = None
                            if user is None:
                                print "Could not find user %s" % msg.couch_recipient
                        user_cache[msg.couch_recipient] = user
                        if user and msg.couch_recipient_doc_type != user.doc_type:
                            msg.couch_recipient_doc_type = user.doc_type
                            msg.save()
                else:
                    if msg.couch_recipient_doc_type is not None or msg.couch_recipient is not None:
                        msg.couch_recipient = None
                        msg.couch_recipient_doc_type = None
                        msg.save()
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:29,代码来源:fix_smslog_recipient_doc_type.py

示例12: tearDown

    def tearDown(self):
        SmsBillable.objects.all().delete()
        SmsGatewayFee.objects.all().delete()
        SmsGatewayFeeCriteria.objects.all().delete()
        SmsUsageFee.objects.all().delete()
        SmsUsageFeeCriteria.objects.all().delete()

        self.currency_usd.delete()
        self.other_currency.delete()
        SMS.by_domain(generator.TEST_DOMAIN).delete()

        for api_id, backend_id in self.backend_ids.iteritems():
            SQLMobileBackend.load(backend_id, is_couch_id=True).delete()

        FakeTwilioMessageFactory.backend_message_id_to_price = {}

        super(TestGatewayFee, self).tearDown()
开发者ID:,项目名称:,代码行数:17,代码来源:

示例13: testSMSSync

    def testSMSSync(self):
        self.deleteAllLogs()
        self.assertEqual(self.getSMSLogCount(), 0)
        self.assertEqual(self.getSMSCount(), 0)

        # Test Create
        sms = SMS()
        self.setRandomSMSValues(sms)
        sms.save()

        sleep(1)
        self.assertEqual(self.getSMSLogCount(), 1)
        self.assertEqual(self.getSMSCount(), 1)

        smslog = FRISMSLog.get(sms.couch_id)
        self.checkFieldValues(smslog, sms, SMS._migration_get_fields())
        self.assertTrue(FRISMSLog.get_db().get_rev(smslog._id).startswith('2-'))

        # Test Update
        self.setRandomSMSValues(sms)
        sms.save()

        sleep(1)
        self.assertEqual(self.getSMSLogCount(), 1)
        self.assertEqual(self.getSMSCount(), 1)
        smslog = FRISMSLog.get(sms.couch_id)
        self.checkFieldValues(smslog, sms, SMS._migration_get_fields())
        self.assertTrue(FRISMSLog.get_db().get_rev(smslog._id).startswith('3-'))
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:28,代码来源:migration.py

示例14: rows

    def rows(self):
        data = SMS.by_domain(
            self.domain,
            start_date=self.datespan.startdate_utc,
            end_date=self.datespan.enddate_utc
        ).exclude(
            direction=OUTGOING,
            processed=False
        ).order_by('date')

        if self.show_only_survey_traffic():
            data = data.filter(
                xforms_session_couch_id__isnull=False
            )

        result = []
        direction_map = {
            INCOMING: _("Incoming"),
            OUTGOING: _("Outgoing"),
        }
        message_bank_messages = get_message_bank(self.domain, for_comparing=True)

        FormProcessorInterface(self.domain).casedb_cache(
            domain=self.domain, strip_history=False, deleted_ok=True
        )
        user_cache = UserCache()

        for message in data:
            # Add metadata from the message bank if it has not been added already
            if (message.direction == OUTGOING) and (not message.fri_message_bank_lookup_completed):
                add_metadata(message, message_bank_messages)

            if message.couch_recipient_doc_type == "CommCareCase":
                recipient = case_cache.get(message.couch_recipient)
            else:
                recipient = user_cache.get(message.couch_recipient)

            if message.chat_user_id:
                sender = user_cache.get(message.chat_user_id)
            else:
                sender = None

            study_arm = None
            if message.couch_recipient_doc_type == "CommCareCase":
                study_arm = case_cache.get(message.couch_recipient).get_case_property("study_arm")

            timestamp = ServerTime(message.date).user_time(self.timezone).done()
            result.append([
                self._fmt(self._participant_id(recipient)),
                self._fmt(study_arm or "-"),
                self._fmt(self._originator(message, recipient, sender)),
                self._fmt_timestamp(timestamp),
                self._fmt(message.text),
                self._fmt(message.fri_id or "-"),
                self._fmt(direction_map.get(message.direction,"-")),
            ])
        return result
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:57,代码来源:reports.py

示例15: arbitrary_messages_by_backend_and_direction

def arbitrary_messages_by_backend_and_direction(backend_ids,
                                                phone_number=None,
                                                domain=None,
                                                directions=DIRECTIONS):
    phone_number = phone_number or TEST_NUMBER
    domain = domain or TEST_DOMAIN
    messages = []
    for api_id, instance_id in backend_ids.items():
        for direction in directions:
            sms_log = SMS(
                direction=direction,
                phone_number=phone_number,
                domain=domain,
                backend_api=api_id,
                backend_id=instance_id,
                text=arbitrary_message(),
                date=datetime.datetime.utcnow()
            )
            sms_log.save()
            messages.append(sms_log)
    return messages
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:21,代码来源:generator.py


注:本文中的corehq.apps.sms.models.SMS类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。