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


Python forms.SettingsForm类代码示例

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


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

示例1: settings_form

def settings_form( request, template = 'settings_form.html' ):
    context = {}
    user = request.user

    if request.method == 'POST':
        form = SettingsForm(request.POST.copy())
        if form.is_valid():
            # Cycle through the settings and save them
            data = form.cleaned_data
            for setting in USER_SETTINGS:
                name = setting['name']
                set_setting(user, name, data[name])
            context['saved'] = True
    else:
        # Read user settings and build the form
        settings = {}
        for setting in USER_SETTINGS:
            name = setting['name']
            settings[name] = get_setting(user, name)
        form = SettingsForm(settings)

    context['form'] = form

    return render_to_response(template,
        context, context_instance=RequestContext(request))
开发者ID:heldergg,项目名称:dre,代码行数:25,代码来源:views.py

示例2: user_settings

def user_settings(request):
    if request.method == 'POST':
        form = SettingsForm(request.POST, request.FILES)

        if form.is_valid():
            im = Image.open(request.FILES['profile_pic'])
            im = ImageOps.fit(im, (120, 120), Image.ANTIALIAS)

            if not os.path.exists(os.path.join(settings.MEDIA_ROOT, "profile")):
                os.makedirs(os.path.join(settings.MEDIA_ROOT, "profile"))

            im.save(os.path.join(settings.MEDIA_ROOT, "profile/{}.png".format(request.user.netid)))
            request.user.photo = "png"
            request.user.save()

            messages.success(request, 'Votre profil a été mis à jour.')

            return render(request, "users/settings.html", {'form': SettingsForm()})
    else:
        form = SettingsForm()

    return render(request, 'users/settings.html', {
        'form': form,
        'stream': actor_stream(request.user),
    })
开发者ID:Mixone-FinallyHere,项目名称:beta402,代码行数:25,代码来源:views.py

示例3: settings

def settings(_id):
    # Authentication
    if current_user.id != _id and not current_user.is_admin():
        flash("You are not authorised to edit user {}'s settings.".format(_id), "danger")
        return redirect(request.referrer or url_for("index"))

    # Check user exists
    _user = User.query.filter(User.id == _id).first()
    if _user is None:
        flash("User {} not found.".format(_id), "danger")
        return redirect(request.referrer or url_for("index"))

    # Validate form, if submitted; else render it.
    form = SettingsForm(_user, request.form)

    if form.validate_on_submit():
        _user.email = form.email.data
        _user.show_ads = form.show_ads.data
        db.session.add(_user)
        db.session.commit()
        return redirect(request.args.get("next") or url_for("users.user", _id=_user.id))

    return render_template("users/settings.html",
                           title="Your settings - Dotabank",
                           user=_user,
                           form=form)
开发者ID:tusharvikky,项目名称:dotabank-web,代码行数:26,代码来源:views.py

示例4: settings

def settings(request):
    if request.method == "POST":
        form = SettingsForm(request.POST)
        if form.is_valid():
            request.user.topic_set = form.cleaned_data["topics"]
            return HttpResponseRedirect("/")
    else:
        form = SettingsForm()

    return render(request, "settings.html", {"form": form})
开发者ID:bkons,项目名称:web_tech_2_3,代码行数:10,代码来源:views.py

示例5: settings

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,代码行数:10,代码来源:views.py

示例6: settings

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,代码行数:11,代码来源:views.py

示例7: post

	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,代码行数:12,代码来源:views.py

示例8: settings

def settings():
    global config
    # we need getattr for WTF
    formdata = namedtuple('Struct', config.keys())(*config.values())
    form = SettingsForm(obj=formdata, bait_session_retain=config['bait_session_retain'])

    if form.validate_on_submit():
        # the potential updates that we want to save to config file.
        options = {'bait_session_retain': form.bait_session_retain.data,
                   'malicious_session_retain': form.malicious_session_retain.data,
                   'ignore_failed_bait_session': form.ignore_failed_bait_session.data}
        update_config(options)
    return render_template('settings.html', form=form, user=current_user)
开发者ID:nghiemnv,项目名称:beeswarm,代码行数:13,代码来源:app.py

示例9: edit_settings

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,代码行数:14,代码来源:views.py

示例10: settings

def settings():
    global config
    form = SettingsForm(obj=MultiDict(config))

    if form.validate_on_submit():
        # the potential updates that we want to save to config file.
        options = {'honeybee_session_retain': form.honeybee_session_retain.data,
                   'malicious_session_retain': form.malicious_session_retain.data,
                   'ignore_failed_honeybees': form.ignore_failed_honeybees.data}
        update_config_file(app.config['BEEKEEPER_CONFIG'], options)
        # update the global config dict.
        config = get_config_dict(app.config['BEEKEEPER_CONFIG'])

    return render_template('settings.html', form=form, user=current_user)
