after making one choice in the list, the model instance would know about this and would offer certain kind of chices2.

2011-11-28 Thread gintare

I would like to have interactive initialization in admin site.

I mean that after making one choice in the list, the model instance
would know about this and would offer certain kind of chices2.
I e, if i make choice1 books, i would get list of the books in the
choice2,
 if i make choice1 institutions, i would get list of the institutions
in the choice2.

How to implement such choices?

regards,
gintare statkute

-- 
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: django testing. random test order with some 'dependency constraints'

2011-11-28 Thread Gelonida N
Hi Russel,

Thanks for your answer.

On 11/28/2011 04:12 AM, Russell Keith-Magee wrote:
> On Mon, Nov 28, 2011 at 9:39 AM, Gelonida N  wrote:
> . . . 
> Unit tests are supposed to be isolated. They shouldn't depend on
> execution order, or have any pre-requisite other than those specified
> as part of the setUp()/teardown() methods. As a result, you won't find
> a whole lot of documentation on how to do what you're describing.
> 
> The right way to approach this is to identify the required
> preconditions for each test, and either construct those preconditions
> in the setUp() method, 
Yes. However setUp() is being called prior to every test,

So either I had to add caching into the setUp() section
or I had to use setUpClass() / tearDownClass()

I think that with a mix of SetUpClass() / setUp() and some 'caching'
logic I should be able to benefit from results of previous tests if I
wanted to.
Benefiting from previous tests is mainly for run time reductions, which
will allow to run more tests in a reasonable amount of time.



or use Django's test fixtures to install test
> data.
> 

> This is all covered in the documentation for Django's testing system;
> most notably in the section on fixtures.
> 
> [1] https://docs.djangoproject.com/en/1.3/topics/testing/#fixture-loading
> 
I try to avoid fixtures, as they don't allow to create smart data
(except I run a fixture generation tool prior to running the tests)

But perhaps I could create the fixture in the setUpClass() section if
not already existing. and just load them if they already existed.

I just had to find some logic, which would expire outdated fixtures (due
to migrations / etc)

> More broadly, you might want to dig into the documentation for
> Python's unittest module, which is what Django's unit test framework
> is built on.

Now I just have to look at how to best do the shuffling of tests in
order to have a random execution order.
Probably only shuffling only within TestCase classes and shuffling the
order of the TestCases would be what gives least penalty for run time,
but some unpredictable order.

So far I found only sortTestMethodsUsing(), which is not exactly
shuffling but might be one way to change the order.

I'll look also at
load_tests(), discover() / etc.

Though I'm still not sure about the *best* place to introduce shuffling
(without dependency checks)


The documentation mentions, that care has to be taken about test
fixtures *if* one does randomize the order. However no suggestion is
made *how* to best randomize the order if one desires to.


I will do some more searching / expereimenting.
The reasons why I asked this  question is to avoid, that I implement a
working, but rather inelegent / inefficient solution to a problem, which
has already been tackled by others in a more elegant way.




-- 
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.



Simple task dispatching (How heavy is celery + RabbitMQ)

2011-11-28 Thread Gelonida N
Hi,

I'd like to use a light weight dispatching system for a web server.

Basically some django post requests might require processing, which
should be done in the back ground due to its run times.

The results would be added to the django data base.

The browser could verify via AJAX requests whether the task is finished.


The server would be running on a rather weak virtual machine with rather
low memory (nginx / uwsgi / django )

