问题列表 - 第40720页

使用Django + Celery更新Haystack搜索索引

在我的Django项目中,我正在使用Celery.我将来自crontab的命令切换为周期性任务,但它运行良好,但它只是在模型上调用方法.是否可以从周期性任务更新我的Haystack索引?有没有人这样做过?

/manage.py update_index
Run Code Online (Sandbox Code Playgroud)

这是从Haystack文档更新索引的命令,但我不确定如何从任务中调用它.

python django indexing celery django-haystack

30
推荐指数
4
解决办法
8026
查看次数

ASP.NET MVC模型验证不适用于ViewModel

我有一个ViewModel,它包含一个Model和一些额外的属性.模型和属性上有验证,但执行时,仅检查模型上的验证,忽略属性中的验证.

该模型:

 [MetadataType(typeof(Customer_Validation))]
 public partial class Customer
 {
 }

 public class Customer_Validation
 {
     [Required(ErrorMessage="Please enter your First Name")]
     public string FirstName { get; set; }

     [Required(ErrorMessage = "Please enter your Last name")]
     public string LastName { get; set; }

     [Required(ErrorMessage = "Sorry, e-mail cannot be empty")]
     [Email(ErrorMessage="Invalid e-mail")]
     public string Email { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

ViewModel

 public class RegisterViewModel
 {
     public Customer NewCustomer { get; private set; }

     [Required(ErrorMessage="Required")]
     public string Password { get; private set; }

     public RegisterViewModel(Customer …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

5
推荐指数
1
解决办法
1万
查看次数

禁用onclick事件jquery

我有以下代码

http://www.jsfiddle.net/uZc8w/

我只是想知道我将如何使用jquery/javascript删除该attr所以它将不再工作

jquery onclick

7
推荐指数
1
解决办法
2万
查看次数

SQLite插入性能

我需要将单行写入文件服务器上的文件.我正在考虑使用SQLite来确保该行的写入成功而不仅仅是部分完成.但是,因为插入性能非常重要.我的问题是,SQLite在向表中插入行时会经历的确切过程(读取此内容,写入,读取此内容等)是什么.该表没有任何索引,也没有主键,约束或任何东西.

sqlite

7
推荐指数
2
解决办法
2万
查看次数

我们应该为python变量名使用哪些缩写?

一般来说,我使用PEP-8中规定的标准命名作为变量.喜欢:

delete_projects
connect_server
Run Code Online (Sandbox Code Playgroud)

但有时我找不到任何好名字,名称只会扩展到一个长名称:

project_name_to_be_deleted 
Run Code Online (Sandbox Code Playgroud)

我可以使用pr_nm_del,但这使代码不可读.我真的很痛苦为函数找到好的变量名.每当我开始编写新函数时,我只是花时间找到一个好的变量名.

是否有任何标准为众所周知的变量名称选择某些缩写,如delete,project,configuration, etc.?你如何选择简短但又好又可读的变量名?

这个问题可能不直接依赖于Python,但由于不同的编程语言使用不同的变量名称格式,我认为我将此问题限制为Python.

python syntax formatting naming-conventions

8
推荐指数
1
解决办法
3289
查看次数

Lua相当于virtualenv?

在lua中有类似python的virtualenv吗?

所以我可以在沙盒环境中安装所有必需的lua模块/岩石.这对测试很有用,因为我不会搞乱系统范围的lua模块或其他lua项目的环境.

自从支持自给式安装以来,luarocks看起来很有前景.但是我很感兴趣,如果有像virtualenv这样的工具可以自动创建,维护和切换沙盒环境.

lua virtualenv

9
推荐指数
2
解决办法
2040
查看次数

是否有必要学习用于Web开发的JavaScript DOM方法,现在我们有jQuery等人吗?

有了JQuery的可用性,是否需要学习使用Javascript直接进行DOM操作才能成为专业的Web开发人员/站点构建者等?

这也许可以用Prototype,MooTools等提出来,但除了他们的名字我不熟悉它们.

javascript jquery dom

6
推荐指数
1
解决办法
279
查看次数

将wstring转换为以UTF-8编码的字符串

我需要在wstring和string之间进行转换.我想,使用codecvt facet应该可以解决问题,但它似乎不适用于utf-8语言环境.

我的想法是,当我将utf-8编码文件读取到字符时,一个utf-8字符被读入两个普通字符(这就是utf-8的工作原理).我想从我的代码中使用的库的wstring表示创建这个utf-8字符串.

有谁知道怎么做?

我已经尝试过了:

  locale mylocale("cs_CZ.utf-8");
  mbstate_t mystate;

  wstring mywstring = L"??žýáí";

  const codecvt<wchar_t,char,mbstate_t>& myfacet =
    use_facet<codecvt<wchar_t,char,mbstate_t> >(mylocale);

  codecvt<wchar_t,char,mbstate_t>::result myresult;  

  size_t length = mywstring.length();
  char* pstr= new char [length+1];

  const wchar_t* pwc;
  char* pc;

  // translate characters:
  myresult = myfacet.out (mystate,
      mywstring.c_str(), mywstring.c_str()+length+1, pwc,
      pstr, pstr+length+1, pc);

  if ( myresult == codecvt<wchar_t,char,mbstate_t>::ok )
   cout << "Translation successful: " << pstr << endl;
  else cout << "failed" << endl;
  return 0;
Run Code Online (Sandbox Code Playgroud)

它为cs_CZ.utf-8语言环境返回'failed',并且对cs_CZ.iso8859-2语言环境正常工作.

c++ string utf-8 wstring

17
推荐指数
3
解决办法
3万
查看次数

在Java中将整数数组写入文件的最快方法?

正如标题所说,我正在寻找将整数数组写入文件的最快方法.阵列的大小会有所不同,并且实际上可以包含2500到25 000 000个整数.

这是我目前使用的代码:

DataOutputStream writer = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));

for (int d : data)
  writer.writeInt(d);
Run Code Online (Sandbox Code Playgroud)

鉴于DataOutputStream有一个写字节数组的方法,我尝试将int数组转换为字节数组,如下所示:

private static byte[] integersToBytes(int[] values) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    for (int i = 0; i < values.length; ++i) {
        dos.writeInt(values[i]);
    }

    return baos.toByteArray();
}
Run Code Online (Sandbox Code Playgroud)

和这样:

private static byte[] integersToBytes2(int[] src) {
    int srcLength = src.length;
    byte[] dst = new byte[srcLength << 2];

    for (int i = 0; i < srcLength; i++) {
        int …
Run Code Online (Sandbox Code Playgroud)

java performance file-io

13
推荐指数
3
解决办法
2万
查看次数

php增加一个值

我已经设置为常量,开始年份和结束年份,
所以我已经建立了一个while循环的条件

if the start year is < than the current year increment until true.
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,而不是像这样:

1999,2000,2001,2002,2003,2004
Run Code Online (Sandbox Code Playgroud)

它就像:

1999,2001,2003,2005,2007,2009
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

function yearCount()
{
  $yearBegin = START_YEAR;
  $yearCurrent = CURRENT_YEAR;
  while($yearBegin < $yearCurrent){
    echo "<option value=\"".$yearBegin++."\">".$yearBegin++."</option>";
  }
}
Run Code Online (Sandbox Code Playgroud)

任何想法都将受到高度赞赏.

php while-loop

1
推荐指数
2
解决办法
3404
查看次数