#
July 7, 2016, 10:28 p.m.

Upgrades Complete!

Frame Breaking 1812

The Nomadic Americans Labs Django Blog project site is pretty much in a finished state regarding all of the functionality and features that I desired to have to "baked-in" to the Django project itself, post Django-Girls tutorial.

Although, this post will go into granular detail regarding the last 4 features to build out. I am listing the desired feature set in it's entirety and there will be another post outlining what went into building out the remaining features on the list itself. So I have 9 features/capabilities that I need to have in this Django Blog app, and it pretty much mirrors everything that I have for my Pelican Based Blog project. That project has not had any new content for a while because I have been focusing on this project, but if you like what you see there then I urge you and challenge you to go there and READ my other content on that site.

Now all of this being said, I really love Django, but it's serious overkill in my opinion in regards to a single user/author blog. Honestly, also from an Application Security perspective I would still just want to go with a flat text file based static generator blog than Django for my personal needs.

On the flip side though, I guess in a nutshell now that I have been "Baptized by Fire" so to speak, I think in hindsight and lessons learned after documenting all of this and rethinking some things, it is possible that I can make some things much easier with this project. Before summer is over maybe I can come up with something.

So there were three files that ultimately were edited, modified and created during this whole process.

  • settings.py
  • sitemaps.py - This is a completely new file needed to implement the sitemaps.xml functionality.
  • post_detail.html - Template: Alot of the original Django girls comments system was commented out in this file
  • add_comment_to_post.html - This file was parked/removed because it is not needed anymore once Disqus was implemented

What follows now are the code snippets from the respective files with the comments:

settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

# Added 07/06/16 in order to implement sitemaps.xml functionality for the site
# https://docs.djangoproject.com/en/1.9/ref/contrib/sitemaps/

    'django.contrib.sitemaps',

# Added 07/06/16 in order to implement robots.txt functionality for the site, pip install django-robots, depends on sites
# framework - https://django-robots.readthedocs.io/en/latest/


    'robots',
    'markup_deprecated',
    'simple_links',
    'ganalytics',
    'blog',

# Added 07/06/16 in order to implement DISQUS COMMENTS functionality across the site

   'disqus',
]

# Added SITE_URL 07/06/16 in order to implement site.xml funcitonality - django-sitemaps

SITE_URL = 'http://nomadicals51.pythonanywhere.com'

# Added SITE_ID 07/06/16 in order to implement site.xml functionality - django-sitemaps - depends on sites-framework
# Note/Caveat: This was a real PITA because normally the default would have been SITE_ID = 1 but because of the or
# sequence in which the default domain example.com was deleted and then added the 'production' domain, I had to guess
# which number it was, or go through the database, but if this not not correct the 'sites' framework will barf and error
# https://docs.djangoproject.com/en/1.9/ref/contrib/sites/ - It would behoove you not to read this

SITE_ID = 4

# Added DISQUS_WEBSITE_SHORTNAME in order to build-out DISQUS COMMENTS functionality for the site
# https://django-disqus.readthedocs.io/en/latest/
DISQUS_WEBSITE_SHORTNAME = 'somesitename'

# Added DISQUS_API_KEY in order to build-out DISQUS COMMENTS functionality for the site
# https://django-disqus.readthedocs.io/en/latest/
DISQUS_API_KEY = 'jnVFExFVHxXcxW0UAhNxhdXXXXXXXXXXXXXX66666666T1jusz30ncF4ifthkq'

# Added SECURE_SSL_REDIRECT in order to SSL encryption across the site for users visiting the site
# https://github.com/rdegges/django-sslify - Suggest you read the docs carefully
# You don't really have to install the package on version 1.9, you just add the setting below and set it to true

SECURE_SSL_REDIRECT = True

sitemap.py

# in the class name "Blog" is the name of my "app", so you name it beginning with your "App" name
# in the import statement of blog.models "Post" is my orm/db object, other might have some other name e.g. Entry, Memo?


from django.contrib.sitemaps import Sitemap
from blog.models import Post

class BlogSitemap(Sitemap):
    changefreq = "never"
    priority = 0.5

def items(self):
    return Post.objects.all()

urls.py

from blog.sitemap import BlogSitemap

from django.contrib.sitemaps.views import sitemap

from django.views.generic import DetailView, ListView

#The above 3 import statements were added when I was troubleshoutting and configuring sitemap.xml functionality
#After seeing them in https://godjango.com/23-robots-and-sitemaps/,Buddy Lindsey's website. They helped all I can say.

# The below two lines were added to roll-out sitemap.xml/robots.txt functionality.
# Watch the video https://godjango.com/23-robots-and-sitemaps/
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
    url(r'^robots.txt$', include('robots.urls')),

post_detail.html

{% extends 'blog/base.html' %}
{% load markup %}
{% block content %}

    <div class="post">
        {% if post.published_date %}
            <div class="date">
                {{ post.published_date }}
        {% else %}
            </div>
            <a class="btn btn-default" href="{% url 'blog.views.post_publish' pk=post.pk %}">Publish</a>
            {% endif %}
    {% if user.is_authenticated %}
            <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-   
 pencil"></span></a>
            <a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-
remove"></span></a>
    {% else %}
            <a href="{% url 'django.contrib.auth.views.login' %}" class="top-menu"><span class="glyphicon glyphicon-
lock"></span></a>
        {% endif %}
        <h1>{{ post.title }}</h1>
     <p>{{ post.text|markdown }}</p>
     </div>
     <hr>

<!--  07/06/16 Insertion of code to load the disqus_tags app and to 'show' comments -->

        {% load disqus_tags %}
        {% disqus_show_comments %}

<!-- 07/06/16 When I initially built this app IAW the Django Girls tutorial it coded a simple native commenting system 
-->
<!-- Everything from this line down has been commented out to omit that old commenting system for posterity -->
<!-- Django Girls Tutorial linke http://tutorial.djangogirls.org/en/index.html -->
<!--    {% for comment in post.comments.all %}
        {% if user.is_authenticated or comment.approved_comment %}
        <div class="comment">
            <div class="date">
                {{ comment.created_date }}
                {% if not comment.approved_comment %}
                    <a class="btn btn-default" href="{% url 'comment_remove' pk=comment.pk %}"><span 
class="glyphicon glyphicon-remove"></span></a>
                    <a class="btn btn-default" href="{% url 'comment_approve' pk=comment.pk %}"><span  
class="glyphicon glyphicon-ok"></span></a>
                {% endif %}
            </div>
             <strong>{{ comment.author }}</strong>
             <p>{{ comment.text|linebreaks }}</p>
        </div>
        {% endif %}
        {% empty %}
         <p>No comments here yet :( --> </p>
     {% endfor %}
 <div class="shariff" data-lang="en" data-theme="grey"></div>
  <a class="btn btn-default" href="{% url 'comment_approve' pk=comment.pk %}"><span class="glyphicon 
glyphicon-ok"></span></a>
            {% endif %}
        </div>
         <strong>{{ comment.author }}</strong>
         <p>{{ comment.text|linebreaks }}</p>
    </div>
   {% endif %}
{% empty %}
    <p>No comments here yet :( --> </p>
{% endfor %}
<div class="shariff" data-lang="en" data-theme="grey"></div>
{% end block %}

Note: All of the snippets and comments provided are just that, they are not each file and it's contents in entirety. But in the very near future I will have a new github repo up for this project. I just have to do some house cleaning.


blog comments powered by Disqus