本文整理汇总了Python中photologue.models.Photo.date_taken方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.date_taken方法的具体用法?Python Photo.date_taken怎么用?Python Photo.date_taken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photologue.models.Photo
的用法示例。
在下文中一共展示了Photo.date_taken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh_media
# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import date_taken [as 别名]
def refresh_media():
"""
Scan media upload folder and add any missing gallery items.
"""
itemized = map(lambda o: o.file.path, MediaModel.objects.all())
my_root = os.path.join(settings.MEDIA_ROOT, PHOTOLOGUE_DIR)
for root, dirs, files in os.walk(my_root, followlinks=True):
# First filter out cache and poster directories
try:
dirs.remove('cache')
dirs.remove('poster')
except:
pass
# Go througth files
for fn in files:
full = os.path.join(root, fn)
if full in itemized:
continue
date_taken = datetime.fromtimestamp(os.path.getmtime(full))
if not is_aware(date_taken):
date_taken = make_aware(date_taken, get_current_timezone())
# Next part is taken from process_zipfile
filetype = False
# Is it an image?
try:
trial_image = Image.open(full)
trial_image.load()
trial_image = Image.open(full)
trial_image.verify()
filetype = 'image'
except Exception, e:
pass
# Is it a video?
if not filetype:
try:
sizes = video_info(full)
# Here comes a problem. If it is a jpeg image, it is
# detected as mjpeg movie...check if it least at least 1s long
if sizes[3] >= 1:
filetype = 'video'
except Exception, e:
pass
if not filetype:
continue
namebase, ext = os.path.splitext(fn)
count = 0
while 1:
if count:
title = ''.join([namebase, '_'+str(count), ext])
else:
title = fn
slug = slugify(title)
try:
p = GalleryItemBase.objects.get(title_slug=slug)
except GalleryItemBase.DoesNotExist:
if filetype == 'image':
item = Photo(title=title,
title_slug=slug)
elif filetype == 'video':
item = Video(title=title,
title_slug=slug)
else:
raise Exception("Unknown file type")
# This will just update path in file entry
move_file(item, full, full)
item.save()
if abs(item.date_taken - item.date_added) < timedelta(seconds=3):
item.date_taken = date_taken
item.save()
print "Added ", item.title, " - ", item.date_taken
break
count = count + 1
示例2: Photo
# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import date_taken [as 别名]
if filetype == 'image':
item = Photo(**kwargs)
elif filetype == 'video':
item = Video(**kwargs)
else:
raise Exception("Unknown file type")
if type(content) == str:
item.file.save(name, ContentFile(content), save=False)
else:
item.file.save(name, File(content), save=False)
item.save()
if tags:
item.tags.add(*tags)
# Assume that item is added to photologue at least 3 seconds after created
if date_taken and abs(item.date_taken - item.date_added) < timedelta(seconds=3):
item.date_taken = date_taken
item.save()
if gallery:
gallery.items.add(item)
if update_dar:
try:
set_mpg_dar(item.file.path)
except:
pass
break
count = count + 1
return count
class TemporaryFile(File):
def temporary_file_path(self):
# This is needed. When we move the file, this will not exist and