开发者ID:idkwim,项目名称:beeswarm,代码行数:14,代码来源:app.py

示例11: settings

def settings():
    bait_session_retain = send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'bait_session_retain'))
    ignore_failed_bait_session = ast.literal_eval(send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'ignore_failed_bait_session')))
    malicious_session_retain = send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'malicious_session_retain'))
    form = SettingsForm(bait_session_retain=bait_session_retain, malicious_session_retain=malicious_session_retain,
                        ignore_failed_bait_session=ignore_failed_bait_session)

    if form.validate_on_submit():
        # the potential updates that we want to save to config file.
        options = {'bait_session_retain': form.bait_session_retain.data,
                   'malicious_session_retain': form.malicious_session_retain.data,
                   'ignore_failed_bait_session': form.ignore_failed_bait_session.data}
        send_config_request('{0} {1}'.format(Messages.SET_CONFIG_ITEM, json.dumps(options)))
    return render_template('settings.html', form=form, user=current_user)
开发者ID:ichakra,项目名称:beeswarm,代码行数:14,代码来源:app.py

示例12: settings

def settings():
    form = SettingsForm()
    if form.validate_on_submit():
        pass  # TODO - Make this actually do something
    elif request.method is not 'POST':
        form.username.data = g.user.username
        form.email.data = g.user.email
        form.gender.data = g.user.gender  # FIXME - Currently doesn't fill in radio button
        form.location.data = g.user.location
        form.about.data = g.user.about
    return render_template(
        'settings.html',
        form=form
    )
开发者ID:Kalenai,项目名称:flask-blog,代码行数:14,代码来源:views.py

示例13: settings

def settings(request):
	if request.method == 'POST':
		form = SettingsForm(request.POST)
		if form.is_valid():
			try:
				Alert.objects.get(user=request.user).delete()
			except:
				pass

			data = form.cleaned_data

			client_t = data['user_time']
			server_t = datetime.now().strftime('%H')
			tz_diff = int(server_t) - int(client_t)
			as_time = datetime(2013, 1, 1, data['time'].hour, data['time'].minute)			
			as_time = as_time + timedelta(hours=tz_diff)

			a = Alert(
				user=request.user,
				alert_server_time=as_time,
				start=data['start'],
				finish=data['finish'],
				period=data['period'],
				time=data['time'],
				alert_email=data['alert_email'],
				email=data['email'],
				alert_sms=data['alert_sms'],
				phone=data['phone']
			)

			alert = {}

			try:
				a.save()
				alert['txt'] = 'Настройки сохранены'
				alert['cls'] = 'alert-success'
			except:
				alert['txt'] = 'Не удалось сохранить настройки, попробуйте повторить позже'
				alert['cls'] = 'alert-danger'

			return render_to_response('settings.html', {'form': form, 'alert': alert}, RequestContext(request))
	else:
		try:
			a = Alert.objects.get(user=request.user)
			form = SettingsForm(instance=a)
		except: 
			form = SettingsForm()

	return render_to_response('settings.html', {'form': form}, RequestContext(request))
开发者ID:ivantsov,项目名称:lens_alert_proto,代码行数:49,代码来源:views.py

示例14: settings

def settings():
    pw_form = PasswordChangeForm()
    set_form = SettingsForm()
    if 'pw_change' in request.form and pw_form.validate_on_submit():
        try:
            g.user.set_password(pw_form.new_password.data)
            db.session.commit()
            flash(u'Passwort wurde geändert.')
        except:
            flash(u'Passwort konnte nicht geändert werden.')
    if 'settings_change' in request.form and set_form.validate_on_submit():
        g.user.name = set_form.name.data
        db.session.commit()
        flash(u'Einstellungen wurde geändert.')
    return render_template('user/settings.html', pw_form=pw_form, set_form=set_form)
开发者ID:danielthiel,项目名称:FlaskFactoryBone,代码行数:15,代码来源:views.py

示例15: profile

def profile(request):
    if request.method == 'POST':
        form = SettingsForm(request.POST, request.FILES)
        if form.is_valid():
            if request.user.check_password(request.POST['old_pass']):
                if request.POST['username'] != '':
                    request.user.username = request.POST['username']
                if request.POST['email'] != '':
                    request.user.email = request.POST['email']
                if request.POST['pass_new'] != '':
                    request.user.password = request.POST['pass_new']
                    request.user.set_password(request.user.password)
                request.user.save()
                return home(request)
    form = SettingsForm()
    return render(request, 'external/profile.html', {'form': form})
开发者ID:ValerGit,项目名称:online_converter,代码行数:16,代码来源:views.py


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