Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share in fb, g+, tw added with micro url #77

Merged
merged 17 commits into from Jul 20, 2016
7 changes: 7 additions & 0 deletions django_blog_it/django_blog_it/templates/posts/blog_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
</ol>
<!-- end -->
<div class="blogs" itemtype="http://schema.org/BlogPosting">
<!-- share -->
<div>
<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u={{short_url}}&t={{blog_name.title}}" class="facebook"><i class="fa fa-facebook"></i></a>
<a target="_blank" href="https://plus.google.com/share?hl=en-US&url={{short_url}}" class="google-plus"><i class="fa fa-google-plus"></i></a>
<a target="_blank" href="https://twitter.com/intent/tweet?text={{blog_name.title}}&url={{short_url}}&via={{blog_title}}" class="twitter"><i class="fa fa-twitter"></i></a>
<a target="_blank" href="https://www.linkedin.com/cws/share?url={{ short_url }}&token=&isFramed=true" class="linkedin"><i class="fa fa-linkedin"></i></a>
</div>
<ul class="blog-list">
<table align="center" class="table table-bordered">
<thead>
Expand Down
12 changes: 6 additions & 6 deletions django_blog_it/django_blog_it/templates/posts/new_blog_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@
<div class="social_block">
<ul class="social_connections">
<li class="text-center">
<a href="#" class="facebook">
<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u={{short_url}}&t={{blog_name.title}}" class="facebook">
<i class="fa fa-facebook"></i>
Facebook
</a>
</li>
<li class="text-center">
<a href="#" class="twitter">
<a target="_blank" href="https://twitter.com/intent/tweet?text={{blog_name.title}}&url={{short_url}}&via={{blog_title}}" class="twitter">
<i class="fa fa-twitter"></i>
Twitter
</a>
</li>
<li class="text-center">
<a href="#" class="google">
<a target="_blank" href="https://plus.google.com/share?hl=en-US&url={{short_url}}" class="google">
<i class="fa fa-google"></i>
Google Plus
</a>
</li>
<li class="text-center">
<a href="#" class="youtube">
<i class="fa fa-youtube-play"></i>
Youtube
<a target="_blank" href="https://www.linkedin.com/cws/share?url={{ short_url }}&token=&isFramed=true" class="youtube">
<i class="fa fa-linkedin"></i>
Linkedin
</a>
</li>
<br clear="all">
Expand Down
2 changes: 1 addition & 1 deletion django_blog_it/django_blog_it/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_blog_post(self):
self.assertTrue(user_login)

response = self.client.get('/dashboard/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 302)

response = self.client.get('/dashboard/blog/')
self.assertEqual(response.status_code, 200)
Expand Down
5 changes: 5 additions & 0 deletions django_blog_it/django_blog_it/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class AdminLoginView(FormView):
template_name = "dashboard/new_admin-login.html"
form_class = AdminLoginForm

def dispatch(self, request, *args, **kwargs):
if(request.user.is_authenticated and request.user.is_active):
return HttpResponseRedirect(reverse("blog"))
return super(AdminLoginView, self).dispatch(request, *args, **kwargs)

def form_valid(self, form):
user = authenticate(username=form.cleaned_data['username'],
password=form.cleaned_data['password'])
Expand Down
15 changes: 14 additions & 1 deletion django_blog_it/posts/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from datetime import datetime
from django.shortcuts import render, get_list_or_404, get_object_or_404
from django_blog_it.django_blog_it.models import Post, Category, Tags, Page
Expand All @@ -6,8 +7,8 @@
from django_blog_it import settings
from django.contrib import messages
from django.http import Http404, JsonResponse
# cbv
from django.views.generic import ListView, DetailView
from microurl import google_mini


def categories_tags_lists():
Expand All @@ -26,6 +27,7 @@ def categories_tags_lists():
# real_tags = Tags.objects.get(slug=tag)
# return real_tags


class Home(ListView):
template_name = "posts/index.html"
queryset = Post.objects.filter(status='Published', category__is_active=True).order_by('-updated_on')
Expand All @@ -49,6 +51,15 @@ class BlogPostView(DetailView):
slug_url_kwarg = "blog_slug"
context_object_name = "blog_name"

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 get_context_data(self, *args, **kwargs):
context = super(BlogPostView, self).get_context_data(*args, **kwargs)
user = self.object.user
Expand All @@ -65,6 +76,8 @@ def get_context_data(self, *args, **kwargs):
"title": self.object.title,
"keywords": self.object.keywords,
"author": author,
"short_url": self.get_mini_url(self.request),
"blog_title": settings.BLOG_TITLE
})
context.update(categories_tags_lists())
return context
Expand Down
1 change: 1 addition & 0 deletions django_blog_it/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
MEDIA_ROOT = settings.MEDIA_ROOT if settings.MEDIA_ROOT else os.path.join(BASE_DIR + '/media/') # settings.MEDIA_ROOT if settings.MEDIA_ROOT else os.path.join(BASE_DIR + '/media/')

DISQUS_SHORTNAME = getattr(settings, 'DISQUS_SHORTNAME', '')

BLOG_TITLE = "My Django Blog"
BLOG_DESCRIPTION = "Rapid development of web applications"
BLOG_KEYWORDS = "django, python, webframework"
Expand Down
22 changes: 0 additions & 22 deletions django_blog_it/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,6 @@
url(r'^dashboard/bulk_actions_themes/$',
bulk_actions_themes, name='bulk_actions_themes'),

# themes management
url(r'^dashboard/themes/$', ThemesList.as_view(), name='themes'),
# url(r'^dashboard/themes/add/$', add_theme, name='add_theme'),
url(r'^dashboard/themes/add/$',
ThemeCreateView.as_view(),
name='add_theme'),
url(r'^dashboard/themes/(?P<theme_slug>[-\w]+)/$',
ThemeDetailView.as_view(),
name='view_theme'),
url(r'^dashboard/themes/edit/(?P<pk>[0-9]+)/$',
ThemeUpdateView.as_view(),
name='edit_theme'),
# url(r'^dashboard/themes/edit/(?P<theme_slug>[-\w]+)/$',
# edit_theme, name='edit_theme'),
url(r'^dashboard/themes/delete/(?P<pk>[-\w]+)/$',
DeleteThemeView.as_view(),
name='delete_theme'),
# url(r'^dashboard/themes/delete/(?P<theme_slug>[-\w]+)/$',
# delete_theme, name='delete_theme'),
url(r'^dashboard/bulk_actions_themes/$',
bulk_actions_themes, name='bulk_actions_themes'),

url(r'^dashboard/contactUs/$',
configure_contact_us, name='configure_contact_us'),

Expand Down
3 changes: 2 additions & 1 deletion sandbox/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ requests==2.10.0
gunicorn==19.6.0
whitenoise==3.1
dj-database-url==0.4.1
psycopg2==2.6.1
psycopg2==2.6.1
microurl==0.1