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


Python users.Users类代码示例

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


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


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