本文整理汇总了Python中models.Album.save方法的典型用法代码示例。如果您正苦于以下问题:Python Album.save方法的具体用法?Python Album.save怎么用?Python Album.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Album
的用法示例。
在下文中一共展示了Album.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_album
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def create_album(request):
if not request.user.is_authenticated():
return redirect('/')
if request.method=='GET':
albums=Album.objects.all()
print albums
maincat=MainCat.objects.all()
nart,cart,rart,cm,tg=getthree()
#日历
today=today=datetime.datetime.now()
s=calendar.HTMLCalendar(6)
cals=list(s.itermonthdays2(today.year,today.month))
tdarts=Article.objects.values('id','createtime').filter(createtime__year=today.year,createtime__month=today.month).order_by('createtime') #列表字典[{'createtime': datetime.datetime(2014, 4, 6, 4, 36, 32, 896000, tzinfo=<UTC>)},
tdart=set([i['createtime'].day for i in tdarts])
tmpq=Article.objects.exclude(createtime__year=today.year,createtime__month=today.month)
premon=tmpq.filter(createtime__lt=today).order_by('-createtime')[:1]
aftmon=tmpq.filter(createtime__gt=today).order_by('createtime')[:1]
tt=[]
for i in cals:
tt.append(list(i))
ttt=[]
for a in tt:
for i in tdart:
if a[0] == i:
a.append(1)
if len(a)==2:
a.append(0)
ttt.append(a)
return render_to_response('create_album.html',locals(),context_instance=RequestContext(request))
else:
albumpath=request.POST['albumpath']
albumname=request.POST['albumname']
a=Album(album_name=albumname,album_path=albumpath)
a.save()
maincat=MainCat.objects.all()
nart,cart,rart,cm,tg=getthree()
#日历
today=today=datetime.datetime.now()
s=calendar.HTMLCalendar(6)
cals=list(s.itermonthdays2(today.year,today.month))
tdarts=Article.objects.values('id','createtime').filter(createtime__year=today.year,createtime__month=today.month).order_by('createtime') #列表字典[{'createtime': datetime.datetime(2014, 4, 6, 4, 36, 32, 896000, tzinfo=<UTC>)},
tdart=set([i['createtime'].day for i in tdarts])
tmpq=Article.objects.exclude(createtime__year=today.year,createtime__month=today.month)
premon=tmpq.filter(createtime__lt=today).order_by('-createtime')[:1]
aftmon=tmpq.filter(createtime__gt=today).order_by('createtime')[:1]
tt=[]
for i in cals:
tt.append(list(i))
ttt=[]
for a in tt:
for i in tdart:
if a[0] == i:
a.append(1)
if len(a)==2:
a.append(0)
ttt.append(a)
return render_to_response('create_album.html',locals(),context_instance=RequestContext(request))
示例2: add_to_db
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def add_to_db(audio_files):
for audio_file in audio_files:
audio_file_id3 = eyed3.load(audio_file)
# If the artist, album or track doesn't exist in the database, create
# table(s) for them.
try:
if not Artist.objects.filter(name=audio_file_id3.tag.artist).exists():
artist = Artist(name=audio_file_id3.tag.artist)
artist.save()
if not Album.objects.filter(title=audio_file_id3.tag.album).exists():
album = Album(title=audio_file_id3.tag.album, \
artist=artist)
album.save()
if not Track.objects.filter(title=audio_file_id3.tag.title).exists():
track = Track(title=audio_file_id3.tag.title, \
album=album, \
artist=artist, \
fspath=audio_file, \
media_url=MEDIA_URL + audio_file.split(MEDIA_ROOT)[1])
track.save()
print 'Added to DB: ' + audio_file_id3.tag.title
except Exception as e:
print 'Error: ' + e
示例3: AlbumTest
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
class AlbumTest(TestCase):
def setUp(self):
self.user = User(username='sholmes', email='[email protected]',
first_name='Sherlock', last_name="Holmes",
password='watson')
self.user.full_clean()
self.user.save()
self.photo = Photo(owner=self.user,
image='images/test.png',
name='test',
caption='testing')
self.photo.clean()
self.photo.save()
self.tag = Tag(name='test tag', owner=self.user)
self.tag.clean()
self.tag.save()
self.photo.tags.add(self.tag)
self.album = Album(owner=self.user,
name='test album')
self.album.clean()
self.album.save()
self.album.photos.add(self.photo)
def test_id_creation(self):
self.assertIsNotNone(self.album.id)
def test_owner_entry(self):
self.assertEqual(self.album.name, 'test album')
def test_name_entry(self):
self.assertEqual(self.photo.name, 'test')
def test_album_to_photo_association(self):
photos = Photo.objects.filter(album=self.album.id)
self.assertEqual(photos[0].name, 'test')
示例4: test_parse_album
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def test_parse_album(self):
response = '''{"response":[{"aid":"16178407","thumb_id":"96509883","owner_id":"6492","title":"qwerty",
"description":"desc","created":"1298365200","updated":"1298365201","size":"3",
"privacy":"3"},{"aid":"17071606","thumb_id":"98054577","owner_id":"-6492",
"title":"","description":"","created":"1204576880","updated":"1229532461",
"size":"3","privacy":"0"}]}
'''
instance = Album()
owner = UserFactory.create(remote_id=6492)
instance.parse(json.loads(response)['response'][0])
instance.save()
self.assertEqual(instance.remote_id, '6492_16178407')
self.assertEqual(instance.thumb_id, 96509883)
self.assertEqual(instance.owner, owner)
self.assertEqual(instance.title, 'qwerty')
self.assertEqual(instance.description, 'desc')
self.assertEqual(instance.created, datetime(2011,2,22,9,0,0))
self.assertEqual(instance.updated, datetime(2011,2,22,9,0,1))
self.assertEqual(instance.size, 3)
self.assertEqual(instance.privacy, 3)
instance = Album()
group = GroupFactory.create(remote_id=6492)
instance.parse(json.loads(response)['response'][1])
instance.save()
self.assertEqual(instance.remote_id, '-6492_17071606')
self.assertEqual(instance.group, group)
示例5: create
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def create(request, albumTitle):
is_auth = request.user.is_authenticated()
if (is_auth):
album = Album(title=request.albumTitle, description=none, userId=request.user)
album.save()
return render_to_response('create.html', {'is_auth':is_auth, 'user':request.user, 'title':albumTitle})
else:
return render_to_response('login.html',{'is_auth':is_auth})
示例6: create_album_view
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def create_album_view(request):
owner = request.user
if request.method == 'POST':
form = CreateAlbumForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
album = Album(name=name, owner=owner)
album.save()
return HttpResponseRedirect('/main')
else:
form = CreateAlbumForm()
return render(request, 'photorizer/create_album.html', {'form': form})
示例7: new_album
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def new_album(self):
form = NewAlbumForm(request.form or None)
if request.method == 'POST' and form.validate():
album = Album()
album_title = request.form['title']
album_description = request.form['description']
album_path, album_thumb = self.gal_man.create_album(album_title)
album.title = album_title
album.description = album_description
album.album_path = album_path
album.thumb_path = album_thumb
album.save()
return redirect(url_for('.show_album', album_id=album.id))
return self.render('admin/new_album.html', form=form)
示例8: test_create_album
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def test_create_album(self):
"""Create an album and verify that it appears as expected."""
album = Album(
title='An Album',
description='A Description',
author=self.u
)
album.full_clean()
album.save()
self.assertIsInstance(album, Album)
self.assertIsInstance(album.date_created, datetime)
self.assertIsInstance(album.date_modified, datetime)
self.assertEqual(album.title, 'An Album')
self.assertEqual(album.description, 'A Description')
self.assertEqual(album.author, self.u)
示例9: test_parse_album
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def test_parse_album(self):
owner = GroupFactory(remote_id=GROUP_ID)
d = {u'count': 16, u'photo_320': u'http://cs619722.vk.me/u8704019/video/l_6369beb6.jpg', u'title': u'Coca-Cola Football',
u'photo_160': u'http://cs619722.vk.me/u8704019/video/m_ef3493e1.jpg', u'id': 54387280, u'owner_id': -16297716}
instance = Album()
instance.parse(d)
instance.save()
self.assertEqual(instance.owner, owner)
self.assertEqual(instance.pk, d['id'])
self.assertEqual(instance.title, d['title'])
self.assertEqual(instance.videos_count, 16)
self.assertEqual(instance.photo_160, d['photo_160'])
示例10: create_db
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def create_db(request):
username = '[email protected]'
gd_client = gdata.photos.service.PhotosService()
albums = gd_client.GetUserFeed(user=username)
for album in albums.entry:
print 'title: %s, number of photos: %s, id: %s' % (album.title.text, album.numphotos.text, album.gphoto_id.text)
try:
alb = Album(title=album.title.text, url=album.GetHtmlLink().href, numphotos=album.numphotos.text, album_id=album.gphoto_id.text)
alb.save()
except:
# do not duplicate albums
pass
photos = gd_client.GetFeed('/data/feed/api/user/%s/albumid/%s?kind=photo' % (username, album.gphoto_id.text))
for photo in photos.entry:
print 'Photo title:', photo.title.text
try:
p = Photo(album=alb, title=photo.title.text, image=photo.media.thumbnail[2].url, url=photo.content.src, pub_date=photo.timestamp.datetime(), filename=photo.media.title.text, photo_id=photo.gphoto_id.text, height=int(photos.entry[0].height.text), width=int(photos.entry[0].width.text))
p.save()
except:
# do not duplicate albums
pass
return HttpResponse("Дані додано")
示例11: test_create_album_with_photos
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def test_create_album_with_photos(self):
"""Create an album containing several photos and assert that they
appear as expected.
"""
photo1 = Photo(author=self.u)
photo1.save()
photo2 = Photo(author=self.u)
photo2.save()
photo3 = Photo(author=self.u)
photo3.save()
album = Album(
title='An Album',
description='A Description',
author=self.u
)
album.save()
album.photos.add(photo1, photo2, photo3)
album.save()
self.assertIn(photo1, album.photos.all())
self.assertIn(photo2, album.photos.all())
self.assertIn(photo3, album.photos.all())
示例12: test_create_album
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def test_create_album(self):
album_title = u"Cats"
owner = ImagrUser.objects.create(username=u'John Doe')
album_access = 1
album_description = u"Photos of cats"
photo1 = create_photo(
'cat_in_tent.jpg',
owner,
'Cat in tent',
1,
'photo of cat in tent'
)
photo2 = create_photo(
'cat_in_drawer.jpg',
owner,
'Cat in a drawer',
1,
'photo of a cat in a drawer'
)
cover_photo = create_photo(
'cat_yawning.jpg',
owner,
'Cat yawning',
1,
'Photo of cat yawning'
)
album = Album(
title=album_title,
owner=owner,
description=album_description,
access=album_access,
cover_photo=cover_photo
)
album.save()
# add the photo
album.photos.add(photo1)
album.photos.add(photo2)
album.save()
# check dates
naive_dt_created = album.date_created.replace(tzinfo=None)
naive_dt_modified = album.date_modified.replace(tzinfo=None)
self.assertTrue(naive_dt_created < datetime.datetime.utcnow())
album.save()
self.assertTrue(
naive_dt_created < naive_dt_modified < datetime.datetime.utcnow()
)
# check that photos are in the album
self.assertTrue(Photo.objects.get(id=1) in album.photos.all())
self.assertTrue(Photo.objects.get(id=2) in album.photos.all())
self.assertEquals(album.owner, owner)
self.assertEquals(album.title, album_title)
self.assertEquals(album.description, album_description)
self.assertEquals(album.access, 1)
示例13: Album
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
# add_data.py
import datetime
import peewee
from models import Album, Artist
new_artist = Artist.create(name="Newsboys")
album_one = Album(artist=new_artist,
title="Read All About It",
release_date=datetime.date(1988,12,01),
publisher="Refuge",
media_type="CD")
album_one.save()
albums = [{"artist": new_artist,
"title": "Hell is for Wimps",
"release_date": datetime.date(1990,07,31),
"publisher": "Sparrow",
"media_type": "CD"
},
{"artist": new_artist,
"title": "Love Liberty Disco",
"release_date": datetime.date(1999,11,16),
"publisher": "Sparrow",
"media_type": "CD"
},
{"artist": new_artist,
"title": "Thrive",
"release_date": datetime.date(2002,03,26),
"publisher": "Sparrow",
"media_type": "CD"}
]
示例14: test_post_save_field
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def test_post_save_field(self):
with open(os.path.join(settings.ASSET_ROOT, 'test.jpg')) as fp:
album = Album(title='hello world', cover=File(fp, 'test.jpg'))
album.save()
self.assertEquals(os.listdir(settings.MEDIA_ROOT), ['album-1.jpg'])
示例15: save
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import save [as 别名]
def save(self, user):
data = self.data
name = unicode(data.get('name'))
data.update({'user_id': user.id, 'name': strip_xss_tags(name)})
album = Album(**data)
return album.save()