banner3

So lately i’ve been trying to get into python development, specifically for web application using Django; everyone says it’s amazing, I want to know what all the fuss it about !

I host this site and a couple others on my own dedicated server running DirectAdmin,  and I wanted to setup a dev space for my  (future) Python / Django projects. I went looking for a little step by step guide on how to install mod_wsgi in a directadmin environment, and to my surprise I couldn’t find one.

After a bit more research and a bit of trial and error, I present to you my own little guide on how to do so :)

Please note that I am doing this on a Centos 6 environment, and cannot guarantee that this will work on any other. Also, I use nano for my text editing needs, feel free to use vi if you prefer it.

Step 1.

download the latest source files from here.

cd /tmp
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
tar xzvf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4

Next we are going to compile our file

./configure
make
make install

Note that I was getting errors when compiling and I had to install the python development tools for it to work (yum install python-devel)

Now you are going to want to open your apache config file and load the module

nano /etc/httpd/conf/extra/httpd-phpmodules.conf

In that file, after all the other “LoadModule”, add the following line

LoadModule      wsgi_module             /usr/lib/apache/mod_wsgi.so

(If you do not have a file called extra/httpd-phpmodules.conf, you will need to add this to “/etc/httpd/conf/httpd.conf”)

Now all we’ve got left to do is recompile apache with custombuild

cd /usr/local/directadmin/custombuild

(Only do the following command if you’ve never added custom modules to apache in the past, otherwise you WILL overwrite your existing modifications)

mkdir -p custom/ap2

cp configure/ap2/configure.apache custom/ap2/configure.apache

Now you will need to open …

nano custom/ap2/configure.apache

And append this to the end of the file

"--with-mod_wsgi"

See all the ” \ ” characters at the end of each line? You should make sure that all but the last line has one. Otherwise apache will not compile. You should end up with something along those lines:

        "--enable-ssl" \
        "--enable-rewrite" \
        "--enable-proxy" \
        "--enable-expires" \
        "--enable-reqtimeout" \
        "--with-ssl=/usr" \
        "--enable-headers" \
        "--with-mod_wsgi"

Finally run

./build clean 

./build apache

And here you have it, mod_wsgi is loaded on to apache !

Let me know if you are having any issues with this :)

I recently have had to work on the opensource e-commerce CMS “Magento” through work. It was my first time using the application and had no knowledge of the inner workings of it all, so it was a real delight when I was given the easy task of adding  promotion coupons / vouchers to the website.

All I had to do was to create a coupon that would reduce the grand total by a given percentage when the total of the basket was bigger than £100. Easy right? Well so I thought until I came to find out that magento, in all it’s V 1.3.2.3 glory, applies the promotion rule (having to be higher than £100) to the subtotal excluding taxes / vat rather than the opposite way!

Because of that, although a user may have had a basket worth £110, the promotion script would only see the price without taxes, in other words around £85 and therefore would not apply the discount. Because all prices throughout the website are displayed including VAT, this would have definitely been really confusing for visitors.

After spending countless hours first looking in vain for a fix on google, then spending days going through the horribly scattered pile of horse shit that is magento’s code, I finally came up with a fix! And because I’m nice and don’t want to put someone through what I went through, I will share it here with the rest of the internet.

It is in itself very straight forward. Locate the “validation.php” file in “app/code/core/mage/SalesRule/Method” and open it. Look for the following code:

$quote = $item->getQuote();
if ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
$address = $item->getAddress();
} elseif ($quote->isVirtual()) {
$address = $quote->getBillingAddress();
} else {
$address = $quote->getShippingAddress();
}

Right after the closing bracket, simply add this little line of code;

$address->setBaseSubtotal(number_format($address->getSubtotal() + $address->getTaxAmount() - $address->getShippingTaxAmount(), 2));

All this does is that it add the total tax amount (while not including shipping tax tax) to the base_subtotal variable within the $address object which is the variable used by the promotion code. This change will however not change to front end value of the subtotal on your website so your basket will still display the correct subtotal without tax !

Let me know if you are having any problems or if you have any comment about my fix.

Till next time …

I’ve started so many blogs in the pasts couple of years, it’s hard to keep track.

“Why are you starting another one then?” Well I’m glad you asked. Simply put, I just started a new job in web development and at the same time just started to get serious with my Arduino project, so I wanted a place where I could put down tips, tricks or just random stuff about what I am doing. This would first and foremost be for my sake, so I can easily go back to something I wrote if I need to (i forget stuff quiet easily) but I am hoping that it will also be helpful to anyone else that somehow gets to this page.

I have for the occasion created a new template for the blog (which is like 50% done, but hell it’ll have to do for now) which is somewhat completely different to what I usually tend to design. It is also a great opportunity for me to try out some CSS3 goodness and see how well I can manage to break Internet Explorer with it.

Any ways, it’s late, I’m tired and I’ve never been great at those “introduction” messages so I’ll just leave it at that.

Catch you on the flip side (I’m trying to bring it back :D)