Bind variables in Oracle backend - how to use them?

2010-08-13 Thread buddhasystem

Friends,

I'm in need of an implementation which calls for using bind variables (in
Oracle sense, not generic) in my SQL in a Django application.

Any experience with that, anyone?

TIA

-- 
View this message in context: 
http://old.nabble.com/Bind-variables-in-Oracle-backend---how-to-use-them--tp29431038p29431038.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Programmatically connecting to a database

2010-08-13 Thread buddhasystem

Do you think that implementing the Router class can be helpful as well? It
might save writing some code, not sure.




Your answer is on this blog post:

http://tidbids.posterous.com/saas-with-django-and-postgresql

Good luck



-- 
View this message in context: 
http://old.nabble.com/Programmatically-connecting-to-a-database-tp29428110p29431072.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Different Django instances running on the same server

2010-08-13 Thread buddhasystem

I think it's even simpler than this. When configuring your Apache, you
specify a few different virtual hosts listening on different ports. For each
host, you give a different PYTHONPAH. And that's it.



CLIFFORD ILKAY wrote:
> 
> On 08/12/2010 12:18 PM, Rick Caudill wrote:
>> Hi,
>>
>> Is it possible to run Django 1.1 and Django 1.2 on the same server?  I
>> have some legacy apps that I need to port to 1.2 but until then I would
>> still like to run 1.1 and also at the same time run 1.2 for some new
>> apps.  Is this possible
> 
> If you Google for pip + virtualenv + virtualenvwrapper, you'll find the 
> best way to do this. In short, you can create virtual Python 
> environments in which you can run not just different versions of Django, 
> or any other Python libraries, but even different versions of Python.
> 
> virtualenvwrapper.project is also quite worthwhile.
> -- 
> Regards,
> 
> Clifford Ilkay
> Dinamis
> 1419-3266 Yonge St.
> Toronto, ON
> Canada  M4N 3P6
> 
> 
> +1 416-410-3326
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Different-Django-instances-running-on-the-same-server-tp29420477p29431093.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: javascript

2010-08-13 Thread buddhasystem

That's easy as other people explained, but not too flexible.
I like putting hidden divs in my HTML and using jQuery to find this and
parse out the data.
This way, you can store complete structures id needed.



elharoussi wrote:
> 
> Hi
> Is it possible to give a javascript function a django variable as a
> parameter?
> thank you
> 

-- 
View this message in context: 
http://old.nabble.com/javascript-tp29429253p29431126.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Different Django instances running on the same server

2010-08-13 Thread buddhasystem

Hello there,
sure it can also be done, but it's hardly worth the effort imho. Just let
these sit on two different ports and inform the client.

If you are still compelled to redirect requests based on origin while using
one external port, it's doable from inside Django as well -- you look at the
requestor IP, rehash the URL and forward request to same physical Apache,
but on a different port. Doesn't seem difficult either.



Steve Holden-4 wrote:
> 
> If you want the different hosts to all respond to the same IP address
> and port 80, being selected by the Host: header coming on from the
> clients then you will have to front-end them with a redirecting server,
> in much the way that Web Faction do. It's quite possible, but it needs a
> little more work to put that extra layer in.
> 
> regards
>  Steve
> -- 
> 

-- 
View this message in context: 
http://old.nabble.com/Different-Django-instances-running-on-the-same-server-tp29420477p29431251.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Bind variables in Oracle backend - how to use them?

2010-08-17 Thread buddhasystem

I guess the problem is that I need to use raw queries to provide "hints" to
Oracle.
The class RawQuerySet does not have the "extra" method, as it appears.



Ian Kelly-2 wrote:
> 
> On Aug 13, 11:04 am, buddhasystem  wrote:
>> Friends,
>>
>> I'm in need of an implementation which calls for using bind variables (in
>> Oracle sense, not generic) in my SQL in a Django application.
>>
>> Any experience with that, anyone?
> 
> To use raw SQL with Django, see:
> http://docs.djangoproject.com/en/1.2/topics/db/sql/#topics-db-sql
> 
> To add parameters to an ordinary Django query, use the
> QuerySet.extra() method
> http://docs.djangoproject.com/en/1.2/ref/models/querysets/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none
> 
> Note that Django placeholders always use the %s syntax regardless of
> backend, so you'll need to use that rather than the named syntax
> normally used with Oracle.
> 
> HTH,
> Ian
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Bind-variables-in-Oracle-backend---how-to-use-them--tp29431038p29449301.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Bind variables in Oracle backend - how to use them?

2010-08-18 Thread buddhasystem

