我想将模型十进制字段与表单选择字段组合在一起.
模型中的字段:
sum = models.DecimalField(max_digits=2, decimal_places=2)
Run Code Online (Sandbox Code Playgroud)
表格中的字段:
sum = forms.ChoiceField(choices=WORK_HOUR_CHOICES, label='Sum Working Hours', required=True)
Run Code Online (Sandbox Code Playgroud)
选择:
WORK_HOUR_CHOICES = (
(0, '0'),
(0.5, '0.5'),
(1, '1'),
(1.5, '1.5'),
(2, '2'),
(2.5, '2.5')
)
Run Code Online (Sandbox Code Playgroud)
但总是当我想存储一个小数位的值时,我得到这个错误:
quantize result has too many digits for current context
Run Code Online (Sandbox Code Playgroud)
当我保存0或1时,它工作正常.
怎么了?
我写了一个单元测试,检查初始数据是否正确加载.但是Node.objects.all().count()总是返回0,因此看起来根本没有加载灯具.命令行中没有输出/错误消息没有加载灯具.
from core.models import Node
class NodeTableTestCase(unittest.TestCase):
fixtures = ['core/core_fixture.json']
def setUp(self):
print "nothing to prepare..."
def testFixture(self):
"""Check if initial data can be loaded correctly"""
self.assertEqual(Node.objects.all().count(), 14)
Run Code Online (Sandbox Code Playgroud)
夹具core_fixture.json包含14个节点,我使用此夹具作为初始数据加载到db中使用以下命令:
python manage.py loaddata core/core_fixture.json
Run Code Online (Sandbox Code Playgroud)
它们位于我在settings.py设置中提供的文件夹中FIXTURE_DIRS.
我正在寻找一种通用的方法来防止多个表单提交.我发现这种方法看起来很有希望.虽然我不希望在我的所有观点中都包含此代码段.使用请求处理器或中间件可能更容易做到这一点.
任何最佳做法建议?
我想知道遍历此函数返回的数据的正确语法是什么:
$.get(url, function(data){
alert(data);
});
Run Code Online (Sandbox Code Playgroud)
data.find("table")或类似的东西不起作用.返回的html数据看起来像这样,从django模板解析:
<div class="pagination">
<span class="step-links">
<span style="visibility:hidden;">previous</span>
<span class="current">
Page 1 of 2.
</span>
<a id="next" href="?page=2">next</a>
</span>
</div>
<form class="" id="action-selecter" action="" method="POST">
<div class="action_dropdown">
<label>Action: <select name="action">
<option value="" selected="selected">---------</option>
<option value="new_selection">Add to new selection</option>
<option value="delete_selected">Delete selected projects</option>
</select></label>
<button type="submit" class="button" title="Run the selected action" name="index" value="1">Go</button>
</div>
<div id="ajax_table_result">
<table cellspacing="5">
...
</thead>
<tbody>
...
</tbody>
</table>
</div>
</form>
Run Code Online (Sandbox Code Playgroud) 我应该将大量用VBA(Excel)编写的代码转换为VB6.但我真的不知道我要照顾什么或从哪里开始.因此,从VB6专家那里得到一些提示会很棒.
我已经安装了MS Visual Studio并且玩了一下.但我不是VB6专家,也不知道我该做什么.
最终目标是将所有VBA代码(当前放在一个excel vba宏中)放入VB6项目中,然后创建一个.dll.这个.dll应该由excel引用,excel应该像现在一样运行:-)
例如,我需要做什么才能将此vba代码转换为VB6.
Public Function getParameterNumberOfMaterial() As Integer
10 On Error Resume Next
Dim a As String
20 a = Sheets("Parameters").name
30 If IsNumeric(Application.Worksheets(a).range("C3").Value) Then
40 If Application.Worksheets(a).range("C3").Value > 0 Then
50 getParameterNumberOfMaterial = Application.Worksheets(a).range("C3").Value
60 Else
70 MsgBox "Please check cell C3 in the sheet 'Parameters'. It should include a numeric value which is greater than zero"
80 MsgBox "Parameter Number of Material/Cost is set to the default value of 10"
90 getParameterNumberOfMaterial = 10 …Run Code Online (Sandbox Code Playgroud) 我有一个表,其构建如下:
styleN = styles["Normal"]
data = []
table_row = ['ID', 'Some Information']
data.append(table_row)
table_row = []
table_row.append(Paragraph(object.ID, styleN))
table_row.append(Paragraph(object.some_information1, styleN))
data.append(table_row)
t = Table(data, (6*cm,6*cm,2*cm,2*cm,2*cm), row_heights, style=ts)
Run Code Online (Sandbox Code Playgroud)
现在我想要实现的是,我可以将包含 object.some_information2 的第二段添加到第二个单元格中。
一些或多或少的伪代码来说明我想要实现的目标:
table_row = []
table_row.append(Paragraph(object.ID, styleN))
info1 = Paragraph(object.some_information1, styleN)
info2 = Paragraph(object.some_information2, styleN)
info_paragraphs = info1 + info2
table_row.append(info_paragraphs)
data.append(table_row)
t = Table(data, (6*cm,6*cm,2*cm,2*cm,2*cm), row_heights, style=ts)
Run Code Online (Sandbox Code Playgroud) 我正在研究如何使用功能强大的D3(我完全可以完全推荐用于数据可视化)来发出POST请求,并找到了D3的作者当前正在处理xhr POST请求(以及其他请求类型)的xhr2分支支持.
似乎它是一个全新的功能,因为合并请求来自昨天(2012年9月18日):)而且好奇我是我已经想尝试一下,使用以下代码序列(我从这个位置)
d3.text("localhost/test",function(d) { console.log(d)})
.method("POST")
.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
.data("a=1&b=2&c=3");
Run Code Online (Sandbox Code Playgroud)
不幸的是我收到以下错误消息.
TypeError:'undefined'不是函数(评估'd3.text("localhost/test",function(d){console.log(d)}).method("POST")')
我正在使用xhr2分支中的缩小D3版本.谁知道要改变什么?
我将jquery datepicker绑定到输入字段.这适用于静态上下文.但是如果我用ajax重新加载部分页面,再次调用bind方法,则找不到新加载的内容,因此我无法将我的datepicker绑定到新加载的字段.
<script type="text/javascript">
function ajax_get_hour_record_form()
{
$.get(url, function(results){
var form = $("form.ajax_form_result", results);
var h3 = $("h3", results);
//update the ajax_form_result div with the return value "form"
$('#ajax_form_result').html(form);ajax_form_h3
$('#ajax_form_h3').html(h3);
}, "html");
}
//ajax for capturing the href link and show the resulting form
$( document ).ready( function() {
$( '.add_hour_record' ).click( function(e) {
e.preventDefault();
url = $(this)[0].href;
ajax_get_hour_record_form();
//here I'm calling the bind_datepicker_to_date_fields to bind the ajax loaded fields to the datepicker. This does not work.
bind_datepicker_to_date_fields();
});
bind_datepicker_to_date_fields(); …Run Code Online (Sandbox Code Playgroud) 我正试图从doc运行hello world app .
我收到以下错误:
render(java.lang.String) in views.html.index cannot be applied to (play.data.Form<controllers.Application.Hello>)
Run Code Online (Sandbox Code Playgroud)
指向以下代码块:
/**
* Home page
*/
public static Result index() {
return ok(index.render(form(Hello.class)));
}
Run Code Online (Sandbox Code Playgroud)
Eclipse也无法解析索引对象上的.render方法.
the method render(String) in the type index is not applicable for the arguments (Form<Application.Hello>)
Run Code Online (Sandbox Code Playgroud)
我定义了以下导入:
package controllers;
import play.*;
import play.mvc.*;
import play.data.*;
import play.data.validation.Constraints.*;
import java.util.*;
import views.html.*;
Run Code Online (Sandbox Code Playgroud)
此外,文件夹app/views /中还提供了hello.scala.html和index.scala.html
知道我做错了什么吗?
我正在创建两个POST调用.一个使用django形式,一个使用角度js通过资源xhr.
角度设置如下所示:
myModule.factory('gridData', function($resource) {
//define resource class
var root = {{ root.pk }};
var csrf = '{{ csrf_token }}';
return $resource('{% url getJSON4SlickGrid root.pk %}:wpID/', {wpID:'@id'},{
get: {method:'GET', params:{}, isArray:true},
update:{method:'POST', headers: {'X-CSRFToken' : csrf }}
});
});
Run Code Online (Sandbox Code Playgroud)
通过创建xhr post请求:
item.$update();
Run Code Online (Sandbox Code Playgroud)
此post请求按预期发送到服务器,但是当我想访问QueryDict时,我无法访问传递的数据:
name = request.POST.get('name', None)
Run Code Online (Sandbox Code Playgroud)
name总是None这样.
这背后的问题是QueryDict对象被解析得很奇怪.
print request.POST
<QueryDict: {u'{"name":"name update","schedule":0"}':[u'']}>
Run Code Online (Sandbox Code Playgroud)
虽然我会期望这个结果,当我通过"正常"的Post请求发送数据时,我得到了这个结果:
<QueryDict: {u'name': [u'name update'], u'schedule': [u'0']}>
Run Code Online (Sandbox Code Playgroud)
所以似乎Django在POST请求中收到一些东西,指示Django将参数解析为一个字符串.知道如何规避这个吗?
更新:
我发现这个讨论,他们说问题是如果你提供除MULTIPART_CONTENT以外的任何内容类型,参数将被解析为一个字符串.我检查了内容类型发送与POST请求,它确实设置为'CONTENT_TYPE': 'application/json;charset=UTF-8'.因此,这可能是问题所在.因此我的问题是:如何为使用angular.js资源创建的xhr post请求设置CONTENT_TYPE MULTIPART_CONTENT?