Tuesday, August 18, 2009

Using autocomplete plugin of jQuery with django

1. Download jQuery auto complete plugin here.

2. Unzip it.

3. Copy below files from the unzipped onto your javascript directory.
  • jquery.autocomplete.css
  • jquery.autocomplete.js
  • jquery.bgiframes.min.js
  • jquery.dimensions.js (from jquery.com)
4. Include them.

5. If you want to activate auto complete onto the html tag with id 'qwerty', add following code onto your js code area.

$(document).ready(function(){
  $("#qwerty").autocomplete{
    '/ajax/autocomplete',
    {multiple: true, multipleSeparator: ', '}
  );
});

6. Setup urls.py so that it can handle '/ajax/autocomplete' with ajax_autocomplete module.

7. in views.py, make ajax_autocomplete module like,

def ajax_autocomplete(request):
  if request.GET.has_key('q'):
    # Write your code here (search dictionary or db, etc..)
    # And put it onto res (separated with '\n').
    return HttpResponse(res)
  return HttpResponse()

8. Done. Have fun :)

Tuesday, August 4, 2009

MSN proxy with ssh using Pidgin

If your company blocked MSN port and you have accessable server out of your company, use it as a proxy with ssh -D option.

Set tunnel with '>ssh -D 1234 yourserveraddress.com'.
(You can use any port number instead of 1234.)

Set proxy option in your pidgin.
Host : localhost
Port : 1234

That's all. Have fun.

Monday, August 3, 2009

Using django - Accounts

Django auth system is in django.contrib.auth.
(Included in INSTALLED_APPS as a default)

Login page
You can use default django login handler.

<urls.py>
urlpatterns = patterns('',
  ...
  (r'^login/$', 'django.contrib.auth.views.login')
<eof>

You need to make a template for login page.

<templates/registration/login.html>
 <form methos='post' action='.'>
  <label for='id_username'>Username : </label>
  {{ form.username }}
  <br>
  <label for='id_password'>Password : </label>
  {{ form.password }}
  <br>
  <input type='hidden' name='next' value='/'/>
  <input type='submit' value='Login'/>
 </form>
<eof>

User objects methods

  • is_authenticated()

  • get_full_name()

  • email_user(subject, message, from_email=None)

  • set_password(raw_password)

  • check_password(raw_password)



Logout
<views.py>
from django.http import HttpResponseRedirect
from django.contrib.auth import logout

def logout_page(request):
  logout(request)
  return HttpResponseRedirect('/')
<eof>

<urls.py>
  ...
  (r'^logout/$', logout_page),
  ...
<eof>