Posted by Dan on
Saturday the 28th of January, 2012
The default behaviour of virtualenv has changed, 1.7 now creates your virtual environment with what was the --no-site-packages option as default.
To create an environment with global packages there is a new option:
| virtualenv --system-site-packages ENV
|
Posted by Dan on
Saturday the 17th of December, 2011
Currently the Google+ API doesn't allow access to a users photo albums and images, however it is possible to access your images stored on Google+ using the Picasa web albums data API
I have written a simple jQuery plugin to get pictures from an album and display them in a simular style and effect to the albums on Google+, you can see a demo of this here and on the front page of my site you can view the jQuery plugin on github.
Install & Setup
Make sure you have at least jQuery 1.4.2.
Download the plugin from here and include the css and js file as below:
| <link rel="stylesheet" href="style.css" type="text/css" media="screen, projection" />
<script type="text/javascript" src="pluspics.js"></script>
|
Run the following script to setup and run the gallery plugin.
| <script type="text/javascript">
$(document).ready(function(){
$('#container-id').plusPics({
userId: 'your_user_id',
albumId: 'your_album_id',
numImages: 3,
title: 'Images'
});
});
</script>
|
Put an empty container div on the page where you want the gallery to display.
| <div id="container-id"></div>
|
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
- pip install -e git+git://github.com/dantium/satchmo-rewardpoints.git#egg=reward
- Add reward to your INSTALLED_APPS setting.
- Activate and change the available options in admin > edit site settings
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.
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.
| #settings.py
FB_PAGE_ID = '6798562721'
INSTALLED_APPS = (
'fbgallery',
)
|
In your urls file you need to include the apps url file like so:
| #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)
|
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.