def blog_article(request, slug): if request.path != request.path.lower(): return redirect(request.path.lower(), permanent=True) blog_post = get_object_or_404(Post, slugs__slug=slug) active_slug = blog_post.slug if active_slug != slug: return redirect( reverse('micro_blog:blog_article', kwargs={'slug': active_slug})) if not blog_post.status == 'P': if not request.user.is_authenticated(): raise Http404 all_blog_posts = list( Post.objects.filter(status='P').order_by('-published_on')) prev_url = '' next_url = '' for post in all_blog_posts: if str(slug) == str(post.slug): try: current_index = all_blog_posts.index(post) next_que = all_blog_posts[current_index + 1] next_url = '/blog/' + str(next_que.slug) + '/' except: next_url = '' try: current_index = all_blog_posts.index(post) prev_que = all_blog_posts[current_index - 1] if current_index == 0: prev_url = '' else: prev_url = '/blog/' + str(prev_que.slug) + '/' except: prev_url = '' break related_posts = Post.objects.filter( category=blog_post.category, status='P').exclude(id=blog_post.id).order_by('?')[:3] minified_url = '' if 'HTTP_HOST' in request.META.keys(): try: minified_url = google_mini( 'https://' + request.META['HTTP_HOST'] + reverse('micro_blog:blog_article', kwargs={'slug': slug}), settings.GGL_URL_API_KEY) except: minified_url = 'https://' + \ request.META[ 'HTTP_HOST'] + reverse('micro_blog:blog_article', kwargs={'slug': slug}) c = {} c.update(csrf(request)) return render( request, 'site/blog/article.html', { 'csrf_token': c['csrf_token'], 'related_posts': related_posts, 'post': blog_post, 'minified_url': minified_url, 'prev_url': prev_url, 'next_url': next_url })
def get_mini_url(self, request): url = request.build_absolute_uri() try: api_key = os.getenv('API_KEY') url = google_mini(url, api_key) except Exception: pass return url
def blog_article(request, slug): blog_post = get_object_or_404(Post, slug=slug) blog_posts = Post.objects.filter(status='P')[:3] fb = requests.get( 'http://graph.facebook.com/?id=https://micropyramid.com//blog/' + slug) tw = requests.get( 'http://urls.api.twitter.com/1/urls/count.json?url=https://micropyramid.com//blog/' + slug) # r2=requests.get('https://plusone.google.com/_/+1/fastbutton?url= https://keaslteuzq.localtunnel.me/blog/'+slug) ln = requests.get( 'https://www.linkedin.com/countserv/count/share?url=https://micropyramid.com/blog/' + slug + '&format=json') minified_url = '' if 'HTTP_HOST' in request.META.keys(): minified_url = google_mini( 'https://' + request.META['HTTP_HOST'] + reverse('micro_blog:blog_article', kwargs={'slug': slug}), 'AIzaSyDFQRPvMrFyBNouOLQLyOYPt-iHG0JVxss') linkedin = {} linkedin.update(ln.json()) facebook = {} facebook.update(fb.json() if fb else {}) twitter = {} twitter.update(tw.json()) fbshare_count = 0 twshare_count = 0 lnshare_count = 0 try: if facebook['shares']: fbshare_count = facebook['shares'] except Exception: pass try: if twitter['count']: twshare_count = twitter['count'] except Exception: pass try: if linkedin['count']: lnshare_count = linkedin['count'] except Exception: pass c = {} c.update(csrf(request)) return render( request, 'site/blog/article.html', { 'csrf_token': c['csrf_token'], 'post': blog_post, 'posts': blog_posts, 'fbshare_count': fbshare_count, 'twshare_count': twshare_count, 'lnshare_count': lnshare_count, 'minified_url': minified_url })
def blog_article(request, slug): blog_post = get_object_or_404(Post, slug=slug) blog_posts = Post.objects.filter(status="P")[:3] fb = requests.get("http://graph.facebook.com/?id=http://micropyramid.com//blog/" + slug) tw = requests.get("http://urls.api.twitter.com/1/urls/count.json?url=http://micropyramid.com//blog/" + slug) # r2=requests.get('https://plusone.google.com/_/+1/fastbutton?url= https://keaslteuzq.localtunnel.me/blog/'+slug) ln = requests.get( "https://www.linkedin.com/countserv/count/share?url=http://micropyramid.com/blog/" + slug + "&format=json" ) minified_url = "" if "HTTP_HOST" in request.META.keys(): minified_url = google_mini( "http://" + request.META["HTTP_HOST"] + reverse("micro_blog:blog_article", kwargs={"slug": slug}), "AIzaSyDFQRPvMrFyBNouOLQLyOYPt-iHG0JVxss", ) linkedin = {} linkedin.update(ln.json()) facebook = {} facebook.update(fb.json() if fb else {}) twitter = {} twitter.update(tw.json()) fbshare_count = 0 twshare_count = 0 lnshare_count = 0 try: if facebook["shares"]: fbshare_count = facebook["shares"] except Exception: pass try: if twitter["count"]: twshare_count = twitter["count"] except Exception: pass try: if linkedin["count"]: lnshare_count = linkedin["count"] except Exception: pass c = {} c.update(csrf(request)) return render( request, "site/blog/article.html", { "csrf_token": c["csrf_token"], "post": blog_post, "posts": blog_posts, "fbshare_count": fbshare_count, "twshare_count": twshare_count, "lnshare_count": lnshare_count, "minified_url": minified_url, }, )
def blog_article(request, slug): blog_post = get_object_or_404(Post, slugs__slug=slug) active_slug = blog_post.slug if active_slug != slug: return redirect(reverse('micro_blog:blog_article', kwargs={'slug': active_slug}) ) if not blog_post.status == 'P': if not request.user.is_authenticated(): return HttpResponseRedirect('/blog/') if request.path != request.path.lower(): return redirect(request.path.lower(), permanent=True) all_blog_posts = list( Post.objects.filter(status='P').order_by('-published_on')) prev_url = '' next_url = '' for post in all_blog_posts: if str(slug) == str(post.slug): try: current_index = all_blog_posts.index(post) next_que = all_blog_posts[current_index + 1] next_url = '/blog/' + str(next_que.slug) + '/' except: next_url = '' try: current_index = all_blog_posts.index(post) prev_que = all_blog_posts[current_index - 1] if current_index == 0: prev_url = '' else: prev_url = '/blog/' + str(prev_que.slug) + '/' except: prev_url = '' break related_posts = Post.objects.filter( category=blog_post.category, status='P').exclude(id=blog_post.id).order_by('?')[:3] minified_url = '' if 'HTTP_HOST' in request.META.keys(): try: minified_url = google_mini('https://' + request.META['HTTP_HOST'] + reverse( 'micro_blog:blog_article', kwargs={'slug': slug}), settings.GGL_URL_API_KEY) except: minified_url = 'https://' + \ request.META[ 'HTTP_HOST'] + reverse('micro_blog:blog_article', kwargs={'slug': slug}) c = {} c.update(csrf(request)) return render(request, 'site/blog/article.html', {'csrf_token': c['csrf_token'], 'related_posts': related_posts, 'post': blog_post, 'minified_url': minified_url, 'prev_url': prev_url, 'next_url': next_url})
def blog_article(request, slug): blog_post = Post.objects.filter(slug=slug) if blog_post: blog_post = blog_post[0] elif Post.objects.filter(old_slugs__icontains=slug): blog_post = Post.objects.filter(old_slugs__icontains=slug) blog_post = blog_post[0] return redirect(reverse('micro_blog:blog_article', kwargs={'slug': blog_post.slug}), permanent=True) else: raise Http404 all_blog_posts = list(Post.objects.filter(status='P').order_by('-published_on')) prev_url = '' next_url = '' for post in all_blog_posts: if str(slug) == str(post.slug): try: current_index = all_blog_posts.index(post) next_que = all_blog_posts[current_index+1] next_url = '/blog/'+str(next_que.slug)+'/' except: next_url = '' try: current_index = all_blog_posts.index(post) prev_que = all_blog_posts[current_index-1] if current_index == 0: prev_url = '' else: prev_url = '/blog/'+str(prev_que.slug)+'/' except: prev_url = '' question = post break if not blog_post.status == 'P': if not request.user.is_authenticated(): raise Http404 related_posts = Post.objects.filter(category=blog_post.category, status='P').exclude(id=blog_post.id).order_by('?')[:3] minified_url = '' if 'HTTP_HOST' in request.META.keys(): try: minified_url = google_mini('https://' + request.META['HTTP_HOST'] + reverse('micro_blog:blog_article', kwargs={'slug': slug}), settings.GGL_URL_API_KEY) except: minified_url = 'https://' + request.META['HTTP_HOST'] + reverse('micro_blog:blog_article', kwargs={'slug': slug}) c = {} c.update(csrf(request)) return render(request, 'site/blog/article.html', {'csrf_token': c['csrf_token'], 'related_posts': related_posts, 'post': blog_post, 'minified_url': minified_url, 'prev_url': prev_url, 'next_url': next_url})
def blog_article(request, slug): blog_post = get_object_or_404(Post, slug=slug) blog_posts = Post.objects.filter(status='P')[:3] fb = requests.get('http://graph.facebook.com/?id=https://micropyramid.com//blog/'+slug) tw = requests.get('http://urls.api.twitter.com/1/urls/count.json?url=https://micropyramid.com//blog/'+slug) # r2=requests.get('https://plusone.google.com/_/+1/fastbutton?url= https://keaslteuzq.localtunnel.me/blog/'+slug) ln = requests.get('https://www.linkedin.com/countserv/count/share?url=https://micropyramid.com/blog/'+slug+'&format=json') minified_url = '' if 'HTTP_HOST' in request.META.keys(): minified_url = google_mini('https://' + request.META['HTTP_HOST'] + reverse('micro_blog:blog_article', kwargs={'slug': slug}), 'AIzaSyDFQRPvMrFyBNouOLQLyOYPt-iHG0JVxss') linkedin = {} linkedin.update(ln.json()) facebook = {} facebook.update(fb.json() if fb else {}) twitter = {} twitter.update(tw.json()) fbshare_count = 0 twshare_count = 0 lnshare_count = 0 try: if facebook['shares']: fbshare_count = facebook['shares'] except Exception: pass try: if twitter['count']: twshare_count = twitter['count'] except Exception: pass try: if linkedin['count']: lnshare_count = linkedin['count'] except Exception: pass c = {} c.update(csrf(request)) return render(request, 'site/blog/article.html', {'csrf_token': c['csrf_token'], 'post': blog_post, 'posts': blog_posts, 'fbshare_count': fbshare_count, 'twshare_count': twshare_count, 'lnshare_count': lnshare_count, 'minified_url': minified_url})