• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python users.Users类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: modify

    def modify(self):
        userInput= self.getInput()

        userObj = Users.get(Users.id == int(userInput['id']))
        current_user = Users.get(Users.name == self.isLogin())   

        if userObj.id != current_user.id and not self.isAdmin():
            return self.error(msg = '权限不足!', url=self.makeUrl('/admin/users/list'))

        thumbnail_id = int(userInput['thumbnail']) if userInput.has_key('thumbnail') else 0
        if thumbnail_id:
            thumbnail_data = Images.get(Images.id == thumbnail_id).thumbnail
        else:
            import base64
            from imaging import imaging
            thumbnail_data = base64.b64encode(buffer(imaging.default_thumbnail()))

        try:
            userObj = Users.get(Users.id == int(userInput['id']))
            userObj.email = userInput['email']
            userObj.name = userInput['name']
            userObj.cellphone = userInput['cellphone']
            userObj.description = userInput['desc']
            userObj.gender = int(userInput['gender'])
            userObj.avatur = thumbnail_data
            if self.isAdmin():
                userObj.role = userInput['role']
            userObj.save()
        except Exception, e:
            return self.error(msg = '会员修改失败: %s' % e, url=self.makeUrl('/admin/users/list'))
开发者ID:XinMa1,项目名称:work,代码行数:30,代码来源:referer.py


示例2: index

def index(direction=None, user=None, date=None, page=1, items_per_page=10):
    '''List loans user has with other users'''

    current_user_id = session.get('logged_in_user')

    our_loans = Loans(current_user_id)
    our_users = Users(current_user_id)

    # fetch loans
    loans = our_loans.get_loans()

    # fetch users from connections from us
    users = our_users.get_connections()

    # provided user?
    if user:
        # valid slug?
        user_id = our_users.is_connection(slug=user)
        if user_id: loans = our_loans.get_loans(user_id=user_id)

    # provided a date range?
    date_range = translate_date_range(date)
    if date_range:
        loans = our_loans.get_loans(date_from=date_range['low'], date_to=date_range['high'])
    # date ranges for the template
    date_ranges = get_date_ranges()

    # provided a direction?
    if direction: loans = our_loans.get_loans(direction=direction)

    # build a paginator
    paginator = Pagination(loans, page, items_per_page, loans.count(),
                           loans.offset((page - 1) * items_per_page).limit(items_per_page))

    return render_template('admin_show_loans.html', **locals())
开发者ID:octavesalois,项目名称:FlaskBudget,代码行数:35,代码来源:loans.py


示例3: save

    def save(self):
        userInput = self.getInput()  
        # 只有admin才能新增用户
        if not self.isAdmin():
            return self.error(msg = '权限不足!', url=self.makeUrl('/admin/users/list'))

        thumbnail_id = int(userInput['thumbnail']) if userInput.has_key('thumbnail') else 0
        if thumbnail_id:
            thumbnail_data = Images.get(Images.id == thumbnail_id).thumbnail
        else:
            import base64
            from imaging import imaging
            thumbnail_data = base64.b64encode(buffer(imaging.default_thumbnail()))

        try:
            Users.create(
                cellphone = userInput['cellphone'],
                email = userInput['email'],
                name = userInput['name'],
                password = hashlib.md5(userInput['passwd']).hexdigest(),
                avatur = thumbnail_data,
                gender = int(userInput['gender']),
                description = userInput['desc'],
                role = int(userInput['role'])
            )
        except Exception, e:
            return self.error(msg = '会员保存失败: %s' % e, url=self.makeUrl('/admin/users/list'))
开发者ID:XinMa1,项目名称:work,代码行数:27,代码来源:referer.py


示例4: export

def export(direction=None, user=None, date=None):
    '''Export loan entries'''

    current_user_id = session.get('logged_in_user')

    our_loans = Loans(current_user_id)
    our_users = Users(current_user_id)

    # fetch loans
    loans = our_loans.get_loans()

    # fetch users from connections from us
    users = our_users.get_connections()

    # provided user?
    if user:
        # valid slug?
        user_id = our_users.is_connection(slug=user)
        if user_id: loans = our_loans.get_loans(user_id=user_id)

    # provided a date range?
    date_range = translate_date_range(date)
    if date_range:
        loans = our_loans.get_loans(date_from=date_range['low'], date_to=date_range['high'])
    # date ranges for the template
    date_ranges = get_date_ranges()

    # provided a direction?
    if direction: loans = our_loans.get_loans(direction=direction)

    response = make_response(render_template('admin_export_loans.html', **locals()))
    response.headers['Content-type'] = 'text/csv'
    response.headers['Content-disposition'] = 'attachment;filename=' + 'loans-' + str(today_date()) + '.csv'
    return response
