python机械化了TextareaCon的内容

2024-04-26 00:04:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在[OSQA>;用户设置]的管理面板中更改一个复选框,但当我使用mechanize提交web表单时,它会将TextareaControl的内容与其他字符分割开来。你知道吗

>>> import mechanize
>>> mech = mechanize.Browser()
>>> mech.open('http://example.com/account/signin/')
>>> mech.select_form(nr=2)
>>> mech["username"] = 'user'
>>> mech["password"] = 'pass'

>>> mech.open('http://example.com/admin/settings/users/')
>>> for el in mech.forms():
...     print el
... 
<POST http://example.com/admin/settings/users/ multipart/form-data
  <HiddenControl(csrfmiddlewaretoken=XxWchtzV5oR6ezkObhnk4nzIemTc8aDC) (readonly)>
  <TextControl(MIN_USERNAME_LENGTH=3)>
  <TextareaControl(RESERVED_USERNAMES=testing, this)>  # << HERE
  <CheckboxControl(TRUNCATE_LONG_USERNAMES=[*on])>
  <CheckboxControl(SHOW_USER_ACCEPT_RATE=[*on])>
  <TextControl(FREEZE_ACCEPT_RATE_FOR=admin)>
  <SubmitControl(submit=Save) (readonly)>>

>>> mech.select_form(nr=0)
>>> print mech["RESERVED_USERNAMES"]
... testing, this

所以,当我现在提交它,甚至没有修改任何领域。。。你知道吗

>>> results = mech.submit()

。。。TextareaControl的内容变为:

>>> mech.open('http://example.com/admin/settings/users/')
>>> mech.select_form(nr=0)
>>> print mech["RESERVED_USERNAMES"]
... t, ,,  , e, ,,  , s, ,,  , t, ,,  , i, ,,  , n, ,,  , g, ,,  , ,, ,,  ,  , ,,  , t, ,,  , h, ,,  , i, ,,  , s

Tags: formcomhttpsettingsadminexampleopenselect
1条回答
网友
1楼 · 发布于 2024-04-26 00:04:09

试图调试机械化,但没有运气。你知道吗

最后,我通过在osqa/forum/settings/users.py中安装之前更改OSQA设置来选择这些复选框

REQUIRE_EMAIL_VALIDATION_TO = Setting('REQUIRE_EMAIL_VALIDATION_TO', [], USERS_SET, dict(
label = _("Require email validation to..."),
help_text = _("Which actions in this site, users without a valid email will be prevented from doing."),
widget=CheckboxSelectMultiple(attrs={"checked":"checked"}),
choices=(("ask", _("ask questions")), ("answer", _("provide answers")), ("comment", _("make comments")), ("flag", _("report posts"))),
required=False,
))

加上(attrs={"checked":"checked"}),这不是我要说的,但解决了我的问题。你知道吗

相关问题 更多 >