Re: @cache_control() and @never_cache not working

2009-01-29 Thread Tomas Kopecek

In that version (0.96) of Django was bug in combination of these
decorators and CacheMiddleware. If you can use upstream version then
everything will be working. Otherwise look for these (closed) tickets on
http://code.djangoproject.com and patch your version.

Tomas Kopecek

--~--~-~--~~~---~--~~
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: Internationalization

2008-01-15 Thread Tomas Kopecek

Grupo Django napsal(a):
> I have a Menu app that takes data from the database and renders it
> into a template. I was wondering if I can translate the output from
> the database. There are only a few entries.
> Can I add the text that the menu will render that is stored in the db
> and add it to the .po file?
> How can I do it?
> Thank you.
> > 

In this case could be usable gettext_noop() function for menu items.

-- 

        Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



random seed with multiple processes

2007-10-20 Thread Tomas Kopecek

Hello,
We are using django with FastCGI deployment and got the following 
problem. Inside is used module random which is imported before forking 
parent process. It means, that each of children processes have same 
sequence of pseudo-random numbers. Is there any simple way to re-seed 
random _after_ forking? Or do we have to wait for desynchronizing 
threads by user?

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Caching binary data

2007-10-15 Thread Tomas Kopecek

Is it possible to use django caching layer with memcached backend for 
caching binary data?

When I store some binary data and try to retrieve them via cache.get, I 
almost always got unicode error. After cache.get is called smart_unicode 
on basestring and it doesn't detect that data are not instance of text 
string.

-- 

    Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Browser Games?

2007-10-08 Thread Tomas Kopecek

We are making advanced web-game which is fourth generation of game 
previously coded in perl (with C excesses). Nowadays we have about 7MB 
of code (python + django templates) and game is running with testing 
users. Official start will be probably during January in local version 
(with english translation but no support) and after evaluating phase it 
will probably go international (cz,sk,pl,en).

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Random objects in view

2007-10-02 Thread Tomas Kopecek

Alessandro Ronchi napsal(a):
> 2007/10/1, Tomas Kopecek <[EMAIL PROTECTED]>:
> 
>> Now, I don't understand. What is the difference between these two cases?
> 
> I don't know. If I put the random order before filter it works, if I
> put it after filter it doesn't.
> 
> 
Maybe it is worth a ticket in trac.

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Random objects in view

2007-10-01 Thread Tomas Kopecek

Alessandro Ronchi napsal(a):
> 2007/10/1, Tomas Kopecek <[EMAIL PROTECTED]>:
> 
>> items = shuffle(items)
> 
> 
> If I do that I get
> 
> Exception Type: TypeError
> Exception Value:object doesn't support item assignment
> 
Oh, sorry, I forget that it works in place. It means you have to do this:

items = list(items)
shuffle(items)

> The '?' works If I put it on objects.all.order_by('?') instead objects.all
> 
Now, I don't understand. What is the difference between these two cases?


-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Random objects in view

2007-10-01 Thread Tomas Kopecek

Alessandro Ronchi napsal(a):
> I tried to create a random view with the code on the bottom. It
> doesn't work, the order is always the same.
> What's wrong?


> items.order_by('?')
? Means, that order is undefined but not random with each call. If you 
want to randmize order, use this

from random import shuffle

items = shuffle(items)

-- 

    Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Incrementing in django templates

2007-09-04 Thread Tomas Kopecek

Rufman napsal(a):
> hey
> 
> does anyone know if there is a way to increment a variable in a django
> template?
> 
> I was thinking somthing like this:
> 
> {% for somthing in varFromView %}
> {{ index = index+1 }}
> 
> {% endfor %}

If you only need this case (indexing for cycle), then use variable 
{{forloop.counter}}. Otherwise you need to create new template tag.

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: QuerySet & memory

2007-08-28 Thread Tomas Kopecek

