我希望在[OSQA>的管理员面板中用户设置]更改一个复选框,但是当我使用机械化提交网页表单时,它会删除包含其他字符的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
答案 0 :(得分:0)
试图调试机械化但没有运气。
我最终通过在osqa/forum/settings/users.py
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"})
,这不是我要做的,而是解决了我的问题。