On 17 jan, 21:58, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> Please open a ticket. What's the latest version that worked? Can you
> show how you expose the service?

The last version I used is 1.94.5 from march/april last year.
Are older web2py archives available somewhere for testing ?...

Here is the code I'm using, it's pretty basic.
It all happens in one controller, which is the same on both
instances :

def upload():
    """ Try to send all current records to a remote instance for
replication ; optionally archive them to local History """
    response.view = "basic.html"
    response.title = "Upload records "
    if not response.flash : response.flash = "Uncheck the 'Move' box
while you're testing your upload parameters !"

    response.local_styles = """
    #target_id { width: 20em; }
    """

    parms = db(db.params.id == 1).select()[0]
    target = parms.remote_host if parms.remote_host else 'http://
localhost:8000/'+request.application
    form = FORM(P("Upload all current records to remote instance
at:"),
                       P(INPUT(_type="text", _name="target",
_id="target_id", _value=target, requires=IS_URL())),
                       P(INPUT(_type="checkbox", _name="archive",
value=True, _id="cb"),
                          LABEL(" Move uploaded records to the History
list", _for="cb")),
                       P(INPUT(_type="submit",_value="Upload")))

    if form.accepts(request.vars, session, keepvalues=True) :
        import xmlrpclib
        move = request.vars.archive
        target = request.vars.target
        client = xmlrpclib.ServerProxy(target+'/current/handle',
allow_none=True)
        rows = db(db.current.id>0).select()
        status, response.flash = client.accept(rows.colnames,
rows.response)
        if status == 'OK' :
            db(db.params.id == 1).select()
[0].update_record(remote_host=target)
            if move and status == 'OK' :
                for record in rows :
                    record.pop('update_record', None)
                    record.pop('delete_record', None)
                    id = record.pop('id', None)
                    db.history.insert(**record)
                db(db.current.id>0).delete()
                response.flash += " and moved to History"

    return dict(form=form)

# xmlrpc handshake function
def handle(): return response.xmlrpc(request,[accept])

def accept(columns,rows):
    """ Receive records from a remote instance and add them to the
local Current list """
    j=len('current.')
    if not session.accept_uploads :
        return 'NOK', "The remote host is not accepting uploads at
this time"
    try:
        for row in rows:
            items=dict([(columns[i][j:],row[i]) for i in
range(len(columns)) if columns[i][-3:]!='id'])
            db.current.insert(**items)
        return 'OK', "%d entries uploaded to remote host's Current
list" % len(rows)
    except :
        return 'NOK', "There was an error at the remote host during
the upload"

Reply via email to