def success(request): if request.session.get('is_login', None): account = request.session.get('user_id', None) user = request.session.get('user_name', None) info = Tools.getInfo(account) pict = Tools.getPicturePath(info['pict']) message = {'pict': pict, 'user': user, 'setting': info['settings']} return render(request, 'fankui.html', {'message': message}) else: return render(request, 'login.html')
def getInfo_Album(request): if not request.session.get('is_login', None): return render(request, 'login.html') account = request.session['user_id'] username = request.session['user_name'] print(account) print(username) message = {} message['userName'] = username message['albumID'] = [] info = Tools.getInfo(account) message['pict'] = Tools.getPicturePath(info['pict']) message['settings'] = info['settings'] if models.Album.objects.filter(account=account).exists(): album = models.Album.objects.filter( account=account).order_by('-alterTime') for _album in album: if not models.Storage.objects.filter( pictureID=_album.pictureID_id).exists(): pictID = Tools.getPictCollect(_album.albumID)['pictID'] path = Tools.getPicturePath(pictID[pictID.length - 1]) else: path = Tools.getPicturePath(_album.pictureID_id) message['albumID'].append(_album.albumID) message['albumID_' + str(_album.albumID)] = { 'albumName': _album.albumName, 'alterTime': _album.alterTime, 'cover': path } message['status'] = 'success' else: message['status'] = 'failed' message['reason'] = '用户还未创建相册' return JsonResponse(message)
def search(request, content): if request.session.get('is_login', None): account = request.session.get('user_id', None) keyword = content result = Tools.search(account, keyword) path = [] for res in result['picture']: pictPath = Tools.getPicturePath(res)['path'] path.append(pictPath) return render(request, 'searchresult.html', { 'status': 'success', 'path': path, 'pictID': result }) else: return render(request, 'login.html')
def changToInfo(request): if request.session.get('is_login', None): account = request.session.get('user_id', None) user = request.session.get('user_name', None) info = Tools.getInfo(account) pict = Tools.getPicturePath(info['pict']) messege = { 'pict': pict, 'user': user, 'info': info['info'], 'email': info['email'], 'setting': info['settings'] } return render(request, 'xinxi.html', {'message': messege}) else: return render(request, 'login.html')
def showRecycle(request): if request.session.get('is_login', None): account = request.session.get('user_id', None) pictID = [] pictPath = [] message = {} if models.User.objects.filter(account=account, is_delete=True).exists(): pict = models.User.objects.filter(account=account, is_delete=True) for pic in pict: pictID.append(pic.pictureID_id) path = Tools.getPicturePath(pic.pictureID_id) pictPath.append(path['path']) message['pictID'] = pictID message['pict'] = pictPath message['status'] = 'success' else: message['status'] = 'no-picture' return JsonResponse(message) else: return render(request, 'login.html')
def addAlbum(request): message = {} message['albumID'] = [] account = request.session['user_id'] albumName = request.GET.get('name') if account is not None and albumName is not None: album = Tools.createAlbum(account, albumName, albumName) if models.Album.objects.filter(account=account).exists(): album = models.Album.objects.filter( account=account).order_by('-alterTime') for _album in album: path = Tools.getPicturePath(_album.pictureID_id) message['albumID'].append(_album.albumID) message['albumID_' + str(_album.albumID)] = { 'albumName': _album.albumName, 'alterTime': _album.alterTime, 'cover': path } message['status'] = 'success' elif albumName is None: message = {'status': 'failed', 'reason': '相册名不能为空'} return JsonResponse(message)
def upload(request): if request.method == 'POST': albumID = request.POST.get('id', None) img = request.FILES.getlist('file') current_account = request.session.get('user_id') message = {} try: for i in img: pictureId = Tools.getPictureID(current_account) originalName = i.name bh_name = os.path.splitext(originalName)[-1] if not is_img(bh_name): continue url = '/' + str(pictureId) + bh_name imageName = '%s%s' % (settings.MEDIA_ROOT, url) with open(imageName, 'wb') as imgWriter: for i in i.chunks(): imgWriter.write(i) # 调用baiduAPI进行图像识别,返回list {'score': 0.838397, 'root': '非自然图像-设计图', 'keyword': '图表'} reco = recognize.shibie(imageName) piture = models.Storage.objects.create( pictureID=pictureId, pictureName=originalName, path=imageName, alterTime=timezone.now()) models.PitTag.objects.create(pictureID=piture, tag_1=str(reco[0]), tag_2=str(reco[1]), tag_3=str(reco[2])) models.User.objects.create( account=models.UserList.objects.filter( account=current_account)[0], pictureID=models.Storage.objects.filter( pictureID=pictureId)[0]) if albumID == '0': Tools.collectPicture(current_account, pictureId) message['albumID'] = [] if models.Album.objects.filter( account=current_account).exists(): album = models.Album.objects.filter( account=current_account).order_by('-alterTime') for _album in album: path = Tools.getPicturePath(_album.pictureID_id) message['albumID'].append(_album.albumID) message['albumID_' + str(_album.albumID)] = { 'albumName': _album.albumName, 'alterTime': _album.alterTime, 'cover': path } message['status'] = 'success' else: models.AlbumStorage.objects.create( albumID=models.Album.objects.get(albumID=int(albumID)), pictureID=piture) album = models.Album.objects.get(albumID=albumID) album.pictureID_id = pictureId album.save() message = Tools.getPictCollect(albumID) if message: message['status'] = 'success' else: message['status'] = 'no-picture' imgWriter.close() except Exception as writeE: message['status'] = 'failed' return JsonResponse(message)