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


Python CommTrackUser.wrap方法代码示例

本文整理汇总了Python中corehq.apps.commtrack.models.CommTrackUser.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python CommTrackUser.wrap方法的具体用法?Python CommTrackUser.wrap怎么用?Python CommTrackUser.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.apps.commtrack.models.CommTrackUser的用法示例。


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

示例1: get_location

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
def get_location(domain, user, site_code):
    location = None
    if user and CommTrackUser.wrap(user.to_json()).location:
        loc = CommTrackUser.wrap(user.to_json()).location
        location = get_supply_point(domain, loc=loc)
    elif site_code:
        location = get_supply_point(domain, site_code=site_code)
    return location
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:10,代码来源:__init__.py

示例2: save

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
 def save(self, user):
     commtrack_user = CommTrackUser.wrap(user.to_json())
     location_id = self.cleaned_data["supply_point"]
     if location_id:
         loc = Location.get(location_id)
         commtrack_user.clear_locations()
         commtrack_user.add_location(loc, create_sp_if_missing=True)
开发者ID:pawelreise,项目名称:commcare-hq,代码行数:9,代码来源:forms.py

示例3: save

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
 def save(self, user):
     commtrack_user = CommTrackUser.wrap(user.to_json())
     location_id = self.cleaned_data['supply_point']
     if location_id:
         loc = Location.get(location_id)
         commtrack_user.clear_locations()
         commtrack_user.add_location(loc)
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:9,代码来源:forms.py

示例4: update_commtrack_form

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
 def update_commtrack_form(self):
     if self.request.method == "POST" and self.request.POST['form_type'] == "commtrack":
         return CommtrackUserForm(self.request.POST, domain=self.domain)
     # currently only support one location on the UI
     linked_loc = CommTrackUser.wrap(self.editable_user.to_json()).location
     initial_id = linked_loc._id if linked_loc else None
     return CommtrackUserForm(domain=self.domain, initial={'supply_point': initial_id})
开发者ID:gmimano,项目名称:commcaretest,代码行数:9,代码来源:users.py

示例5: location_fixture_generator

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
def location_fixture_generator(user, version, last_sync):
    project = user.project
    if (not project or not project.commtrack_enabled
        or not project.commtrack_settings
        or not project.commtrack_settings.sync_location_fixtures):
            return []

    rewrapped_user = CommTrackUser.wrap(user.to_json())
    location_db = _location_footprint(rewrapped_user.locations)

    if not should_sync_locations(last_sync, location_db):
        return []

    root = ElementTree.Element('fixture',
                               {'id': 'commtrack:locations',
                                'user_id': user.user_id})

    loc_types = project.commtrack_settings.location_types
    type_to_slug_mapping = dict((ltype.name, ltype.code) for ltype in loc_types)

    def location_type_lookup(location_type):
        return type_to_slug_mapping.get(location_type, unicode_slug(location_type))

    root_locations = filter(lambda loc: loc.parent_id is None, location_db.by_id.values())
    _append_children(root, location_db, root_locations, location_type_lookup)
    return [root]
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:28,代码来源:fixtures.py

示例6: __init__

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
    def __init__(self, domain, v):
        self.domain = domain
        self.v = v

        self.location = None
        u = v.owner
        if domain.commtrack_enabled:
            # currently only support one location on the UI
            linked_loc = CommTrackUser.wrap(u.to_json()).location
            if linked_loc:
                self.location = get_supply_point(self.domain.name, loc=linked_loc)['case']

        self.C = domain.commtrack_settings
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:15,代码来源:sms.py

示例7: save

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
    def save(self, user):
        commtrack_user = CommTrackUser.wrap(user.to_json())
        location_id = self.cleaned_data['supply_point']
        if location_id:
            loc = Location.get(location_id)

            commtrack_user.clear_locations()
            commtrack_user.add_location(loc, create_sp_if_missing=True)

            # add the supply point case id to user data fields
            # so that the phone can auto select
            supply_point = SupplyPointCase.get_by_location(loc)
            user.user_data['commtrack-supply-point'] = supply_point._id
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:15,代码来源:forms.py

示例8: setUp

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
    def setUp(self):
        super(UserLocMapTest, self).setUp()

        self.user = CommCareUser.create(
            self.domain.name,
            'commcareuser',
            'password',
            phone_numbers=['123123'],
            user_data={},
            first_name='test',
            last_name='user'
        )
        self.ct_user = CommTrackUser.wrap(self.user.to_json())

        self.loc = make_loc('secondloc')
        self.sp = make_supply_point(self.domain, self.loc)
        self.cache = LocationCache()
        self.mapping = UserLocMapping(self.user.username, self.user.domain, self.cache)
开发者ID:rigambhir,项目名称:commcare-hq,代码行数:20,代码来源:bulk_upload.py

示例9: __init__

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
    def __init__(self, domain, v):
        self.domain = domain
        self.v = v

        self.location = None
        u = v.owner

        if domain.commtrack_enabled:
            # if user is not actually a user, we let someone else process
            if not isinstance(u, CouchUser):
                raise NotAUserClassError

            # currently only support one location on the UI
            linked_loc = CommTrackUser.wrap(u.to_json()).location
            if linked_loc:
                self.location = get_supply_point(self.domain.name, loc=linked_loc)

        self.C = domain.commtrack_settings
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:20,代码来源:sms.py