Thank you,

however, I am at loss to the syntax of specifying the bind variables for the
raw Django query! I've tried everything (like separating the select
statement and the "exec" addition with ;) and still  get a variety of error
messages. 

Do you know how to write a query with binds that will go through?

Thanks
Maxim


Ian Kelly-2 wrote:
> 
> On Aug 17, 4:59 pm, buddhasystem  wrote:
>> I guess the problem is that I need to use raw queries to provide "hints"
>> to
>> Oracle.
> 
> There has been some chatter recently on the developers list about
> adding support for optimizer hints, but I don't believe the syntax has
> settled yet.  For now you're correct in that you'll need to use raw
> queries for this.
> 
>> The class RawQuerySet does not have the "extra" method, as it appears.
> 
> The "extra" method is for adding custom columns, where clauses, etc.
> to a query constructed via the Django ORM.  A raw query is written
> entirely by the developer, so there is no reason for it to have an
> "extra" method.
> 
> Cheers,
> Ian
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Bind-variables-in-Oracle-backend---how-to-use-them--tp29431038p29471298.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Bind variables in Oracle backend - how to use them?

2010-08-18 Thread buddhasystem

Thank you,

however, I am at loss to the syntax of specifying the bind variables for the
raw Django query! I've tried everything (like separating the select
statement and the "exec" addition with ;) and still  get a variety of error
messages.

Do you know how to write a query with binds that will go through?

Thanks
Maxim 


Ian Kelly-2 wrote:
> 
> On Aug 17, 4:59 pm, buddhasystem  wrote:
>> I guess the problem is that I need to use raw queries to provide "hints"
>> to
>> Oracle.
> 
> There has been some chatter recently on the developers list about
> adding support for optimizer hints, but I don't believe the syntax has
> settled yet.  For now you're correct in that you'll need to use raw
> queries for this.
> 
>> The class RawQuerySet does not have the "extra" method, as it appears.
> 
> The "extra" method is for adding custom columns, where clauses, etc.
> to a query constructed via the Django ORM.  A raw query is written
> entirely by the developer, so there is no reason for it to have an
> "extra" method.
> 
> Cheers,
> Ian
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Bind-variables-in-Oracle-backend---how-to-use-them--tp29431038p29472095.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Bind variables in Oracle backend - how to use them?

2010-08-18 Thread buddhasystem

Thanks, I'll look into that. In the meantime, I managed to just use the
cursor from cx_Oracle (as in the example on Oracle site) and the code looks
slightly more elegant.

However, both "my" and yours solution suffer from the same defect imho --
that the ORM machinery of Django is unusable. We are back to manual mapping
of rows onto objects... Or -- am I mistaken?



Tim Sawyer-6 wrote:
> 
>> Friends,
>>
>> I'm in need of an implementation which calls for using bind variables (in
>> Oracle sense, not generic) in my SQL in a Django application.
>>
>> Any experience with that, anyone?
> 
> Here's an example using bind variables to return output values from a 
> PL/SQL block.
> 
>   >>> import cx_Oracle
>   >>> from django.db import connection
>   >>> cursor = connection.cursor()
>   >>> lOutput = cursor.var(cx_Oracle.STRING)
>   >>> cursor.execute("BEGIN %s := 'N'; END; ", [lOutput])
>   >>> print lOutput
>   
>   >>> print lOutput.getvalue()
>   None
>   >>>
> 
> There was a bug in Django that prevented this working (hence the None in 
> the code above) - it's fixed in Django 1.2. The full thread for this is 
> at
> http://www.mail-archive.com/django-users@googlegroups.com/msg100490.html
> 
> Hope that will help send you in the right direction.
> 
> Tim.
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Bind-variables-in-Oracle-backend---how-to-use-them--tp29431038p29475966.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Bind variables in Oracle backend - how to use them?

2010-08-19 Thread buddhasystem

Hello there,
I'm 90% sure that you can't get the cx cursor out of Django connection.
These are similar but different classes. I tried something like that.

Thanks for pointing me to sqlalchemy. Ultimately, the queries I intend to
run are so laden with hints and binds, that it's almost easier to do direct
SQL. Django ORM is excellent in most cases, just not in most hairy ones.




