Re: How to pass values between views/templates

2009-10-02 Thread djfis...@gmail.com

Mike,

I think you're doing it right. Unless you want that data to be in the
URL (perhaps) or sent page to page in post data (probably a bad idea)
sessions are your best option.

-David

On Oct 2, 6:16 pm, adelaide_mike  wrote:
> Hi
> In my app the user needs to drill down through a series of templates
> and their views to identify a house.  We start with the city, then the
> street and finally the house, in each case chosen from a rendering of
> the possible values selected from the relevant database table.
>
> I have all this working nicely using request.session['insert value
> here'] as the tool for storing the choices as they are made.
>
> My question is: is there a better or more proper way?
>
> Mike
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help debug strange errors

2009-10-02 Thread djfis...@gmail.com

The built-in Django development server handles 404s and 500s, but when
you deploy onto mod_python or mod_wsgi, you need a 404.html and a
500.html.

On Oct 2, 4:52 am, Gustavo Senise  wrote:
> Hey Mak,
>
> I understand that. The point is that locally the app is running fine! So how
> can I understand whats wrong?
>
> 2009/10/2 Maksymus007 
>
>
>
>
>
> > On Fri, Oct 2, 2009 at 1:46 PM, gustavo  wrote:
>
> > > Hello fellows,
>
> > > I have been developing a little blog app as described in
> > >http://www.aprendendodjango.com, what means Learning Django. It this
> > > very interesting.
>
> > > But I've got problems when I tryed to deploy. It seems everything is
> > > ok, but the log server is telling me that it is searching for a
> > > 500.html template, so the app crashes sending me these messages:
>
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34] mod_wsgi
> > > (pid=15934): Exception occurred processing WSGI script '/home/edah/
> > > public_html/meu_blog/index.wsgi'.
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34] Traceback
> > > (most recent call last):
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]   File "/
> > > usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line
> > > 239, in __call__
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]
> > > response = self.get_response(request)
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]   File "/
> > > usr/lib/python2.6/site-packages/django/core/handlers/base.py", line
> > > 128, in get_response
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]     return
> > > self.handle_uncaught_exception(request, resolver, exc_info)
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]   File "/
> > > usr/lib/python2.6/site-packages/django/core/handlers/base.py", line
> > > 160, in handle_uncaught_exception
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]     return
> > > callback(request, **param_dict)
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]   File "/
> > > usr/lib/python2.6/site-packages/django/views/defaults.py", line 23, in
> > > server_error
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]     t =
> > > loader.get_template(template_name) # You need to create a 500.html
> > > template.
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]   File "/
> > > usr/lib/python2.6/site-packages/django/template/loader.py", line 80,
> > > in get_template
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]     source,
> > > origin = find_template_source(template_name)
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]   File "/
> > > usr/lib/python2.6/site-packages/django/template/loader.py", line 73,
> > > in find_template_source
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]     raise
> > > TemplateDoesNotExist, name
> > > [Wed Sep 30 16:27:00 2009] [error] [client 200.198.212.34]
> > > TemplateDoesNotExist: 500.html
>
> > > Well, I've played a little with my settings and index.wsgi, but got no
> > > good results. Someone please help me!?
>
> > > Thanks a lot!
>
> > "# You need to create a 500.html
> > template."
>
> --
> Gustavo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to establish foreign key contraints across models living in different applications

2009-09-26 Thread djfis...@gmail.com

Guillermo,

It is possible to have a model in one application have a foreign key
to another application as of Django 1.0.

From:
http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey
---
To refer to models defined in another application, you can explicitly
specify a model with the full application label. For example, if the
Manufacturer model above is defined in another application called
production, you'd need to use:

class Car(models.Model):
manufacturer = models.ForeignKey('production.Manufacturer')

This sort of reference can be useful when resolving circular import
dependencies between two applications.
---

Hopefully this is what you need.

-David

On Sep 26, 12:07 pm, Guillermo 
wrote:
> Hi all,
>
> I have one app with a Project model and another app with a TodoItem
> model. How can I declare Project to be the foreign key of TodoItem?
> Or, rather, how can I make TodoItem accept an arbitrary model as
> foreign key?
>
> Regards,
>
> Guillermo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Remote login via XML-RPC or SOAP?