示例10: test_location_migration

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
    def test_location_migration(self):
        user = CommCareUser.create(
            self.domain.name,
            'commcareuser',
            'password',
            phone_numbers=['123123'],
            user_data={},
            first_name='test',
            last_name='user'
        )

        loc = make_loc('someloc')
        make_supply_point(self.domain.name, loc)

        user.commtrack_location = loc._id
        ct_user = CommTrackUser.wrap(user.to_json())

        self.assertEqual(1, len(ct_user.locations))
        self.assertEqual('someloc', ct_user.locations[0].name)
        self.assertFalse(hasattr(ct_user, 'commtrack_location'))
开发者ID:dslowikowski,项目名称:commcare-hq,代码行数:22,代码来源:test_locations.py

示例11: location_fixture_generator

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
def location_fixture_generator(user, version, case_sync_op=None, last_sync=None):
    """
    By default this will generate a fixture for the users
    location and it's "footprint", meaning the path
    to a root location through parent hierarchies.

    There is an admin feature flag that will make this generate
    a fixture with ALL locations for the domain.
    """
    project = user.project
    if (not project or not project.commtrack_enabled
        or not project.commtrack_settings
        or not project.commtrack_settings.sync_location_fixtures):
            return []

    rewrapped_user = CommTrackUser.wrap(user.to_json())
    if toggles.SYNC_ALL_LOCATIONS.enabled(user.domain):
        location_db = _location_footprint(Location.by_domain(user.domain))
    else:
        location_db = _location_footprint(rewrapped_user.locations)

    if not should_sync_locations(last_sync, location_db):
        return []

    root = ElementTree.Element('fixture',
                               {'id': 'commtrack:locations',
                                'user_id': user.user_id})

    loc_types = project.commtrack_settings.location_types
    type_to_slug_mapping = dict((ltype.name, ltype.code) for ltype in loc_types)

    def location_type_lookup(location_type):
        return type_to_slug_mapping.get(location_type, unicode_slug(location_type))

    if toggles.SYNC_ALL_LOCATIONS.enabled(user.domain):
        root_locations = Location.root_locations(user.domain)
    else:
        root_locations = filter(lambda loc: loc.parent_id is None, location_db.by_id.values())

    _append_children(root, location_db, root_locations, location_type_lookup)
    return [root]
开发者ID:dslowikowski,项目名称:commcare-hq,代码行数:43,代码来源:fixtures.py

示例12: save

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
    def save(self):
        """
        Calculate which locations need added or removed, then submit
        one caseblock to handle this
        """
        user = CommTrackUser.wrap(CommTrackUser.get_by_username(self.username).to_json())
        current_locations = user.locations
        current_location_codes = [loc.site_code for loc in current_locations]

        commit_list = {}
        for loc in self.to_add:
            if loc not in current_location_codes:
                sp = self.get_supply_point_from_location(loc)
                commit_list.update(user.supply_point_index_mapping(sp))

        for loc in self.to_remove:
            if loc in current_location_codes:
                sp = self.get_supply_point_from_location(loc)
                commit_list.update(user.supply_point_index_mapping(sp, True))

        if commit_list:
            submit_mapping_case_block(user, commit_list)
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:24,代码来源:bulkupload.py

示例13: save

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
    def save(self):
        """
        Calculate which locations need added or removed, then submit
        one caseblock to handle this
        """
        user = CommTrackUser.get_by_username(self.username)
        if not user:
            raise UserUploadError(_('no username with {} found!'.format(self.username)))

        # have to rewrap since we need to force it to a commtrack user
        user = CommTrackUser.wrap(user.to_json())
        current_locations = user.locations
        current_location_codes = [loc.site_code for loc in current_locations]

        commit_list = {}
        messages = []
        def _add_loc(loc, clear=False):
            sp = self.get_supply_point_from_location(loc)
            if sp is None:
                messages.append(_("No supply point found for location '{}'. "
                   "Make sure the location type is not set to administrative only "
                   "and that the location has a valid sms code."
                ).format(loc or ''))
            else:
                commit_list.update(user.supply_point_index_mapping(sp, clear))

        for loc in self.to_add:
            if loc not in current_location_codes:
                _add_loc(loc)
        for loc in self.to_remove:
            if loc in current_location_codes:
                _add_loc(loc, clear=True)

        if commit_list:
            submit_mapping_case_block(user, commit_list)

        return messages
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:39,代码来源:bulkupload.py

示例14: bootstrap_user

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
def bootstrap_user(setup, username=TEST_USER, domain=TEST_DOMAIN,
                   phone_number=TEST_NUMBER, password=TEST_PASSWORD,
                   backend=TEST_BACKEND, first_name='', last_name='',
                   home_loc=None, user_data=None,
                   ):
    user_data = user_data or {}
    user = CommTrackUser.create(
        domain,
        username,
        password,
        phone_numbers=[TEST_NUMBER],
        user_data=user_data,
        first_name=first_name,
        last_name=last_name
    )
    if home_loc == setup.loc.site_code:
        if not SupplyPointCase.get_by_location(setup.loc):
            make_supply_point(domain, setup.loc)

        user.add_location(setup.loc)
        user.save()

    user.save_verified_number(domain, phone_number, verified=True, backend_id=backend)
    return CommTrackUser.wrap(user.to_json())
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:26,代码来源:util.py

示例15: add_location

# 需要导入模块: from corehq.apps.commtrack.models import CommTrackUser [as 别名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import wrap [as 别名]
def add_location(user, location_id):
    commtrack_user = CommTrackUser.wrap(user.to_json())
    if location_id:
        loc = Location.get(location_id)
        commtrack_user.clear_locations()
        commtrack_user.add_location(loc, create_sp_if_missing=True)
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:8,代码来源:commtrack.py


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