James Bennett napsal(a):
> On 8/27/07, Jeremy Dunck <[EMAIL PROTECTED]> wrote:
>> QuerySet.iterator does what you want.
> 
> I was going to follow up with a documentation link, but it appears we
> lost the documentation for QuerySet.iterator at some point. Opened a
> ticket
> 
> In any case, Jeremy's right: the "iterator" method returns a generator
> which fetches the data in chunks and only instantiates objects when
> they're actually needed, yielding them one at a time as you iterate
> over it. So you can replace a call to 'all()' with a call to
> 'iterator()', or chain 'iterator()' on after a call to 'filter()', and
> you should see greatly improved memory usage for situations where
> you're dealing with huge numbers of objects.
> 
> 
Thanks for responses. I look to iterator() code and it does this thing 
ok. With some experimenting I saw that mysql backend is probably the 
worst. Even with iterator mysql sends whole result set and Python DB 
imitates cursor() semantics. As I said I get 2GB of memory footprint. 
With SQLite I got only 20MB with same code. So it looks that I have to 
more think about switching to some other DBMS or to use explicit slicing.

For me it could be more appropriate to change iterator() to do some 
slicing for me (by explicit LIMIT clause), maybe a small patch for our 
application. I understand, that changing it in general would be a bad 
design decision.

So again, thank for help.

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



QuerySet & memory

2007-08-27 Thread Tomas Kopecek

Hello,
I've thought, that QuerySets whose are iterated does not allocate memory 
for all objects. But simple test shows otherwise. When I iterate through
SomeModel.objects.all() I get same memory consumption like with 
list(SomeModel.objects.all()). It is very frustrating, because with test 
database (which is definitely not as large as production one) with 
approximately 3 records I get about two GB of memory per process. 
Iterating through all records in my app is a special case, but needed one.

So my question is: Is (or should be) there a difference between 
iterating and enumerating objects? Is there any way to load object on 
demand only, so to use memory only roughly equal to sizeof(SomeModel)?

-- 

    Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ugettext vs. ugettext_lazy

2007-08-21 Thread Tomas Kopecek

Malcolm Tredinnick napsal(a):
> makes 's1' a Unicode object. It's value will be based on the locale when
> it is executed and then never change, no matter what the locale is. So
> anything that is executed at *import* time should not be using
> ugettext(). Since it's a cause of great confusion for some people about
> what when particular lines are executed, I simplified a little in the
> docs and wrote "use ugettext_lazy() everywhere", since it's not actually
> harmful to do so.

Oh, that's the paragraph I've been looking for. Note about *import*
time is crucial. I've should thought about it. Now it makes much more
sense. Everytime I've played with ugettext* I've used it inside 
functions and so I didn't noticed this behaviour and everything looked 
same for both of them. Maybe, it should be mentioned in documentation also.

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ugettext vs. ugettext_lazy

2007-08-20 Thread Tomas Kopecek

Hello,
I've been playing with these functions and finally I've become totally 
confused.

I've expected that there would be some difference in behaviour, but I 
was not able to create such use case in which these two functions 
produces different results. More precisely, I haven't find place where 
would be better to use ugettext_lazy. In documentation is said to use 
this function in models.py everywhere. But for me it looks that ugettext 
makes the same work. All text marked to translation is translated 
accordingly to locale set by user via browser with both of them.

Furthermore i was not able to use template strings and stay in __proxy__ 
mode. anything like ugettext_lazy('xyz %s') % 'some_text' comes to 
unicode string representation immediately. So, it looks there is no way 
to use template strings with *_lazy. From my view it is little bit 
painful to use it.

But I think I must be completely missing something important in this 
area. Can anybody enlighten me, please?

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Template tag and combining variables & text

2007-07-30 Thread Tomas Kopecek

