Archive for the 'pyAMF' Category

VEsession - Flex photography studio management and client ordering application

My wife saw the application that I am working on at work to manage tasks and immediately asked, "Where's mine?"

21st century honey-do list.

So far, this is what I have created. PureMVC is the underlying framework. The photos are loaded from SlideShowPro Director XML galleries. Unforutately, the most recent version of SSP-D won't let you use it as a service in this way. This older version is has all the functionality I need though, so it isn't an issue. Eventually I will implement functionality to eliminate the need for SSP-D with some gallery management. It will be better to keep it all under one roof.

The backend is Django using pyAMF for communications back and forth. Django elminates the pain of CRUD operations and provides an excellent admin interface for free.

My goal is to open source the application and provide it as a PureMVC/Django example.

UPDATED: This version is a little jacked because I am working on a new version. The demo images are way too big and cause the application to scroll in unsightly ways. The new demo is located here, and uses the same credentials as below.

[Here is the demo]
user: demo_client
pass:demo_client

session_sshot.jpg

[source]

Do to some, uh, laziness on my part, this will only compile with strict mode turned off The new version does not have this problem.

pyAMF - Communication with Django from Flex

Up until this point I have been using Django AMF for my remote services. It was working fairly well on my windows machine, but when I tried to deploy my application to my Ubuntu slice, it started kicking up weird errors. I'd spoken with one of the pyAMF developers in a Reddit thread, and they seemed like a motivated group, so I decided to give pyAMF a go.

*sigh*

Now I have new errors to deal with. Not a problem though, signed up to their mailing list and Thijs and Nick were extremely helpful in hunting down the bugs and squishing them dead. pyAMF is still in alpha, but they are moving over to beta soon. It is working well now, so give it a try if you need communication between Flash/Flex/AIR and Python.

The Gateway

They have a couple of examples on the pyAMF site, but here are a couple things that I learned. In my amfgateway.py, which is the equivelant of a Django views.py, I had to register my models so that pyAMF would send and recieve typed custom objects. It ended up looking something like this:

amfgateway.py

import pyamf
from pyamf.remoting.djangogateway import DjangoGateway
from django.contrib.auth.models import Userpyamf.register_class( User, 'django.contrib.auth.models.User' )
 
def get_users(request):
    return User.objects.all()
 
sessionGateway = DjangoGateway({'ve.get_users'  : get_users})  # could include other functions as well

I am using the Django auth structure to authenticate users in my application, so that is the bare bones of what you need to get that going. Here's what the urls.py looks like:

urls.py

from django.conf.urls.defaults import *urlpatterns = patterns(' ',
     (r'^ve/gateway/', 've.clients.amfgateway.sessionGateway'),
)

As you can see, it is extremely simple. It is setup in the same fashion you would use to link up a Django view.

In Flex, I've set up a RemoteServiceDelegate which is extending the Seasar RemotingService [the site is in japanese]. This is actually a holdover from Django AMF, but it works well, so I am going to continue to use it. Here's the code:

RemoteServiceDelegate.as

package com.visualempathy.session.model.delegate
{
 import mx.controls.Alert;
 import mx.rpc.events.FaultEvent;	import org.seasar.flex2.rpc.remoting.RemoteService;
 
  public class RemoteServiceDelegate extends RemoteService
  {
 	public static const gatewayURL:String = "http://myserver.com/ve/gateway/"
 	public function RemoteServiceDelagate()
        {
 		super();
 		useAMF0 = false;
 		gatewayUrl = gatewayURL;
 		destination = 've';
                addEventListener(FaultEvent.FAULT, handleDataFault);
 	}
 
 	private function handleDataFault( fe:FaultEvent ):void
 	{
 		Alert.show( fe.fault.faultDetail );
 	}
 }
}

Using this setup, the destination in the remoting service is used like this:

 sessiongateway = DjangoGateway({'ve.get_users' : ve.get_users
've.get_orders': ve.get_orders})

where 've', the destination in the RemotingService class precedes the method name in the DjangoGateway argument. This can be added to as much as needed as demonstrated above.