def post_view(request): # -----------------------------------------here is the function logic------------------------------------------------------------ user = check_validation(request) if user: if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() path = str(BASE_DIR + "//" + post.image.url) client = ImgurClient(client_id, client_sec) post.image_url = client.upload_from_path(path, anon=True)['link'] post.save() return redirect('/feed/') else: form = PostForm() return render(request, 'posts.html', {'form' : form}) return render(request, 'posts.html', {'form': form}) else: return redirect('/login/')
def post_view(request): user = check_validation(request) if user: if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') text = form.cleaned_data.get('text') post = PostModel(user=user, image=image, caption=caption, text=text) post.save() path = str(BASE_DIR + '/' + post.image.url) client = ImgurClient('37e25d0cbc857c0', 'f7a8c883baef922700e185d6b987a607c7a56840') post.image_url = client.upload_from_path(path,anon=True)['link'] post.save() return redirect('/feed/') else: form = PostForm() return render(request, 'feed.html', {'form': form}) else: return redirect('/')
def post_view(request): user = check_validation(request) form = PostForm() if user: if request.method == 'GET': form = PostForm() return render(request, 'post.html', {'form': form}) elif request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') userpost = PostModel(user=user, image=image, caption=caption) userpost.save() print userpost.image.url path = os.path.join(BASE_DIR, userpost.image.url) print BASE_DIR print path client = ImgurClient( '152e68c38c8c4b3', 'b1f871c0a6d1cb40fbdd3eab5d9b6d8f5e17dbc5') userpost.image_url = client.upload_from_path(path, anon=True)['link'] userpost.save() return redirect('/feed/') else: form = PostForm() return render(request, 'post.html', {'form': form}) else: return redirect('/login/')
def post_view(request): user = check_validation(request) if user: if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() path = str(BASE_DIR +'/'+ post.image.url) client = ImgurClient(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET) post.image_url = client.upload_from_path(path, anon=True)['link'] #Creating instance of an API with KEY app = ClarifaiApp(api_key=KEY) model = app.models.get('nsfw-v1.0') response_image = model.predict_by_url(url=post.image_url) safe=response_image['outputs'][0]['data']['concepts'][0]['value'] set_api_key(PKEY) response = sentiment(str(caption)) sentiment_value = response['sentiment'] if sentiment_value > 0.6 and safe > 0.6: post.save() success_message = 'Post can be submitted' return render(request, 'post.html', {'success_message': success_message}) else: error_message = 'Post cannot be submitted' post.delete() return render(request, 'post.html', {'error_message': error_message}) return redirect('/feed/') else: form = PostForm() return render(request, 'post.html', {'form' : form}) else: return redirect('/login/')
def post_view(request): user = check_validation(request) dict = {} if user: if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() path = str(BASE_DIR + '/' + post.image.url) client = ImgurClient(client_id, client_secret) post.image_url = client.upload_from_path(path, anon=True)['link'] post.save() app = ClarifaiApp(api_key=clarifai_api) model = app.models.get('logo') response = model.predict_by_url(url=post.image_url) try: val = float(response['outputs'][0]['data']['regions'][0]['data']['concepts'][0]['value']) * 10 val = float("%.2f" % (val)) except: val = 7.55 else: pass point = PointsModel(post=post, point=val) point.save() return redirect('/feed/') else: form = PostForm() dict['form'] = form return render(request, 'post.html', dict) else: return redirect('/login/')
def post_view(request): user = check_validation(request) if user: if request.method == 'POST': form = Postform(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() path = str(BASE_DIR + post.image.url) client = ImgurClient('4669283752027f6','8f2acc853f96e16e10e2c112bfe945b6d8e1dc08') post.image_url = client.upload_from_path(path, anon=True)['link'] post.save() return redirect('/feed/') else: form = Postform() return render(request, 'post.html', {'form': form}) else: return redirect('/login/')