简体   繁体   English

PyAMF,Django和Python的“属性”功能出现问题

[英]Issue with PyAMF, Django, and Python's “property” feature

So far, I've had great success using PyAMF to communicate between my Flex front-end and my Django back-end. 到目前为止,使用PyAMF在Flex前端和Django后端之间进行通信已经取得了巨大的成功。 However, I believe I've encountered a bug. 但是,我相信我遇到了一个错误。 The following example (emphasis on the word "example") demonstrates the (potential) bug: 以下示例(强调单词“ example”)演示了(潜在)错误:

My Flex app contains the following VO: 我的Flex应用程序包含以下VO:

package myproject.model.vo
{
    [Bindable]
    [RemoteClass(alias="myproject.models.Book")]

    public class BookVO
    {
        public var id:int;
        public var title:String;
        public var numberOfOddPages:int;
    }
}

My Django app contains the following model: 我的Django应用包含以下模型:

class Book(models.Models):
    title = models.CharField(max_length=20)

    def _get_number_of_odd_pages(self):
        #some code that calculates odd pages
       return odd_page_total

    numberOfOddPages = property(_get_number_of_odd_pages)

When I attempt to retrieve the book objects to display in a DataGrid, the books display in the grid as expected. 当我尝试检索书籍对象以显示在DataGrid中时,书籍按预期显示在网格中。 However, "numberOfOddPages" is always set to 0. I have even attempted to explicitly set this attribute with a default value (ie, "numberOfOddPages=100") to see if my "_get_number_of_odd_pages()" method had an error in it. 但是,“ numberOfOddPages”始终设置为0。我什至尝试使用默认值(即“ numberOfOddPages = 100”)显式设置此属性,以查看我的“ _get_number_of_odd_pages()”方法中是否有错误。 Unfortunately, it yields the same result: the value in the VO remains at 0. 不幸的是,它产生了相同的结果:VO中的值保持为0。

Does anyone have any insight into what I may be doing wrong? 有人对我可能做错的事情有任何见解吗?

I just received the following response from PyAMF's lead developer. 我刚刚收到PyAMF首席开发人员的以下回复。 It's definitely a bug: 绝对是一个错误:

This is a bug in the way the Django adapter handles non models.fields.* properties. 这是Django适配器处理非models.fields。*属性的方式中的一个错误。

If I do: 如果我做:

import pyamf

class Book(object):    
def _get_number_of_odd_pages(self):
  return 52

numberOfOddPages = property(_get_number_of_odd_pages)

pyamf.register_class(Book, 'Book')

encoded = pyamf.encode(Book()).getvalue() 
print pyamf.decode(encoded).next().numberOfOddPages

Then i get the correct values of 52. 然后我得到52的正确值。

I have created a ticket for this and will look into getting a patch a little later. 我已经为此创建了票证 ,稍后会考虑获得补丁。

Cheers, 干杯,

Nick 缺口

UPDATE : Nick has fixed this bug and it will be released in PyAMF 0.4.1 (which should be released this weekend). 更新 :Nick已修复此错误,它将在PyAMF 0.4.1中发布(应在本周末发布)。

Not at all. 一点也不。

Do you think the error is from Django or from Flex? 您认为错误是来自Django还是来自Flex? You could first of all trace the AMF Object in Flex. 您首先可以在Flex中跟踪AMF对象。 If the value there is allready 0 then have a good look what PyAMF does. 如果该值全为0,则可以很好地了解PyAMF的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM