當前位置: 首頁>>代碼示例>>Python>>正文


Python models.CommCareCaseGroup類代碼示例

本文整理匯總了Python中corehq.apps.casegroups.models.CommCareCaseGroup的典型用法代碼示例。如果您正苦於以下問題:Python CommCareCaseGroup類的具體用法?Python CommCareCaseGroup怎麽用?Python CommCareCaseGroup使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CommCareCaseGroup類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_group

 def create_group(self, domain):
     group = CommCareCaseGroup(
         name=self.cleaned_data['name'],
         domain=domain
     )
     group.save()
     return group
開發者ID:johan--,項目名稱:commcare-hq,代碼行數:7,代碼來源:forms.py

示例2: handle

    def handle(self, *labels, **options):
        existing_samples = CommCareCaseGroup.get_db().view(
            'reminders/sample_by_domain',
            startkey=[],
            endkey=[{}],
            include_docs=True
        ).all()

        print "Found %d SurveySamples to migrate..." % len(existing_samples)
        print "Migrating"

        for sample in existing_samples:
            try:
                sample_doc = sample["doc"]
                sample_doc["timezone"] = sample_doc.get("time_zone")
                del sample_doc["time_zone"]
                sample_doc["cases"] = sample_doc.get("contacts", [])
                del sample_doc["contacts"]
                sample_doc["doc_type"] = CommCareCaseGroup.__name__

                case_group = CommCareCaseGroup.wrap(sample_doc)
                case_group.save()
                sys.stdout.write('.')
            except Exception:
                sys.stdout.write('!')
            sys.stdout.flush()

        print "\nMigration complete."
開發者ID:puttarajubr,項目名稱:commcare-hq,代碼行數:28,代碼來源:migrate_surveysample_group_2013_09.py

示例3: test_case_group_recipient_with_user_data_filter

    def test_case_group_recipient_with_user_data_filter(self):
        # The user data filter should have no effect here because all
        # the recipients are cases.

        schedule = TimedSchedule.create_simple_daily_schedule(
            self.domain,
            TimedEvent(time=time(9, 0)),
            SMSContent(message={'en': 'Hello'})
        )
        schedule.user_data_filter = {'role': ['nurse']}
        schedule.save()

        with create_case(self.domain, 'person') as case:
            case_group = CommCareCaseGroup(domain=self.domain, cases=[case.case_id])
            case_group.save()
            self.addCleanup(case_group.delete)

            instance = CaseTimedScheduleInstance(
                domain=self.domain,
                timed_schedule_id=schedule.schedule_id,
                recipient_type=ScheduleInstance.RECIPIENT_TYPE_CASE_GROUP,
                recipient_id=case_group.get_id,
            )
            recipients = list(instance.expand_recipients())
            self.assertEqual(len(recipients), 1)
            self.assertEqual(recipients[0].case_id, case.case_id)
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:26,代碼來源:test_recipients.py

示例4: get_recipient_info

    def get_recipient_info(self, recipient_doc_type, recipient_id, contact_cache):
        if recipient_doc_type in ['SQLLocation']:
            return self.get_orm_recipient_info(recipient_doc_type, recipient_id, contact_cache)

        if recipient_id in contact_cache:
            return contact_cache[recipient_id]

        doc = None
        if recipient_id not in [None, ""]:
            try:
                if recipient_doc_type.startswith('CommCareCaseGroup'):
                    doc = CommCareCaseGroup.get(recipient_id)
                elif recipient_doc_type.startswith('CommCareCase'):
                    doc = CommCareCase.get(recipient_id)
                elif recipient_doc_type in ('CommCareUser', 'WebUser'):
                    doc = CouchUser.get_by_user_id(recipient_id)
                elif recipient_doc_type.startswith('Group'):
                    doc = Group.get(recipient_id)
            except Exception:
                pass

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

        contact_cache[recipient_id] = doc_info

        return doc_info
開發者ID:johan--,項目名稱:commcare-hq,代碼行數:29,代碼來源:sms.py

示例5: add_cases_to_case_group

def add_cases_to_case_group(domain, case_group_id, uploaded_data):
    response = {"errors": [], "success": []}
    try:
        case_group = CommCareCaseGroup.get(case_group_id)
    except ResourceNotFound:
        response["errors"].append(_("The case group was not found."))
        return response

    for row in uploaded_data:
        identifier = row.get("case_identifier")
        case = None
        if identifier is not None:
            case = get_case_by_identifier(domain, str(identifier))
        if not case:
            response["errors"].append(_("Could not find case with identifier '%s'." % identifier))
        elif case.doc_type != "CommCareCase":
            response["errors"].append(_("It looks like the case with identifier '%s' is deleted" % identifier))
        elif case._id in case_group.cases:
            response["errors"].append(_("A case with identifier %s already exists in this group." % identifier))
        else:
            case_group.cases.append(case._id)
            response["success"].append(_("Case with identifier '%s' has been added to this group." % identifier))

    if response["success"]:
        case_group.save()

    return response
開發者ID:puttarajubr,項目名稱:commcare-hq,代碼行數:27,代碼來源:utils.py

示例6: get_recipient_info

    def get_recipient_info(self, recipient_doc_type, recipient_id, contact_cache):
        if recipient_doc_type in ['SQLLocation']:
            return self.get_orm_recipient_info(recipient_doc_type, recipient_id, contact_cache)

        if recipient_id in contact_cache:
            return contact_cache[recipient_id]

        doc = None
        if recipient_id not in [None, ""]:
            try:
                if recipient_doc_type.startswith('CommCareCaseGroup'):
                    doc = CommCareCaseGroup.get(recipient_id)
                elif recipient_doc_type.startswith('CommCareCase'):
                    doc = CommCareCase.get(recipient_id)
                elif recipient_doc_type in ('CommCareUser', 'WebUser'):
                    doc = CouchUser.get_by_user_id(recipient_id)
                elif recipient_doc_type.startswith('Group'):
                    doc = Group.get(recipient_id)
            except Exception:
                pass

        doc_info = None
        if doc:
            try:
                doc_info = get_doc_info(doc.to_json(), self.domain)
            except DomainMismatchException:
                # This can happen, for example, if a WebUser was sent an SMS
                # and then they unsubscribed from the domain. If that's the
                # case, we'll just leave doc_info as None and no contact link
                # will be displayed.
                pass

        contact_cache[recipient_id] = doc_info

        return doc_info
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:35,代碼來源:sms.py

示例7: get_number_of_case_groups_in_domain

def get_number_of_case_groups_in_domain(domain):
    data = CommCareCaseGroup.get_db().view(
        'casegroups/groups_by_domain',
        startkey=[domain],
        endkey=[domain, {}],
        reduce=True
    ).first()
    return data['value'] if data else 0
開發者ID:puttarajubr,項目名稱:commcare-hq,代碼行數:8,代碼來源:dbaccessors.py

示例8: get_deleted_item_data

 def get_deleted_item_data(self, item_id):
     case_group = CommCareCaseGroup.get(item_id)
     item_data = self._get_item_data(case_group)
     case_group.soft_delete()
     return {
         'itemData': item_data,
         'template': 'deleted-group-template',
     }
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:8,代碼來源:views.py

示例9: clean

 def clean(self):
     cleaned_data = super(UpdateCaseGroupForm, self).clean()
     try:
         self.current_group = CommCareCaseGroup.get(self.cleaned_data.get('item_id'))
     except AttributeError:
         raise forms.ValidationError("You're not passing in the group's id!")
     except ResourceNotFound:
         raise forms.ValidationError("This case group was not found in our database!")
     return cleaned_data
開發者ID:johan--,項目名稱:commcare-hq,代碼行數:9,代碼來源:forms.py

示例10: clean

 def clean(self):
     cleaned_data = super(UpdateCaseGroupForm, self).clean()
     try:
         self.current_group = CommCareCaseGroup.get(self.cleaned_data.get('item_id'))
     except AttributeError:
         raise forms.ValidationError(_("Please include the case group ID."))
     except ResourceNotFound:
         raise forms.ValidationError(_("A case group was not found with that ID."))
     return cleaned_data
開發者ID:kkrampa,項目名稱:commcare-hq,代碼行數:9,代碼來源:forms.py

