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


Python models.CommTrackUser類代碼示例

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


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

示例1: get_location

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,代碼行數:8,代碼來源:__init__.py

示例2: save

 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,代碼行數:7,代碼來源:forms.py

示例3: update_commtrack_form

 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,代碼行數:7,代碼來源:users.py

示例4: location_fixture_generator

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,代碼行數:26,代碼來源:fixtures.py

示例5: save

 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,代碼行數:7,代碼來源:forms.py

示例6: _get_location

def _get_location(form):
    if 'location_id' in form.form:
        loc_id = form.form['location_id']
        loc = Location.get(loc_id)
    else:
        user_id = form['auth_context']['user_id']
        user = CommTrackUser.get(user_id)
        loc = user.location
    return loc
開發者ID:thedevelopermw,項目名稱:commcare-hq,代碼行數:9,代碼來源:__init__.py

示例7: send_soh_reminder

def send_soh_reminder(domain, date):
    sp_ids = set()
    for user in CommTrackUser.by_domain(domain):
        if user.is_active and user.location and user.location.location_type == 'FACILITY':
            sp = SupplyPointCase.get_by_location(user.location)
            if sp and not StockTransaction.objects.filter(case_id=sp._id, report__date__gte=date,
                                                          type='stockonhand').exists():
                if user.get_verified_number():
                        send_sms_to_verified_number(user.get_verified_number(), REMINDER_STOCKONHAND)
                        sp_ids.add(sp._id)
    update_statuses(sp_ids, SupplyPointStatusTypes.SOH_FACILITY, SupplyPointStatusValues.REMINDER_SENT)
開發者ID:dslowikowski,項目名稱:commcare-hq,代碼行數:11,代碼來源:stockonhand.py

示例8: send_supervision_reminder

def send_supervision_reminder(domain, date):
    sp_ids = set()
    for user in CommTrackUser.by_domain(domain):
        if user.is_active and user.location and user.location.location_type == 'FACILITY':
            sp = SupplyPointCase.get_by_location(user.location)
            if sp and not SupplyPointStatus.objects.filter(supply_point=sp._id,
                                                           status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY,
                                                           status_date__gte=date).exists():
                if user.get_verified_number():
                        send_sms_to_verified_number(user.get_verified_number(), REMINDER_SUPERVISION)
                        sp_ids.add(sp._id)
    update_statuses(sp_ids, SupplyPointStatusTypes.SUPERVISION_FACILITY, SupplyPointStatusValues.REMINDER_SENT)
開發者ID:SEL-Columbia,項目名稱:commcare-hq,代碼行數:12,代碼來源:supervision.py

示例9: save

    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,代碼行數:22,代碼來源:bulkupload.py

示例10: __init__

    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,代碼行數:13,代碼來源:sms.py

示例11: save

    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,代碼行數:13,代碼來源:forms.py

示例12: get_location_rows

def get_location_rows(domain):
    users = CommTrackUser.by_domain(domain)

    mappings = []
    for user in users:
        locations = user.locations
        for location in locations:
            mappings.append([
                user.raw_username,
                location.site_code,
                location.name
            ])

    return mappings
開發者ID:NoahCarnahan,項目名稱:commcare-hq,代碼行數:14,代碼來源:bulkupload.py

示例13: save

    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,代碼行數:37,代碼來源:bulkupload.py

示例14: bootstrap_user

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,代碼行數:24,代碼來源:util.py

示例15: __init__

    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,代碼行數:18,代碼來源:sms.py


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