Source

django-admin-tools / admin_tools / dashboard / views.py

Full commit
David Jean Louis fca6b85 
David Jean Louis c8c2dda 
Victor Safronovi… 2abe928 

David Jean Louis fca6b85 

Preston Timmons e6497d3 
David Jean Louis fca6b85 








David Jean Louis c971b7e 
David Jean Louis fca6b85 



David Jean Louis c971b7e 



David Jean Louis fca6b85 




David Jean Louis 8bcc0fb 
David Jean Louis fca6b85 










David Jean Louis c971b7e 

David Jean Louis 8bcc0fb 
David Jean Louis c971b7e 

Victor Safronovi… 2abe928 
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.template import RequestContext
from django.shortcuts import render_to_responce

try:
    from django.views.decorators.csrf import csrf_exempt
except ImportError:
    from django.contrib.csrf.middleware import csrf_exempt

from forms import DashboardPreferencesForm
from models import DashboardPreferences


@login_required
@csrf_exempt
def set_preferences(request, dashboard_id):
    """
    This view serves and validates a preferences form.
    """
    try:
        preferences = DashboardPreferences.objects.get(
            user=request.user,
            dashboard_id=dashboard_id
        )
    except DashboardPreferences.DoesNotExist:
        preferences = None
    if request.method == "POST":
        form = DashboardPreferencesForm(
            user=request.user,
            dashboard_id=dashboard_id,
            data=request.POST,
            instance=preferences
        )
        if form.is_valid():
            preferences = form.save()
            if request.is_ajax():
                return HttpResponse('true')
            request.user.message_set.create(message='Preferences saved')
        elif request.is_ajax():
            return HttpResponse('false')
    else:
        form = DashboardPreferencesForm(
            user=request.user,
            dashboard_id=dashboard_id,
            instance=preferences
        )
    return render_to_response('personal/personal_contacts.html',
                              RequestContext(request, {'form': form}))