开发者ID:octavesalois,项目名称:FlaskBudget,代码行数:34,代码来源:loans.py


示例5: connect_with_user

def connect_with_user():
    '''Make a connection with a 'normal' user'''

    error = None
    current_user_id = session.get('logged_in_user')

    if request.method == 'POST':
        # fetch values and check they are actually provided
        if 'key' in request.form:
            key_value = request.form['key']

            useri = Users(current_user_id)

            key_user_id = useri.validate_key(key_value)

            # valid key
            if key_user_id:
                # cannot connect to ourselves and make a connection that has already been made ;)
                if not key_user_id == current_user_id and not useri.is_connection(user_id=key_user_id):

                    # create connections from us to them and back
                    useri.add_connection(key_user_id)

                    flash('Connection made')

                else: error = 'I can haz myself impossible'
            else: error = 'Invalid key'
        else: error = 'You need to provide a key'

    return render_template('admin_connect_with_user.html', **locals())
开发者ID:egeriicw,项目名称:FlaskBudget,代码行数:30,代码来源:users.py


示例6: give

def give():
    '''Give a loan or pay someone back'''

    current_user_id = session.get('logged_in_user')

    our_accounts = Accounts(current_user_id)

    if request.method == 'POST':

        dict = __validate_give_loan_form()
        for key in dict.keys(): exec(key + " = dict['" + key + "']")

        # 'heavier' checks
        if not error:
            # valid amount?
            if is_float(amount):
                # valid date?
                if is_date(date):
                    # valid account?
                    if our_accounts.is_account(account_id=deduct_from_account):

                        # add our loans entry
                        our_loans = Loans(current_user_id)
                        our_loan_id = our_loans.add_loan(other_user_id=to_user, date=date, account_id=deduct_from_account,
                                     description=description, amount=-float(amount))

                        # add their loans entry
                        their_loans = Loans(to_user)
                        their_loan_id = their_loans.add_loan(other_user_id=current_user_id, date=date,
                                                           account_id=deduct_from_account, description=description,
                                                           amount=amount)

                        # generate slugs for the new loans
                        our_slugs = Slugs(current_user_id)
                        slug = our_slugs.add_slug(type='loan', object_id=our_loan_id, description=description)
                        their_slugs = Slugs(to_user)
                        their_slugs.add_slug(type='loan', object_id=their_loan_id, slug=slug)

                        their_accounts = Accounts(to_user)

                        # transfer money from/to respective accounts
                        our_accounts.modify_user_balance(account_id=deduct_from_account, amount=-float(amount))
                        their_accounts.modify_user_balance(amount=amount)

                        # fudge loan 'account' monies
                        our_accounts.modify_loan_balance(amount=amount, with_user_id=to_user)
                        their_accounts.modify_loan_balance(amount=-float(amount), with_user_id=current_user_id)

                        flash('Loan given')

                    else: error = 'Not a valid source account'
                else: error = 'Not a valid date'
            else: error = 'Not a valid amount'

    # fetch users from connections from us
    our_users = Users(current_user_id)
    users = our_users.get_connections()
    accounts = our_accounts.get_accounts()

    return render_template('admin_give_loan.html', **locals())
开发者ID:octavesalois,项目名称:FlaskBudget,代码行数:60,代码来源:loans.py


