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


Python UserManager.add方法代碼示例

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


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

示例1: setUp

# 需要導入模塊: from supysonic.managers.user import UserManager [as 別名]
# 或者: from supysonic.managers.user.UserManager import add [as 別名]
 def setUp(self):
     # Create an empty sqlite database in memory
     self.store = db.get_store("sqlite:")
     # Read schema from file
     with open('schema/sqlite.sql') as sql:
         schema = sql.read()
     # Create tables on memory database
     for command in schema.split(';'):
         self.store.execute(command)
     # Create some users
     self.assertEqual(UserManager.add(self.store, 'alice', 'alice', '[email protected]', True), UserManager.SUCCESS)
     self.assertEqual(UserManager.add(self.store, 'bob', 'bob', '[email protected]', False), UserManager.SUCCESS)
     self.assertEqual(UserManager.add(self.store, 'charlie', 'charlie', '[email protected]', False), UserManager.SUCCESS)
開發者ID:hhm0,項目名稱:supysonic,代碼行數:15,代碼來源:test_manager_user.py

示例2: setUp

# 需要導入模塊: from supysonic.managers.user import UserManager [as 別名]
# 或者: from supysonic.managers.user.UserManager import add [as 別名]
    def setUp(self):
        # Create an empty sqlite database in memory
        self.store = db.get_store("sqlite:")
        # Read schema from file
        with io.open('schema/sqlite.sql', 'r') as sql:
            schema = sql.read()
            # Create tables on memory database
            for command in schema.split(';'):
                self.store.execute(command)

        # Create some users
        self.assertEqual(UserManager.add(self.store, 'alice', 'ALICE', '[email protected]', True), UserManager.SUCCESS)
        self.assertEqual(UserManager.add(self.store, 'bob', 'BOB', '[email protected]', False), UserManager.SUCCESS)
        self.assertEqual(UserManager.add(self.store, 'charlie', 'CHARLIE', '[email protected]', False), UserManager.SUCCESS)

        folder = db.Folder()
        folder.name = 'Root'
        folder.path = 'tests/assets'
        folder.root = True

        artist = db.Artist()
        artist.name = 'Artist'

        album = db.Album()
        album.name = 'Album'
        album.artist = artist

        track = db.Track()
        track.title = 'Track'
        track.disc = 1
        track.number = 1
        track.duration = 1
        track.artist = artist
        track.album = album
        track.path = 'tests/assets/empty'
        track.folder = folder
        track.root_folder = folder
        track.duration = 2
        track.content_type = 'audio/mpeg'
        track.bitrate = 320
        track.last_modification = 0
        self.store.add(track)
        self.store.commit()

        playlist = db.Playlist()
        playlist.name = 'Playlist'
        playlist.user = self.store.find(db.User, db.User.name == 'alice').one()
        playlist.add(track)
        self.store.add(playlist)
        self.store.commit()
開發者ID:andrenam,項目名稱:supysonic,代碼行數:52,代碼來源:test_manager_user.py

示例3: add_user

# 需要導入模塊: from supysonic.managers.user import UserManager [as 別名]
# 或者: from supysonic.managers.user.UserManager import add [as 別名]
def add_user():
	if request.method == 'GET':
		return render_template('adduser.html', admin = UserManager.get(store, session.get('userid'))[1].admin)

	error = False
	(name, passwd, passwd_confirm, mail, admin) = map(request.form.get, [ 'user', 'passwd', 'passwd_confirm', 'mail', 'admin' ])
	if name in (None, ''):
		flash('The name is required.')
		error = True
	if passwd in (None, ''):
		flash('Please provide a password.')
		error = True
	elif passwd != passwd_confirm:
		flash("The passwords don't match.")
		error = True

	if admin is None:
		admin = True if store.find(User, User.admin == True).count() == 0 else False
	else:
		admin = True

	if not error:
		status = UserManager.add(store, name, passwd, mail, admin)
		if status == UserManager.SUCCESS:
			flash("User '%s' successfully added" % name)
			return redirect(url_for('user_index'))
		else:
			flash(UserManager.error_str(status))

	return render_template('adduser.html', admin = UserManager.get(store, session.get('userid'))[1].admin)
