26 March, 2010

Restrict the input in textarea in actionscript3

Without restriction, user can input anything in the textarea.

In my internship program, users need according to the test text to input text in the textarea, after test we give them the typing speed and accuracy results.

But, user can input anything they want, even some html tags or javascript, so we need to restrict their input.

In actionscript3, there is a method of textarea to do this. For example:
var my_ta:mx.controls.TextArea;
my_ta.restrict = "^<>{}@"; 

That means user cannot input"<>{}@" these characters. "^" means characters after it are unacceptable. Without "^" means only characters in the my_ta.restrict are allowed.

20 March, 2010

无知很可怕

绞尽脑汁想了大半个月的设计难题,终于被解决了。
前天本来想了一个自以为很巧妙的设计,当时很是觉得自己聪明,都忍不住高兴的笑了,但到最后又被自己给推翻了。
后来仔细研究发现,原来一直认为python 的return HttpResponse()对ActionScript3是无用的,后者不能接收到任何的response,所以不能在python 中做判断,然后传结果让flash执行相应的function。
当我发现自己的想法是错误的时候,豁然开朗,这个难题不是设计难题,而是知识的缺陷。有时候一个巧妙的设计确实可以让代码简单化,从另一个方面解决难题,但是,如果没有足够的知识和经验的积累,很可能一句简单的代码就可以解决的问题,非要用另一种设计就会更麻烦。

原来Django里的{{ %for% }}有这个模板变量 {{ forloop.counter }},让我在views中到处安插的 
           #i = 1
            #for user in toplist:
            #  user.rank = i
            #  i = i + 1
顿时显得很丑陋。

无知很可怕,还是多学习吧!!


notes from django book--ch4

Dot lookups can be summarized like this: when the template system encounters a dot in a variable name, it tries the following lookups, in this order:
  • Dictionary lookup (e.g., foo["bar"])

  • Attribute lookup (e.g., foo.bar)

  • Method call (e.g., foo.bar())

  • List-index lookup (e.g., foo[2])

The system uses the first lookup type that works. It’s short-circuit logic.
Say, for instance, you have a BankAccount object that has a delete() method. If a template includes something like {{ account.delete }}, where account is a BankAccount object, the object would be deleted when the template is rendered!

To prevent this, set the function attribute alters_data on the method:

def delete(self):
    # Delete the account
delete.alters_data = True


The template system won’t execute any method marked in this way. Continuing the above example, if a template includes {{ account.delete }} and the delete() method has the alters_data=True, then thedelete() method will not be executed when the template is rendered. Instead, it will fail silently
.