示例7: check

    def check(self):
        from web import form
        validList=(
            form.Textbox("username", form.regexp(r".{3,20}$", 'User name: 3-20 chars')),
            form.Password("password", form.regexp(r".{3,20}$", 'Password: 3-20 chars')),
        )

        if not self.validates(validList):
            return self.error(self.errorMessage)

        inputData = self.getInput()
        if config.ADMIN_USERNAME == inputData['username'] and config.ADMIN_PASSWORD == inputData['password']:
            self.setLogin(inputData['username'])
            return self.success(msg='管理员登陆成功', url=self.makeUrl('/admin'))
        else:
            if not self.isInstalled():
                return self.error(msg='用户登录失败, 系统未初始化!', url=self.makeUrl('/admin'))

            userName = inputData['username']
            password = hashlib.md5(inputData['password']).hexdigest()
            try:
                userObj = Users().select().where(Users.name == userName)
                if userObj.where(Users.name == userName, Users.password == password).exists() == False:
                    return self.error(msg='用户登录失败,请检查用户名和密码是否匹配', url=self.makeUrl('/admin'))
                self.setLogin(inputData['username'])
                return self.success(msg='用户登陆成功', url=self.makeUrl('/admin'))
            except  Users.DoesNotExist:
                return self.error(msg='用户登录失败,请检查用户名和密码是否匹配!', url=self.makeUrl('/admin'))
开发者ID:XinMa1,项目名称:work,代码行数:28,代码来源:referer.py


示例8: testAdd

 def testAdd(self):
     users = Users()
     before_count = len(users.all())
     self.assertTrue(users.add(users.new(), persist=False))
     after_count = len(users.all())
     self.assertGreater(after_count, before_count)
     self.assertEqual(before_count + 1, after_count)
开发者ID:masom,项目名称:Puck,代码行数:7,代码来源:test_users.py


示例9: get_key

def get_key():
    '''Get a user key for a logged in user'''

    u = Users(session.get('logged_in_user'))
    # fetch/generate key
    key = u.get_key()

    return make_response(key.key, 200)
开发者ID:egeriicw,项目名称:FlaskBudget,代码行数:8,代码来源:tests.py


示例10: testInit

    def testInit(self):
        users = Users()
        self.assertIsInstance(users, ModelCollection)
        self.assertGreater(users._items, 0)
        self.assertIsInstance(users.all(), list)

        for i in users.all():
            self.assertIsInstance(i, User)
开发者ID:masom,项目名称:Puck,代码行数:8,代码来源:test_users.py


示例11: register

def register():
	register_error = None
	form = RegisterFormExt(csrf_enabled=False)
	if request.method == 'POST' and form.validate():
		password = security.generate_password_hash(form.password.data, length=32)
		user = Users(username=form.username.data, password=password)
		user.put()
		return redirect(url_for('login'), code=302)
	return render_template('register.html', form=form, register_error=register_error)
开发者ID:jideobs,项目名称:flask-gae-ndb-starter,代码行数:9,代码来源:main.py


示例12: SignUpWidget

class SignUpWidget(QtGui.QWidget):

    _path = SIGN_UP_WIDGET

    def __init__(self, *args, **kwargs):
        super(SignUpWidget, self).__init__(*args, **kwargs)
        uic.loadUi(self._path, self)
        self.show()

        self.role_selector.currentIndexChanged\
            .connect(self.changed_role_selector)
        self._driver_form = DriverForm()
        self._company_form = CompanyForm()
        self.additional_data.addWidget(self._driver_form)
        self.additional_data.addWidget(self._company_form)
        self.role_selector.setCurrentIndex(0)
        self.changed_role_selector(0)
        self.sign_up.clicked.connect(self.sign_up_user)
        self.cancel.clicked.connect(self.cancel_sign_up)
        self.users = Users()

    def changed_role_selector(self, index):
        role = self.role_selector.itemText(index)
        if role == 'Driver':
            self.additional_data.setCurrentWidget(self._driver_form)
        else:
            self.additional_data.setCurrentWidget(self._company_form)

    def sign_up_user(self):
        login = self.login_input.text()
        password = self.password_input.text()
        repeated_password = self.repeated_password.text()
        data = self.additional_data.currentWidget().get_data()
        if data['success'] and password == repeated_password and len(login) > 0:
            role = self.role_selector.currentText()
            if role == 'Driver':
                self.users.register_driver(
                    login,
                    hashlib.sha224(password).hexdigest(),
                    data['capacity'],
                    data['location'],
                )
            else:
                self.users.register_organization(
                    login,
                    hashlib.sha224(password).hexdigest(),
                    data['name'],
                    data['location'],
                )
            self.parent().close_sign_up()
        else:
            self.error.setText('Something wrong with your form data.')

    def cancel_sign_up(self):
        self.parent().close_sign_up()