( For testing  I run the server on windows with one of the following
setups (depending on what I'd like to test)
- django runserver
- twisted - django
- cygwin/nginx - fastcgi - django

Most people seem to recommend celery with RabbitMQ.
If I understood well, rabbit MQ requires Erlang to be installed and I
found some posts indicating that RabbitMQ requires quite some memory

So I wondered whether celery / RabbitMq wouldn't be a little on the
heavy side and eat away a little too much from my meory.


Is there any good light weight dispatching alternative to celery or
would this be one of these  'roll your own dispatcher' tasks?


-- 
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: Bulk import of data

2011-11-28 Thread Anler Hernandez Peral
Hi, this is probably not your case, but in case it is, here is my story:
Creating a script for import CSV files is the best solution as long as they
are few, but in my case, the problem was that I need to import nearly 40
VERY BIG CSV files, each one mapping a database table, and I needed to do
it quickly. I thought that the best way was to use MySQL's "load data in
local..." functionality since it works very fast and I could create only
one function to import all the files. The problem was that my CSV files
were pretty big and my database server were eating big amounts of memory
and crashing my site so I ended up slicing each file in smaller chunks.
Again, this is a very specific need, but in case you find yourself in such
situation, here's my base code from which you can extend ;)

https://gist.github.com/1dc28cd496d52ad67b29

--
anler


On Sun, Nov 27, 2011 at 7:56 PM, Andre Terra  wrote:

> This should be run asynchronously (i.e. celery) when importing large files.
>
> If you have a lot of categories/subcategories, you will need to bulk
> insert them instead of looping through the data and just using
> get_or_create. A single, long transaction will definitely bring great
> improvements to speed.
>
> One tool is DSE, which I've mentioned before.
>
> Good luck!
>
>
> Cheers,
> AT
>
>
> On Sat, Nov 26, 2011 at 8:44 PM, Petr Přikryl  wrote:
>
>>
>> >>> import csv
>> >>> data = csv.reader(open('/path/to/csv', 'r'), delimiter=';')
>> >>> for row in data:
>> >>> category = Category.objects.get_or_create(name=row[0])
>> >>> sub_category = SubCategory.objects.get_or_create(name=row[1],
>> >>> defaults={'parent_category': category})
>> >>> product = Product.objects.get_or_create(name=row[2],
>> >>> defaults={'sub_category': sub_category})
>>
>> There are few potential problems with the cvs as used here.
>>
>> Firstly, the file should be opened in binary mode.  In Unix-based
>> systems, the binary mode is technically similar to text mode.
>> However, you may once observe problems when you move
>> the code to another environment (Windows).
>>
>> Secondly, the opened file should always be closed -- especially
>> when building application (web) that may run for a long time.
>> You can do it like this:
>>
>> ...
>> f = open('/path/to/csv', 'rb')
>> data = csv.reader(f, delimiter=';')
>> for ...
>> ...
>> f.close()
>>
>> Or you can use the new Python construct "with".
>>
>> P.
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>

-- 
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: Simple task dispatching (How heavy is celery + RabbitMQ)

2011-11-28 Thread Tom Evans
On Mon, Nov 28, 2011 at 11:14 AM, Gelonida N  wrote:
> Hi,
>
> I'd like to use a light weight dispatching system for a web server.
>
> Basically some django post requests might require processing, which
> should be done in the back ground due to its run times.
>
> The results would be added to the django data base.
>
> The browser could verify via AJAX requests whether the task is finished.
>
>
> The server would be running on a rather weak virtual machine with rather
> low memory (nginx / uwsgi / django )
>
> ( For testing  I run the server on windows with one of the following
> setups (depending on what I'd like to test)
> - django runserver
> - twisted - django
> - cygwin/nginx - fastcgi - django
>
> Most people seem to recommend celery with RabbitMQ.
> If I understood well, rabbit MQ requires Erlang to be installed and I
> found some posts indicating that RabbitMQ requires quite some memory
>
> So I wondered whether celery / RabbitMq wouldn't be a little on the
> heavy side and eat away a little too much from my meory.
>
>
> Is there any good light weight dispatching alternative to celery or
> would this be one of these  'roll your own dispatcher' tasks?
>
>

On my personal, doesn't-really-do-much, 5k messages a day, home
server, rabbitmq uses a grand total of 19 MB RAM.

On one of our production servers handling millions of messages a day,
rabbitmq uses a total of 27 MB of RAM.

I guess it all depends on your definition of "too much". I doubt a
home-brew python process would be as slender.

Cheers

Tom

-- 
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: Simple task dispatching (How heavy is celery + RabbitMQ)

2011-11-28 Thread Markus Gattol
You don't need to roll your own... have a look at 
https://github.com/dmgctrl/django-ztask It's based on ZeroMQ and really 
lightweight compared to any alternative with a broker (yes, it's brokerless 
but that's a good thing I think for most use cases which don't really need 
a broker).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/xcmtk-oHe6wJ.
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: Simple task dispatching (How heavy is celery + RabbitMQ)

2011-11-28 Thread Carlos Daniel Ruvalcaba Valenzuela
Celery has a bunch of alternative brokers, depending on your
constrains you may not need something as "heavy" as RabbitMQ, you
could for example use db broker if you don't have many tasks, it is
slower but does not add a new server (apart from celery) to your
stack, other option is to use Redis as a broker, redis is light and
very fast, you can limit the amount of memory used by it too.

Check the celery page for alternative brokers. I have tested DB broker
and works ok, redis broker worked wonders in another setup where it
was also being used for caching.

Regards,
Carlos Daniel Ruvalcaba Valenzuela

-- 
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: Simple task dispatching (How heavy is celery + RabbitMQ)

2011-11-28 Thread Andre Terra
I'm also using redis for both brokering and caching. So far, so good. My
use case consists in one HUGE (5 hours) task, and several tiny (30s or
less) scheduled tasks.


Cheers,
AT

On Mon, Nov 28, 2011 at 10:54 AM, Carlos Daniel Ruvalcaba Valenzuela <
clsdan...@gmail.com> wrote:

> Celery has a bunch of alternative brokers, depending on your
> constrains you may not need something as "heavy" as RabbitMQ, you
> could for example use db broker if you don't have many tasks, it is
> slower but does not add a new server (apart from celery) to your
> stack, other option is to use Redis as a broker, redis is light and
> very fast, you can limit the amount of memory used by it too.
>
> Check the celery page for alternative brokers. I have tested DB broker
> and works ok, redis broker worked wonders in another setup where it
> was also being used for caching.
>
> Regards,
> Carlos Daniel Ruvalcaba Valenzuela
>
> --
> 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.
>
>

-- 
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: Security design questions

2011-11-28 Thread Javier Guerra Giraldez
On Mon, Nov 28, 2011 at 2:21 AM, Mike Dewhirst  wrote:
> 1. Do I have to create many-to-many relationships and before serving a page
> make sure the user making the request is "permitted" to see it?

that's how i've done this in the past.  it's not too much burden.

in my case, i had several image 'banks', and a user could have access
to one or more, so there was a many-to-many between the user and bank
models.   in addition, the user could be on a single bank at a time
(but could easily hop from one to the other), so i chose to store the
bank ID in the session.  to make it easier, i wrote a decorator
similar that added a 'bank' field to the request, something like this
(from failing memory):

request.bank = get_object_or_404 (Bank, user=request.user,
pk=request.session['bank_id'])

that way, if a user somehow modified his session to point to a bank he
doesn't have access to, he would get a 404.

then, in any view that included a picture id, instead of doing the usual:

@login_required
def showpicture (request, pict_id):
   picture = get_object_or_404 (Picture, pk=pict_id)
   ..

 i did like:

@login_required
@bank_required
def showpicture (request, pict_id):
  picture = get_object_or_404 (Picture, bank=request.bank, pk=pict_id)
  

with the same "404 if not allowed" result

-- 
Javier

-- 
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: Large Queryset Calculation In Background?

2011-11-28 Thread Nan

We're using MySQL 5 (don't know off the top of my head what specific
release).  I don't think a master/slave DB configuration is something
we can manage to set up at this point.

Querysets are fetched from the database in chunks, right?  I imagine
that the select itself is actually quite quick, but do the tables
remain locked between chunks?  I.e. if the query returns a total of N
records and Django fetches N/10 records and then performs a bunch of
calculations and saves before returning to the DB for another N/10
records, will the DB be locked during all those calculations/saves?



On Nov 24, 4:47 am, Tom Evans  wrote:
> On Wed, Nov 23, 2011 at 8:09 PM, Nikolas Stevenson-Molnar
>
>  wrote:
> > What database are you using? You should be able to find information in
> > the documents about the locking behavior for that database. Compare that
> > with the operations your running and determine whether they would result
> > in an exclusive lock.
>
> > From your pseudocode, it looks like you're performing a possibly-lengthy
> > select, followed by lengthy calculations (not involving database
> > operations), and then a (presumably) quick save. AFAIK, databases never
> > lock when doing selects, so depending on the nature of your
> > calculations, you should be fine.
>
> MySQL will always lock tables for writes when reading from them.
> Therefore, any long running query on a mysql table will result in
> updates to that table being locked out.
>
> The easiest way around this is with hardware. Use a master-slave DB
> setup, and perform your long reads on the slave(s), and all your
> writes on the master.
>
> Cheers
>
> Tom

-- 
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: Large Queryset Calculation In Background?

2011-11-28 Thread Tom Evans
On Mon, Nov 28, 2011 at 2:54 PM, Nan  wrote:
>
> We're using MySQL 5 (don't know off the top of my head what specific
> release).  I don't think a master/slave DB configuration is something
> we can manage to set up at this point.
>
> Querysets are fetched from the database in chunks, right?  I imagine
> that the select itself is actually quite quick, but do the tables
> remain locked between chunks?  I.e. if the query returns a total of N
> records and Django fetches N/10 records and then performs a bunch of
> calculations and saves before returning to the DB for another N/10
> records, will the DB be locked during all those calculations/saves?
>

Well, it depends upon the database, but no, it doesn't work like that.

With MySQL, the query will cause the server to lock the table until
the client has finished reading all of the result. There are then two
modes to read the result from the server, row-by-row or all-at-once.
Django currently always fetches the entire result all at once,
regardless of how you then fetch the data from the queryset.

Cheers

Tom

-- 
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: Large Queryset Calculation In Background?

2011-11-28 Thread Javier Guerra Giraldez
On Mon, Nov 28, 2011 at 10:10 AM, Tom Evans  wrote:
> Django currently always fetches the entire result all at once,
> regardless of how you then fetch the data from the queryset.

but this result isn't the whole queryset result, it's a chunk of it.
the ORM adds 'LIMIT' arguments to the query.  I think the answer to
Nan's question is that there's no lock across chunked reads.

-- 
Javier

-- 
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: Simple task dispatching (How heavy is celery + RabbitMQ)

2011-11-28 Thread Roberto De Ioris

Il giorno 28/nov/2011, alle ore 12:14, Gelonida N ha scritto:

> Hi,
> 
> I'd like to use a light weight dispatching system for a web server.
> 
> Basically some django post requests might require processing, which
> should be done in the back ground due to its run times.
> 
> The results would be added to the django data base.
> 
> The browser could verify via AJAX requests whether the task is finished.
> 
> 
> The server would be running on a rather weak virtual machine with rather
> low memory (nginx / uwsgi / django )
> 
> ( For testing  I run the server on windows with one of the following
> setups (depending on what I'd like to test)
> - django runserver
> - twisted - django
> - cygwin/nginx - fastcgi - django
> 
> 
> 

Celery is very good, but as you will run uWSGI in production you can look at

http://projects.unbit.it/uwsgi/wiki/Spooler

and its abstraction:

http://projects.unbit.it/uwsgi/wiki/Decorators#spool

(check https://github.com/jaysonsantos/django-uwsgi-mail for a real-world usage)

If you want to go lower-level, check for mules:

http://projects.unbit.it/uwsgi/wiki/Mules

Even django-zeromq (as already suggested by someone) is very good.

Another solution is using python thread queues:

http://projects.unbit.it/uwsgi/wiki/Example#threadqueue


--
Roberto De Ioris
http://unbit.it
JID: robe...@jabber.unbit.it

-- 
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: Large Queryset Calculation In Background?

2011-11-28 Thread Nan


On Nov 28, 10:17 am, Javier Guerra Giraldez 
wrote:
> On Mon, Nov 28, 2011 at 10:10 AM, Tom Evans  wrote:
> > Django currently always fetches the entire result all at once,
> > regardless of how you then fetch the data from the queryset.

Ah, I must have been misunderstanding a discussion[1] on Django-
Developers.

> but this result isn't the whole queryset result, it's a chunk of it.
> the ORM adds 'LIMIT' arguments to the query.  I think the answer to
> Nan's question is that there's no lock across chunked reads.
>
> --
> Javier

Thanks, Javier -- that's a huge help!

[1] 
http://groups.google.com/group/django-developers/browse_thread/thread/f19040e2e3229d7a#

-- 
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: Large Queryset Calculation In Background?

2011-11-28 Thread Tom Evans
On Mon, Nov 28, 2011 at 3:17 PM, Javier Guerra Giraldez
 wrote:
> On Mon, Nov 28, 2011 at 10:10 AM, Tom Evans  wrote:
>> Django currently always fetches the entire result all at once,
>> regardless of how you then fetch the data from the queryset.
>
> but this result isn't the whole queryset result, it's a chunk of it.
> the ORM adds 'LIMIT' arguments to the query.  I think the answer to
> Nan's question is that there's no lock across chunked reads.
>

(NB: you snipped the bit where I say that I am specifically talking
about MySQL - I still am)

No-one mentioned slicing or adding LIMITs into the query - but it is
irrelevant. When you issue a query, the DB tables that are read from
are locked until that data is returned to the client. That happens as
soon as mysql_store_result() in the MySQL C API finishes, at which
point all the data has been transferred from the server to the client.
This happens at the moment that you evaluate your query in django.

When you iterate through or otherwise access that query result in
django, it is no longer talking to the DB server, it does not fetch
any additional data, in chunks or otherwise. The queryset object cache
is built in chunks, but this relates to when Django creates model
instances, not communication with the database.

Cheers

Tom

-- 
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.



Django or python question about classes

2011-11-28 Thread youpsla
Hello,
in my code, I like to overrride the form_valid() method in both
CreateView and UpdateView generic class views.

I've put my code in views.py.

class MyCreateView(UpdateView):
.
def form_valid(self, form, **kwargs):
some code

class MyUpdateView(CreateView):
.
def form_valid(self, form, **kwargs):
some code

The both form_valid() methods are exactly the same (Only the
dispatch() method differ from both classes).

My question is : is there a way of doing this more in a DRY way ?

Thanks in advance.

Best regards

Alain

-- 
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: Django or python question about classes

2011-11-28 Thread Tom Evans
On Mon, Nov 28, 2011 at 4:07 PM, youpsla  wrote:
> Hello,
> in my code, I like to overrride the form_valid() method in both
> CreateView and UpdateView generic class views.
>
> I've put my code in views.py.
>
> class MyCreateView(UpdateView):
>    .
>    def form_valid(self, form, **kwargs):
>        some code
>
> class MyUpdateView(CreateView):
>    .
>    def form_valid(self, form, **kwargs):
>        some code
>
> The both form_valid() methods are exactly the same (Only the
> dispatch() method differ from both classes).
>
> My question is : is there a way of doing this more in a DRY way ?
>
> Thanks in advance.
>
> Best regards
>
> Alain
>

http://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are-they-useful

Cheers

Tom

-- 
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.



What server configuration should I use for a Django site like this?

2011-11-28 Thread Andre Lopes
I need to put in production a Django website, but I don't know what
machine I should use... this is not a commercial project, probably the
monetary return will be very very little in ads...

I have:
-Django
-PostgreSQL
-Solr

Do you think that will be enough a linode with 512mb ram?

- Visitors day expected at the end of the first year, 1000 day.
- Size of the database at the end of the first year, 20gb.

How well will do a linode with 512mb? Any clues?

Best Regards,

-- 
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.



better datepicker

2011-11-28 Thread marjenni
Hi,

class SearchForm(forms.Form):

date = forms.DateField(required=True,
input_formats=('%d/%m/%Y',))


I am trying to change this so that it displays a calendar when the
user starts to enter a date.
I have seen various examples using JQuery, but I can't find an example
that explains what I have to do quite clearly enough. Ideally I would
like to use a date range picker.

many thanks

Mark

-- 
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: django.conf.urls import question

2011-11-28 Thread Ian Clelland
On Fri, Nov 25, 2011 at 6:39 PM, Chet  wrote:

> Hello,
>
> I just finished to tutorial and for in both my urls.py files, if I
> use:
>
> from django.conf.urls import patterns, include, url
>
> I get an http500 error: TemplateDoesNotExist: 500.html
>

This message is from Django, trying to tell you that there is a
configuration error, but it can't display that error to you because it is
missing the template for the "500" server error page. (Do you have DEBUG
disabled in your settings? Set it to True, and Django should use its
built-in technical error page, which will show you all of the details of
the underlying error.)

The error itself is very likely an import error, because that line in your
urls.py shouldn't work. Specifically, 'patterns', 'include', and 'url'
aren't defined directly inside of the django.conf.urls module, but as part
of django.conf.urls.defaults. (at least, until Django 1.4)

>
> before I had it as:
>
> from django.conf.urls.defaults import patterns, include, url
>

This line is correct for all released versions of Django.

>
> and when I change this statement to be default, everything works fine.
> I don't know why. In the tutorial it says to do it the first way
>
>
What Django version are you using to run through the tutorial?

It sounds to me like you are have a released version of Django (1.2, 1.3,
etc) installed, but you are following the tutorial for the development
version. (There used to be a big warning about this at the top of all every
page in the development docs, but it seems to have disappeared.)

Try following the tutorial starting at
https://docs.djangoproject.com/en/1.3/intro/tutorial01/
instead, and see how far you can get.


-- 
Regards,
Ian Clelland


-- 
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.



Referring to same model records as a parent

2011-11-28 Thread Swaroop Shankar V
Hi,
I am trying to implement a menu system for my project which would enable
the admin to create menu's that will be displayed on the webpage. So i
should be able to create sub-menus which will have a parent menu. My table
structure will be as follows

id
name
url
parent_id

Here the parent_id will be the id of the menu of the same table. So on the
admin area i want a select box for the parent_id which will display the
already entered records. How can it be done?

Thanks and Regards,
Swaroop Shankar V

-- 
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.



Boolean test on queryset

2011-11-28 Thread Adam Nelson
When one tests for the boolean value of a queryset in the following way:

examples = Example.objects.all()

if examples:
. do something


You might think (I did) that Django will call a __nonzero__ special 
attribute that would either execute an EXISTS SQL STATEMENT or a SELECT 
statement with a LIMIT of 1.  Instead, the ORM evaluates the entire 
queryset through the __len__ attribute.

Is there a best practice for working around this?

Thanks,
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/G_V4jwWVh4MJ.
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: Boolean test on queryset

2011-11-28 Thread Jirka Vejrazka
Hi Adam,

  I tend to use:

  if examples.count():

...something...

  HTH

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-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: Security design questions

2011-11-28 Thread Mike Dewhirst

Javier

Thank you - that looks great. I'll start coding ...

Cheers

Mike

On 29/11/2011 1:24am, Javier Guerra Giraldez wrote:

On Mon, Nov 28, 2011 at 2:21 AM, Mike Dewhirst  wrote:

1. Do I have to create many-to-many relationships and before serving a page
make sure the user making the request is "permitted" to see it?


that's how i've done this in the past.  it's not too much burden.

in my case, i had several image 'banks', and a user could have access
to one or more, so there was a many-to-many between the user and bank
models.   in addition, the user could be on a single bank at a time
(but could easily hop from one to the other), so i chose to store the
bank ID in the session.  to make it easier, i wrote a decorator
similar that added a 'bank' field to the request, something like this
(from failing memory):

request.bank = get_object_or_404 (Bank, user=request.user,
pk=request.session['bank_id'])

that way, if a user somehow modified his session to point to a bank he
doesn't have access to, he would get a 404.

then, in any view that included a picture id, instead of doing the usual:

@login_required
def showpicture (request, pict_id):
picture = get_object_or_404 (Picture, pk=pict_id)
..

  i did like:

@login_required
@bank_required
def showpicture (request, pict_id):
   picture = get_object_or_404 (Picture, bank=request.bank, pk=pict_id)
   

with the same "404 if not allowed" result



--
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: Boolean test on queryset

2011-11-28 Thread Adam Nelson
Jirka,

That doesn't solve the problem.  That will still do a very expensive
count() operation on the queryset.  In fact, examples.count() is what
happens when you do bool(examples) anyway.

Thanks,
Adam

On Mon, Nov 28, 2011 at 8:11 PM, Jirka Vejrazka wrote:

> Hi Adam,
>
>  I tend to use:
>
>  if examples.count():
>
>...something...
>
>  HTH
>
>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-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.
>
>

-- 
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.



hasattr() and model attrname for foreign keys appending "_id"

2011-11-28 Thread Daniel Stekloff

Hi,

I'm new to django, so it's possible I'm doing something wrong.

I have a model defined that has the following field:

parent_host_uuid = models.ForeignKey(Mgmt_host_model,
to_field='uuid', blank=True, db_column="parent_host_uuid")

The database has created the column:

| parent_host_uuid |

I have a line in my code that checks first to see if the attribute
exists before I set it - doing hasattr(mobj, "parent_host_uuid")

This is failing but "parent_host_uuid_id" is there.

In the debugger:

(Pdb) print self.mobj.parent_host_uuid
*** DoesNotExist:
(Pdb) print self.mobj.parent_host_uuid_id
None

I'd rather not special case - looking specifically for individual
attributes that are foreign keys and have "_id" appended on the end so
I can set them.

What am I doing wrong? Or, is there way to get around this?

Thanks,

Dan

-- 
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: django tests. where to create users

2011-11-28 Thread Gelonida N
On 11/28/2011 01:58 AM, Gelonida N wrote:
> Hi,
> 
> I'd like to run some django tests, which use the test client and which
> should check, that certain users can only access certain contents.
> 
> Where would you create this users / passwords.
> - With a fixture
> - as part of a test class in the SetUp section and tear
>  it down afterwards?
> 
> - create a custom test runner with a setup phase ?
> 
> Is there any other recommended code section, which could do the setup
> prior to running tests.
> 
> Ideally I'd like to avoid fixtures.
> Of course I could create a script to generate certain fixtures and run
> only then the tests, but I'd prefer, the user data is created ad part of
> the test procedure.
> 
> 

I played a little more with django unit tests.

Django will reset the data base after each single test.

So it seems, I am stuck with fixtures at least at the moment I do not
know how to create users without fixtures such, that they would be
persistent between unit tests.

I really don't want to use fixtures, but some warm up code run only once
prior to running tests.

Any ideas?


-- 
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: Simple task dispatching (How heavy is celery + RabbitMQ)

2011-11-28 Thread Gelonida N
On 11/28/2011 12:14 PM, Gelonida N wrote:
> Hi,
> 
> I'd like to use a light weight dispatching system for a web server.
> 
> Basically some django post requests might require processing, which
> should be done in the back ground due to its run times.
> 
> The results would be added to the django data base.
> 
> The browser could verify via AJAX requests whether the task is finished.
> 
> 
> The server would be running on a rather weak virtual machine with rather
> low memory (nginx / uwsgi / django )
> 
> ( For testing  I run the server on windows with one of the following
> setups (depending on what I'd like to test)
> - django runserver
> - twisted - django
> - cygwin/nginx - fastcgi - django
> 
> Most people seem to recommend celery with RabbitMQ.
> If I understood well, rabbit MQ requires Erlang to be installed and I
> found some posts indicating that RabbitMQ requires quite some memory
> 
> So I wondered whether celery / RabbitMq wouldn't be a little on the
> heavy side and eat away a little too much from my meory.
> 
> 
> Is there any good light weight dispatching alternative to celery or
> would this be one of these  'roll your own dispatcher' tasks?
> 
> 
Thanks a lot for all your answers.


To summarize quickly
RabbitMQ doe snot seem to be as greedy as I expected (probably around
19MB for my expected load)

Django-ztask is a small brokerless solution

Celery supports multiple brokers with difference performance. the dd
broker would not require an additional process (apart from celery)


uwsgi has a spooler which might be what I'm looking for I just would
like to execute some tasks, which are too slow to be treated directly
within an HTTP request  sequentially one after the other.

However if I used uwsgi I had to look for an alternative implementation
and a small wrapper such, that the system would still be working on a
windows host without uwsgi. (performance on windows is not crucial, but
it should work)

Now I just need some time to test some of these options on  windows PC
and on my tiny virtual linux host.


-- 
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: django tests. where to create users

2011-11-28 Thread Mike Dewhirst

On 29/11/2011 12:12pm, Gelonida N wrote:

So it seems, I am stuck with fixtures at least at the moment I do not
know how to create users without fixtures such, that they would be
persistent between unit tests.



I agree - you are stuck. Perhaps a two tier approach might work. If you 
bite the bullet and completely re-load the test database for every unit 
test but use an in-memory sqlite it should run fairly quickly especially 
if you have a mega-swag of RAM. Then once a week, switch to PostgreSQL 
and leave them running while you go and have lunch.


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: Simple task dispatching (How heavy is celery + RabbitMQ)

2011-11-28 Thread Brian Schott
There are plenty of tutorials about memory management with RabbitMQ.  There are 
mechanisms for setting the high watermark for memory to throttle producers.   
You could look at the database backend for django-kombu.  It might have a 
smaller footprint.  django-ztask looks interesting, but you don't seem to get 
reliable message delivery, but maybe I misread the site.  

Brian Schott
bfsch...@gmail.com



On Nov 28, 2011, at 8:34 PM, Gelonida N wrote:

> On 11/28/2011 12:14 PM, Gelonida N wrote:
>> Hi,
>> 
>> I'd like to use a light weight dispatching system for a web server.
>> 
>> Basically some django post requests might require processing, which
>> should be done in the back ground due to its run times.
>> 
>> The results would be added to the django data base.
>> 
>> The browser could verify via AJAX requests whether the task is finished.
>> 
>> 
>> The server would be running on a rather weak virtual machine with rather
>> low memory (nginx / uwsgi / django )
>> 
>> ( For testing  I run the server on windows with one of the following
>> setups (depending on what I'd like to test)
>> - django runserver
>> - twisted - django
>> - cygwin/nginx - fastcgi - django
>> 
>> Most people seem to recommend celery with RabbitMQ.
>> If I understood well, rabbit MQ requires Erlang to be installed and I
>> found some posts indicating that RabbitMQ requires quite some memory
>> 
>> So I wondered whether celery / RabbitMq wouldn't be a little on the
>> heavy side and eat away a little too much from my meory.
>> 
>> 
>> Is there any good light weight dispatching alternative to celery or
>> would this be one of these  'roll your own dispatcher' tasks?
>> 
>> 
> Thanks a lot for all your answers.
> 
> 
> To summarize quickly
> RabbitMQ doe snot seem to be as greedy as I expected (probably around
> 19MB for my expected load)
> 
> Django-ztask is a small brokerless solution
> 
> Celery supports multiple brokers with difference performance. the dd
> broker would not require an additional process (apart from celery)
> 
> 
> uwsgi has a spooler which might be what I'm looking for I just would
> like to execute some tasks, which are too slow to be treated directly
> within an HTTP request  sequentially one after the other.
> 
> However if I used uwsgi I had to look for an alternative implementation
> and a small wrapper such, that the system would still be working on a
> windows host without uwsgi. (performance on windows is not crucial, but
> it should work)
> 
> Now I just need some time to test some of these options on  windows PC
> and on my tiny virtual linux host.
> 
> 
> -- 
> 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.
> 

-- 
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: better datepicker

2011-11-28 Thread Mario Gudelj
Hey,

I use http://docs.jquery.com/UI/Datepicker on the front end.

It's as simple as placing $("#datepicker").datepicker(); inside the page
where you want to convert the text fields to date picker fields. I'll you
have to do is change the ID inside $("#datepicker").datepicker(); to an ID
of your field. e.g. change $("#datepicker").datepicker(); to
$("#your_field_id").datepicker();

You can also use a class as a selector if you have multiple fields.

To change the format use $("#your_field_id").datepicker({ dateFormat:
'yy-mm-dd' }); or $("#your_field_id").datepicker({ dateFormat: 'dd-mm-yy'
}); in your case

I hope that helps!

On 29 November 2011 03:32, marjenni  wrote:

> Hi,
>
> class SearchForm(forms.Form):
>
>date = forms.DateField(required=True,
> input_formats=('%d/%m/%Y',))
>
>
> I am trying to change this so that it displays a calendar when the
> user starts to enter a date.
> I have seen various examples using JQuery, but I can't find an example
> that explains what I have to do quite clearly enough. Ideally I would
> like to use a date range picker.
>
> many thanks
>
> Mark
>
> --
> 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.
>
>

-- 
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: Boolean test on queryset

2011-11-28 Thread Ian Clelland
On Monday, November 28, 2011, Adam Nelson  wrote:
> Jirka,
> That doesn't solve the problem.  That will still do a very expensive
count() operation on the queryset.  In fact, examples.count() is what
happens when you do bool(examples) anyway.

I'm confused here -- examples.count() is definitely not the same as
examples.__len__(), which is what you originally claimed that bool() was
doing. examples.count() should issue a SELECT COUNT query, while len()
iterates through the rows in the result set.

If you just need to know whether at least one row exists in the result, use
examples.exists() -- that's what it's for.

https://docs.djangoproject.com/en/1.3/ref/models/querysets/#exists

>From the (linked) docs:

> Returns True if the QuerySet contains any results, and False if not. This
tries to perform the query in the simplest and fastest way possible, but it
does execute nearly the same query. This means that calling
QuerySet.exists() is faster than bool(some_query_set), but not by a large
degree.


> Thanks,
> Adam
>
> On Mon, Nov 28, 2011 at 8:11 PM, Jirka Vejrazka 
wrote:
>>
>> Hi Adam,
>>
>>  I tend to use:
>>
>>  if examples.count():
>>
>>...something...
>>
>>  HTH
>>
>>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-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.
>>
>
> --
> 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.
>

-- 
Regards,
Ian Clelland


-- 
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.



Customized authentication backend.

2011-11-28 Thread shaini sasidhar
Hi..

  Need to customize authentication backend in my Django
project.Also want to authenticate based on one of my MySQL table
data(table Customers).How can I modify that Customers class in
model.py file for declaring user robject.Please help me with some
example.

-- 
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.