本文整理汇总了Python中models.Photo.save方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.save方法的具体用法?Python Photo.save怎么用?Python Photo.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Photo
的用法示例。
在下文中一共展示了Photo.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: savePhoto
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def savePhoto(self, galleryId, photoId, photoName, photoDescription, photoPosition, file):
photo = None
if(photoId):
photo = Photo.objects.get(id=photoId)
else:
gid = uuid.uuid1().__str__()
gid = gid.replace('-', '')
photo = Photo()
photo.id = gid
photo.name = photoName
photo.description = photoDescription
photo.position = photoPosition
photo.gallery_id = galleryId
if(file):
photoType = file.name.split('.')
photo.type = photoType[1] if photoType.__len__() == 2 else ''
destination = open(constant.upload_path + galleryId + '/' +
photo.id + '.' + photo.type, 'wb')
try:
for chunk in file.chunks():
destination.write(chunk)
finally:
destination.close()
photo.save()
示例2: photos_from_zip
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def photos_from_zip(path,approved=True,user=None):
"""turn a zip file into a photos"""
now = datetime.datetime.now()
_ = now.strftime(Photo._meta.get_field('file').upload_to)
zip_name = path.split('/')[-1]
root = os.path.join(settings.MEDIA_ROOT,_)
if not os.path.exists(root):
os.mkdir(root)
directory = os.path.join(root,'%s_%s'%(now.day,now.time()))
os.mkdir(directory)
new_path = os.path.join(directory,zip_name)
os.chdir(directory)
os.rename(path,new_path)
command = 'unzip %s'%new_path
process = Popen(command, stdout=PIPE, shell=True)
process.communicate()
for folder,_,files in os.walk('.'):
for f in files:
os.rename(os.path.join(folder,f),os.path.join(directory,f))
folders = [f for f in os.listdir(directory) if os.path.isdir(f)]
for f in folders:
os.rmdir(f)
files = [f for f in os.listdir(directory) if not os.path.isdir(f)]
for f_path in files:
print "creating photo!"
photo = Photo(
file = os.path.join(directory,f_path).split(settings.MEDIA_ROOT)[-1],
source = "misc",
approved = approved,
user=user
)
photo.save()
#all done, delete the zip!
os.remove(new_path)
示例3: AlbumTest
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo 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: add_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def add_photo(self, album_id=''):
if request.method == 'POST':
album = Album.get(id=album_id)
photo = Photo()
photo.album = album
file = request.files['files']
photo_title, size, photo_path, photo_url, thumb_url, thumb_path = self.gal_man.add_photo(album, file)
result = []
result.append({
'name':photo_title,
'size':size,
'url':photo_url,
'thumbnail_url':thumb_path,
"delete_type":"POST",
})
photo.title = photo_title
photo.photo_path = photo_path
photo.thumb_path = thumb_path
photo.photo_url = photo_url
photo.thumb_url = thumb_url
photo.size = size
photo.save()
return json.dumps(result)
else:
return 'response'
示例5: create_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def create_photo(file_path):
photo_path, width, height = image_utils.fit_and_save(file_path)
thumb_path = image_utils.generate_thumbnail(photo_path)
photo_path, thumb_path = (relp(rp(p), PARENT_DIR) for p in (photo_path, thumb_path))
photo = Photo(image_path=photo_path, thumbnail_path=thumb_path, width=width, height=height)
photo.save()
return photo
示例6: create_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def create_photo(user, image):
m = Photo(user=user)
if image:
image.seek(0)
m.save_file(image)
m.save()
lookedup = Photo.objects.get(id=m.id)
return lookedup
示例7: photo_save
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def photo_save(request):
if request.user.client_photo.count() >= 7:
return HttpResponse('Max is 7')
avatar = get_or_none(Photo, user=request.user, avatar=True)
photo = Photo(user=request.user, photo=request.FILES['file'])
if not avatar:
photo.avatar = True
photo.save()
return HttpResponse('Uploaded')
示例8: create_conversation
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def create_conversation(user_id, conversation):
conversation_type = conversation.get('conversation_type')
conversationees_list = conversation.get('conversationees_list')
conversationees_list = list(set(conversation.get('conversationees_list',[])))
if conversation_type == conversations_config.get('CONVERSATION_DIRECT_TYPE') and len(conversationees_list) != 2:
raise InvalidConversationException('Direct conversations should have 2 conversationees')
ct = ConversationType.get(ConversationType.name == conversation_type)
c = Conversation()
c.conversation_type = ct
p_url = conversation.get('picture','')
picture = None
if p_url:
picture = Photo()
picture.url = p_url
name = conversation.get('name','')
cps = []
myself = None
for index, conversationee in enumerate(conversationees_list):
n = None
p = None
if conversation_type == 'group':
n = name
p = picture
else:
data = get_user_data(index, conversationees_list)
n = data[0]
p = data[1]
cp = ConversationParty()
cp.conversation = c
cp.name = n
cp.user = User.get(User.id==conversationee)
cp.picture = p
cps.append(cp)
if conversationee == user_id:
myself = cp
with database.transaction():
c.save()
if picture:
picture.save()
for cp in cps:
cp.save()
return __jsonify_one_conversation(myself)
示例9: setUp
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def setUp(self):
'''
Метод начальной инициализации
'''
photo = Photo(photo = 'this is a photo, believe me ;)')
photo.save()
user = User(login='test',password='test',avatarId = photo, rating = 0)
user.save()
user = User(login='TestUser',password='test_pass',avatarId = photo, rating = 0)
user.save()
示例10: create_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def create_photo(path, owner, title, access, description):
with open('imagr_images/test_data/'+path, 'rb') as f:
image = ImageFile(f)
photo = Photo(
image=image,
owner=owner,
title=title,
access=access,
description=description
)
photo.save()
return photo
示例11: test_create_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def test_create_photo(self):
"""Create a photo and assert that its fields appear as expected."""
photo = Photo(
author=self.u,
description='A Photo',
image=self.image
)
photo.full_clean()
photo.save()
self.assertIsInstance(photo, Photo)
self.assertIsInstance(photo.date_created, datetime)
self.assertIsInstance(photo.date_modified, datetime)
self.assertEqual(photo.description, 'A Photo')
self.assertEqual(photo.author, self.u)
示例12: index
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def index(request):
"Obtains the attachment and saves it to the disk"
if request.method == 'POST':
form = AttachmentForm(request.POST, request.FILES)
if form.is_valid():
f = form.cleaned_data['image']
foto = Photo()
foto.image.save(f.name, f)
foto.comments = form.cleaned_data['comments']
foto.save()
return HttpResponseRedirect('/')
else:
form = AttachmentForm()
fotos = Photo.objects.all()
return render_to_response('index.html', {'form':form, 'fotos': fotos})
示例13: load_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def load_photo(request):
if request.method=='POST':
if request.FILES is None:
return HttpResponseBadRequest('No file[] found')
try:
id = int(request.POST['id'])
tournament = Tournament.objects.get(pk=id)
if tournament is None:
return HttpResponseBadRequest('Cannot find corresponding dress')
except:
return HttpResponseBadRequest('Cannot find id')
file = request.FILES[u'files[]']
if str(file).lower()[-4:] not in ['.jpg', 'jpeg', '.gif', '.png', '.bmp', '.ico',]:
return HttpResponseBadRequest('Only images allowed')
wrapped_file = UploadedFile(file)
filename = wrapped_file.name
file_size = wrapped_file.file.size
photo = Photo()
photo.tournament = tournament
photo.description = filename
photo.image = file
photo.save()
try:
im = get_thumbnail(photo.image, "200", quality=50)
thumb_url = im.url
except Exception, ex:
photo.delete()
return HttpResponseBadRequest('Cannot read thumbnail')
result = [{"name": filename,
"id": photo.id,
"size": file_size,
"url": photo.image.url,
"thumbnail_url": thumb_url,
}]
response_data = simplejson.dumps(result)
mimetype = 'text/plain'
if 'HTTP_ACCEPT_ENCODING' in request.META.keys():
if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
mimetype = 'application/json'
return HttpResponse(response_data, mimetype=mimetype)
示例14: img_save
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def img_save(self):
"""
Tests that we can save a Photo.
"""
# self.failUnlessEqual(1 + 1, 2)
from PIL import Image
from models import Photo
im = Image.open('P1020515.JPG')
photo = Photo()
photo.img=im
photo.url='http://go00gle.com'
photo.save()
self.failUnlessEqual(im,photo.img)
self.failUnlessEqual(photo.url, 'http://google.com')
示例15: add_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import save [as 别名]
def add_photo(user_state, object_id, name, from_name, link, source):
photo_list = Photo.objects.filter(object_id=object_id)
photo = None
if len(photo_list) == 0:
photo = Photo()
photo.user_state = user_state
photo.object_id = object_id
photo.retrieval_time = int(time.time())
photo.name = name
photo.from_name = from_name
photo.link = link
photo.source = source
photo.save()
else:
photo = photo_list[0]
return photo