开发者ID:Belyashi,项目名称:LogisticTask,代码行数:55,代码来源:sign_up_controller.py


示例13: generate_key

def generate_key():
    '''Generate/get a user key for the current user'''

    current_user_id = session.get('logged_in_user')

    useri = Users(current_user_id)

    # fetch/generate key
    key = useri.get_key()

    return render_template('admin_generate_user_key.html', **locals())
开发者ID:egeriicw,项目名称:FlaskBudget,代码行数:11,代码来源:users.py


示例14: test_InsertQuery

    def test_InsertQuery(self):
        users = Users()
        entity = users.new()

        expected = OrderedDict([
            ('id', None), ('user_group', 'user'), ('username', None),
            ('name', None), ('email', None), ('password', None),
            ('virt_auth_data', None)
        ])
        data = users._generate_query_data(entity)
        self.assertEqual(expected, data)

        expected = 'INSERT INTO users(id,user_group,username,name,email,password,virt_auth_data) VALUES (?,?,?,?,?,?,?)'
        self.assertEqual(users._generate_insert_query(data), expected)
开发者ID:masom,项目名称:Puck,代码行数:14,代码来源:test_users.py


示例15: confirm_select_order

 def confirm_select_order(self):
     inputs = self.getInput()
     try:
         product = Products.get(Products.id == int(inputs['product']))
         user =Users.get(Users.name == self.isLogin())
         price = inputs['price']
         if inputs.has_key('add'):
             order = Orders.create(
                 owner = user,
                 price = price,
                 description = product.category.name,
             )
         else:
             if not inputs.has_key('selected'):
                 return self.orders_list()
             order = Orders.get(Orders.id == int(inputs['selected']))
         
         details = OrderDetails.create(
             name = product.category.name + "   "+product.diameter,
             product = product,
             count = user,
             price = price,
             ratio = 0.0,
             order = order,
         )
         return web.seeother(self.makeUrl('/wap/edit_price_sheet', {'id': order.id}))
     except Exception, e:
         print 'exc',e
         return self.error(msg='保存订单失败!')
开发者ID:XinMa1,项目名称:work,代码行数:29,代码来源:referer.py


示例16: save_my_information

 def save_my_information(self):
     inputs = web.input()
     try:
         try:
             if len(inputs['imgfile'])>10:
                 htmlimg = httpUploadedFile(inputs['imgfile'])
                 userimg=Images().create(
                     uuid =  htmlimg.uuid(),
                     description = self.htmlunquote("上传图片"),
                     thumbnail = self.wap_imgsave(htmlimg)
                     )
         except Exception, e:
             print e
             userimg=Images().get(Images.id == 1)
         
         user = Users.get(Users.id == int(inputs['userid']))
         user.name = inputs['name']
         user.cellphone = inputs['cellphone']
         user.gender = inputs['gender']
         user.email = inputs['email']
         user.job = inputs['job']
         user.avatur=userimg
         user.address = inputs['address']
         user.save()
         return self.my_information()
开发者ID:XinMa1,项目名称:work,代码行数:25,代码来源:referer.py


示例17: list

    def list(self):
        inputParams = self.getInput()
        page = int(inputParams['page']) if inputParams.has_key('page') else 1
        count = config.COUNT_PER_PAGE
        offset= (page-1)*count if page > 0 else 0

        current_user = Users.get(Users.name == self.isLogin())   
        usersList = Users().select()
        if not self.isAdmin():
            usersList = usersList.where(Users.id == current_user)

        usersList = usersList.order_by(Users.id.desc())
        pageString = self.getPageStr('/admin/users/list', page, count, usersList.count())
        self.privData['USERS_LIST'] = usersList
        self.privData['PAGE_STRING'] = pageString
        return self.display('usersList')
开发者ID:XinMa1,项目名称:work,代码行数:16,代码来源:referer.py


