Пример #1
0
def settings_page(request):
    if request.method == "POST":
        form = UserSettingsForm(request.POST, instance=get_current_user(request))
    
        if form.is_valid():
            form.save()
            confirmation = dict({"message": "Updated settings!"})
            return HttpResponse(simplejson.dumps(confirmation),
                                mimetype="application/json")
    else:
        # Create unbound form if GET
        initialData = {
            'cell_phone': get_current_user(request).cell_phone,
            'location': get_current_user(request).location,
            'email_notifications': get_current_user(request).email_notifications,
            'sms_notifications': get_current_user(request).sms_notifications,
        }
        form = UserSettingsForm(initial=initialData)
    
    render_params = base_params(request)
    render_params[NAV_PAGE] = SETTINGS
    render_params['form'] = form
    
    return render(request, 'settings.html', render_params,
                  context_instance=RequestContext(request))
Пример #2
0
def settings_page(request):
    if request.method == "POST":
        form = UserSettingsForm(request.POST, instance=get_current_user(request))
    
        if form.is_valid():
            form.save()
            return redirect('data.views.settings_page')
    else:
        # Create unbound form if GET
        initialData = {
            'cell_phone': get_current_user(request).cell_phone,
            'location': get_current_user(request).location
        }
        form = UserSettingsForm(initial=initialData)
    
    render_params = base_params(request)
    render_params['form'] = form
    
    return render(request, 'settings.html', render_params,
                  context_instance=RequestContext(request))