2009-09-15 Thread djfis...@gmail.com

SOAP and XMLRPC have quite a few tradeoffs, but without knowing
exactly what your setup is (other than Python/Django) I'd advise you
to go with XMLRPC. However, I'll lay out why I think so and perhaps
SOAP does make more sense for you.

SOAP is the successor to XMLRPC and some people -- notably people from
the Java and .NET worlds -- think that SOAP is "better". In the Java
and .NET worlds, SOAP is pretty common but a lot of the scripting
language worlds are moving toward a third option REST which I won't
get into here since it doesn't seem to be an option for you. With
Python, XMLRPC is built into the standard library where you'll have to
go to Pypi for a SOAP library. Rolling your own SOAP library is
probably not a good idea since SOAP is complex and verbose. In
addition, there are occasionally incompatibilities with .NET SOAP
services or so I've been led to believe from others at work.

While SOAP is certainly more complex, in some cases it can make up for
it with type checking, code generation or object translation. SOAP
services usually make use of a web service description language
document (WSDL) that describes the service and can contain XML schemas
that describe in great detail the properties of the objects in the
service. Using this, a SOAP library may be able to automatically take
native objects and send them in web service calls or take web service
responses and translate them into objects. It is possible that with a
good library, you may need to write less code with SOAP. In general,
XMLRPC in Python will translate your objects into requests and
responses into objects, but XMLRPC only supports a few data types
(int, float, list, dict, datetime) compared with SOAP. Possibly
because of this lack of complexity, XMLRPC is pretty well standardized
between various clients and servers. If you just need to use a couple
services that your client is exposing and those services accept just a
couple primitive parameters, XMLRPC is your best bet.




On Sep 14, 7:07 pm, Rodrigo Cea  wrote:
> I am creating a Django website for a client who won't give me access
> to their database or server, but will allow login / account creation
> on their server via SOAP or XML-RPC from my server, where the Django-
> based website will reside.
> I would like to get an idea beforehand about which route, SOAP or XML-
> RPC, is easier, more stable, less buggy, more widely used, etc.
>
> The process will be:
> a) user inputs new account info on my server (lets call it D for
> Django).
> b) account is created on client's server (lets call it C for client)
> c) C responds with Success or Fail.
> d) next morning, user logs in via D
> e) C responds with Success or Fail, plus some user info such as name,
> age and other info gleaned during step (a).
> f) D stores this information to use during the session and logs in
> user.
>
> Any help, caveats, libraries or suggestions are much appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem sending json objects

2009-07-16 Thread djfis...@gmail.com

Gustavo,

I believe this is a problem (feature?) of jquery. It is not
serializing your full settings object to a string. Instead, it creates
a series of url-encoded key value pairs. It looks like it is just
calling .toString() on the value side as well. When .toString() is
called on:

{"id": {"label":"", "width":"10px"}, "name":{"label":"Nome",
"width":"300px;"}}

the response is simply "[object Object]". This is what is actually
being sent to Django. It looks like jquery does this so that all the
data can be encoded into the URL string if this was sent as a GET
request.

If you must send a full JSON object, one possibility is to send your
JSON structure as a string and just decode the full raw_post_data in
Django. This might look like the below code:

def datagrid(request):
try:
jsondict = json.loads(request.raw_post_data)
except Exception, e:
logging.error(e)
jsondict = {}
logging.info(jsondict)
return HttpResponse(json.dumps(jsondict, indent=2))

Your jquery code could look like this although there's probably a
better way to do it:

obj = '{"model_name": "Client", "cols": {"id": {"label":"",
"width":"10px"}, "name": {"label":"Nome", "width":"300px;"}}}';

$.ajax({
type: "POST",
url: "/datagrid/",
dataType: "text",
data: obj,
processData: false,
success: function(data, textStatus) {
alert(data);
}
})

If you run into issues like this in the future, log the full
raw_post_data and you can see what is being transmitted from client to
server.

-David


