Theju's tryst with life

Yet another redesign at thejaswi.info

Oh yes!!! You are seeing it right! There's been another redesign of my site.

Technology fascinates me and I cannot get enough of it. This time I wanted my blog powered by the latest and coolest technology. Want to know more?

CouchDB powers the heart of the blogging engine as opposed to an RDBMS. CouchDB-python talks to the DB and the web app. How on earth could I have left my favourite framework out of this cool stuff! I make use of the Django templates and views for the presentation and logic.

CouchDB stores the posts, comments, authentication related data and session data. I have written custom auth and session backends in Django that store the data on the DB. The source has been released and is available here.

The advantages of using couchDB:

  • It scales tremendously. Suppose my blog readership touches a few million, all I would need to do is to add more couchDB nodes and voila it scales!!!
  • Since couchDB uses HTTP as the underlying protocol, it can be cached very easily using standard cache utilities like Squid and Varnish.
  • It is schema-less. I could easily add/edit and remove fields from the DB without having to get frightened about it's integrity.

The disadvantages of using couchDB:

  • couchDB is growing fast and still does not have a few features (slated to be released soon) and the API is a moving target.
  • It can give you a few scares from time to time. I almost lost my data when I made a few cfg changes. After googling around, I figured out that the data was safe but couchDB would require a reinstall.

Hope this time, the technology powering my blog is not obsoleted so fast ;-).

PS1: If you have come to the site from a previous bookmark, please update your bookmarks. I am sorry about breaking your results.

PS2: Some services on my blog are still missing, I promise to have them up at the earliest.

PS3: I am in the process of releasing the source code of the site. If you are one of the impatient folks, please ping me.

Followup Comments

Very often we post comments on many sites and it becomes very tedious to keep track of discussion thereafter. To make life easy, the site owners need to provide a "Follow-up" feature which would send an email whenever a comment is posted. From the user perspective, this option should be optional ie he should receive the email followups only if he subscribes to them.

So yesterday, I tried my hand at one such reusable app and it turned out to be easier than I thought.

Here's how to go about using it:

  • Fetch the source from here.

  • Add the COMMENTS_APP attribute to settings.py to reference followup_comments.

  • Add a few additional attributes to the settings.py namely

    • EMAIL_HOST: If your SMTP server is on a different machine
    • EMAIL_PORT: If your port is different than a default
    • EMAIL_HOST_USER: If authentication is enabled on SMTP server
    • EMAIL_HOST_PASSWORD: If authentication is enabled
    • DEFAULT_FROM_EMAIL: If you want to specify the from address
  • Go to the admin page and add a Followup Message for the site of your choice.

  • Then use the comments just like you would have used the vanilla comments framework.

Since I have worked on this app for a couple of hours, it still has some rough edges to it. A couple that I could find out were:

  • The signal is getting invoked twice. Not sure why this is happening! Anyone experienced this situation before?
  • Should I make the from email address a part of the FollowUpMessage model? This would make it possible to have a different email address for each site that uses the feature.

Please give me your feedback on how you like this project.

Django 1.1 beta released

Though slightly behind schedule, Django 1.1 beta was released yesterday. It offers a lot of new features compared to the last stable release 1.0. A few of the notable ones are:

  • Model Aggregation
  • Query Expressions
  • Fast Tests
  • Unmananaged & Proxy Models
  • Deferred Fields
  • Batch functionality in Admin (like bulk edit etc)
  • Host of CSRF related changes

The two changes that I was personally interested in were:

  • Extensibililty of the comments framework
  • Integration of Comment-utils

I would like to thank Jacob Kaplan-Moss, Jannis Leidel, Carl JM, James Bennett and all others involved for the previous two changes.

A special thanks to Malcolm Tredinnick, Russell Keith-Magee and others for the huge improvements to the ORM.

My thanks also goes to Adrian Holovaty for releasing Django Book 2.0 to the community.

I would make a big mistake if I forget to thank the wonderful Django community that uses, supports and contributes to the wonderful project. Thanks guys.

Django Project rocks!!!

Yet another threaded comments app

This week I am releasing code for yet another reusable app and yet another threaded-comments app. There are quite a few threaded comment apps around but the best one being this by Eric Florenzano.

The motive of releasing this code is not to compete with any of the apps available but as a proof of how portable django and it's apps (here I am referring to the comments app, but the statement holds true for most third-party apps) can be.

Probably with some work this app should be as good as other apps.