開發者ID:hhm0,項目名稱:supysonic,代碼行數:32,代碼來源:user.py

示例4: add_user_post

# 需要導入模塊: from supysonic.managers.user import UserManager [as 別名]
# 或者: from supysonic.managers.user.UserManager import add [as 別名]
def add_user_post():
    error = False
    (name, passwd, passwd_confirm, mail, admin) = map(request.form.get, [ 'user', 'passwd', 'passwd_confirm', 'mail', 'admin' ])
    if not name:
        flash('The name is required.')
        error = True
    if not passwd:
        flash('Please provide a password.')
        error = True
    elif passwd != passwd_confirm:
        flash("The passwords don't match.")
        error = True

    if admin is None:
        admin = True if store.find(User, User.admin == True).count() == 0 else False
    else:
        admin = True

    if not error:
        status = UserManager.add(store, name, passwd, mail, admin)
        if status == UserManager.SUCCESS:
            flash("User '%s' successfully added" % name)
            return redirect(url_for('user_index'))
        else:
            flash(UserManager.error_str(status))

    return add_user_form()
開發者ID:andrenam,項目名稱:supysonic,代碼行數:29,代碼來源:user.py

示例5: user_add

# 需要導入模塊: from supysonic.managers.user import UserManager [as 別名]
# 或者: from supysonic.managers.user.UserManager import add [as 別名]
def user_add():
	if not request.user.admin:
		return request.error_formatter(50, 'Admin restricted')

	username, password, email, admin = map(request.args.get, [ 'username', 'password', 'email', 'adminRole' ])
	if not username or not password or not email:
		return request.error_formatter(10, 'Missing parameter')
	admin = True if admin in (True, 'True', 'true', 1, '1') else False

	status = UserManager.add(store, username, password, email, admin)
	if status == UserManager.NAME_EXISTS:
		return request.error_formatter(0, 'There is already a user with that username')

	return request.formatter({})
開發者ID:glogiotatidis,項目名稱:supysonic,代碼行數:16,代碼來源:user.py

示例6: open

# 需要導入模塊: from supysonic.managers.user import UserManager [as 別名]
# 或者: from supysonic.managers.user.UserManager import add [as 別名]
from supysonic.managers.user import UserManager

import sys
import unittest
import uuid

# Create an empty sqlite database in memory
store = db.get_store("sqlite:")
# Read schema from file
with open('schema/sqlite.sql') as sql:
    schema = sql.read()
# Create tables on memory database
for command in schema.split(';'):
    store.execute(command)
# Create some users
UserManager.add(store, 'alice', 'alice', '[email protected]', True)
UserManager.add(store, 'bob', 'bob', '[email protected]', False)
UserManager.add(store, 'charlie', 'charlie', '[email protected]', False)

# Create a mockup of web
from flask import Flask
app = Flask(__name__)
class web():
    app = app
    store = store
sys.modules['supysonic.web'] = web()

# Import module and set app in test mode
import supysonic.api

class ApiTestCase(unittest.TestCase):
開發者ID:hhm0,項目名稱:supysonic,代碼行數:33,代碼來源:test_api.py

示例7: test_add_user

# 需要導入模塊: from supysonic.managers.user import UserManager [as 別名]
# 或者: from supysonic.managers.user.UserManager import add [as 別名]
 def test_add_user(self):
     # Create duplicate
     self.assertEqual(UserManager.add(self.store, 'alice', 'alice', '[email protected]', True), UserManager.NAME_EXISTS)
開發者ID:hhm0,項目名稱:supysonic,代碼行數:5,代碼來源:test_manager_user.py

示例8: test_add_user

# 需要導入模塊: from supysonic.managers.user import UserManager [as 別名]
# 或者: from supysonic.managers.user.UserManager import add [as 別名]
    def test_add_user(self):
        # Added in setUp()
        self.assertEqual(self.store.find(db.User).count(), 3)

        # Create duplicate
        self.assertEqual(UserManager.add(self.store, 'alice', 'Alic3', '[email protected]', True), UserManager.NAME_EXISTS)
開發者ID:andrenam,項目名稱:supysonic,代碼行數:8,代碼來源:test_manager_user.py


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