PyAMF nogo, try DjangoAMF

6 views
Skip to first unread message

iongion

unread,
Nov 26, 2007, 3:36:14 PM11/26/07
to Django users
DjangoAMF seems a viable solution for bridging django with flash/flex
applications.

I gave it a shot, reached all the way to authentication but then
halted.

Here is a sample view:

from amf.django import permission_required

in settings.py i have

AMF_AUTH_FUNC = 'amfapp.views.login'

@permission_required('user')
def getCredentials(request, version):
return request

def login(request, username, password):
return 'user'

and the actionscript file:

import mx.remoting.debug.NetDebug;

import cinqetdemi.remoting.*; // i am using this remoting helpers from
cinqetdemi
import mx.rpc.*;

import mx.utils.Delegate;

class ro.gion.Console extends MovieClip
{
var gatewayUrl:String = "http://localhost:8000/gateway/";
var serviceName:String = "ConsoleService";
var service:RemotingService;
var user:String = "user";
var pass:String = "pass";
var app_version:String = "1.0";

function onLoad()
{
this.init();
}

function init()
{
NetDebug.initialize();
service = new RemotingService(gatewayUrl, "ConsoleService");

service.addEventListener('timeout', Delegate.create(this,
onTimeOut));
service.addEventListener('result', Delegate.create(this, onResult));
service.addEventListener('fault', Delegate.create(this, onFault));
service.addEventListener('busy', Delegate.create(this, onBusy));
service.addEventListener('clear', Delegate.create(this, onClear));
service.setCredentials(user, pass);
service.getCredentials([app_version], this, onGetCredentials,
onGetCredentialsFault);
}

function onGetCredentials(re)
{
}

function onGetCredentialsFault(fe)
{
}

function onTimeOut()
{
}

function onResult()
{
}

function onFault()
{
}

function onBusy()
{
}

function onClear()
{
}
}

Now i dont know how to hook built in django authentication to this
If you request object to be passed back to flash (no one would want
this, but it is a good complex object test) you will not be able to
make it, it hangs, i used this to patch djangoamf (i dont know either
python or django)

in djangoamf-0.5.5/amf/utils.py

you change get_as_type to this:

def get_as_type(obj):
"""Find the name of ActionScript class mapped to the class of
given python object.
If the mapping for the given object class is not found, return
the class name of the object."""
if hasattr(obj, '__module__'): # <- this is my addition to
utils.py
type = obj.__module__ + '.' + obj.__class__.__name__
if class_mappings:
for as_class, py_class in class_mappings.iteritems():
if type == py_class:
return as_class
return type
return None

and then again in djangoamf-0.5.5/amf/amf0.py

def write_custom_class(d, output):
#amf.logger.debug("amf0.write_custom_class(%s)", repr(d))
write_byte(TYPED_OBJECT, output)
type = amf.utils.get_as_type(d)
write_utf(type, output)
items = None # <- here is first change in amf0.py
if 'iteritems' in dir(d): # d is a dict
items = d.iteritems()
else:
if hasattr(d, '__dict__'): # <- here is another change amf0.py
items = d.__dict__.iteritems()
if items != None:
for key, value in items:
write_utf(key, output)
write_data(value, output)
write_int(0, output)
write_byte(END_OF_OBJECT, output)

now you will be able to return request object with no issues (i hope)

Now what i dont grasp is how to use this authentication scheme with
builtin django authentication even if DjangoAMF developer mentions it
is supported.

I would love to see these posts having some follow ups.

iongion

unread,
Nov 26, 2007, 3:55:09 PM11/26/07
to Django users
sorry for the double post, confusing gmail authentication

akaihola

unread,
Jan 5, 2008, 9:56:12 AM1/5/08
to Django users
DjangoAMF almost worked for us except for two problems:
- with hundreds of object it started to corrupt data
- it needs the S2Flex2 library on the ActionScript side

Since the December alpha version we have switched to PyAMF which works
nicely with the native mx:RemoteObject mechanism.

Joel Hooks

unread,
Jan 6, 2008, 12:23:43 PM1/6/08
to Django users
There was a couple bugs in pyAMF that they have squished as of
yesterday. Great guys.

http://joelhooks.com/?p=5

I'm still using the S2Flex2 RemotingService, but just because it
works.
Reply all
Reply to author
Forward
0 new messages