示例18: edit

    def edit(self):
        inputParams = self.getInput()
        album_id = int(inputParams['id'])
        album = Albums.get(Albums.id == album_id)

        current_user = Users.get(Users.name == self.isLogin())
        if current_user.id != album.owner.id and not self.isAdmin():
            return self.error(msg = '权限不足!', url=self.makeUrl('/admin/albums/list'))

        self.privData['ALBUM_ID'] =   album.id
        self.privData['ALBUM_NAME'] = album.name
        self.privData['ALBUM_DESC'] = album.description
        self.privData['ENABLE_SELECT_THUMBNAIL'] = False

        imagesList = Images().select()
        if not self.isAdmin():
            imagesList = imagesList.where(Images.owner == current_user)

        imagesList = imagesList.where(Images.album == album)
        if imagesList.count():
            self.privData['ENABLE_SELECT_THUMBNAIL'] = True
            self.privData['ALBUMS_LIST'] = [album]
            self.privData['IMG_ALBUMS_LIST'] = {album.id: imagesList}
            self.privData['CURRENT_IMG'] = imagesList[0]
            self.privData['CURRENT_ALBUM'] = album
            self.privData['SUBMIT_NAME'] = "thumbnail"

        return self.display('albumEdit')
开发者ID:XinMa1,项目名称:work,代码行数:28,代码来源:referer.py


示例19: add

    def add(self):
        chatroomsList = Chatrooms().select()

        userName = self.isLogin()
        if userName != 'admin':
            return self.error(msg = '权限不足!', url=self.makeUrl('/admin/chatrooms/list'))
        user = Users.get(Users.name == userName)
        albumsList = Albums().select().where(Albums.owner == user.id)
        imagesList = Images().select().where(Images.owner == user.id)

        if not albumsList.count():
            return self.error(msg = '请创建至少一个专辑!', url=self.makeUrl('/admin/chatrooms/list'))
        if not imagesList.count():
            return self.error(msg = '请创建至少一个图片!', url=self.makeUrl('/admin/chatrooms/list'))

        album_images_map = {}
        excluded_albums = []
        for album in albumsList:
            album_images = imagesList.where(Images.album == album.id)
            if album_images.count():
                album_images_map[album.id] = album_images
            else:
                excluded_albums.append(album.id)

        self.privData['ALBUMS_LIST'] = \
            [album for album in albumsList if album.id not in excluded_albums]
        self.privData['IMG_ALBUMS_LIST'] = album_images_map

        # 默认专辑为当前用户的第一个专辑
        self.privData['CURRENT_ALBUM'] = self.privData['ALBUMS_LIST'][0]
        # 默认图片为默认专辑的第一张图片
        self.privData['CURRENT_IMG'] = album_images_map[self.privData['CURRENT_ALBUM'].id][0]
        self.privData['SUBMIT_NAME'] = "thumbnail"

        return self.display('chatroomAdd')
开发者ID:XinMa1,项目名称:work,代码行数:35,代码来源:referer.py


示例20: update

    def update(self):
        inputParams= self.getInput() 
        group = Groups.get(Groups.id == int(inputParams['id']))
 
        current_user = Users.get(Users.name == self.isLogin())
        if current_user.id != group.owner.id and not self.isAdmin() or not current_user.role.type < 100:
            return self.error(msg = '权限不足!', url=self.makeUrl('/admin/groups/list'))

        try:
            group.regions = inputParams['regions']
            group.name = inputParams['name']
            group.owner = current_user
            group.phoneno = inputParams['phoneno']
            group.cellphone = inputParams['cellphone']
            group.faxno = inputParams['faxno']
            group.postcode = inputParams['postcode']
            group.contact = inputParams['contact']
            group.description = self.htmlunquote(inputParams['description'])
            group.thumbnail = int(inputParams['thumbnail'])
            group.team_description = self.htmlunquote(inputParams['team_description'])
            group.regions = inputParams['regions']
            group.service_modes = inputParams['service_modes']
            group.specials = inputParams['specials']
            group.swipeshow_album = int(inputParams['swipeshow_album'])
            group.groups_album = int(inputParams['groups_album'])
            group.price1 = float(inputParams['price1'])
            group.price2 = float(inputParams['price2'])
            group.address = inputParams['address']
            group.longitude = float(inputParams['longitude'])
            group.latitude = float(inputParams['latitude'])
            group.category = int(inputParams['category'])
            group.save()
        except Exception, e:
            return self.error(msg = '公司修改失败: %s' % e, url=self.makeUrl('/admin/groups/list'))
开发者ID:XinMa1,项目名称:work,代码行数:34,代码来源:referer.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python translator.get_options_for_model函数代码示例发布时间:2022-05-27
下一篇:
Python users.User类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap