コード例 #1
0
ファイル: views.py プロジェクト: pH14/Geddit
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
ファイル: views.py プロジェクト: sarine/Geddit
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))