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


Python UserModel.get方法代碼示例

本文整理匯總了Python中kallithea.model.user.UserModel.get方法的典型用法代碼示例。如果您正苦於以下問題:Python UserModel.get方法的具體用法?Python UserModel.get怎麽用?Python UserModel.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在kallithea.model.user.UserModel的用法示例。


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

示例1: update

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import get [as 別名]
    def update(self, id):
        """PUT /users/id: Update an existing item"""
        # Forms posted to this method should contain a hidden field:
        #    <input type="hidden" name="_method" value="PUT" />
        # Or using helpers:
        #    h.form(url('update_user', id=ID),
        #           method='put')
        # url('user', id=ID)
        c.active = 'profile'
        user_model = UserModel()
        c.user = user_model.get(id)
        c.extern_type = c.user.extern_type
        c.extern_name = c.user.extern_name
        c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
        _form = UserForm(edit=True, old_data={'user_id': id,
                                              'email': c.user.email})()
        form_result = {}
        try:
            form_result = _form.to_python(dict(request.POST))
            skip_attrs = ['extern_type', 'extern_name']
            #TODO: plugin should define if username can be updated
            if c.extern_type != kallithea.EXTERN_TYPE_INTERNAL:
                # forbid updating username for external accounts
                skip_attrs.append('username')

            user_model.update(id, form_result, skip_attrs=skip_attrs)
            usr = form_result['username']
            action_logger(self.authuser, 'admin_updated_user:%s' % usr,
                          None, self.ip_addr, self.sa)
            h.flash(_('User updated successfully'), category='success')
            Session().commit()
        except formencode.Invalid, errors:
            defaults = errors.value
            e = errors.error_dict or {}
            defaults.update({
                'create_repo_perm': user_model.has_perm(id,
                                                        'hg.create.repository'),
                'fork_repo_perm': user_model.has_perm(id, 'hg.fork.repository'),
                '_method': 'put'
            })
            return htmlfill.render(
                render('admin/users/user_edit.html'),
                defaults=defaults,
                errors=e,
                prefix_error=False,
                encoding="UTF-8",
                force_defaults=False)
開發者ID:zhumengyuan,項目名稱:kallithea,代碼行數:49,代碼來源:users.py

示例2: __init__

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import get [as 別名]
    def __init__(self, user_id=None, dbuser=None, authenticating_api_key=None,
            is_external_auth=False):

        self.is_authenticated = False
        self.is_external_auth = is_external_auth
        self.authenticating_api_key = authenticating_api_key

        user_model = UserModel()
        self._default_user = User.get_default_user(cache=True)

        # These attributes will be overridden by fill_data, below, unless the
        # requested user cannot be found and the default anonymous user is
        # not enabled.
        self.user_id = None
        self.username = None
        self.api_key = None
        self.name = ''
        self.lastname = ''
        self.email = ''
        self.admin = False
        self.inherit_default_permissions = False

        # Look up database user, if necessary.
        if user_id is not None:
            log.debug('Auth User lookup by USER ID %s', user_id)
            dbuser = user_model.get(user_id)
        else:
            # Note: dbuser is allowed to be None.
            log.debug('Auth User lookup by database user %s', dbuser)

        is_user_loaded = self._fill_data(dbuser)

        # If user cannot be found, try falling back to anonymous.
        if not is_user_loaded:
            is_user_loaded =  self._fill_data(self._default_user)

        self.is_default_user = (self.user_id == self._default_user.user_id)
        self.is_anonymous = not is_user_loaded or self.is_default_user

        if not self.username:
            self.username = 'None'

        log.debug('Auth User is now %s', self)
開發者ID:t-kenji,項目名稱:kallithea-mirror,代碼行數:45,代碼來源:auth.py

示例3: update

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import get [as 別名]
    def update(self, id):
        user_model = UserModel()
        user = user_model.get(id)
        _form = UserForm(edit=True, old_data={'user_id': id,
                                              'email': user.email})()
        form_result = {}
        try:
            form_result = _form.to_python(dict(request.POST))
            skip_attrs = ['extern_type', 'extern_name',
                         ] + auth_modules.get_managed_fields(user)

            user_model.update(id, form_result, skip_attrs=skip_attrs)
            usr = form_result['username']
            action_logger(request.authuser, 'admin_updated_user:%s' % usr,
                          None, request.ip_addr)
            h.flash(_('User updated successfully'), category='success')
            Session().commit()
        except formencode.Invalid as errors:
            defaults = errors.value
            e = errors.error_dict or {}
            defaults.update({
                'create_repo_perm': user_model.has_perm(id,
                                                        'hg.create.repository'),
                'fork_repo_perm': user_model.has_perm(id, 'hg.fork.repository'),
            })
            return htmlfill.render(
                self._render_edit_profile(user),
                defaults=defaults,
                errors=e,
                prefix_error=False,
                encoding="UTF-8",
                force_defaults=False)
        except Exception:
            log.error(traceback.format_exc())
            h.flash(_('Error occurred during update of user %s') \
                    % form_result.get('username'), category='error')
        raise HTTPFound(location=url('edit_user', id=id))
開發者ID:t-kenji,項目名稱:kallithea-mirror,代碼行數:39,代碼來源:users.py


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