Skip to content

Commit

Permalink
Added SEO tags
Browse files Browse the repository at this point in the history
Added SEO tags
  • Loading branch information
Anjaneyulu authored and ashwin31 committed Jul 19, 2016
1 parent a7d8c23 commit 8bb2678
Show file tree
Hide file tree
Showing 23 changed files with 613 additions and 580 deletions.
13 changes: 12 additions & 1 deletion django_blog_it/django_blog_it/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from .models import Post, Category, Page, Menu, ContactUsSettings, Theme
from .models import Post, Category, Page, Menu, ContactUsSettings, ROLE_CHOICE, Theme
from django.template.defaultfilters import slugify
# for authentication
from django.contrib.auth import authenticate
Expand All @@ -8,6 +8,7 @@

class UserForm(forms.ModelForm):
password = forms.CharField(required=False, widget=forms.PasswordInput)
role = forms.ChoiceField(choices=ROLE_CHOICE, required=True)

class Meta:
model = User
Expand Down Expand Up @@ -129,6 +130,16 @@ def __init__(self, *args, **kwargs):
'class': 'form-control', "placeholder": "Please enter your Page " + field.capitalize()
})

def clean_title(self):
if not self.instance.id:
if self.Meta.model.objects.filter(slug=slugify(self.cleaned_data['title'])).exists():
raise forms.ValidationError('Page with this title already exists.')
else:
if self.Meta.model.objects.filter(title__icontains=self.cleaned_data['title']).exclude(id=self.instance.id):
raise forms.ValidationError('Page with this title already exists.')

return self.cleaned_data['title']


class MenuForm(forms.ModelForm):
class Meta:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-07-15 06:53
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('django_blog_it', '0009_contactussettings'),
]

operations = [
migrations.AlterField(
model_name='post',
name='featured_image',
field=models.ImageField(blank=True, null=True, upload_to='static/blog/uploads/%Y/%m/%d/'),
),
]
25 changes: 0 additions & 25 deletions django_blog_it/django_blog_it/migrations/0010_theme.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-07-19 10:28
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('django_blog_it', '0010_auto_20160715_0653'),
]

operations = [
migrations.CreateModel(
name='Theme',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=20, unique=True)),
('slug', models.CharField(max_length=20, unique=True)),
('description', models.CharField(max_length=500)),
('enabled', models.BooleanField(default=False)),
],
),
migrations.AddField(
model_name='category',
name='meta_description',
field=models.TextField(blank=True, max_length=160, null=True),
),
migrations.AddField(
model_name='category',
name='meta_keywords',
field=models.TextField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='post',
name='meta_description',
field=models.TextField(blank=True, max_length=160, null=True),
),
migrations.AlterField(
model_name='post',
name='slug',
field=models.SlugField(max_length=100, unique=True),
),
migrations.AlterField(
model_name='post',
name='title',
field=models.CharField(max_length=100, unique=True),
),
]
15 changes: 15 additions & 0 deletions django_blog_it/django_blog_it/mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.http.response import HttpResponseRedirect
from .models import UserRole, Post
from django.shortcuts import render, render_to_response, get_object_or_404
from django.contrib import messages


def get_user_role(user):
Expand All @@ -10,12 +11,26 @@ def get_user_role(user):
return 'No User Role'


class AdminOnlyMixin(object):

def dispatch(self, request, *args, **kwargs):
user = self.request.user
if not (user.is_authenticated and user.is_active):
return HttpResponseRedirect('/dashboard/')
if not user.is_superuser:
messages.warning(request, "You don't have permission")
return HttpResponseRedirect(request.META.get('HTTP_REFERER', "/"))
return super(AdminOnlyMixin, self).dispatch(request, *args, **kwargs)


class AdminMixin(object):

def dispatch(self, request, *args, **kwargs):
user = self.request.user
if not (user.is_authenticated and user.is_active):
return HttpResponseRedirect('/dashboard/')
# if not user.is_superuser:
# return HttpResponseRedirect("/")
return super(AdminMixin, self).dispatch(request,
*args,
**kwargs)
Expand Down
7 changes: 5 additions & 2 deletions django_blog_it/django_blog_it/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Category(models.Model):
slug = models.CharField(max_length=20, unique=True)
description = models.CharField(max_length=500)
is_active = models.BooleanField(default=False)
meta_description = models.TextField(max_length=160, null=True, blank=True)
meta_keywords = models.TextField(max_length=255, null=True, blank=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL)

