Archive

Tips and Tricks

What is django-userena?

django-userena is a Django application that supplies your Django project with full account management. It’s a fully customizable application that takes care of the signup, activation, messaging and more.

How to install django-userena?
You can install the latest version of django-userena using:
pip install django-userena

Source Code:
https://github.com/bread-and-pepper/django-userena

How to setup django-userena?
Add AUTHETICATION_BACKEND tuple as given below:

AUTHENTICATION_BACKENDS = (
    'userena.backends.UserenaAuthenticationBackend',
    'guardian.backends.ObjectPermissionBackend',
    'django.contrib.auth.backends.ModelBackend',
)

Add userena, gaurdian and easy_thumbnails to your INSTALLED_APPS settings of your project.

The URI’s
Userena has a URLConf that sets all the url’s and views for you. This should be included in your project’s URLConf. For example, if you wants the urls to show up under ‘/accounts/’, add the following under urlpattern in you URLConf.

(r'^accounts/', include('userena.urls')),

Required Settings
1. Django-guardian requires you to set the ANONYMOUS_USER_ID setting.

ANONYMOUS_USER_ID = -1

2. Set AUTH_PROFILE_MODULE point to the model that is your custom made profile.For example: set AUTH_PROFILE_MODULE to the path of MyProfile

from userena.models import UserenaBaseProfile

class MyProfile(UserenaBaseProfile):
    user = models.OneToOneField(User,
                                unique=True,
                                verbose_name=_('user'),
                                related_name='my_profile')
    favourite_snack = models.CharField(_('favourite snack'),
                                       max_length=5)

3. To integrate with Django, you need to alter three settings to reflect in you URI.
For example, if your userena lives under ‘/accounts/’

LOGIN_REDIRECT_URL = '/accounts/%(username)s/'
LOGIN_URL = '/accounts/signin/'
LOGOUT_URL = '/accounts/signout/'

References:django-userena documentation

Advertisements

What is Transifex?

Transifex is an open source platform for localization. It is a service offering users with an easy-to-use interface to submit translations to various projects hosted on a number of hosting platform types.

What is virtualenv?

virtualenv is a tool to build isolated Python environments. It’s a great way to quickly test new libraries without cluttering your global site-packages or run multiple projects on the same machine which depend on a particular library but not the same version of the library.

How to install virtualenv?

You can install the virtualenv by running
easy_install virtualenv
or
pip install virtualenv


You can install easy_install using:
pip install setuptools

How to activate virtualenv?

Once you have successfully installed virtualenv, you can use it to create virtual environments by running:
virtualenv --no-site-packages site


Activate the virtualenv using:
source site/bin/activate
or
. site/bin/activate

How to install Transifex?

Now create a fork of Transifex from bitbucket, clone the repository and install
cd site
hg clone https://bitbucket.org/indifex/transifex
cd transifex

python setup.py develop

But the latest tip requires Django==1.3.1,so to upgrade django use:
pip install Django --upgrade

To install the other modules(if required) in virtualenv using:
pip install <module name>

To install the userprofile module from the http://transifex.org/files/deps/ use:
pip install http://trac.transifex.org/files/deps/userprofile-0.6.tar.gz

To install the django-piston, for creating application programming interface(APIs) use:
easy_install django-piston
or
easy_install http://trac.transifex.org/files/deps/django-piston-0.2.3-devel-r278.tar.gz

How to configure Transifex?

Now to install the server use:
cd transifex
./manage.py txcreatedirs                       #Create necessary directories
./manage.py syncdb                                     # Setup DB tables, create superuser
./manage.py migrate                                   # Setup more DB tables

While running ./mange.py migrate, it raised a resources migration error, for that I removed the respective the resource migration file from resources/migrations to succeed migration.

./manage.py txlanguages                          # Create a standard set of languages
./manage.py txcreatenoticetypes       # Create a standard set of notice types
./manage.py collectstatic                     #Copy all the addons files to the static dir
./manage.py runserver 8000                   #Start the development server

Now that the server‘s running, visit http://127.0.0.1:8000/ with your Web browser.

References

http://help.transifex.net/
http://www.arthurkoziel.com/2008/10/22/working-virtualenv/

I have been trying to install Askbot using virtualenv.Askbot is an open source an Q&A forum which is written in Python and Django and virtualenv is a tool to create isolated Python environments.

You can get a brief introduction about virtualenv here.After installing virtualenv, activate the the virtualenv using the following steps:

First of all, create a project dir with virtualenv.


$cd /home/development
$virtualenv site --no-site-packages
$. site/bin/activate

Now copy the sources of askbot for customize and install

$cd /home/developments/site/
$git clone git://github.com/ASKBOT/askbot-devel.git
$cd askbot-devel
#python setup.py develop

Now move to the sub directory /home/development/site, and execute the command

$cd /home/development/site
$startforumaskbot-setup

When prompted for the name of the directory type forum.Now, edit the settings.py file accordingly.

Execute the commands ‘python manage.py syncdb’ ‘python manage.py migrate’.
Now run the development server:
$python manage.py runserver
Go to the browser and enter the URL as http://127.0.0.1:8000/.

While executing the command, python manage.py develop, in virtualenv, I often faced the problem of module missing. In that case I usually used the command
$pip install -E site
This would install the modules in the /lib/python2.7/site-packages/ directory inside the virtualenv.

But I eventually got stuck in a problem with the module functional,Though I installed the package celery and django-celery, it did not help. At last Evgeny helped me sort out the problem. A detail conversation and the solution is shown here.

Recently,I was having problems on installing via yum via proxy..after a bit searching on google i found a the way to configure yum through proxy.
Edit the yum.conf file in /etc/ folder
$vi /etc/yum.conf

[main]
proxy=http://proxy_address:port_number/
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
…..
save the file and now you can use yum through proxy.

%d bloggers like this: