示例#1
0
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')
            messages.success(request, '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('admin_tools/dashboard/preferences_form.html',
                              RequestContext(request, {'form': form}))
示例#2
0
文件: views.py 项目: Alerion/BombIt
def set_preferences(request):
    """
    This view serves and validates a preferences form.
    """
    try:
        preferences = DashboardPreferences.objects.get(user=request.user)
    except DashboardPreferences.DoesNotExist:
        preferences = None
    if request.method == "POST":
        form = DashboardPreferencesForm(
            user=request.user,
            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, instance=preferences)
    return direct_to_template(request, 'admin_tools/dashboard/preferences_form.html', {
        'form': form,   
    })
示例#3
0
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 TemplateResponse(request,
                            'client_admin/dashboard/preferences_form.html',
                            context={
                                'form': form,
                            })
示例#4
0
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')
            messages.success(request, '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('admin_tools/dashboard/preferences_form.html',
                              RequestContext(request, {'form': form}))