本文整理汇总了Python中models.Playlist类的典型用法代码示例。如果您正苦于以下问题:Python Playlist类的具体用法?Python Playlist怎么用?Python Playlist使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Playlist类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_playlist
def create_playlist():
playlist_json = request.json
playlist = Playlist(request.json['name'])
playlist.user_id = session['user_id']
playlist.save()
g.user.add_playlist(playlist)
return ""
开发者ID:mcherkassky,项目名称:listen,代码行数:9,代码来源:__init__.py
示例2: add
def add(request, animation):
dajax = Dajax()
dajax.remove_css_class('#movie-inspector label', 'error')
animation = json.loads(animation)
animation.update({
'type': 'm',
'user': request.user is None and '' or request.user.id,
})
if int(animation['max_duration']) > 60:
animation['max_duration'] = 60
movie_duration = 0
for frame in animation['data']:
frame['duration'] = int(frame['duration'])
if frame['duration'] > 2000:
frame['duration'] = 2000
movie_duration += frame['duration']
if movie_duration > 60000:
dajax.script('MessageWidget.msg("Animation darf insgesamt nicht laenger als 60 Sekunden sein! Bitte Frames loeschen oder kuerzer anzeigen lassen!")')
return dajax.json()
form = AnimationForm(animation)
if form.is_valid():
a = form.save()
p = Playlist(
title = 'stub \'%s\' playlist' % form.cleaned_data['title'],
user = User.objects.all()[0]
)
p.save()
ai = AnimationInstance(
playlist = p,
animation = a
)
ai.save()
# queue playlist
sj = SpoolJob(
playlist = p,
priority = 2,
added = datetime.now()
)
sj.save()
dajax.script('MessageWidget.msg("Great success! Animootion mit ID %s gespeichert!")' % p.id)
else:
for error in form.errors:
dajax.add_css_class('#movie-inspector label[for="%s"]' % error, 'error')
dajax.script('MessageWidget.msg("Bitte fehlende Felder ausfuellen.")')
return dajax.json()
开发者ID:alx,项目名称:acabed,代码行数:56,代码来源:ajax.py
示例3: test_add_song_to_playlist
def test_add_song_to_playlist(self):
with gillard.app.app_context():
song = Song()
playlist = Playlist()
playlist.songs = [song]
playlist = test_utils.save_and_refresh(gillard.db.session, playlist)
assert len(playlist.songs) == 1
# cascading add
assert playlist.songs[0].id is not None
开发者ID:spncrlkt,项目名称:gillard,代码行数:13,代码来源:playlist_model_tests.py
示例4: generate_playlist
def generate_playlist(request):
print(request.POST.keys())
artists = request.POST.get("artists").replace('/', '\n').split('\n')
if artists:
client = soundcloud.Client(access_token=request.COOKIES['access_token'])
print(artists)
all_tracks = []
for artist in artists:
artist = artist.strip()
print artist
tracks = client.get('/tracks', q=artist, limit=20)
short_tracks = []
count = 0
for track in tracks:
max_tracks = int(request.POST.get("max_tracks"))
if count > max_tracks:
break
max_length = int(request.POST.get("max_length"))
if max_length == 0 or track.duration < (max_length * 60 * 1000):
#Skip ones longer than max_length mins
count += 1
short_tracks.append(track)
all_tracks.extend(track.id for track in short_tracks)
print len(all_tracks)
if request.POST.get("randomize"):
print("Randomize = true")
random.shuffle(all_tracks)
# create an array of track ids
all_tracks_ids = map(lambda id: dict(id=id), all_tracks)
# create the playlist
# FIXME: timeout more than ~400 sounds in total
print("Creating Playlist...")
ret = client.post('/playlists', playlist={
'title': request.POST.get("title"),
'sharing': "public", #TODO: cutomize this viw a tickbox
'tracks': all_tracks_ids
})
try:
user = client.get('/me')
plst = Playlist(name=ret.title, author=user.username, author_id=user.uri, url=ret.permalink_url)
plst.save()
except Exception as exc:
print("++ ERROR while trying to save the playlist: %s" % exc)
print("Created %s available at: %s!" % (ret.title, ret.permalink_url))
return HttpResponse(simplejson.dumps({"link": ret.permalink_url, "title": ret.title}), content_type="application/json")
else:
print("no artists found!")
return HttpResponseServerError()
开发者ID:browniebroke,项目名称:festilist,代码行数:51,代码来源:views.py
示例5: get_playlist
def get_playlist(user, name):
"""
Checks to see if the user has a playlist named name
If not, create the playlist
:param user: User object
:param name: String of name of playlist
:return: Playlist owned by user, named name
"""
search = Playlist.objects.filter(name=name, owner=user)
if search.exists():
return search[0]
else:
playlist = Playlist(owner=user, name=name)
playlist.save()
return playlist
开发者ID:ianhblakley,项目名称:steazy-server,代码行数:15,代码来源:spotifyviews.py
示例6: createPlaylist
def createPlaylist(request, track_id, playlist_name, owner_id):
created_by = User.objects.get(id=owner_id)
new_list = Playlist(
name = playlist_name,
owner = created_by,
pub_date = timezone.now(),
)
new_list.save()
track = Track.objects.get(id=track_id)
new_list.tracks.add(track)
context = {
'track' : track,
'playlist' : new_list,
'msg' : "has been added into the new playlist! "
}
return HttpResponseRedirect('/playlist/')
开发者ID:Jmq14,项目名称:Back-End-Web,代码行数:16,代码来源:views.py
示例7: add_playlist
def add_playlist(request):
postdata = request.POST.copy()
track_slug = postdata.get('track_slug', '')
p = get_object_or_404(Track, link = track_slug)
playlist_list = get_playlist(request)
track_in_playlist = False
for list in playlist_list:
if list.track.id == p.id :
track_in_playlist = True
if not track_in_playlist:
ci = Playlist()
ci.track = p
ci.playlist_id = _playlist_id(request)
ci.save()
开发者ID:param107,项目名称:music_album,代码行数:16,代码来源:playlist.py
示例8: playlist_title_dicts
def playlist_title_dicts():
return map(lambda playlist: {
"title": playlist.title,
"key": str(playlist.key()),
"ka_url": playlist.relative_url, # remove once js clients update
"url": playlist.relative_url
}, Playlist.all())
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:7,代码来源:autocomplete.py
示例9: add_video
def add_video():
playlist_id = request.form.get("playlist_id")
if playlist_id.strip() == "":
return jsonify({'error': "You must specify a playlist ID for this video."})
playlist = Playlist.query.get(playlist_id)
if playlist == None:
return jsonify({'error': "Playlist not found"})
slug = request.form.get("slug")
if slug.strip() == "":
return jsonify({'error': "You must specify a slug for this video."})
thumbnail_url = request.form.get("thumbnail_url")
if thumbnail_url.strip() == "":
return jsonify({'error': "You must specify a thumbnail for this video."})
title = request.form.get("title")
if title.strip() == "":
return jsonify({'error': "You must specify a title for this video."})
v = Video(playlist_id, slug, thumbnail_url, title)
db_session.add(v)
db_session.commit()
# Publish to Redis so that all clients update playlist
data = {
"action": "update_playlist",
"playlist": Playlist.get_videos(playlist_id)
}
redis.publish(playlist_id, json.dumps(data))
return jsonify({"success": True})
开发者ID:camerongray1515,项目名称:HackDee-2015,代码行数:34,代码来源:api.py
示例10: get_all_tracks_in_playlist
def get_all_tracks_in_playlist(self, playlist_id):
try:
playlist = Playlist.get(playlist_id)
except ValueError as e:
raise
tracks = playlist.get_all_tracks()
ret = [track.__dict__ for track in tracks]
return ret
开发者ID:estock,项目名称:dogvibes,代码行数:8,代码来源:dogvibes.py
示例11: create_playlist
def create_playlist(self, request):
""" Creates a playlist for the user """
# TODO: Max amount of playlists at 20 for a user
user = Account.find_by_id(request.userid)
if user is None:
print "User not found"
return PlaylistResponse(errmsg="User ID not found")
new_pl = Playlist.add_new_playlist(user.key, request.name)
return PlaylistResponse(pid=new_pl.key.id())
开发者ID:chris-womack,项目名称:Party-Queue,代码行数:9,代码来源:party_queue_api.py
示例12: playlist
def playlist(user_id):
if request.method == 'GET':
playlists = Playlist.objects().filter(user_id=user_id)
return playlists.to_json()
if request.method == 'POST':
playlist = Playlist()
playlist.user_id = user_id
playlist.name = 'New Playlist'
playlist.song_ids = []
playlist.save()
return playlist.to_json()
开发者ID:mcherkassky,项目名称:listen,代码行数:11,代码来源:views.py
示例13: playlist_content_html
def playlist_content_html():
"""" Returns the HTML for the structure of the playlists as they will be
populated ont he homepage. Does not actually contain the list of video
names as those are filled in later asynchronously via the cache.
"""
# No cache found -- regenerate HTML
smart_history = getSmartHistoryContent()
dict_playlists_by_title = {}
all_playlists = []
for playlist in Playlist.all():
if playlist.title in topics_list:
dict_playlists_by_title[playlist.title] = playlist
for topic in topics_list:
if topic in dict_playlists_by_title:
playlist = dict_playlists_by_title[topic]
video_count = playlist.get_video_count()
# 3 columns, 18px per row. This must be updated in conjunction
# with code in homepage.js
height = math.ceil(video_count / 3) * 18
playlist_data = {
'title': topic,
'topic': topic,
'playlist': playlist,
'list_height': height,
'next': None,
}
all_playlists.append(playlist_data)
playlist_data_prev = None
for playlist_data in all_playlists:
if playlist_data_prev:
playlist_data_prev['next'] = playlist_data
playlist_data_prev = playlist_data
timestamp = time.time()
template_values = {
'App' : App,
'all_playlists': all_playlists,
'smart_history': smart_history,
# convert timestamp to a nice integer for the JS
'timestamp': int(round(timestamp * 1000)),
}
html = shared_jinja.get().render_template("library_playlist_template.html",
**template_values)
Setting.cached_playlist_content_date(
str(datetime.datetime.fromtimestamp(timestamp)))
return html
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:56,代码来源:library.py
示例14: test_playlist_updated_at
def test_playlist_updated_at(self):
with gillard.app.app_context():
playlist = Playlist()
playlist = test_utils.save_and_refresh(
gillard.db.session, playlist
)
# updated_at starts empty
assert playlist.updated_at is None
playlist.display_id = 'NEWTESTDISPID'
playlist = test_utils.save_and_refresh(
gillard.db.session, playlist
)
# on update, updated_at gets set to now-ish
assert (datetime.datetime.now() - playlist.updated_at).\
total_seconds() < 2
开发者ID:spncrlkt,项目名称:gillard,代码行数:20,代码来源:playlist_model_tests.py
示例15: get_playlist
def get_playlist():
playlist_id = request.args.get("playlist_id")
# Now get the updated playlist and send it to the client
videos = Video.query.filter(Video.playlist_id==playlist_id).order_by("rank desc")
data = {
"playlist": Playlist.get_videos(playlist_id)
}
return jsonify(data)
开发者ID:camerongray1515,项目名称:HackDee-2015,代码行数:11,代码来源:api.py
示例16: fork
def fork(request, username, slug):
""" creates new for of playlist, with parent set as current playlist
Does not copy editors, followers or votes
"""
parent_owner = shortcuts.get_object_or_404(User, username=username)
parent_playlist = shortcuts.get_object_or_404(Playlist, slug=slug, user=parent_owner)
# create new fork
new_playlist = Playlist(use=request.user,
title = parent_playlist.title,
slug = parent_playlist.slug,
parent_fork=parent_playlist)
new_playlist.save()
Playlist.objects.save_bookmarks(new_playlist, parent_playlist.bookmarks.values_list('id'))
messages.info(request, 'Playlist forked - You are now viewing your fork')
return http.HttpResponseRedirect(reverse('bookmarks.playlist_views.view', args=[new_playlist.user.username,new_playlist.slug,]))
开发者ID:favOERites,项目名称:favOERites,代码行数:21,代码来源:playlist_views.py
示例17: get_playlist_by_id
def get_playlist_by_id(self, request):
""" Returns a playlist based on the plalist id """
pl = Playlist.find_by_id(request.pid)
response = PlaylistResponse(pid=pl.key.id(),
name=pl.name,
songs=[])
songs = Song.find_by_playlist(pl.key).fetch()
for song in songs:
response.songs.append(SongMessage(id=song.key.id(),
spotify_id=song.spotify_id,
name=song.name,
vote_count=song.vote_count))
return response
开发者ID:chris-womack,项目名称:Party-Queue,代码行数:13,代码来源:party_queue_api.py
示例18: load_videos
def load_videos(version, title=None):
root = Topic.get_by_id("root", version)
if title is None:
playlist = Playlist.all().order('title').get()
else:
playlist = Playlist.all().filter('title = ', title).get()
title = playlist.title
nextplaylist = Playlist.all().filter('title >', title).order('title').get()
if nextplaylist:
next_title = nextplaylist.title
playlists = [playlist]
# playlists = Playlist.all().order('title').fetch(100000)
for i, p in enumerate(playlists):
videos = p.get_videos()
content_keys = [v.key() for v in videos]
added = 0
for i, v in enumerate(videos):
for e in v.related_exercises():
if e.key() not in content_keys:
content_keys.insert(i + added, e.key())
added += 1
topic = Topic.insert(title=p.title,
parent=root,
description=p.description,
tags=p.tags,
child_keys=content_keys)
logging.info("loading " + title)
if nextplaylist:
deferred.defer(load_videos, version, next_title)
else:
deferred.defer(hide_topics, version)
开发者ID:di445,项目名称:server,代码行数:38,代码来源:topics.py
示例19: create
def create(request):
if request.method == 'POST':
url = request.POST.get('playlist_location', '')
#
#regexp here!!!!!!!!!
#
result = urlfetch.fetch(url + "code/xspf.php")
if result.status_code == 200:
# xml = minidom.parseString(unicode(result.content, "utf-8" ))
try:
xml = minidom.parseString(result.content.replace("&", "&"))
except:
return render_to_response('create.html', {'flash' : "Ops. Something went wrong!!!..."})
tracks = xml.getElementsByTagName('track')
playlist = Playlist(title="lorem ipsum dolor", location=url)
playlist.save()
for song in tracks:
loc = song.getElementsByTagName('location')[0]
me = song.getElementsByTagName('meta')[0]
ti = song.getElementsByTagName('title')[0]
fo = song.getElementsByTagName('info')[0]
s = SongForm({
'location': getText(loc.childNodes),
'meta': getText(me.childNodes),
'title': getText(ti.childNodes),
'info': getText(fo.childNodes),
})
if s.is_valid():
s.playlist = playlist
s.save()
return render_to_response('create.html', {'flash' : "Playlist added! <a href=\"/\">Go back to home page.</a>"})
return render_to_response('create.html')
开发者ID:walkandre,项目名称:opentapes,代码行数:38,代码来源:views.py
示例20: get_playlists
def get_playlists():
playlists = []
for playlist_title in all_topics_list:
query = Playlist.all()
query.filter('title =', playlist_title)
playlist = query.get()
playlist_dict = {'youtube_id': playlist.youtube_id,
'youtube_url': playlist.url,
'title': playlist.title,
'description': playlist.description,
'api_url': "http://www.khanacademy.org/api/playlistvideos?playlist=%s" % (urllib.quote_plus(playlist_title)),
}
playlists.append(playlist_dict)
return json.dumps(playlists, indent=4)
开发者ID:adamwulf,项目名称:old-khan,代码行数:14,代码来源:api.py
注:本文中的models.Playlist类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论