Add class attribute to Django form fields

Having realized how hard it is to manually write code to display django form, I decided to implement a small hack to enable me attach bootstrap classes to django form fields.

 

  1. Create a python file under the templatetags folder in your django project.
  2. In this file (named say, my_form_tag.py) add the following:
    from django.template import Library
    
    register = Library()
    
    @register.filter(name='addclass')
    def addclass(field, class_attr):
        return field.as_widget(attrs={'class': class_attr})
    
  3. In the rendered html template, load the file with the template tags and use it to relike so
<html>

{% load staticfiles %}
{% load my_form_tag %}

4. Use the tag in the body of your page

   {{ field | addclass:"form-control" }}

Docker: re-exec error: exit status 1: output: write /var/lib/mysql/ibdata1: no space left on device

I usually find myself in a very annoying situation where my docker containers keeping getting full anytime I am building mysql containers.

Here are the series of steps I employ to get myself rid of such issues.

boot2docker config > ~/.boot2docker/profile

change the line with DiskSize from DiskSize = 20000 to 24000
Feel free to increase this number to your choice.

boot2docker poweroff

boot2docker destroy

Eclipse Tomcat not starting in 45 seconds (Solution ?)

In a bid to keep my Java skills alive, I decided to start from the ground up, from Servlets to EJB’s using Eclipse. I hit a stumbling block anytime I tried to start the Tomcat Server v. 7. I pops up this annoying “Tomcat not starting in 45 seconds”. One may be tempted to increase the timeout period but that barely solves the problem.

Try the following first.

1. http://crunchify.com/step-by-step-guide-to-setup-and-install-apache-tomcat-server-in-eclipse-development-environment-ide/

2. https://sansatechnology.wordpress.com/2011/09/26/how-to-fix-eclipse-tomcat-not-starting-in-45-seconds/

If the above fails, do the following.

1. Setup your eclipse + tomcat as per point 1.

2. Now eclipse views the Server as a project. So click on “Servers” under the Project Explorer Tab.

3. Click on the drop down part of the “Run button” and choose the first option like the image below.

Screen Shot 2015-06-20 at 10.23.54 PM

4. Did it work ?

morgan deprecated undefined format: specify a format

Learning about middleware with node.js I encountered a problem.
When I installed morgan, and run the following piece of code I get an error.


var express = require("express");
var http = require("http");
var logger = require("morgan");
var app = express();


// Logging middleware
app.use(logger());


// Send "hello world"
app.use(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.end("Hello world!\n");
});

http.createServer(app).listen(1337);


The error goes something like

morgan deprecated undefined format: specify a format app.js:13:9

This page seems to suggest that I have to specify the format of the output. So change from

app.use(logger());

to

app.use(logger("combined"));

Errrh, you are welcome.

Python Decorators: A cool breeze tutorial

When I started learning Java EE, I liked the dependency injection that was used to create EJB and Managed beans. Anytime you wanted to inject some dependency just use @SomeComponent and you have it.

Now I am having to use Python. The same syntactic sugar is being used here. But this time, it is for extending the functionality that a function gives. I really thought I could not comprehend this concept but this blog did a very good job of dissecting the issue.

I went like,” Ohhh, these people have introduced yet another difficult to understand concept. Ah, can’t they just stick to simple python stuff. They just want to worry mankind. ”

So after going through this blog I am stunned. Check it out.

Moving from Solr to Lucene in Alfresco 4.0.e ( FULL REINDEX)

I decided to change the indexing subsystem from Solr  to Lucene since Solr was getting stuck on some nodes. There was a script that was moving and renaming folders in Alfresco and this seemed to get Solr broken during indexing.

In order to change over from Solr to Lucene the following procedure should suffice.

-> Stop Afresco.
-> Open the /tomcat/shared/classes/alfresco-global.properties file.
-> Comment out the solr section like this;

### Solr indexing ###
#index.subsystem.name=solr
#dir.keystore=${dir.root}/keystore
#solr.port.ssl=8943

-> Add the following lines

 ###lucene###
 index.subsystem.name=lucene
 dir.indexes=C:/Alfresco/alf_indexes/lucene-indexes
 dir.indexes.backup=C:/Alfresco/alf_indexes/backup-lucene-indexes
 index.recovery.mode=FULL

-> Create the above folders if they do not exist.
-> Start alfresco
-> Stop alfresco.
Change from index.recovery.mode=FULL to index.recovery.mode=AUTO in the said file.

Start afresco again if you please.