Tim Sawyer-6 wrote:
> 
> No, I don't think you're mistaken, especially if you want to use hints.
> 
> I tried this code again today with the django database connection (using 
> 1.2 final), and it didn't work.  This only works with cx_Oracle
> connections.
> 
> See 
> http://drumcoder.co.uk/blog/2010/apr/23/output-parameters-cx_oracle-and-plsql/
> 
> Ian said in the other thread: "Otherwise, you can get the
> cx_Oracle cursor from cursor.cursor and use that directly."  This sounds 
> like a way of being able to use the django connection but use the direct 
> cx_Oracle functionality.
> 
> Random thought - have you tried sqlalchemy?  Does that have hint 
> support?  I've never used it.
> 
> Tim.
> 
> On 18/08/10 21:58, buddhasystem wrote:
>>
>> Thanks, I'll look into that. In the meantime, I managed to just use the
>> cursor from cx_Oracle (as in the example on Oracle site) and the code
>> looks
>> slightly more elegant.
>>
>> However, both "my" and yours solution suffer from the same defect imho --
>> that the ORM machinery of Django is unusable. We are back to manual
>> mapping
>> of rows onto objects... Or -- am I mistaken?
>>
>>
>>
>> Tim Sawyer-6 wrote:
>>>
>>>> Friends,
>>>>
>>>> I'm in need of an implementation which calls for using bind variables
>>>> (in
>>>> Oracle sense, not generic) in my SQL in a Django application.
>>>>
>>>> Any experience with that, anyone?
>>>
>>> Here's an example using bind variables to return output values from a
>>> PL/SQL block.
>>>
>>>>>>  import cx_Oracle
>>>>>>  from django.db import connection
>>>>>>  cursor = connection.cursor()
>>>>>>  lOutput = cursor.var(cx_Oracle.STRING)
>>>>>>  cursor.execute("BEGIN %s := 'N'; END; ", [lOutput])
>>>>>>  print lOutput
>>>
>>>>>>  print lOutput.getvalue()
>>>None
>>>>>>
>>>
>>> There was a bug in Django that prevented this working (hence the None in
>>> the code above) - it's fixed in Django 1.2. The full thread for this is
>>> at
>>> http://www.mail-archive.com/django-users@googlegroups.com/msg100490.html
>>>
>>> Hope that will help send you in the right direction.
>>>
>>> Tim.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@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.
>>>
>>>
>>>
>>
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Bind-variables-in-Oracle-backend---how-to-use-them--tp29431038p29484970.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



What's the best practice for initializing the state of the server?

2010-08-19 Thread buddhasystem

I need to initialize a few data structures and potentially do other set-up as
needed, only when the Django server comes up. What's the optimal way of
doing that?

-- 
View this message in context: 
http://old.nabble.com/What%27s-the-best-practice-for-initializing-the-state-of-the-server--tp29487847p29487847.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: What's the best practice for initializing the state of the server?

2010-08-19 Thread buddhasystem

Thank you! I actually had something less fancy in mind, like initializing
data structures (possibly from a file), when the server is starts.
Basically, looking for "init" handle.



hcarvalhoalves wrote:
> 
> If it's loading data on model's tables, you can use fixtures:
> 
> http://docs.djangoproject.com/en/dev/howto/initial-data/
> 
> Because it's also possible to define SQL files to run on syncdb, you
> can also run SQL-specific tasks (like defining functions, full text
> search indexes, etc...).
> 
> If the your other setup tasks involve messing with the server, it's
> better to factor this out of Django. You can use something like Fabric
> for automating deployment tasks instead:
> 
> http://docs.fabfile.org/0.9.1/
> 
> On 19 ago, 21:55, buddhasystem  wrote:
>> I need to initialize a few data structures and potentially do other
>> set-up as
>> needed, only when the Django server comes up. What's the optimal way of
>> doing that?
>>
>> --
>> View this message in
>> context:http://old.nabble.com/What%27s-the-best-practice-for-initializing-the...
>> Sent from the django-users mailing list archive at Nabble.com.
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/What%27s-the-best-practice-for-initializing-the-state-of-the-server--tp29487847p29488292.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Caching JSON in Django

2010-08-24 Thread buddhasystem

Hello,

I'm trying to use native caching in Django as per
http://docs.djangoproject.com/en/dev/topics/cache/

