Skip to content

Commit

Permalink
added replication safe decorators for use with master, slave environm…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
tschellenbach committed Jun 6, 2012
1 parent eab1748 commit c9570fe
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion django_facebook/__init__.py
Expand Up @@ -4,7 +4,7 @@


__license__ = 'BSD'
__version__ = '4.0.4'
__version__ = '4.0.5'
__maintainer__ = 'Thierry Schellenbach'
__email__ = 'thierryschellenbach@gmail.com'
__status__ = 'Production'
Expand Down
5 changes: 3 additions & 2 deletions django_facebook/auth_urls.py
Expand Up @@ -27,14 +27,15 @@

from django.contrib.auth import views as auth_views
from django_facebook import registration_views
from django_facebook.utils import replication_safe

urlpatterns = patterns('',
url(r'^login/$',
auth_views.login,
replication_safe(auth_views.login),
{'template_name': 'registration/login.html'},
name='auth_login'),
url(r'^logout/$',
auth_views.logout,
replication_safe(auth_views.logout),
{'template_name': 'registration/logout.html'},
name='auth_logout'),
url(r'^password/change/$',
Expand Down
3 changes: 3 additions & 0 deletions django_facebook/decorators.py
Expand Up @@ -123,3 +123,6 @@ def facebook_connect_required():
"""
#TODO: BUILD THIS :)
pass



21 changes: 21 additions & 0 deletions django_facebook/utils.py
Expand Up @@ -352,6 +352,27 @@ def cleanup_oauth_url(redirect_uri):
return redirect_uri


def replication_safe(f):
'''
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
'''
from functools import wraps

@wraps(f)
def wrapper(request, *args, **kwargs):
request.replication_safe = True
response = f(request, *args, **kwargs)
return response

return wrapper

def get_class_from_string(path, default='raise'):
"""
Return the class specified by the string.
Expand Down
4 changes: 3 additions & 1 deletion django_facebook/views.py
Expand Up @@ -15,7 +15,8 @@
require_persistent_graph
from django_facebook.canvas import generate_oauth_url
from django_facebook.connect import CONNECT_ACTIONS, connect_user
from django_facebook.utils import next_redirect, get_registration_backend
from django_facebook.utils import next_redirect, get_registration_backend,\
replication_safe
from django_facebook.decorators import (facebook_required,
facebook_required_lazy)
from open_facebook.utils import send_warning
Expand Down Expand Up @@ -66,6 +67,7 @@ def image_upload(request):


@csrf_exempt
@replication_safe
@facebook_required_lazy(extra_params=dict(facebook_login='1'))
def connect(request):
'''
Expand Down

0 comments on commit c9570fe

Please sign in to comment.