Procedure to use it

  • Download the source from here and place the threaded_comments app in your django project.

  • Patch your django source with the latest patch from #8630.

  • Add the following attributes in the settings.py.

    COMMENTS_APP = "threaded_comments"
    
  • Make use of the new comment tags that are available to help with the threaded support. Here's an example template:

     {% extends "test_app/base.html" %}
    
     {% block head %}
     <script type="text/javascript">
       function showCommentForm(id) {
           var commentForm = document.getElementById('commentForm'+id);
           var linkHolder  = document.getElementById('linkReply'+id);
           if (commentForm.style.display == "none") {
               commentForm.style.display = "block";
               linkHolder.innerHTML="Hide Reply";
           } else {
               commentForm.style.display = "none";
               linkHolder.innerHTML="Reply";
           }
       }
    </script>
    {% endblock %}
    
    {% block content %}
    {% load threaded_comments %}
    {% get_comment_list for app.model object.pk as comment_list order_by thread %}
    {# To order comments by date use order_by date #}
    {% if comment_list %}
      <h2>Comments</h2>
      {% for comment in comment_list %}
      <div id="c{{ comment.id }}" style="margin-left: {{ comment.level }}0px;">
        <h4>{{ comment.name|escape }}
            {% if comment.parent %}
               in reply to
               <a href="#c{{ comment.parent_id }}">{{ comment.parent_id }}</a>
            {% endif %}
               at {{ comment.submit_date|date:"r"}}</h4>
        <p>{{ comment.comment|escape|urlizetrunc:"100"|linebreaks }}</p>
        <p><a id="linkReply{{ comment.id }}" href="#"
              onclick="showCommentForm({{ comment.id }});">Reply</a></p>
        <div id="commentForm{{ comment.id }}" style="display: none">
           <h4>Reply to the above comment ({{ comment.id }})</h4>
           {% render_comment_form for app.model object.pk with comment.id %}
           {# Alternatively use #}
           {# {% get_comment_form for app.model object.pk as form with parent_id %} #}
        </div>
      </div>
      <hr>
      {% endfor %}
    {% endif %}
    <h2>Leave a comment</h2>
    {% render_comment_form for app.model object.pk %}
    {% endblock %}
    
  • Most of the code is unchanged except for the comment tags which now take additional arguments and some optional javascript.

As mentioned in my previous post, the toughest decision is to patch Django because people don't like to pollute their code bases (don't even ask about organizations, they get hysterical when you want to patch any code base).

Please let me know how you find this app and suggest ways to make it DRYer and better.

Reusable recaptcha comments app

One aim of Jacob's code for the comments framework in Django 1.0 was to make it as extensible as possible. At the same time this process should be quite generic and as DRY as possible.

It is here that I worked for a very long time but in last minute goof-ups could not push these changes to be included in 1.0.

Well anyways, I opened a ticket quick enough so that this feature didn't fade off with time. I attached an initial patch and soon there was a lot of activity and within no time people contributed tests and docs for the patches. I want to thank all those people who contributed or are interested in the ticket. Luckily this ticket will be in trunk by 1.1 championed by Jacob himself (See roadmap).

So in this blog post I announce a reusable app called recaptcha-django-comments It is a very simple app that appends a Recaptcha field to the comment form.

Procedure to use it

  • Fetch the source from here and place the recaptcha_comments app in your django project.

  • Patch your django source with the latest patch from #8630.

  • Update the INSTALLED_APPS in the settings.py to reflect this app.

  • Add the following attributes in the settings.py.

    COMMENTS_APP = "recaptcha_comments"
    RECAPTCHA_PUBLIC_KEY = "xyz....."
    RECAPTCHA_PRIVATE_KEY = "abc...."
    
  • Add the following middleware to the settings.py. It will help pass on the IP Address to recaptcha if you are behind a reverse proxy. This step is not required if you are not behind a reverse proxy.

    MIDDLEWARE_CLASSES= ('...',
                         'django.middleware.http.SetRemoteAddrFromForwardedFor',
                         )
    
  • Copy the comments/ directory from recaptcha_comments/templates into your templates directory as referenced by your settings.py.

  • Edit the project's urls.py to have the following line.

    (r'^comments/', include('recaptcha_comments.urls')),
    

That's it!!!

Well, the toughest part in the procedure is to patch the django source (by difficult I mean the decision to patch django).

Please let me know your opinions about this app.

Stay tuned for more and oops I forgot...**HAPPY NEW YEAR**!!!

Previous The number of posts are 24. The number of pages are 5. Next