I followed the setup procedure to the tee (it's not hard, of course). What I
observe is that my app caches only views that deliver HTML. Since my
application is heavily AJAX, that's not what I want -- I want to cache JSON
-- but it doesn't work!

Any hints how I can make it work?

I can always code it up myself (I have, actually), but I try to avoid that.

Thanks.

-- 
View this message in context: 
http://old.nabble.com/Caching-JSON-in-Django-tp29526535p29526535.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Caching JSON in Django

2010-08-25 Thread buddhasystem

Sort of -- with AJAX (meaning I just serve JSON) I don't
use RequestContext at all. Just HttpResponse(jsonData), which
works fine for my purposes.

It's really puzzling though why context request should affect
caching. It's a shame I can't use it.



Reinout van Rees wrote:
> 
> On 08/24/2010 11:15 PM, buddhasystem wrote:
>>
>> I'm trying to use native caching in Django as per
>> http://docs.djangoproject.com/en/dev/topics/cache/
>>
>> I followed the setup procedure to the tee (it's not hard, of course).
>> What I
>> observe is that my app caches only views that deliver HTML. Since my
>> application is heavily AJAX, that's not what I want -- I want to cache
>> JSON
>> -- but it doesn't work!
>>
>> Any hints how I can make it work?
> 
> Quick guess: difference in RequestContext between regular html pages and 
> ajax views?
> 
> 
> Reinout
> 
> -- 
> Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
> Programmer at http://www.nelen-schuurmans.nl
> "Military engineers build missiles. Civil engineers build targets"
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Caching-JSON-in-Django-tp29526535p29531093.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Caching JSON in Django

2010-08-25 Thread buddhasystem

Thanks for you reply. I'm away from my coding machine, so I'll just answer a
part of your question --

When I use the cache decorator in a view, I expect that as long as cache is
valid, the code in the view
does not get executed. And that's what I see when rendering a template with
some little context attached to it. However, in a different view adorned
with same decorator, which does not use a template and just wraps
HttpResponse around JSON (which is plain ASCII after all) I see that the
whole database glue shebang inside the view comes into motion every time I
hit the view, any time. This correlates with the content of the
CACHE_BACKEND (which in my case is file storage) -- in the former case, I
have cryptic little dirs sprouting up, in the latter I see nothing. I think
that proves the general picture i.e. cache not working -- am I wrong?



jtiai wrote:
> 
>> Hello,
>> 
>> I'm trying to use native caching in Django as per
>> http://docs.djangoproject.com/en/dev/topics/cache/
>> 
>> I followed the setup procedure to the tee (it's not hard, of course).
>> What
>> I observe is that my app caches only views that deliver HTML. Since my
>> application is heavily AJAX, that's not what I want -- I want to cache
>> JSON -- but it doesn't work!
> 
> It doesn't work how? How you observed caching?
> 
>> Any hints how I can make it work?
>> 
>> I can always code it up myself (I have, actually), but I try to avoid
>> that.
> 
> View code would be helpful and don't forget the caching parts.
> 
> -- 
> 
> Jani Tiainen
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Caching-JSON-in-Django-tp29526535p29531180.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Caching JSON in Django

2010-08-25 Thread buddhasystem

Thanks much!

a) I'm using GET

b) In current set of queries, JSON data size is quite moderate

PS. I am considering tweaking the links I sent to the AJAX app such that
when possible, it accesses cache file space on the server as a directory,
statically, bypassing Django. That's fast. The set of URLs the AJAX client
is receiving is configurable.



jtiai wrote:
> 
> Is your AJAX query POST or GET query? Because as you may know, POST
> queries 
> are not cached, GET queries are.
> 
> Note that if you're still using large pieces of JSON data, upstream caches
> are 
> not used (data is always sent from Django) which makes some extra load on 
> Django app.
> 
>> Thanks for you reply. I'm away from my coding machine, so I'll just
>> answer
>> a part of your question --
>> 
>> When I use the cache decorator in a view, I expect that as long as cache
>> is
>> valid, the code in the view
>> does not get executed. And that's what I see when rendering a template
>> with
>> some little context attached to it. However, in a different view adorned
>> with same decorator, which does not use a template and just wraps
>> HttpResponse around JSON (which is plain ASCII after all) I see that the
>> whole database glue shebang inside the view comes into motion every time
>> I
>> hit the view, any time. This correlates with the content of the
>> CACHE_BACKEND (which in my case is file storage) -- in the former case, I
>> have cryptic little dirs sprouting up, in the latter I see nothing. I
>> think
>> that proves the general picture i.e. cache not working -- am I wrong?
>> 
>> jtiai wrote:
>> >> Hello,
>> >> 
>> >> I'm trying to use native caching in Django as per
>> >> http://docs.djangoproject.com/en/dev/topics/cache/
>> >> 
>> >> I followed the setup procedure to the tee (it's not hard, of course).
>> >> What
>> >> I observe is that my app caches only views that deliver HTML. Since my
>> >> application is heavily AJAX, that's not what I want -- I want to cache
>> >> JSON -- but it doesn't work!
>> > 
>> > It doesn't work how? How you observed caching?
>> > 
>> >> Any hints how I can make it work?
>> >> 
>> >> I can always code it up myself (I have, actually), but I try to avoid
>> >> that.
>> > 
>> > View code would be helpful and don't forget the caching parts.
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Caching-JSON-in-Django-tp29526535p29531559.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Caching JSON in Django

2010-08-25 Thread buddhasystem

Hello -- 

I think that might be the case... I do extract parameters from GET.

Am I out of luck?




Jirka Vejrazka wrote:
> 
>> Is your AJAX query POST or GET query? Because as you may know, POST
>> queries
>> are not cached, GET queries are.
> 
> 
> Also, GET requests are not cached in some cases (e.g. when GET
> parameters are used) - it's really difficult to figure out what's
> wrong without knowing specific details.
> 
>   Cheers
> 
> Jirka
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Caching-JSON-in-Django-tp29526535p29531574.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Caching JSON in Django

2010-08-25 Thread buddhasystem

Thank you so very much. It works like a clock!
I use urlencode to to convert the complete URL hash into a key, that's just
logical.
I wrap set and get. A total of 10 lines of extra code isn't bad, of course
the simple
use of decorator would be even nicer!



Piotr Zalewa-2 wrote:
> 
>   In such case it would better to not cache entire method, but simply 
> the data - build the unique key per GET requests, check if the data is 
> already stored in cache, if so - use it, else - retrieve it from 
> database and store it in cache.
> 
> from django.core.cache import cache
> 
> def someview(req):
> 
>  par = req.GET.get('somepar')
>  key = "someview:%s" % par
>  data = cache.get(key, None)
> 
>  if not data:
>  # get data from database
>  # ...
>  cache.set(key, data)
> 
>  # here normal usage of data
> 
> On 10-08-25 13:12, buddhasystem wrote:
>> Hello --
>>
>> I think that might be the case... I do extract parameters from GET.
>>
>> Am I out of luck?
>>
>>
>>
>>
>> Jirka Vejrazka wrote:
>>>> Is your AJAX query POST or GET query? Because as you may know, POST
>>>> queries
>>>> are not cached, GET queries are.
>>>
>>> Also, GET requests are not cached in some cases (e.g. when GET
>>> parameters are used) - it's really difficult to figure out what's
>>> wrong without knowing specific details.
>>>
>>>Cheers
>>>
>>>  Jirka
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@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.
>>>
>>>
>>>
> 
> 
> -- 
> blog http://piotr.zalewa.info
> jobs http://webdev.zalewa.info
> twit http://twitter.com/zalun
> face http://www.facebook.com/zaloon
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Caching-JSON-in-Django-tp29526535p29535253.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Surreptitious caching of JS in Django

2010-08-30 Thread buddhasystem

Hello,
with the generous help of many of you, I easily set up JSON caching feature
in my Django app, in a few views.

The problem I'm now facing is that according to what I observe, Django also
caches Javascript code in its memcached backend. While this is a welcome
behavior in a deployed app, it makes development quite a pain -- I need to
flush cache after any code update and therefore wait for the lengthy DB
interaction to happen...

Is this a known behavior? Can it be defeated? I statically serve JS:

urlpatterns += patterns("", (r'^include/(?P.*)$',
'django.views.static.serve', {'document_root': INCLUDE_DIR}),)

TIA!

-- 
View this message in context: 
http://old.nabble.com/Surreptitious-caching-of-JS-in-Django-tp29575393p29575393.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Surreptitious caching of JS in Django

2010-09-01 Thread buddhasystem

I really didn't configure any caching of JS myself, with the exception that
it gets served statically. Disabling cache altogether is not an attractive
option as my testing goes against expensive queries.



Reinout van Rees wrote:
> 
> On 08/30/2010 07:52 PM, buddhasystem wrote:
>>
>> Hello,
>> with the generous help of many of you, I easily set up JSON caching
>> feature
>> in my Django app, in a few views.
>>
>> The problem I'm now facing is that according to what I observe, Django
>> also
>> caches Javascript code in its memcached backend.
> 
> That's probably something you configured yourself.
> 
> Anyway, in development you can uncomment any CACHE_BACKEND in your 
> settings.py and no caching will happen.
> 
> 
> Reinout
> 
> 
> -- 
> Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
> Collega's gezocht!
> Django/python vacature in Utrecht: http://tinyurl.com/35v34f9
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Surreptitious-caching-of-JS-in-Django-tp29575393p29594246.html
Sent from the django-users mailing list archive at Nabble.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.