We have been creating some real cool stuff with drupal CMS and django since January 2007. That is why most of our clients come back to us when they have to get a second(or third or forth) project done
Drop us an email at info (at) ikraftsoft (dot) com to know more about what kind of work we have accomplished and what our clients say about our work.
Visit http://ikraftsoft.com if you prefer, but most of the stuff about our knowledge is here ;).
I am a vim user, and by user I mean I do all(not counting using the textarea inside the web browser) of my editing inside vim. Even when I need to use a word processor, I first type my content inside vim and then open the word processor to format it.
Check my new blog post on list of vim plugins I use on daily basis along with mini tutorials on installation and usage.
A common task in a web developer’s day to day work is to add an ‘active’ class to anchor tags for styling the link to currently active page. In PHP world, this generally involves anĀ if-else chain. But how do we do it in Django?
I searched the web but couldn’t find anything specific; therefore I coded a simple template tags for the purpose.
This little template tag can be used both with url names as well as the actual url strings. Check them out.
Here is the template tag code.
and here is how to use it in your templates.
Today, when I tried creating a new virtual environment for a project, it failed with the following error.
I guessed that it should have something to do with replacement of setuptools with distribute recent versions of virtualenv(because it could not find easy_install executable) and since as we know that python packaging is outdated and brain dead on Linux distos(at least on Ubuntu in my case), I upgraded the virtualenv installation with following commands:
And as it turns out my guess was correct and upgrading the relevant packages fixed this problem.
Recently I faced a problem in one of our Django project where I had to display drop down select box and checkboxes on a webpage which on initial page load had a about 20 - 30 choices. These choices could change via Ajax depending on the actions performed by the user. Also the choices come from a pool of hundreds of thousands of possible values.
Default forms.ChoiceField provided by Django, requires a list(or a tuple) of pairs of possible choices to be provided in the choices argument as follows.
The value of choices argument is used to build the html widget as well as for validating the form field. Therefore, if the submitted value for the my_choice_field is not present in the list_of_choices, an error is flagged and the form submission is not valid. Now we could not pre create a list with hundreds of thousands of possible values because of the obvious memory usage concerns and also the fact that we would have to modify the rendering logic of the widget to a very large extent which would have been time consuming both in terms of development & debugging.
For our particular use case, we solved this issue by subclassing forms.ChoiceField and overriding its valid_value method as described in following code snippet.
The valid_value method is fired to validate the value of the ChoiceField received through the form submission. The default definition of this method simply checks the presence of the received value in the choices list provided during the definitions of form class. By overriding this method and adding our own logic to check for the validity of received value we solved this issue with simplicity and minimal time investment.
PS: We could not use the django validators system for this purpose because in the case of ChoiceField, validators are fired after valid_value method.
After going through lot of custom functions for generating ordinal number in PHP, I was finally able to find the best way (so far) for doing it.
What’s happening here?
I hope this saves someone’s time.
This post is in continuation to Multisite Installation In Drupal 6.
In the previous post mentioned above, we were using separate databases for each site within the same drupal core. There will be requirements where you will be required to have a single database to be shared among multiple drupal site installs. One important requirement being sharing of user access. It will be quite possible that multiple sites setup on same drupal core will want to share the user base. Also, it will be important that user login sessions be shared among those multiple sub sites. Under these circumstances, you will be required to have a single database with some of the tables (if not all) to be shared among the sub sites.
Below are the steps to do that assuming you have one sub site configured like http://example.com/subsite1/ using database ‘example_db’, and you create another sub site like http://example.com/subsite2/ to use same database. Just before running install.php for subsite2 make below mentioned changes to /subsite2/settings.php file by setting $db_prefix as an array like below
# /subsite2/settings.php
$db_url = 'mysql://user:pwd@localhost/example_db';
$db_prefix = array(
'default' => 'subsite2_',
'users' => '',
'sessions' => '',
'authmap' => '',
);
# By setting $db_prefix array like above, we are prefixing every other table with 'subsite2' except for 'users', 'sessions' and 'authmap' tables thereby marking them as shared.
The other way of doing the same thing will be to specify non shared tables like
# /subsite2/settings.php
$db_url = 'mysql://user:pwd@localhost/example_db';
$db_prefix = array(
'default' => '',
'users' => 'subsite2_',
'sessions' => 'subsite2_',
'authmap' => 'subsite2_',
);
# By setting $db_prefix array like above, we are sharing every table between 'subsite1' and 'subsite2' except for 'users', 'sessions' and 'authmap' tables.
Now, you should be ready to run install on subsite2.
Nutshell: The only important point for using a single database between multiple drupal sites with some or none shared tables is the ability to specify shared/non shared tables which is as simple as specifying list of tables within $db_prefix as key/value pairs.
Note: if you want to have single database to be used between multiple drupal sites with no tables shared, just specify table prefix as
$db_prefix = 'subsite2_';
Assuming you have basic drupal 6 installation already working on a LAMP server. Below are the steps to setup multiple sites to work on same drupal core like site1.com, site2.com etc.
Create site databases Start by creating databases for each site like site1, site2 etc thereby setting specific credentials to each database created.
Setup drupal site configuration directories Copy and paste /sites/default directory and rename the copied directories to /sites/site1.com, /sites/site2.com directories. The only important file from the /sites/default directory being settings.php, you can skip all the other files/directories while copying /sites/default directory. Although, later on you might need to create several different directories within each site directory like files, modules, themes etc contents of whom will be specific to that site. Edit settings.php file of each site and set database details specific to each site.
Create virtual hosts for each site under Apache2 Steps for creating virtual hosts under debian/ubuntu based systems. Open terminal use below commands
$ cd /etc/apache2/sites-available $ sudo gedit site1.com
Put below contents within this file
<VirtualHost 127.0.1.5:80>
ServerAdmin webmaster@localhost
ServerName site1.com
DocumentRoot /home/umar/Work/htdocs/drupal6
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/umar/Work/htdocs/drupal6>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Now enable the site with following command
$ sudo a2ensite site1.com
Repeat the above steps for all sites with unique local IP’s for each site. When done with creation of all files reload apache
$ /etc/init.d/apache2 reload
Now edit the /etc/hosts file to include mapping of these new sites like
$ sudo gedit /etc/hosts
With contents like
127.0.0.1 localhost 127.0.1.5 site1.com 127.0.1.6 site2.com
Thats all there is to it, now go to url like http://site1.com/install.php of each site and follow normal drupal installation procedure.
I will soon be posting article showing usage of single DB between multiple drupal sites configuration.
Cheers
Today, due to sudden rush of adrenaline and energy powered by lots of caffeine, I decided to sit down and redesigned our web site ikraftsoft.com, which I have been intending of doing for quite some time now, but procrastinating for one reason or the other. And I am quite satisfied with the result.
I know already that when my team will see the new design, I will have to answer a thousand questions, especially from Irfan(THE CEO). To avoid lot of discussions about my design decisions, I will try to defend my design designs right before they are attacked.
DISCLAIMER: Although, I have always wanted to be a skilled designer, but I am not. I cannot use image manipulation programs for anything more than basic editing like croping, scaling and some retouching of images. So please do not expect any miracles.
Let me first start by describing what I wanted to accomplish and what my goals were.
DON’T WASTE ANYONE’S TIME; HIGHLIGHT THE POINT
This was the most important thing, that I wanted to reflect in the final design. Basically, what I wanted to accomplish is(or should be) what a company’s website is expected to accomplish. ‘Provide the necessary information about a company with as less text as possible’. I wanted that as soon as a visitor is on our website, what we do should jump on to visitor’s eyes immediately, preferably without reading each and every written word.
Right from the start, I knew exactly, towards what I wanted to draw the attention of visitors of my site. That is why I made certain things very prominent. Like the main banner that says “we are passionate about web & we enjoy creating great web applications”. This one sentence speaks of our heart. In this one sentence, I tried to make a statement about our passion as a company and what we enjoy.
Secondly, you will notice that words DRUPAL and DJANGO strongly highlighted. Now, when a new visitor comes to our website he immediately knows that we are doing something with Drupal & Django. And if the visitor is someone who is looking for hiring the Drupal or Django devs, BINGO! We have made ourselves know immediately.
CLEAN IS COOL
Another thing that I wanted is cleanliness and readability. I strongly hold the opinion that cool photoshop/gimp techniques are not the only way to spice up your website. Unfortunately, most of the designers give a second seat to the typography, which should be the primary concern for the designer. Graphics and images should be made to compliment the typography, not the other way round.
That is the reason, I choose a text heavy design, with only two images, one for the logo and other for the arrows for list styles. I user the font stacks that I talked about in my blog post about my favourite font-stacks
PROVIDE AN EXPLICIT EXIT LOCATION
Now that we have made clear what we do, provide exit locations to the visitors form where they can find more information about us. For that reason, Link to our blog and the email is provided. Address, phone number etc are provided in the footer.
Although, I have layout out my rationale behind design decisions, there is still a room for some unanswered questions. I will try to answer few of those questions and end this looooong post after that.
Why did not I put up a work portfolio?
I definitely will do that, it just I could not envision best way to do so right. So, I decided to give myself a bit of time to think about it and discuss it with my team. May be we will simply publish a portfolio page that describe our major projects. Personally, I am bordering on the idea of having portfolio related posts(properly tagged) in our blog and linking to that page from the main site. But right now, this is an open ended problem.
Why are Django and Drupal not defined?
Let first clarify how we get work.
More that 70% of our work comes from client referrals and not from website. One client referring us to another, who in turn refers us to another client.
Almost all of our clients are techies who understand the technology very well and have come to us with very specific needs and most of them are already aware of Drupal/Django and related technologies.
So, we do not need to say anything about drupal and/or django. Even if some visitor is not aware of drupal/django, both have been duly linked to their respective websites as those sites do a much better job of defining themselves. Visitor can go there and get enlightened.
Why pages like vision/mission/about missing
I wanted people to know about us in the simplest and most concise way. I could not think of better words than “we develop web apps using drupal and django” Rest of the answer has already been explained in previous paras.
That was brief of the rationale behind my design decisions. I would love to hear more from you and my team. Let’s take the discussion forward from this point.
It seems like IE’s successor has been confimed to be “Gazelle”, a browser currently under development at Microsoft Research. It is said to be more secure than FireFox and Chrome; keeping plug-in’s sandboxed within the browser, so it will not affect the PC if you stumble upon some malwar