当前位置: 首页>>代码示例>>Python>>正文


Python SettingsForm.save方法代码示例

本文整理汇总了Python中forms.SettingsForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsForm.save方法的具体用法?Python SettingsForm.save怎么用?Python SettingsForm.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.SettingsForm的用法示例。


在下文中一共展示了SettingsForm.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings(request):
    if request.POST:
        settingsForm = SettingsForm(request.POST, instance=request.user)
        if settingsForm.is_valid():
            settingsForm.save()
            messages.info(request, 'User settings saved.')
            return redirect('dashboard')
    else:
        settingsForm = SettingsForm(instance=request.user)
    return render(request, 'settings.html', {'settingsForm': settingsForm})
开发者ID:thehappyhippo,项目名称:opensubmit,代码行数:12,代码来源:views.py

示例2: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings(request, user_id):
    user = get_object_or_404(User, id=user_id)
    if request.user != user and not request.user.is_superuser:
        return HttpResponseForbidden("Forbidden operation.")
    form = SettingsForm(data=request.POST or None,
                        initial={"email": user.email, "intro": user.get_profile().intro})
    if request.method == "POST" and form.is_valid():
        form.save(user)
        return redirect(reverse("user_profile", kwargs={"user_id": user_id}))
    return render(request, "settings.html",
                  {"form": form, "settings_user": user})
开发者ID:Corea,项目名称:algospot,代码行数:13,代码来源:views.py

示例3: post

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
	def post(self):
		args = self.request.arguments()
		post_data = {}
		for arg in args:
			d = self.request.get(arg)
			post_data[arg] = d

		form = SettingsForm(post_data)
		if form.is_valid():
			form.save()

		self.get(form=form)
开发者ID:ghinch,项目名称:Mail-Engine,代码行数:14,代码来源:views.py

示例4: edit_settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def edit_settings(request):
    context = {}
    settings = Settings.get_by_user(request.user)

    if request.method == "POST":
        form = SettingsForm(request.POST, instance=settings)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/settings")
    else:
        form = SettingsForm(instance=settings)

    context["form"] = form
    return r2r(request, "edit_settings", context)
开发者ID:Veterun,项目名称:questions,代码行数:16,代码来源:views.py

示例5: settings_edit

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings_edit(request, response_format='html'):
    "Settings"

    if request.POST:
        form = SettingsForm(request.user.profile, request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('changes_settings_view'))
    else:
        form = SettingsForm(request.user.profile)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('changes/settings_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
开发者ID:tovmeod,项目名称:anaf,代码行数:18,代码来源:views.py

示例6: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings(request):

    context_vars = {}
    context_vars.update(csrf(request))

    if request.method == 'POST':
        form = SettingsForm(request.POST, request.FILES, instance=request.user.profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('profile', kwargs={"username": request.user.username}))
    else:
        form = SettingsForm(instance=request.user.profile)

    context_vars.update({'form': form})
    template = 'settings.html'
    context = RequestContext(request)
    return render_to_response(template, context_vars, context_instance=context)
开发者ID:frenchbread,项目名称:mazeapp,代码行数:19,代码来源:views.py

示例7: save_settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def save_settings(request, cid):
	print 'update_settings request.method = %s' % request.method
	if request.method == 'POST':
		con = get_construct(request.user, cid)
		if not con:
			return JsonResponse({
				'errors': {
					'all':"Construct with id '%s' not found",
					},} % cid, ERROR)
		form = SettingsForm(request.POST, instance=con.settings)
		if form.is_valid():
			form.save()
			con.reset()
			data = {}
			for key,value in form.cleaned_data.items():
				data[key] = str(value);
			return JsonResponse({'modified': con.last_modified(), 'fields': data})
		return JsonResponse({'errors': form.errors,}, ERROR)
	raise Http404
开发者ID:igemsoftware,项目名称:Heidelberg_2013,代码行数:21,代码来源:api.py

示例8: settings_edit

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings_edit(request, response_format='html'):
    "Settings edit"

    if request.POST:
        if 'cancel' not in request.POST:
            form = SettingsForm(
                request.user.profile, request.POST, request.FILES)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('core_settings_view'))
        else:
            return HttpResponseRedirect(reverse('core_settings_view'))

    else:
        form = SettingsForm(request.user.profile)

    return render_to_response('core/administration/settings_edit',
                              {
                                  'form': form,
                              },
                              context_instance=RequestContext(request), response_format=response_format)
开发者ID:tovmeod,项目名称:anaf,代码行数:23,代码来源:views.py

示例9: settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings(request):
    settings_form = SettingsForm()
    next = request.REQUEST.get('next')
    if request.method == 'POST':
        settings_form = SettingsForm(request.POST)
        if settings_form.is_valid():
            username = settings_form.save()
            request.session['username'] = username
            if next:
                return HttpResponseRedirect(next)
            return HttpResponseRedirect('/')

    context = {
        'settings_form': settings_form,
        'next': next,
    }
    return render_to_response('settings.html', context,
        context_instance=RequestContext(request))
开发者ID:octobertech,项目名称:m,代码行数:20,代码来源:views.py

示例10: cms_settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def cms_settings(request):
    config = None
    message = get_messages(request)
    config = lookup_settings(request)
    
    if request.method == 'POST':
        form = SettingsForm(request.POST)
        if form.is_valid():
            email = request.user.email
            delete_settings(email=email)
            config = form.save()
            config.email = request.user.email
            config.save()
            message = "Settings saved."
            request.session['cms_email'] = config.email
            return HttpResponseRedirect(settings.ROOT_URL+'options/')
    else:
        form = SettingsForm(instance=config)
    
    
    return direct_to_template(request, 'settings.html', 
        {'config': config, 'message': message, 'form': form, })
开发者ID:cksopher,项目名称:cms_utility,代码行数:24,代码来源:views.py

示例11: render_settings

# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def render_settings(request):
    user = User.objects.get(pk=request.user.id)
    delete_account_request = False
    try:
        delete_request = DeleteAccountRequest.objects.filter(user=user).first()
        if delete_request:
            delete_account_request = True
    except ObjectDoesNotExist:
        delete_account_request = False
    try:
        settings = UserProfile.objects.get(user=user)
        user_groups = user.groups.all()
        group_list = []
        for g in user_groups:
            group_list.append({
                'id': g.id,
                'name': g.name,
                'receive_updates': settings.get_group_notification_preference(g.id)
            })
    except UserProfile.DoesNotExist:
        settings = None
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=user)
        if settings:
            settings_form = SettingsForm(request.POST, instance=settings)
        else:
            settings_form = SettingsForm(request.POST)
        if user_form.is_valid() and settings_form.is_valid():
            user = user_form.save()
            settings = settings_form.save(commit=False)
            settings.user_id = request.user.id
            settings.save()
            settings_form.save_m2m()
            # update the interface language
            if settings.interface_lang:
                translation.activate(settings.interface_lang)
                request.LANGUAGE_CODE = translation.get_language()

            # get group update settings
            for g in group_list:
                gets_notif = True if request.POST.get('group_notif_' + str(g.get('id'))) else False
                settings.set_group_notification_preference(g.get('id'), gets_notif)
                g['receive_updates'] = gets_notif

            # check for delete account requests
            if request.POST.get('delete_account_option') == 'delete':
                DeleteAccountRequest.objects.create(user=user)
                delete_account_request = True
                settings.set_active(False)
                ctx = {
                    "user": user,
                }
                html = render_to_string('emails/delete_account_request.html', ctx)
                email = EmailMessage('Delete user account request',
                                     html,
                                     constance.config.NO_REPLY_EMAIL,
                                     [config.ACTIVATE_USER_EMAIL])
                email.content_subtype = "html"
                email.send()
            else:
                if delete_account_request:
                    DeleteAccountRequest.objects.filter(user=user).delete()
                    delete_account_request = False
                    settings.set_active(True)
            messages.add_message(request, messages.SUCCESS, 'Profile Update Successful.')
    else:
        user_form = UserForm(instance=request.user)
        settings_form = SettingsForm(instance=settings)

    errors = dict(user_form.errors)
    errors.update(settings_form.errors)

    interest_types = {'languages': [(lang.id, lang.name) for lang in Language.objects.all()],
                      'interests': [(interest.id, interest.name) for interest in Interest.objects.all()],
                      'regions': [(region.id, region.name) for region in Region.objects.all()]}

    return render_to_response('users/user_settings_v2.html',
                              {
                                'settings_form': settings_form,
                                'user_form': user_form,
                                'group_list': group_list,
                                'interest_types': interest_types,
                                'has_password': user.has_usable_password(),
                                'errors': errors,
                                'delete_account_request': delete_account_request,
                              },
                              context_instance=RequestContext(request))
开发者ID:Utsira,项目名称:movements,代码行数:89,代码来源:views.py


注:本文中的forms.SettingsForm.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。