Notes

Loyalty Rewards Point System for Satchmo

Posted by Dan on Friday the 9th of December, 2011

I have created a module for Satchmo (an ecommerce system for Django) that deals with customer reward points. Customers can receive rewards for signing up and for purchasing products and are able to redeem their reward points when buying products.

You can view and download the source code from Github.

Features

  • Set sign-up points value.
  • Set percentage of points a customer will get from an order.
  • Set money value of points.
  • Allow for partial points payment on an order.
  • Customer points transaction history.

Install & Setup

  1. pip install -e git+git://github.com/dantium/satchmo-rewardpoints.git#egg=reward
  2. Add reward to your INSTALLED_APPS setting.
  3. Activate and change the available options in admin > edit site settings

Korean quick address lookup using Django and jQuery

Posted by Dan on Friday the 7th of October, 2011

I was making an eCommerce site using Django for a Korean company, being as this company ships products to customers parts of the site need users to enter their address. Typically Korean sites will have a popup window where you then need to type in part of the address and then press a search button and then click on the address you want to select. I wanted to make a simple app using Django that is slick and fast for the user to select their address.

You can download the Korean Address Lookup app from Github and you can view a demo of it online.

Retrieve and display facebook albums using FQL and Django

Posted by Dan on Sunday the 11th of September, 2011

Here is a useful little Django app that I have created to get and display albums and pictures from a facebook 'page' using Facebook Query Language (FQL). You can get the app django-fbgallery from Github and view a demo of it here.

Setup

To set up the app you first need to get the facebook id from the 'Page' that you want to retrieve the albums from, you can do this by looking at the URL on facebook, for example: http://www.facebook.com/media/albums/?id=6798562721 on the album page it's just the id part of the URL. If you look at the URL from a photo from the album: http://www.facebook.com/photo.php?fbid=10150265446187722&set;=a.436358817721.235581.6798562721 it's the code at the end.

Then in your settings file you can add the ID of the facebook album you want to list, also make sure to include the app in installed apps.

1
2
3
4
5
6
#settings.py
FB_PAGE_ID = '6798562721'

INSTALLED_APPS = (
        'fbgallery',
)

In your urls file you need to include the apps url file like so:

1
2
3
4
#urls.py
urlpatterns += patterns('',
    (r'^gallery/', include('fbgallery.urls')),              
)

How it works

The main function takes a FQL query and returns the results as JSON, the results are also cached for each separate query to prevent too many requests to facebook.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def get_fql_result(fql):
    cachename = 'fbgallery_cache_' + defaultfilters.slugify(fql)
    data = None
    if cache_expires > 0:
        data = cache.get(cachename)
    if data == None: 
        options ={
            'query':fql,
            'format':'json',
        }
        f = urllib2.urlopen(urllib2.Request(fql_url, urllib.urlencode(options)))
        response = f.read()
        f.close()
        data = json.loads(response)
        if cache_expires > 0:
            cache.set(cachename, data, cache_expires*60)
    return data

The albums are retrieved from the facebook id, a separate query is made to get each album cover as I don't think FQL supports joins.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def display_albums(request, fb_id):
    """ Fetch all facebook albums for specified id """
    fql = "select aid, cover_pid, name from album where owner=%s" % fb_id;
    albums = get_fql_result(fql)
    for i in range(len(albums)):
        fql = "select src from photo where pid = '%s'" % albums[i]['cover_pid'];
        [item for sublist in get_fql_result(fql) for item in sublist]
        albums[i]['src'] = sublist['src']
          
    data = RequestContext(request, {
        'albums':albums,
        })
    
    return render_to_response('fbgallery/albums.html', context_instance=data)

To display all pictures from an album the album id is passed in through the URL and then checked to see if it belongs to the facebook page specified.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def display_album(request, album_id, fb_id):
    """ Display a facebook album, first check that the album id belongs to the page id specified """
    fql = "select aid, name from album where owner=%s and aid='%s'" % (fb_id, album_id)
    valid_album = get_fql_result(fql)
    if valid_album:
        fql = "select pid, src, src_small, src_big, caption from photo where aid = '%s'  order by created desc" % album_id
        album = get_fql_result(fql)
        [item for album_detail in valid_album for item in album_detail]       
    else:
        raise Http404
    
    data = RequestContext(request, {
        'album':album,
        'album_detail':album_detail,
        })
    return render_to_response('fbgallery/album.html', context_instance=data)

New Website and Portfolio

Posted by Dan on Thursday the 11th of February, 2010

After owning the domain name danatkinson.com since 2000 I have eventually gotten around to getting a Website on it!

You can view a selection of work that I have done over the last few years in the portfolio section. The notes area will be used to store general notes and articles. If you want to get in contact with me please use the contact form.