class django_facebook.utils.ScriptRedirect(redirect_to, show_body=True)[source]

Redirect for Facebook Canvas pages


We have to maintain order with respect to the queryparams which is a bit of a pain TODO: Very hacky will subclass QueryDict to SortedQueryDict at some point And use a decent sort function


Clears the caches for the graph cache

django_facebook.utils.error_next_redirect(request, default='/', additional_params=None, next_key=None, redirect_url=None, canvas=False)[source]

Short cut for an error next redirect


Usage: conversion_class = get_class_for(‘user_conversion’)

django_facebook.utils.get_class_from_string(path, default=None)[source]

Return the class specified by the string.

IE: django.contrib.auth.models.User Will return the user class or cause an ImportError


Returns new, old or None depending on the version of django registration Old works with forms New works with backends

django_facebook.utils.get_form_class(backend, request)[source]

Will use registration form in the following order: 1. User configured RegistrationForm 2. backend.get_form_class(request) from django-registration 0.8 3. RegistrationFormUniqueEmail from django-registration < 0.8

django_facebook.utils.get_instance_for(purpose, *args, **kwargs)[source]


conversion_instance = get_instance_for(
    'facebook_user_conversion', user=user)

Support for Django custom user models See this blog post for inspiration

http://kevindias.com/writing/django-custom-user-models-south-and-reusable-apps/ https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/core/migrations/0005_auto__chg_field_sitepermission_user__del_unique_sitepermission_user.py

django_facebook.utils.get_oauth_url(scope, redirect_uri, extra_params=None)[source]

Returns the oAuth URL for the given scope and redirect_uri


Get profile


Tries to get the profile according to the class configured on AUTH_PROFILE_MODULE


Get the profile model if present otherwise return None


Ensures compatability with the new and old version of django registration


This should be compatible with both django 1.3, 1.4 and 1.5 In 1.5 the verify_exists argument is removed and always False


For Django < 1.5 backward compatibility

django_facebook.utils.mass_get_or_create(*args, **kwargs)[source]

Updates the data by inserting all not found records Doesnt delete records if not in the new data

example usage >>> model_class = ListItem #the class for which you are doing the insert >>> base_query_set = ListItem.objects.filter(user=request.user, list=1) #query for retrieving currently stored items >>> id_field = ‘user_id’ #the id field on which to check >>> default_dict = {‘12’: dict(comment=’my_new_item’), ‘13’: dict(comment=’super’)} #list of default values for inserts >>> global_defaults = dict(user=request.user, list_id=1) #global defaults


Turns ‘email,user_about_me’ or (‘email’,’user_about_me’) into a nice consistent [‘email’,’user_about_me’]


Just here for your convenience, actual logic is in the FacebookAuthorization class

django_facebook.utils.queryset_iterator(queryset, chunksize=1000, getfunc=<built-in function getattr>)[source]

‘’ Iterate over a Django Queryset ordered by the primary key

This method loads a maximum of chunksize (default: 1000) rows in it’s memory at the same time while django normally would load all rows in it’s memory. Using the iterator() method only causes it to not preload all the classes.

Note that the implementation of the iterator does not support ordered query sets.


Usually views which do a POST will require the next page to be read from the master database. (To prevent issues with replication lag).

However certain views like login do not have this issue. They do a post, but don’t modify data which you’ll show on subsequent pages.

This decorators marks these views as safe. This ensures requests on the next page are allowed to use the slave db

django_facebook.utils.response_redirect(redirect_url, script_redirect=False)[source]

Abstract away canvas redirects


Makes the decorator syntax uniform Regardless if you call the decorator like

Decorator examples::
@decorator or @decorator() or @decorator(staff=True)

Complexity, Python’s class based decorators are weird to say the least: http://www.artima.com/weblogs/viewpost.jsp?thread=240845

This function makes sure that your decorator class always gets called with

Methods called:

__init__(fn, *option_args, *option_kwargs)
    return a function which accepts the *args and *kwargs intended
    for fn
django_facebook.utils.to_bool(input, default=False)[source]

Take a request value and turn it into a bool Never raises errors

django_facebook.utils.to_int(input, default=0, exception=(<type 'exceptions.ValueError'>, <type 'exceptions.TypeError'>), regexp=None)[source]

Convert the given input to an integer or return default

When trying to convert the exceptions given in the exception parameter are automatically catched and the default will be returned.

The regexp parameter allows for a regular expression to find the digits in a string. When True it will automatically match any digit in the string. When a (regexp) object (has a search method) is given, that will be used. WHen a string is given, re.compile will be run over it first

The last group of the regexp will be used as value

django_facebook.utils.update_user_attributes(user, profile, attributes_dict, save=False)[source]

Write the attributes either to the user or profile instance