示例11: recipient

    def recipient(self):
        if self.recipient_type == self.RECIPIENT_TYPE_CASE:
            try:
                case = CaseAccessors(self.domain).get_case(self.recipient_id)
            except CaseNotFound:
                return None

            if case.domain != self.domain:
                return None

            return case
        elif self.recipient_type == self.RECIPIENT_TYPE_MOBILE_WORKER:
            user = CouchUser.get_by_user_id(self.recipient_id, domain=self.domain)
            if not isinstance(user, CommCareUser):
                return None

            return user
        elif self.recipient_type == self.RECIPIENT_TYPE_WEB_USER:
            user = CouchUser.get_by_user_id(self.recipient_id, domain=self.domain)
            if not isinstance(user, WebUser):
                return None

            return user
        elif self.recipient_type == self.RECIPIENT_TYPE_CASE_GROUP:
            try:
                group = CommCareCaseGroup.get(self.recipient_id)
            except ResourceNotFound:
                return None

            if group.domain != self.domain:
                return None

            return group
        elif self.recipient_type == self.RECIPIENT_TYPE_USER_GROUP:
            try:
                group = Group.get(self.recipient_id)
            except ResourceNotFound:
                return None

            if group.domain != self.domain:
                return None

            return group
        elif self.recipient_type == self.RECIPIENT_TYPE_LOCATION:
            location = SQLLocation.by_location_id(self.recipient_id)

            if location is None:
                return None

            if location.domain != self.domain:
                return None

            return location
        else:
            raise UnknownRecipientType(self.recipient_type)
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:55,代碼來源:models.py

示例12: setUpClass

 def setUpClass(cls):
     cls.domain = 'skbanskdjoasdkng'
     cls.cases = [
         CommCareCase(name='A', domain=cls.domain),
         CommCareCase(name='B', domain=cls.domain),
         CommCareCase(name='C', domain=cls.domain),
         CommCareCase(name='D', domain=cls.domain),
         CommCareCase(name='X', domain='bunny'),
     ]
     CommCareCase.get_db().bulk_save(cls.cases)
     cls.case_groups = [
         CommCareCaseGroup(name='alpha', domain=cls.domain,
                           cases=[cls.cases[0]._id, cls.cases[1]._id]),
         CommCareCaseGroup(name='beta', domain=cls.domain,
                           cases=[cls.cases[2]._id, cls.cases[3]._id]),
         CommCareCaseGroup(name='gamma', domain=cls.domain,
                           cases=[cls.cases[0]._id, cls.cases[3]._id]),
         CommCareCaseGroup(name='delta', domain=cls.domain,
                           cases=[cls.cases[1]._id, cls.cases[2]._id]),
     ]
     CommCareCaseGroup.get_db().bulk_save(cls.case_groups)
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:21,代碼來源:tests.py

示例13: get_case_group_meta_in_domain

def get_case_group_meta_in_domain(domain):
    """
    returns a list (id, name) tuples sorted by name

    ideal for creating a user-facing dropdown menu, etc.
    """
    return [(r['id'], r['key'][1]) for r in CommCareCaseGroup.view(
        'casegroups/groups_by_domain',
        startkey=[domain],
        endkey=[domain, {}],
        include_docs=False,
        reduce=False,
    ).all()]
開發者ID:puttarajubr,項目名稱:commcare-hq,代碼行數:13,代碼來源:dbaccessors.py

示例14: get_case_groups_in_domain

def get_case_groups_in_domain(domain, limit=None, skip=None):
    extra_kwargs = {}
    if limit is not None:
        extra_kwargs['limit'] = limit
    if skip is not None:
        extra_kwargs['skip'] = skip
    return CommCareCaseGroup.view(
        'casegroups/groups_by_domain',
        startkey=[domain],
        endkey=[domain, {}],
        include_docs=True,
        reduce=False,
        **extra_kwargs
    ).all()
開發者ID:puttarajubr,項目名稱:commcare-hq,代碼行數:14,代碼來源:dbaccessors.py

示例15: case_groups

 def case_groups(self):
     return [CommCareCaseGroup.get(g) for g in self.case_group_ids]
開發者ID:kkrampa,項目名稱:commcare-hq,代碼行數:2,代碼來源:__init__.py


注:本文中的corehq.apps.casegroups.models.CommCareCaseGroup類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。