def save(self, *args, **kwargs):
Expand Down Expand Up @@ -75,10 +77,11 @@ def create_tag_slug(tempslug):


class Post(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField(max_length=100)
title = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateField(auto_now=True)
meta_description = models.TextField(max_length=160, null=True, blank=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL)
content = models.TextField()
category = models.ForeignKey(Category)
Expand Down
18 changes: 13 additions & 5 deletions django_blog_it/django_blog_it/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
{% load blog_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blog - {% block title %}Home{% endblock %}</title>
<title>{% blog_title as blogtitle %}{{ blogtitle }} - {% block title %}Home{% endblock %}</title>
{% block description %}
<meta property="og:title" content="Home - micro-blog - simple blog package - MicroPyramid." />
<meta property="og:description" content="micro-blog - simple blog package - MicroPyramid." />
<meta name="description" content="micro-blog - simple blog package - MicroPyramid." />
<meta name="keywords" content="simple" />
<link rel="canonical" href="{{ request.build_absolute_uri }}"/>
<meta property="og:url" content="{{ request.build_absolute_uri }}" />
<meta property="og:image" content="{{ og_image }}" />
<meta property="og:title" content="{{ title }}" />
<meta property="og:description" content="{{ description|truncatechars:160 }}" />

<meta name="title" content="{{ title }}" />
<meta name="description" content="{{ description|truncatechars:160 }}" />
<meta name="keywords" content="{{ keywords }}" />
<meta name="author" content="{{ author }}" />
<meta name="robots" content="index, follow">
{% endblock %}

{% load staticfiles %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
{% endif %}
</div>
<div class="col-md-6 filter_right">
<form action="" method="post" id="menus_data" class="form-inline">
{% csrf_token %}
<input type="text" placeholder="Filter By Title" value="{% if request.POST %}{{ request.POST.search_text }}{% endif %}" name='search_text' class="form-control" />
<form action="" method="GET" id="menus_data" class="form-inline">
<input type="text" placeholder="Filter By Title" value="{{ request.GET.search_text }}" name='search_text' class="form-control" />
<select class="form-control" id="select_status" name="select_status">
<option value="" default>Status</option>
<option value="True" {% ifequal request.POST.select_status "True" %}Selected{% endifequal %}>Active</option>
<option value="False" {% ifequal request.POST.select_status "False" %}Selected{% endifequal %}>Inactive</option>
<option value="True" {% ifequal request.GET.select_status "True" %}Selected{% endifequal %}>Active</option>
<option value="False" {% ifequal request.GET.select_status "False" %}Selected{% endifequal %}>Inactive</option>
</select>
<button class="btn btn-default" type="submit">Apply Filter</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
{% endif %}
</div>
<div class="col-md-6 filter_right">
<form action="" method="post" id="pages_data" class="form-inline">
{% csrf_token %}
<input type="text" placeholder="Filter By Title" value="{% if request.POST %}{{ request.POST.search_text }}{% endif %}" name='search_text' class="form-control" />
<form action="" method="GET" id="pages_data" class="form-inline">
<input type="text" placeholder="Filter By Title" value="{{ request.GET.search_text }}" name='search_text' class="form-control" />
<select class="form-control" id="select_status" name="select_status">
<option value="" default>Status</option>
<option value="True" {% ifequal request.POST.select_status "True" %}Selected{% endifequal %}>Active</option>
<option value="False" {% ifequal request.POST.select_status "False" %}Selected{% endifequal %}>Inactive</option>
<option value="True" {% ifequal request.GET.select_status "True" %}Selected{% endifequal %}>Active</option>
<option value="False" {% ifequal request.GET.select_status "False" %}Selected{% endifequal %}>Inactive</option>
</select>
<button class="btn btn-default" type="submit">Apply Filter</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@
</div>
{% endif %}
{% endfor %}
<div class="form-group col-md-12">
<label>User Role :</label>
<select class='input form-control' id="id_role" name="role">
<option value="">Role</option>
{% for role in roles %}
<option value="{{ role.0 }}" {% ifequal user_role.0.role role.0 %}Selected{% endifequal %}>{{ role.1 }}</option>
{% endfor %}
</select>
</div>
</div>
</div>
<br clear="all">
<div class=" col-md-12 buttons_row text-left">
Expand Down Expand Up @@ -100,13 +90,12 @@
$('#post-form').submit(function(event){
event.preventDefault();
$.post(".",$('#post-form').serialize(), function(data){
$('p.error').remove();
if(data.error){
$('p.error_required').remove();
for (var list in data.response){
for (var key in data.response[list]) {
$('#id_' + key).after('<p class="error_required">* ' + data.response[list][key] + '</p>');
}
}
$.each(data.response, function(field_name, error){
error = "<p class=\"error\">" + error + "</p>"
$("[name=" + field_name + "]").after(error)
});
}else{
//alert(data['response']);
window.location="{% url 'users' %}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
{% endif %}
</div>
<div class="col-md-6 filter_right">
<form action="" method="post" id="users_data" class="form-inline">
{% csrf_token %}
<input type="text" placeholder="Filter By Title" value="{% if request.POST %}{{ request.POST.search_text }}{% endif %}" name='search_text' class="form-control" />
<form action="" method="GET" id="users_data" class="form-inline">
<input type="text" placeholder="Filter By Title" value="{{ request.GET.search_text }}" name='search_text' class="form-control" />
<select class='input form-control' id="select_role" name="select_role">
<option value="" default>Role</option>
{% for role in roles %}
<option value="{{ role.0 }}" {% ifequal request.POST.select_role role.0 %}Selected{% endifequal %}>{{ role.1 }}</option>
<option value="{{ role.0 }}" {% ifequal request.GET.select_role role.0 %}Selected{% endifequal %}>{{ role.1 }}</option>
{% endfor %}
</select>
<button class="btn btn-default" type="submit">Apply Filter</button>
Expand Down Expand Up @@ -79,7 +78,7 @@
<td>{% if user.first_name %}{{ user.first_name }}{% else %}<center> -- </center>{% endif %}</td>
<td>{% if user.last_name %}{{ user.last_name }}{% else %}<center> -- </center>{% endif %}</td>
<td><a href="#">{{ user.email }}</a></td>
<td>{{ user|get_user_role_name }}</td>
<td>{{ user.userrole_set.last.role }}</td>
<td class="status_on_off text-center">
{% if user.is_active %}
<a href="#" class="status_on" data-toggle="tooltip" data-placement="bottom" title="Active"><i class="fa fa-circle" aria-hidden="true"></i></a>
Expand Down
2 changes: 1 addition & 1 deletion django_blog_it/django_blog_it/templates/posts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h3><span> Categories </span></h3>
</ul>
</div>
<div class="col-xs-12 widget blog-posts" id="green">
<h3><span> Blog-Posts </span></h3>
<h3><span> Blog Archive </span></h3>
<ul style="margin:0px;padding:0px;">
{% get_archives as archives %}
{% for archive in archives %}
Expand Down
3 changes: 2 additions & 1 deletion django_blog_it/django_blog_it/templates/posts/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends 'posts/base.html' %}
{% block title %} {{ title }} {% endblock %}
{% load paginate %}
{% load blog_tags %}
{% block blog_content %}
Expand All @@ -7,7 +8,7 @@
<li itemprop="itemListElement" itemscope
itemtype="http://schema.org/ListItem">
<a itemprop="item" href="/">
<span itemprop="name">Blog</span></a>
<span itemprop="name">Home</span></a>
<meta itemprop="position" content="1" />
</li>
{% if tag %}
Expand Down
6 changes: 6 additions & 0 deletions django_blog_it/django_blog_it/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django import template
from django_blog_it.django_blog_it.models import Post, Tags, Menu
from django_blog_it.django_blog_it.views import get_user_role
from django_blog_it import settings

register = template.Library()

Expand Down Expand Up @@ -73,6 +74,11 @@ def user_published_posts(user):
).count()


@register.assignment_tag
def blog_title():
return settings.BLOG_TITLE


@register.filter
def category_posts(category):
return Post.objects.filter(category=category).count()

0 comments on commit 8bb2678

Please sign in to comment.