Пример #1
0
 def post(self, request):
     create_time = request.POST.get('create_time', '1')
     photo_name = request.POST.get('photo_name', '1')
     photo = Photo()
     photo.create_time = create_time
     photo.image = photo_name
     photo.save()
     print(create_time, photo_name)
     return JsonResponse({"res": 1, "message": "chenggong"})
Пример #2
0
 def test_read_exif(self):
     """
     测试exif读取,需要准备一张含有exif的照片
     :return: None
     """
     photo = Photo(path="/IMG_20181202_084309.jpg")
     photo._read_exif()
     print("datetime_original:", photo.datetime_original)
     print("gps:", photo.gps_longitudes, photo.gps_latitudes)
     self.assertIsNotNone(photo.datetime_original)
     self.assertIsNotNone(photo.gps_longitudes)
     self.assertIsNotNone(photo.addr_text)
Пример #3
0
def photo_load(request, pk, apk):
    o = get_object_or_404(Object, pk=pk)
    a = get_object_or_404(Album, pk=apk)
    if request.method == 'POST':
        for file in request.FILES.getlist('file'):
            p = Photo()
            p.owner = request.user
            p.published_date = timezone.now()
            p.album = a
            p.photo.save(str(file), file, save=True)
            p.thumb_make()
            p.save()
    return redirect('object.views.object_view', pk=o.pk)
Пример #4
0
 def pipeline(self, mediaItem):
     # only download images
     try:
         # get the image data
         filename = mediaItem['filename']
         imagebinary = self.session.get(mediaItem['baseUrl'] + '=d').content
         with open(f'{self.IFR}/{self.userId}/{filename}',
                   mode='wb') as handler:
             handler.write(imagebinary)
         image = Image(content=imagebinary)
         response = self.client.label_detection(image=image)
         if response.error.message:
             raise Exception(response.error.message)
         labels = response.label_annotations
         ltemp = list(map(getLabelDescription, labels))
         mLabels = toMandarin(ltemp)
         t = Tag()
         bs = BasicStructure()
         for el, l in zip(ltemp, labels):
             bs.main_tag.append(ATag(tag=el, precision=l.score))
         t.en = bs
         if mLabels and len(mLabels) > 0:
             bs = BasicStructure()
             for ml, l in zip(mLabels, labels):
                 bs.main_tag.append(ATag(tag=ml, precision=l.score))
             t.zh_tw = bs
         tempcreationTime = mediaItem['mediaMetadata']['creationTime']
         sliceTime = tempcreationTime.split('Z')[0].split(
             '.')[0] if '.' in tempcreationTime else tempcreationTime.split(
                 'Z')[0]
         realTime = datetime.datetime.strptime(sliceTime,
                                               "%Y-%m-%dT%H:%M:%S")
         pho = Photo(
             photoId=mediaItem['id'],
             filename=filename,
             userId=self.userId,
             tag=t,
             createTime=make_aware(realTime,
                                   timezone=pytz.timezone(
                                       settings.TIME_ZONE)),
         )
         pho.save()
     except Exception as e:
         logging.error(e)
         print(f'Error from initial vision api pipline {e}')
         print(traceback.format_exc())
Пример #5
0
def photo_handle(request):
    userFolder = "img/" + str(request.user.id) + "-" + \
        str(request.user.username)
    ffolder = '{}/{}'.format(settings.MEDIA_ROOT, userFolder)
    if not os.path.exists(ffolder):
        os.makedirs(ffolder)

    f1 = request.FILES.get('pic')  # 从前端获取上传的图片
    fname = ffolder + "/" + f1.name  # 图片的完整路径
    # print(fname)

    with open(fname, 'wb') as pic:  # 文件操作
        for c in f1.chunks():  # 因为图片存储的方式是二进制流,用f1.chunks()获取图片的字节
            pic.write(c)

    pic1 = Photo()
    pic1.pic = '{}/{}'.format(userFolder, f1.name)
    pic1.author = request.user

    pic1.save()
    return HttpResponse('OK')
Пример #6
0
def photo_save(request: HttpRequest, auction_id: int):
    if not request.user.is_authenticated:
        return JsonResponse({'result': 0, 'msg': 'Вы не авторизованы'})
    try:
        auction = Auction.objects.get(pk=auction_id)
    except Auction.DoesNotExist:
        return JsonResponse({'result': 0, 'msg': 'Аукцион не существует'})
    if auction.user.id != request.user.id:
        return JsonResponse({'result': 0, 'msg': 'Ошибка загрузки файла'})

    photo = Photo(auction_id=auction_id)
    form = PhotoForm(request.POST, request.FILES, instance=photo)
    if form.is_valid():
        try:
            form.save()
        except IntegrityError:
            return JsonResponse({'result': 0, 'msg': 'Ошибка загрузки файла'})
    else:
        return JsonResponse({'result': 0, 'msg': 'Ошибка загрузки файла'})
    request.session['open_gallery_tab'] = True
    return JsonResponse({'result': 1})
Пример #7
0
 def test_build_faces_from_photo(self):
     photo = Photo(path="/0e67e4b99c2c4028a7bfc9c7dabe5152_r.jpg")
     photo.save()
     face = Face.build_faces_from_photo(photo)
     self.assertIsNotNone(face)