Friday, August 31, 2012

Modifying Dictionary in Django Session Does Not Modify Session

I think this is worth knowing because I spent quite a long time trying to debug a related issue.

This is the original post from SO. Read the whole thing. Very useful.

In short,

Whenever editing a session object, it is also required to explicitly say that the object was modified. This can be achieved like so:
request.session['xyz'] = 'xyz'
request.session.modfied = True
or in the settings we set,
SESSION_SAVE_EVERY_REQUEST True 
 .

Thursday, August 16, 2012

Whenever creating a new folder/module put a blank __init__.py in it

Whenever creating a new folder/module put a blank __init__.py in it. This is required if you want to import from this module into another file.

Wednesday, August 15, 2012

Creating a Sproc/Function in your mysql db

I kept getting  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line x.

I was trying to run the sql to create the sproc via a txt/sql file and then via terminal do a
$mysql -u root -p < sproc_create_filename.sql

Turns out, you need to have a DELIMITER when doing this. This is how I got it to finally work..


DELIMITER //
CREATE DEFINER = `username`@`%` PROCEDURE `sp_get_mainpage_data`(lpIntCustomerId INT)
BEGIN
-- , lpIntLocationId INT, lpStrLoanOfficerCode VARCHAR(48), lpIntDecision TINYINT, lpDateInitialScoreDate DATETIME,  lpDateEndScoreDate DATETIME

.
.
.
. and (shi.id IS NOT NULL OR (sbjasmt.repeated = 'y' OR sbjasmt.status = 'incomplete'));
END//

Just adding the DELIMITER // and END// sorted out the issue.

Tuesday, August 7, 2012

Addressing localhost from a VirtualBox VM

I believe this could be pretty useful if you use VirtualBox a lot..

If you're developing on your local machine (on localhost) and want to access localhost from a browser from inside a virtualmachine (which resides on the same local-machine) (maybe to test IE6?), you can reach localhost via 10.0.2.2

So the address for our app would typically be http://10.0.2.2:8000/

Ref: http://stackoverflow.com/questions/1261975/addressing-localhost-from-a-virtualbox-virtual-machine

Wednesday, August 1, 2012

Popular Posts