本文整理汇总了Python中Cheetah.Template.Template.songs方法的典型用法代码示例。如果您正苦于以下问题:Python Template.songs方法的具体用法?Python Template.songs怎么用?Python Template.songs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cheetah.Template.Template
的用法示例。
在下文中一共展示了Template.songs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_songs
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import songs [as 别名]
def list_songs(self, artists=None, albums=None, query=None, output='json'):
result = {}
if albums and not artists:
albums = albums.split(',')
for album in albums:
for artist in self.relationships:
if album in self.relationships[artist]:
for song in self.relationships[artist][album]:
result[song] = self.songs[song]
if artists and not albums:
artists = artists.split(',')
for artist in artists:
for album in self.relationships[artist]:
for song in self.relationships[artist][album]:
result[song] = self.songs[song]
if (artists != None) and (albums != None):
artists = artists.split(',')
albums = albums.split(',')
for album in albums:
for artist in artists:
try:
for song in self.relationships[artist][album]:
result[song] = self.songs[song]
except:
pass
if query:
filter_result = {}
if not result:
result = self.songs
for song in result:
if query.lower() in result[song]['artist'].lower() and song not in filter_result:
filter_result[song] = result[song]
elif query.lower() in result[song]['album'].lower() and song not in filter_result:
filter_result[song] = result[song]
elif query.lower() in result[song]['title'].lower() and song not in filter_result:
filter_result[song] = result[song]
result = filter_result
if output =='json':
return str(result)
template = Template(file=os.path.join(self._path, 'templates/list_songs.tmpl'))
template.songs = result
return template.respond()
示例2: list_songs
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import songs [as 别名]
def list_songs(self, artists=None ,albums=None, start=None, length=None,
query=None, list_all=False, archive=False, output='json'):
logger.debug("%s (%s)\tlist_songs(artists=%s, albums=%s, start=%s, length=%s, query=%s, list_all=%s, archive=%s, output=%s)\tHeaders: %s" % (utils.find_originating_host(cherrypy.request.headers), cherrypy.request.login, artists, albums, start, length, query, list_all, archive, output, cherrypy.request.headers))
if not list_all and not artists and not albums and not query and not archive:
songs = []
else:
if artists:
artists = artists.split(',')
if albums:
albums = albums.split(',')
songs = self.library.songs(artists, albums, query)
#log_message = "%s (%s) is " % (cherrypy.request.login, utils.find_originating_host(cherrypy.request.headers))
#if query:
# log_message += 'searching for "%s".' % query
#elif artists or albums:
# log_message += "browsing "
# if artists and not albums:
# log_message += "albums by %s." % ', '.join(self.library.artists(artists, query))
# elif albums:
# log_message += "%s by %s." % (', '.join(self.library.albums(artists, query)), ', '.join(self.library.artists(artists, albums, query)))
#if not archive and not list_all:
# logger.info(log_message)
if start and length:
start = int(start)
end = int(length) + start
if len(songs) - 1 < end:
end = -1
songs = songs[start:end]
songs.sort(key=itemgetter('albumartist', 'album', 'date', 'discnumber', 'tracknumber'))
if output == 'json':
cherrypy.response.headers['Content-Type'] = 'application/json'
return json.dumps({'songs': songs})
elif output == 'html':
template = Template(file=os.path.join(cfg['THEME_DIR'], 'list_songs.tmpl'))
template.songs = songs
return template.respond()
else:
raise cherrypy.HTTPError(501,'Not Implemented')
示例3: index
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import songs [as 别名]
def index(self):
songs = db.selectSongs()
t = Template(file=tempdir + 'songs.tmpl')
t.songs = songs
return _tostr(t)
示例4: index
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import songs [as 别名]
def index(self):
template = Template(file=os.path.join(self._path, 'templates/index.tmpl'))
template.songs = self.songs
return template.respond()