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 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 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 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 getPictByAlbum(request): messege = {} if request.session.get('is_login', None): albumID = request.GET.get('albumID') if albumID: messege = Tools.getPictCollect(albumID) if messege: messege['status'] = 'success' else: messege['status'] = 'no-picture' else: messege['status'] = 'failed' return JsonResponse(messege) else: return render(request, 'login.html')
def email_auth(request): check_Code = Tools.get_CheckCode(6, False) email_addr = request.POST.get('reg_email_addr') try: models.Email_CheckCode.objects.filter(email_addr=email_addr).delete() except: print('notexist') finally: models.Email_CheckCode.objects.create(email_addr=email_addr, check_code=check_Code, time=timezone.now()) message = '感谢你注册本网站,您的验证码是:' + check_Code send_mail('云图集注册验证', message, settings.DEFAULT_FROM_EMAIL, [email_addr], fail_silently=True) return JsonResponse({'status': 'success'})
def register(request): if request.method == 'POST': _email_checkCode = request.POST.get('reg_chech_code') _username = request.POST.get('reg_username') _password = request.POST.get('reg_pwd') _email_addr = request.POST.get('reg_email_addr') message = {} try: check = models.Email_CheckCode.objects.get(email_addr=_email_addr) checkCode = check.check_code if _email_checkCode == checkCode: now = timezone.now() time = check.time if (now - time) > timezone.timedelta(minutes=10): message = {'status': 'failed', 'reason': '验证码已过期,请重新获取'} else: flag = True try: while flag: account = Tools.get_CheckCode(n=8, alpha=False) if not account == models.UserList.objects.filter( account=account)[0].account: flag = False except: try: user = models.UserList.objects.create( account=int(account), username=_username, password=_password, e_mail_address=_email_addr, administration=0, VIP=False) message = {'status': 'success', 'account': account} except Exception as e: message = {'status': 'failed', 'reason': '迷之错误'} else: message = {'status': 'failed', 'reason': '验证码错误'} except: message = {'status': 'failed', 'reason': '请先获取验证码'} finally: return JsonResponse(message)
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 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)