Emanuele Pucciarelli napsal(a):
> 
> Il giorno 29/lug/07, alle ore 22:48, Tomas Kopecek ha scritto:
> 
>> I know, it's syntactical nonsense. But does anybody know about some  
>> way
>> how to combine variable content with string content? Is it possible?
>>
>> For example, very crude way could be something like
>>
>> {% img %} {{BASE_URL}}/path/z.gif {% endimg %}
> 
> Maybe something like {% img base_url "path/z.gif" %}: let string  
> content be surrounded by double quotes, and let the tag join  
> everything for you.
> 
> Code:
> 
> from django.template import Node, TemplateSyntaxError, Library
> 
> register = Library()
> 
> class MixedNode(Node):
>   class Variable(object):
>   def __init__(self, name):
>   self.name = name
>   def __str__(self):
>   return self.name
>   def __init__(self, args):
>   self.parameters = [
>   [self.Variable(arg), 
> arg.rstrip('"').lstrip('"')][arg[0] == arg 
> [-1] == '"']
>   for arg in args]
>   def get_param(self, i, context):
>   if isinstance(i, self.Variable):
>   return context[str(i)]
>   else:
>   return i
>   def get_string(self, context):
>   return ''.join([self.get_param(param, context) for param in  
> self.parameters])
>   
> class ImageNode(MixedNode):
>   def render(self, context):
>   return '' % self.get_string(context)
>   
> def do_img(parser, token):
>   arglist = token.split_contents()
>   if len(arglist) < 2:
>   raise TemplateSyntaxError, "%r tag requires at least one 
> argument"  
> % token.contents.split()[0]
>   return ImageNode(arglist[1:])
>   
> register.tag('img', do_img)
> 
> (you can then subclass MixedNode for pretty much everything...)
> 
> Regards,
> 
It looks like a good idea, thanks.

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Template tag and combining variables & text

2007-07-29 Thread Tomas Kopecek

Hello,
imagine tag, that has one parameter. Typical usage will look like this:

{% img img_url %} or {% img "http://x.y/z.gif"; %}

These two cases are simple to implement, the problem arises when 
parameter would be a combination of variable content and string - 
something like this:

{% img {{BASE_URL}}/path/z.gif %}

I know, it's syntactical nonsense. But does anybody know about some way 
how to combine variable content with string content? Is it possible?

For example, very crude way could be something like

{% img %} {{BASE_URL}}/path/z.gif {% endimg %}

-- 

        Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cross-refering models across files

2007-05-26 Thread Tomas Kopecek

Tomas Kopecek napsal(a):
> Tim Chase napsal(a):
> I> does anybody knows, how to implement cross-refering models across files?
>>   # in example_app/models_a.py
>>   class A(models.Model):
>> # no ref_to_b here
>> ...
>>
>>   # in example_app/models_b.py
>>   import a
>>   class B(models.Model):
>> ref_to_a = models.OneToOneField(a.A,
>>   related_name='ref_to_b')
>>
>>   # in example_app/models.py
>>   from models_a import *
>>   from models_b import *
>>
> Is this correct method for future django releases? Documentation says on 
> one-to-one: "The semantics of one-to-one relationships will be changing 
> soon, so we don't recommend you use them." Maybe this is more question 
> for django-devel...
> 
Moreover, it is not sufficient (general enough) solution. if ref_to_b 
and ref_to_a are two independent many-to-one relations, I can't use 
one-to-one semantics.

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Cross-refering models across files

2007-05-26 Thread Tomas Kopecek

Tim Chase napsal(a):
I> does anybody knows, how to implement cross-refering models across files?
>   # in example_app/models_a.py
>   class A(models.Model):
> # no ref_to_b here
> ...
> 
>   # in example_app/models_b.py
>   import a
>   class B(models.Model):
> ref_to_a = models.OneToOneField(a.A,
>   related_name='ref_to_b')
> 
>   # in example_app/models.py
>   from models_a import *
>   from models_b import *
> 
Is this correct method for future django releases? Documentation says on 
one-to-one: "The semantics of one-to-one relationships will be changing 
soon, so we don't recommend you use them." Maybe this is more question 
for django-devel...

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Cross-refering models across files

2007-05-26 Thread Tomas Kopecek

Hello,
does anybody knows, how to implement cross-refering models across files?

Simple example:
file 'models/a.py'
class A(models.Model):
 ref_to_b = models.ForeignKey('B')
 ...
 class Meta:
 app_label = 'example_app'

file 'models.b.py;
class B(models.Model):
 ref_to_a = models.ForeignKey('A')
 ...
 class Meta:
 app_label = 'example_app'

REason for doing this is that models.py is becoming a _huge_ one. But 
when i put these two files in models directory (with appropriate 
__init__.py) I get (logical) error from get_all_related_objects from 
djago.db.core.options which coredumps in point where it wants to load 
some data from (not yet defined) class B. Is there any general technique 
to workaround this behaviour, or it is completely problem of model design?

Thanks for some future response.

-- 

Tomas Kopecek
e-mail: permonik at mesias.brnonet.cz
 ICQ: 114483784

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---