本文整理汇总了Python中supysonic.web.store.find函数的典型用法代码示例。如果您正苦于以下问题:Python find函数的具体用法?Python find怎么用?Python find使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: search_id3
def search_id3():
query, artist_count, artist_offset, album_count, album_offset, song_count, song_offset = map(
request.args.get, [ 'query', 'artistCount', 'artistOffset', 'albumCount', 'albumOffset', 'songCount', 'songOffset' ])
try:
artist_count = int(artist_count) if artist_count else 20
artist_offset = int(artist_offset) if artist_offset else 0
album_count = int(album_count) if album_count else 20
album_offset = int(album_offset) if album_offset else 0
song_count = int(song_count) if song_count else 20
song_offset = int(song_offset) if song_offset else 0
except:
return request.error_formatter(0, 'Invalid parameter')
if not query:
return request.error_formatter(10, 'Missing query parameter')
artist_query = store.find(Artist, Artist.name.contains_string(query))[artist_offset : artist_offset + artist_count]
album_query = store.find(Album, Album.name.contains_string(query))[album_offset : album_offset + album_count]
song_query = store.find(Track, Track.title.contains_string(query))[song_offset : song_offset + song_count]
return request.formatter({ 'searchResult2': {
'artist': [ a.as_subsonic_artist(request.user) for a in artist_query ],
'album': [ a.as_subsonic_album(request.user) for a in album_query ],
'song': [ t.as_subsonic_child(request.user) for t in song_query ]
}})
开发者ID:glogiotatidis,项目名称:supysonic,代码行数:26,代码来源:search.py
示例2: new_search
def new_search():
query, artist_count, artist_offset, album_count, album_offset, song_count, song_offset = map(
request.args.get, [ 'query', 'artistCount', 'artistOffset', 'albumCount', 'albumOffset', 'songCount', 'songOffset' ])
try:
artist_count = int(artist_count) if artist_count else 20
artist_offset = int(artist_offset) if artist_offset else 0
album_count = int(album_count) if album_count else 20
album_offset = int(album_offset) if album_offset else 0
song_count = int(song_count) if song_count else 20
song_offset = int(song_offset) if song_offset else 0
except:
return request.error_formatter(0, 'Invalid parameter')
if not query:
return request.error_formatter(10, 'Missing query parameter')
parent = ClassAlias(Folder)
artist_query = store.find(parent, Folder.parent_id == parent.id, Track.folder_id == Folder.id, parent.name.contains_string(query)).config(distinct = True, offset = artist_offset, limit = artist_count)
album_query = store.find(Folder, Track.folder_id == Folder.id, Folder.name.contains_string(query)).config(distinct = True, offset = album_offset, limit = album_count)
song_query = store.find(Track, Track.title.contains_string(query))[song_offset : song_offset + song_count]
return request.formatter({ 'searchResult2': {
'artist': [ { 'id': str(a.id), 'name': a.name } for a in artist_query ],
'album': [ f.as_subsonic_child(request.user) for f in album_query ],
'song': [ t.as_subsonic_child(request.user) for t in song_query ]
}})
开发者ID:glogiotatidis,项目名称:supysonic,代码行数:27,代码来源:search.py
示例3: do_user_import
def do_user_import():
if not request.files['file']:
return render_template('importusers.html', admin = UserManager.get(store, session.get('userid'))[1].admin)
users = []
reader = csv.reader(request.files['file'])
for id, name, mail, password, salt, admin, lfmsess, lfmstatus in reader:
mail = None if mail == 'None' else mail
admin = admin == 'True'
lfmsess = None if lfmsess == 'None' else lfmsess
lfmstatus = lfmstatus == 'True'
user = User()
user.id = uuid.UUID(id)
user.name = name
user.password = password
user.salt = salt
user.admin = admin
user.lastfm_session = lfmsess
user.lastfm_status = lfmstatus
users.append(user)
store.find(User).remove()
for u in users:
store.add(u)
store.commit()
return redirect(url_for('user_index'))
开发者ID:hhm0,项目名称:supysonic,代码行数:29,代码来源:user.py
示例4: index
def index():
stats = {
'artists': store.find(Artist).count(),
'albums': store.find(Album).count(),
'tracks': store.find(Track).count()
}
return render_template('home.html', stats = stats, admin = UserManager.get(store, session.get('userid'))[1].admin)
开发者ID:andrenam,项目名称:supysonic,代码行数:7,代码来源:__init__.py
示例5: try_unstar
def try_unstar(ent, eid):
try:
uid = uuid.UUID(eid)
except:
return request.error_formatter(0, 'Invalid id')
store.find(ent, ent.user_id == request.user.id, ent.starred_id == uid).remove()
return None
开发者ID:hhm0,项目名称:supysonic,代码行数:8,代码来源:annotation.py
示例6: get_starred_id3
def get_starred_id3():
return request.formatter({
'starred2': {
'artist': [ sa.starred.as_subsonic_artist(request.user) for sa in store.find(StarredArtist, StarredArtist.user_id == User.id, User.name == request.username) ],
'album': [ sa.starred.as_subsonic_album(request.user) for sa in store.find(StarredAlbum, StarredAlbum.user_id == User.id, User.name == request.username) ],
'song': [ st.starred.as_subsonic_child(request.user) for st in store.find(StarredTrack, StarredTrack.user_id == User.id, User.name == request.username) ]
}
})
开发者ID:glogiotatidis,项目名称:supysonic,代码行数:8,代码来源:albums_songs.py
示例7: user_profile
def user_profile(uid):
if uid == 'me':
prefs = store.find(ClientPrefs, ClientPrefs.user_id == uuid.UUID(session.get('userid')))
return render_template('profile.html', user = UserManager.get(store, session.get('userid'))[1], api_key = config.get('lastfm', 'api_key'), clients = prefs, admin = UserManager.get(store, session.get('userid'))[1].admin)
else:
if not UserManager.get(store, session.get('userid'))[1].admin or not UserManager.get(store, uid)[0] is UserManager.SUCCESS:
return redirect(url_for('index'))
prefs = store.find(ClientPrefs, ClientPrefs.user_id == uuid.UUID(uid))
return render_template('profile.html', user = UserManager.get(store, uid)[1], api_key = config.get('lastfm', 'api_key'), clients = prefs, admin = UserManager.get(store, session.get('userid'))[1].admin)
开发者ID:hhm0,项目名称:supysonic,代码行数:9,代码来源:user.py
示例8: get_starred
def get_starred():
folders = store.find(StarredFolder, StarredFolder.user_id == User.id, User.name == request.username)
return request.formatter({
'starred': {
'artist': [ { 'id': str(sf.starred_id), 'name': sf.starred.name } for sf in folders.find(Folder.parent_id == StarredFolder.starred_id, Track.folder_id == Folder.id).config(distinct = True) ],
'album': [ sf.starred.as_subsonic_child(request.user) for sf in folders.find(Track.folder_id == StarredFolder.starred_id).config(distinct = True) ],
'song': [ st.starred.as_subsonic_child(request.user) for st in store.find(StarredTrack, StarredTrack.user_id == User.id, User.name == request.username) ]
}
})
开发者ID:glogiotatidis,项目名称:supysonic,代码行数:10,代码来源:albums_songs.py
示例9: list_playlists
def list_playlists():
query = store.find(Playlist, Or(Playlist.user_id == request.user.id, Playlist.public == True)).order_by(Playlist.name)
username = request.args.get('username')
if username:
if not request.user.admin:
return request.error_formatter(50, 'Restricted to admins')
query = store.find(Playlist, Playlist.user_id == User.id, User.name == username).order_by(Playlist.name)
return request.formatter({ 'playlists': { 'playlist': [ p.as_subsonic_playlist(request.user) for p in query ] } })
开发者ID:glogiotatidis,项目名称:supysonic,代码行数:11,代码来源:playlists.py
示例10: list_playlists
def list_playlists():
query = store.find(Playlist, Or(Playlist.user_id == request.user.id, Playlist.public == True)).order_by(
Playlist.name
)
username = request.values.get("username")
if username:
if not request.user.admin:
return request.error_formatter(50, "Restricted to admins")
query = store.find(Playlist, Playlist.user_id == User.id, User.name == username).order_by(Playlist.name)
return request.formatter({"playlists": {"playlist": [p.as_subsonic_playlist(request.user) for p in query]}})
开发者ID:spl0k,项目名称:supysonic,代码行数:13,代码来源:playlists.py
示例11: try_unstar
def try_unstar(starred_ent, eid):
""" Unstars an entity
:param starred_ent: class used for the db representation of the starring of the entity
:param eid: id of the entity to unstar
:return error dict, if any. None otherwise
"""
try:
uid = uuid.UUID(eid)
except:
return { 'code': 0, 'message': 'Invalid id {}'.format(eid) }
store.find(starred_ent, starred_ent.user_id == request.user.id, starred_ent.starred_id == uid).remove()
return None
开发者ID:andrenam,项目名称:supysonic,代码行数:15,代码来源:annotation.py
示例12: add_user
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,代码行数:30,代码来源:user.py
示例13: add_user_post
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,代码行数:27,代码来源:user.py
示例14: change_username_post
def change_username_post(uid):
code, user = UserManager.get(store, uid)
if code != UserManager.SUCCESS:
return redirect(url_for('index'))
username = request.form.get('user')
if username in ('', None):
flash('The username is required')
return render_template('change_username.html', user = user)
if user.name != username and store.find(User, User.name == username).one():
flash('This name is already taken')
return render_template('change_username.html', user = user)
if request.form.get('admin') is None:
admin = False
else:
admin = True
if user.name != username or user.admin != admin:
user.name = username
user.admin = admin
store.commit()
flash("User '%s' updated." % username)
else:
flash("No changes for '%s'." % username)
return redirect(url_for('user_profile', uid = uid))
开发者ID:andrenam,项目名称:supysonic,代码行数:27,代码来源:user.py
示例15: list_folders
def list_folders():
return request.formatter({
'musicFolders': {
'musicFolder': [ {
'id': str(f.id),
'name': f.name
} for f in store.find(Folder, Folder.root == True).order_by(Folder.name) ]
}
})
开发者ID:hhm0,项目名称:supysonic,代码行数:9,代码来源:browse.py
示例16: now_playing
def now_playing():
query = store.find(User, Track.id == User.last_play_id)
return request.formatter({
'nowPlaying': {
'entry': [ dict(
u.last_play.as_subsonic_child(request.user).items() +
{ 'username': u.name, 'minutesAgo': (now() - u.last_play_date).seconds / 60, 'playerId': 0 }.items()
) for u in query if u.last_play_date + timedelta(seconds = u.last_play.duration * 2) > now() ]
}
})
开发者ID:glogiotatidis,项目名称:supysonic,代码行数:11,代码来源:albums_songs.py
示例17: get_chat
def get_chat():
since = request.args.get('since')
try:
since = int(since) / 1000 if since else None
except:
return request.error_formatter(0, 'Invalid parameter')
query = store.find(ChatMessage).order_by(ChatMessage.time)
if since:
query = query.find(ChatMessage.time > since)
return request.formatter({ 'chatMessages': { 'chatMessage': [ msg.responsize() for msg in query ] }})
开发者ID:glogiotatidis,项目名称:supysonic,代码行数:12,代码来源:chat.py
示例18: old_search
def old_search():
artist, album, title, anyf, count, offset, newer_than = map(request.values.get, [ 'artist', 'album', 'title', 'any', 'count', 'offset', 'newerThan' ])
try:
count = int(count) if count else 20
offset = int(offset) if offset else 0
newer_than = int(newer_than) / 1000 if newer_than else 0
except:
return request.error_formatter(0, 'Invalid parameter')
min_date = datetime.fromtimestamp(newer_than)
if artist:
parent = ClassAlias(Folder)
query = store.find(parent, Folder.parent_id == parent.id, Track.folder_id == Folder.id, parent.name.contains_string(artist), parent.created > min_date).config(distinct = True)
elif album:
query = store.find(Folder, Track.folder_id == Folder.id, Folder.name.contains_string(album), Folder.created > min_date).config(distinct = True)
elif title:
query = store.find(Track, Track.title.contains_string(title), Track.created > min_date)
elif anyf:
folders = store.find(Folder, Folder.name.contains_string(anyf), Folder.created > min_date)
tracks = store.find(Track, Track.title.contains_string(anyf), Track.created > min_date)
res = list(folders[offset : offset + count])
if offset + count > folders.count():
toff = max(0, offset - folders.count())
tend = offset + count - folders.count()
res += list(tracks[toff : tend])
return request.formatter({ 'searchResult': {
'totalHits': folders.count() + tracks.count(),
'offset': offset,
'match': [ r.as_subsonic_child(request.user) if isinstance(r, Folder) else r.as_subsonic_child(request.user, request.prefs) for r in res ]
}})
else:
return request.error_formatter(10, 'Missing search parameter')
return request.formatter({ 'searchResult': {
'totalHits': query.count(),
'offset': offset,
'match': [ r.as_subsonic_child(request.user) if isinstance(r, Folder) else r.as_subsonic_child(request.user, request.prefs) for r in query[offset : offset + count] ]
}})
开发者ID:andrenam,项目名称:supysonic,代码行数:40,代码来源:search.py
示例19: rand_songs
def rand_songs():
size = request.values.get('size', '10')
genre, fromYear, toYear, musicFolderId = map(request.values.get, [ 'genre', 'fromYear', 'toYear', 'musicFolderId' ])
try:
size = int(size) if size else 10
fromYear = int(fromYear) if fromYear else None
toYear = int(toYear) if toYear else None
fid = uuid.UUID(musicFolderId) if musicFolderId else None
except:
return request.error_formatter(0, 'Invalid parameter format')
query = store.find(Track)
if fromYear:
query = query.find(Track.year >= fromYear)
if toYear:
query = query.find(Track.year <= toYear)
if genre:
query = query.find(Track.genre == genre)
if fid:
if not store.find(Folder, Folder.id == fid, Folder.root == True).one():
return request.error_formatter(70, 'Unknown folder')
query = query.find(Track.root_folder_id == fid)
count = query.count()
if not count:
return request.formatter({ 'randomSongs': {} })
tracks = []
for _ in xrange(size):
x = random.choice(xrange(count))
tracks.append(query[x])
return request.formatter({
'randomSongs': {
'song': [ t.as_subsonic_child(request.user, request.prefs) for t in tracks ]
}
})
开发者ID:andrenam,项目名称:supysonic,代码行数:39,代码来源:albums_songs.py
示例20: user_info
def user_info():
username = request.args.get('username')
if username is None:
return request.error_formatter(10, 'Missing username')
if username != request.username and not request.user.admin:
return request.error_formatter(50, 'Admin restricted')
user = store.find(User, User.name == username).one()
if user is None:
return request.error_formatter(0, 'Unknown user')
return request.formatter({ 'user': user.as_subsonic_user() })
开发者ID:glogiotatidis,项目名称:supysonic,代码行数:13,代码来源:user.py
注:本文中的supysonic.web.store.find函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论