本文整理汇总了Python中playlists.models.PlaylistTrack类的典型用法代码示例。如果您正苦于以下问题:Python PlaylistTrack类的具体用法?Python PlaylistTrack怎么用?Python PlaylistTrack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlaylistTrack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_track_by_free_entry
def test_track_by_free_entry(self):
selector = create_dj()
playlist = ChirpBroadcast()
track = PlaylistTrack(
selector=selector,
playlist=playlist,
freeform_artist_name="Stevie Wonder",
freeform_album_title="Talking Book",
freeform_track_title='You Are The Sunshine Of My Life',
freeform_label='Warner Bros.',
notes="This track is a bit played out but it still has some nice melodies"
)
track.put()
self.assertEqual(track.artist_name, "Stevie Wonder")
self.assertEqual(track.album_title, "Talking Book")
self.assertEqual(track.album_title_display, "Talking Book")
self.assertEqual(track.track_title, "You Are The Sunshine Of My Life")
self.assertEqual(track.label, "Warner Bros.")
self.assertEqual(track.label_display, "Warner Bros.")
self.assertEqual(track.notes,
"This track is a bit played out but it still has some nice melodies")
# for sanity, not real tests:
self.assertEqual(
track.established_display.timetuple()[0:2],
datetime.datetime.now().timetuple()[0:2])
self.assertEqual(
track.modified_display.timetuple()[0:2],
datetime.datetime.now().timetuple()[0:2])
示例2: test_cannot_delete_someone_elses_track
def test_cannot_delete_someone_elses_track(self):
other_user = User(email="[email protected]")
other_user.roles.append(auth.roles.DJ)
other_user.put()
time.sleep(0.4)
other_track = PlaylistTrack(
playlist=self.playlist,
selector=other_user,
freeform_artist_name="Peaches",
freeform_track_title="Rock Show",)
other_track.put()
with fudge.patched_context(playlists.tasks, "_fetch_url", stub_fetch_url):
resp = self.client.get(reverse('playlists_delete_event',
args=[other_track.key()]))
self.assertRedirects(resp, reverse('playlists_landing_page'))
# simulate the redirect:
resp = self.client.get(reverse('playlists_landing_page'))
# should be no change:
context = resp.context[0]
tracks = [t.artist_name for t in context['playlist_events']]
self.assertEquals(tracks, ["Peaches", "Steely Dan"])
示例3: PlaylistTest
class PlaylistTest(APITest):
def setUp(self):
super(PlaylistTest, self).setUp()
dbconfig['lastfm.api_key'] = 'SEKRET_LASTFM_KEY'
self.dj = User(dj_name='DJ Night Moves', first_name='Steve',
last_name='Dolfin', email='[email protected]',
roles=[auth.roles.DJ])
self.dj.save()
self.playlist = ChirpBroadcast()
(self.stevie,
self.talking_book,
self.tracks) = create_stevie_wonder_album_data()
def play_stevie_song(self, song_name):
self.playlist_track = PlaylistTrack(
playlist=self.playlist,
selector=self.dj,
artist=self.stevie,
album=self.talking_book,
track=self.tracks[song_name],
notes='from 1972!',
freeform_label='Motown')
self.playlist_track.save()
return self.playlist_track
示例4: bootstrap
def bootstrap(request):
# Don't create dummy playlist tracks if playlist tracks already exist!
pl_tracks = PlaylistTrack.all().fetch(1)
if len(pl_tracks) > 0:
return HttpResponse(status=404)
playlist = ChirpBroadcast()
minutes = 0
tracks = Track.all().fetch(100)
for track in tracks:
pl_track = PlaylistTrack(
playlist=playlist,
selector=request.user,
established=datetime.now() - timedelta(minutes=minutes),
artist=track.album.album_artist,
album=track.album,
track=track,
)
pl_track.put()
if minutes > 0 and minutes % 25 == 0:
pl_break = PlaylistBreak(playlist=playlist, established=datetime.now() - timedelta(minutes=minutes - 1))
pl_break.put()
minutes += 5
return HttpResponseRedirect("/playlists/")
示例5: make_track
def make_track():
playlist = ChirpBroadcast()
track = PlaylistTrack(
selector=selector,
playlist=playlist,
artist=self.stevie,
album=self.talking_book
)
track.put()
示例6: create_track
def create_track(artist, album, track, label):
track = PlaylistTrack(
playlist=playlist,
selector=selector,
freeform_artist_name=artist,
freeform_album_title=album,
freeform_track_title=track,
freeform_label=label)
track.put()
return track
示例7: save
def save(self):
if not self.current_user:
raise ValueError("Cannot save() without a current_user")
playlist_track = PlaylistTrack(
playlist=self.playlist,
selector=self.current_user)
if self.cleaned_data['artist_key']:
playlist_track.artist = Artist.get(self.cleaned_data['artist_key'])
else:
playlist_track.freeform_artist_name = self.cleaned_data['artist']
if self.cleaned_data['song_key']:
playlist_track.track = Track.get(self.cleaned_data['song_key'])
else:
playlist_track.freeform_track_title = self.cleaned_data['song']
if self.cleaned_data['album_key']:
playlist_track.album = Album.get(self.cleaned_data['album_key'])
elif self.cleaned_data['album']:
playlist_track.freeform_album_title = self.cleaned_data['album']
if self.cleaned_data['label']:
playlist_track.freeform_label = self.cleaned_data['label']
if self.cleaned_data['song_notes']:
playlist_track.notes = self.cleaned_data['song_notes']
if self.cleaned_data['is_heavy_rotation']:
playlist_track.categories.append('heavy_rotation')
if self.cleaned_data['is_light_rotation']:
playlist_track.categories.append('light_rotation')
if self.cleaned_data['is_local_current']:
playlist_track.categories.append('local_current')
if self.cleaned_data['is_local_classic']:
playlist_track.categories.append('local_classic')
AutoRetry(playlist_track).save()
return playlist_track
示例8: test_partial_track_by_free_entry
def test_partial_track_by_free_entry(self):
selector = create_dj()
playlist = ChirpBroadcast()
track = PlaylistTrack(
selector=selector,
playlist=playlist,
freeform_artist_name="Stevie Wonder",
freeform_track_title='You Are The Sunshine Of My Life'
)
track.put()
self.assertEqual(track.album_title_display, "[Unknown Album]")
self.assertEqual(track.label_display, "[Unknown Label]")
示例9: test_different_tracks
def test_different_tracks(self):
self.count()
new_trk = PlaylistTrack(
playlist=self.track.playlist,
selector=self.track.selector,
freeform_artist_name='Prince',
freeform_album_title='Purple Rain',
freeform_track_title='When Doves Cry')
new_trk.put()
self.count(track_key=new_trk.key())
count = PlayCount.all()[0]
track_ids = [str(w.key()) for w in PlayCount.all()]
assert track_ids[0] != track_ids[1], (
'Different artist/albums cannot have the same key')
示例10: clear_data
def clear_data():
for pl in Playlist.all():
for track in PlaylistTrack.all().filter('playlist =', pl):
track.delete()
pl.delete()
for ob in PlayCount.all():
ob.delete()
示例11: test_count_different_track
def test_count_different_track(self):
self.count()
# Copy the same artist/track into a new track.
new_trk = PlaylistTrack(
playlist=self.track.playlist,
selector=self.track.selector,
freeform_artist_name=self.track.freeform_artist_name,
freeform_album_title=self.track.freeform_album_title,
freeform_track_title='Another track from the album')
new_trk.put()
self.count(track_key=new_trk.key())
count = PlayCount.all()[0]
eq_(count.artist_name, self.track.freeform_artist_name)
eq_(count.album_title, self.track.freeform_album_title)
eq_(count.label, self.track.label)
eq_(count.play_count, 2)
示例12: clear_data
def clear_data():
for pl in Playlist.all():
for track in PlaylistTrack.all().filter('playlist =', pl):
track.delete()
pl.delete()
for u in User.all():
u.delete()
示例13: post
def post(self):
links_fetched = 0
if not self.request.POST.get('id'):
# This is a temporary workaround to free up the task queue. It
# seems that old tasks are stuck in an error-retry loop
log.error('id not found in POST')
self.response.out.write(simplejson.dumps({'success': False}))
return
track = PlaylistTrack.get(self.request.POST['id'])
if track is None:
# Track was deleted by DJ, other scenarios?
log.warning('track does not exist: %s' % self.request.POST['id'])
self.response.out.write(simplejson.dumps({'success': False}))
return
try:
fm = pylast.get_lastfm_network(
api_key=dbconfig['lastfm.api_key'])
fm_album = fm.get_album(track.artist_name, track.album_title)
track.lastfm_url_sm_image = \
fm_album.get_cover_image(pylast.COVER_SMALL)
track.lastfm_url_med_image = \
fm_album.get_cover_image(pylast.COVER_MEDIUM)
track.lastfm_url_large_image = \
fm_album.get_cover_image(pylast.COVER_LARGE)
except pylast.WSError:
# Probably album not found
log.exception('IGNORED while fetching LastFM data')
track.lastfm_urls_processed = True # Even on error
track.save()
memcache.delete(CurrentPlaylist.cache_key)
self.response.out.write(simplejson.dumps({
'success': True,
'links_fetched': links_fetched
}))
示例14: get_json
def get_json(self):
playlist_key = chirp_playlist_key()
recent_tracks = list(PlaylistTrack.all().filter("playlist =", playlist_key).order("-established").fetch(6))
return {
"now_playing": self.track_as_data(recent_tracks.pop(0)),
# Last 5 played tracks:
"recently_played": [self.track_as_data(t) for t in recent_tracks],
}
示例15: test_track_by_references
def test_track_by_references(self):
selector = create_dj()
playlist = ChirpBroadcast()
track = PlaylistTrack(
selector=selector,
playlist=playlist,
artist=self.stevie,
album=self.talking_book,
track=self.tracks['You Are The Sunshine Of My Life']
)
track.put()
self.assertEqual(track.artist_name, "Stevie Wonder")
self.assertEqual(track.artist, self.stevie)
self.assertEqual(track.album_title, "Talking Book")
self.assertEqual(track.album, self.talking_book)
self.assertEqual(track.track_title, "You Are The Sunshine Of My Life")
self.assertEqual(track.track, self.tracks['You Are The Sunshine Of My Life'])