I'm not an expert in rails but i know ActiveResource's workflow and i
don't get the same feeling using pyactiveresource.
I'm retrieving data using pyactiveresource but i don't know how to
retrieve info from an url with this patterns: 'http://
www.railsapplication.org/entries/1234.xml' or 'http://
myrailsapplication.org/entries/1234.xml'
With a class defined as:
class Entries(ActiveResource):
_site = 'http://www.railsapplication.org'
When i retrieve an entry i do in this way:
entry = Entries.find(id_ = 1234)
This search retrieves info with given id from 'http://
www.railsapplication.org/entries.xml'
I have been reading a little of module's code, but i don't get still
make the patterns commented above.
Another due is when i want to update entry i get a 'True' but changes
doesn't occur in database.
I'm doing it like this:
entry.comment = 'New comment'
entry.update()
Thanks in advance!
Hi, i'm using pyactiveresource for a personal project and i'm a little
confused on how to use it. Project consists in a pygtk desktop client
for a rails application.
I'm not an expert in rails but i know ActiveResource's workflow and i
don't get the same feeling using pyactiveresource.
I'm retrieving data using pyactiveresource but i don't know how to
retrieve info from an url with this patterns: 'http://
www.railsapplication.org/entries/1234.xml' or 'http://
myrailsapplication.org/entries/1234.xml'
With a class defined as:
class Entries(ActiveResource):
_site = 'http://www.railsapplication.org'
When i retrieve an entry i do in this way:
entry = Entries.find(id_ = 1234)
This search retrieves info with given id from 'http://
www.railsapplication.org/entries.xml'
I have been reading a little of module's code, but i don't get still
make the patterns commented above.
Another due is when i want to update entry i get a 'True' but changes
doesn't occur in database.
I'm doing it like this:
entry.comment = 'New comment'
entry.update()
Thanks in advance!
--
You received this message because you are subscribed to the Google Groups "pyactiveresource" group.
To post to this group, send email to pyactive...@googlegroups.com.
To unsubscribe from this group, send email to pyactiveresour...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyactiveresource?hl=en.
I think it could be that i'm not getting all data correctly because
there are so many xml fields like this:
<author id='12' name='jimmy neutron' />
When i get an entry, entry.author = None
If i make a 'PUT/POST' method, entry.author = None, probabaly, the error
is here.
In ruby, i can get author's id like this:
'entry.author.name'
So, how can i easy access/modify this attribute entry?
Thanks again!
>
>
> Thanks in advance!
>
> --
> You received this message because you are subscribed to the Google
> Groups "pyactiveresource" group.
> To post to this group, send email to
> pyactive...@googlegroups.com
> <mailto:pyactive...@googlegroups.com>.
> To unsubscribe from this group, send email to
> pyactiveresour...@googlegroups.com
> <mailto:pyactiveresource%2Bunsu...@googlegroups.com>.
I'm not sure how you're ending up with xml like that. Is that xml
generated by the server or by pyactiveresource?
> When i get an entry, entry.author = None
>
> If i make a 'PUT/POST' method, entry.author = None, probabaly, the error is
> here.
>
> In ruby, i can get author's id like this:
> 'entry.author.name'
On the server, or via ActiveResource? Seeing a comparison of what
ActiveResource is doing vs. what pyActiveResource is doing would be
helpful. A snippet of your client side code and the related xml is
probably what is needed.
First, sorry for give you only examples, but i think that was enough.
That xml was generated by the server, a real 'entry', seen with a web
browser, is like that
<issue>
<id>12571</id>
<project name="REST API Tests" id="9883"/>
<tracker name="Bug" id="1"/>
<status name="In Progress" id="2"/>
<priority name="Normal" id="4"/>
<author name="javier hernandez" id="20366"/>
<assigned_to name="javier hernandez" id="20366"/>
<subject>primera peticion</subject>
<description>descripcion \n</description>
<start_date>2010-02-20</start_date>
<due_date></due_date>
<done_ratio>40</done_ratio>
<estimated_hours>5.0</estimated_hours>
<spent_hours>0.0</spent_hours>
<custom_fields>
<custom_field name="Has been tested" id="1">0</custom_field>
</custom_fields>
<created_on>Sat Feb 20 18:28:16 -0800 2010</created_on>
<updated_on>Mon Feb 22 15:06:48 -0800 2010</updated_on>
</issue>
>
> > When i get an entry, entry.author = None
In pyactiveresource's client code
>
> > If i make a 'PUT/POST' method, entry.author = None, probabaly, the error is
> > here.
>
> > In ruby, i can get author's id like this:
> > 'entry.author.name'
In ActiveResouce's client code
>
> On the server, or via ActiveResource? Seeing a comparison of what
> ActiveResource is doing vs. what pyActiveResource is doing would be
> helpful. A snippet of your client side code and the related xml is
> probably what is needed.
In pyactiveresource, my code is something like this:
from pyactiveresource.activeresource import ActiveResource
class Issues(ActiveResource):
"""Represents Issues object"""
_site = HOST
_user = USER
_password = PASSWORD
I create the class, and using ipython, i do:
issue = Issues.find(12571)
I get the issue successfully as you can see in debug lines
INFO:pyactiveresource.connection:GET http://demo.redmine.org/issues/12571.xml
DEBUG:pyactiveresource.connection:request-headers:Authorization:Basic
amF2aXViZTpyZWRtaW5ldGVzdHM=
INFO:pyactiveresource.connection:--> 200 OK 960b
now i have issue's attributes as a dict object:
issue.attributes
and i get:
{'assigned_to': None,
'author': None,
'created_on': 'Sat Feb 20 18:28:16 -0800 2010',
'custom_fields': custom_fields(None),
'description': 'descripcion \n',
'done_ratio': '40',
'due_date': None,
'estimated_hours': '5.0',
'id': '12571',
'priority': None,
'project': None,
'spent_hours': '0.0',
'start_date': '2010-02-20',
'status': None,
'subject': 'primera peticion',
'tracker': None,
'updated_on': 'Mon Feb 22 17:08:29 -0800 2010'}
This issue is what pyactiveresource gets from the server, corresponds
with xml posted before.
Note that there are attributes with 'None' as value like 'project' or
'author'.
You can check in xml that 'project' field has two properties, both
with its values, 'name' and 'id'.
I tried to get this values using pyactiveresource's in many ways, but
with no successfull.
Maybe i'm doing something wrong?
Using ruby, i get this values without problems, doing it like that:
require 'rubygems'
require 'active_resource'
# Issue model on the client side
class Issue < ActiveResource::Base
self.site = 'http://redmine.server/'
self.user = 'foo'
self.password = 'bar'
end
# Retrieving an issue
issue = Issue.find(1)
# Print author's name
puts issue.author.name
Hope this time you've got detailed info!
Lot of thanks again!
It looks as though the xml -> dictionary converter is not handling
that method of attribute specification (it generally assumes that it's
getting the output from ActiveRecord::Base#to_xml)
I have submitted a fix for this that seems to do the trick, can you
please give it a try and let me know if it fixes your issue?
http://code.google.com/p/pyactiveresource/source/detail?r=65
Thanks,
Mark
On Feb 24, 10:24 pm, Mark Roach <mrro...@google.com> wrote:
> Hi again. That helps very much. You have some interesting xml going on there.
>
> It looks as though the xml -> dictionary converter is not handling
> that method of attribute specification (it generally assumes that it's
> getting the output from ActiveRecord::Base#to_xml)
>
> I have submitted a fix for this that seems to do the trick, can you
> please give it a try and let me know if it fixes your issue?http://code.google.com/p/pyactiveresource/source/detail?r=65
> > INFO:pyactiveresource.connection:GEThttp://demo.redmine.org/issues/12571.xml
Why you replace all '_' to '-' when you convert a dictionary to an
xml?
In my case i don't need that at all. I have removed all replaces and
now it fits my needs.
FYI
I read this in http://api.rubyonrails.org/classes/ActiveResource/Base.html#M000914
It is implemented in pyActiveResource? If not, can you implement this?
I pretend to distribute my code and i want my application works using
'official' pyactiveresource's code.