On Jul 16, 1:32 pm, Gustavo Henrique  wrote:
> Hi list!
> I'm a problem with json and django. My javascript code send all data
> by ajax but my view don't accept the content [Object Object] like json
> object.
> I try using jquery:
>
> settings = {
>         model_name: 'Client',
>         cols: {"id": {"label":"", "width":"10px"}, "name":
> {"label":"Nome", "width":"300px;"}}
>
> }
>
> $.ajax({
>             type: 'POST',
>             url: '/datagrid/',
>             dataType: 'json',
>             data: settings,
>             success: function(r) {
>             
>
> Django raise exception:
> Exception Value: Expecting object: line 1 column 1 (char 1)
> Exception Location: /usr/lib/python2.5/site-packages/django/utils/
> simplejson/decoder.py in JSONArray, line 221
>
> in my view I use:
>
> def myview(request)
>     P = request.POST
>     cols = "%s" % simplejson.loads(P.get('cols'))
>
> but the request's content is:
> 
>
>
> Can you help me?
>
> Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Ajax with JSON-RPC -- new Django handler

2009-07-10 Thread djfis...@gmail.com

According to the jsonrpc 1.1 working draft, the request type and
response should be application/json not application/javascript. Even
if you handle requests that are in other types for compatibility, you
probably want your responses to be the correct type.

http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#RequestHeaders

-David

On Jul 10, 9:21 am, BenW  wrote:
> I fixed the above problem with URL reversing by refactoring the
> JSONRPCService.__call__ method to grab it from the request object.
>
>     def __call__(self, request, extra=None):
>
>         if request.method == "POST":
>             return HttpResponse(self.process(request),
>                 mimetype="application/javascript")
>
>         url = request.get_full_path()
>         return HttpResponse(self.get_smd(url),
>             mimetype="application/javascript")
>
> This makes more sense since the service url was already defined in the
> urlconf, so there's no point in redefining it just so that it can go
> in the SMD.
>
> I also reworked the get_smd() method in JSONRPCServiceBase to take the
> url parameter:
>
>     def get_smd(self, url):
>
>         smd = {
>             "serviceType": "JSON-RPC",
>             "serviceURL": url,
>             "methods": []
>         }
>
>         import inspect
>         for method in self.listmethods():
>             sig = inspect.getargspec(self.methods[method])
>             smd["methods"].append({
>                 "name": method,
>                 "parameters": [ {"name": val} for val in sig.args if \
>                     val not in ("self", "request") ]
>             })
>
>         return simplejson.dumps(smd)
>
> It now defines the smd directly rather than it being defined in
> __init__ then populated here.  I also added a test to remove 'self'
> and 'request' from the reported method parameters since those are
> internal and having them reported will cause an RPC client that
> imports the remote methods into their namespace (as was discussed in
> previous post) to throw errors.
>
> Purely for my own needs, I added an optional param to
> JSONRPCServiceBase.__init__:
>
> def __init__(self, auth_method=None)
>     self.auth_method = auth_method
>
> in JSONRPCServiceBase I fixed up process() to call the auth_method (if
> it was defined) to determine if the remote client is allowed to call
> that method:
>
>     def process(self, request):
>
>         data = simplejson.loads(request.raw_post_data)
>         id, method, params = data["id"], data["method"], data
> ["params"]
>
>         if self.auth_method:
>             answer = self.auth_method(request, method, params)
>             try:
>                 answer, message = answer
>             except TypeError:
>                 message = "not authorized"
>
>             if not answer:
>                 return self.error(id, 100, message)
>
> ...
>
> You can use it like so:
>
> def adminrpc_auth(request, method, params):
>
>     return request.session.user.is_admin
>
> adminrpc = JSONRPCService(auth_method=adminrpc_auth)
>
> @jsonremote(adminrpc)
> def save_realm(request, realm_obj):
>
>     return realm_obj
>
> This way if you have a collection of methods that should only be
> available to an admin user, you can test that in one place rather than
> in every method.  The auth_method can optionally return a custom error
> message:
>
> return request.session.user.is_admin, "Admins Only"
>
> The default is just "not authorized" -- I'll post my complete mods on
> the wiki later.
>
> Any opinions on my modifications are welcome!
>
> Thanks,
>
> Ben

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---