Tuesday, February 8, 2011

Installing pinax 0.7.3 on windows

This is what has worked for me on Windows XP & Windows7 for Pinax 0.7.3 :
Note : Thanks to SO, helped a lot.
Assumption : 
1.) You have python 2.4+ already running and in your path, hence if you open a command prompt and run "python" it works





Here are the steps I followed.
  1. download the pinax (zip) at http://pinaxproject.com
  2. extract the download to some working directory  (maybe c:\pinax-0.7.3)
  3. open a command prompt
  4. cd c:\pinax-0.7.3\scripts folder
  5. create a new folder for your pinax environment - c:\pinaxenv
  6. run python pinax-boot.py c:\pinaxenv
You now have pinax installed. Since the whole point of pinax is to get you up & running with dJango as fast as possible, there are some base projects already created.
We are going to copy one of those base projects and work on them.

  1. cd to c:\pinaxenv\Scripts
  2. run activate.bat . Once you run this, the virtual environment will show you the new environment prompt. You are in a python virtual environment. Mess up here and it'll only affects what's here 8-) The prompt will be similar to - "(pinaxenv) C:\pinaxenv\Scripts>"
  3. Now lets check the available template projects we can use. Run pinax-admin.exe clone_project -l
  4. If you like the social_project which is the all-you-can-eat project, then copy it by running - pinax-admin.exe clone_project social_project ..\myfirstsite . This will create a directory "myfirstsite" at c:\pinaxenv directory
  5. To use most of the projects you will need the python image library - PIL. Download the exe from the site and just run it. 2 minutes later, you should have it installed and ready to go. If you don't install it, you're most likely to see the below error when you syncdb - "gblocks.image: "image": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ ."
  6. Once you have installed the PIL, just sync the database and with any other dJango project - 
  7. cd ..\myfirstsite\
  8. python manage.py syncdb
  9. Now run the test server - python manage.py runserver
  10. Enjoy 8-)
social_project has a lot of stuff, which I didn't want, hence cloned the basic_project and started hammering stuff around it.

The important point to understand here is that each tab is a django app in itself. Its not mandatory, but that is how it is currently designed for the sample apps. and I actually like it.

Since I want to add a new tab to the basic_project, I first created a new app. by running this in the pinax environment   python manage.py startapp nikapp 

Create a directory inside the templates director of base_project and name it nikapp. All our templates will go there.

Now to actually show the tab  site_base.html inside the  base_project/templates  added this line   inside the block starting with  {% block right_tabs %} -

If you refresh the page, you should see a new tab saying "Nik's Tab".

Lets understand the above line we added.
All we are doing is adding a list, with an id unique to our app. The list has an anchor link inside it.
The link is a block statement  {% url nikapp_landing %} . Which means that when someone clicks on this tab link on the right-top corner, a link needs to be loaded.

We need to now configure this link in our urls.py. Pinax is beautiful, due to how django is, we can just hook in a whole set of urls by plugging one line.
So open the urls.py in the base_project/ directory, and add this line there -
(r'^nikapp/', include('nikapp.urls')),

In our nikapp directory create a urls.py and add this -


urlpatterns = patterns('',
    url(r'^$', 'nikapp.views.landing', name='nikapp_landing'),
)

Hence when the link is clicked, a function in our view called landing, which we'll write next, will be called.

Open the views.py file inside the nikapp folder and add function -

def landing(request):
print " **** Inside nikapp landing"
return render_to_response('nikapp/nikapp_base.html', {}, context_instance=RequestContext(request));

Great, so our view simply returns an html page, when someone clicks on it.

Lets retrace what we've done - When you click on the new tab, it calls your view function, your view function returns an HTML page to show to the user.

Lets create this nikapp_base.html page inside the template/nikapp directory and add this to it -

{% extends "site_base.html" %}

{% load i18n %}
{% load ifsetting_tag %}

{% block head_title %}{% trans "Custom Niks App page" %}{% endblock %}

{% block body_class %}nikapp{% endblock %}

{% block body %}

This is inside the body now !!

{% endblock %}


The important lines here are {% block body_class %}nikapp{% endblock %}
And - {% block body %}

The first line describes the css class the tag should use, while the second implements the actual body of the page.

We haven't defined the css class yet, lets open the site_tabs.css and edit it like below -

/* SITE-SPECIFIC TAB STYLING */

body.profile #tab_profile a,
body.nikapp #tab_nikapp a,
body.notices #tab_notices a
{
    color: #000; /* selected tab text colour */
}



body.profile #tab_profile,
body.nikapp #tab_nikapp,
body.notices #tab_notices
{
    margin: 0; /* to compensate for border */
    padding: 5px 0 5px;
    background-color: #DEF; /* selected tab colour */
    border-left: 1px solid #000; /* tab border */
    border-top: 1px solid #000; /* tab border */
    border-right: 1px solid #000; /* tab border */
}

99% of this code already existed there, all we have done is added 
body.nikapp #tab_nikapp a, body.nikapp #tab_nikapp,

Simple enough, if you have questions on this feel free to ask though.

Refresh the page and click on the new tab and you should see the page loading nicely and showing this line - "This is inside the body now !!"

Hoooosh..... Pinax is ready to roll...

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. You might not have installed the MySQL module, which is required for python to interact with MySQL.

    You can download & install it from here -
    http://sourceforge.net/projects/mysql-python/

    ReplyDelete