Re: Random File Path

2011-08-19 Thread Shawn Milochik
The reason it's generating the same one every time is that the code as 
written executes when Django starts and that name is kept until you 
restart your Django process.


You can use a lambda to fix that in general

Example:

wrong:
#all records get the datetime the Django process was launched
created_date = models.DateTimeField(default = datetime.now())

right (ignoring the auto_now_add shortcut):
#datetime.now() will be executed each time an instance is created
#you can also forgo the lambda and the parentheses, and just 
use datetime.now,

#because it's callable
created_date = models.DateTimeField(default = lambda: 
datetime.now())


According to the Django docs you can do this with upload_to as well:
https://docs.djangoproject.com/en/1.3/ref/models/fields/#filefield
"This may also be a callable, such as a function, which will be 
called to obtain the upload path, including the filename"


Rather than using random, I recommend using the tempfile module in 
Python's standard library:

http://docs.python.org/library/tempfile

You can use mkdtemp to create a unique directory and mkstemp to create a 
filename if you want that to be unique as well. That will ensure your 
random path doesn't accidentally overwrite any other.
Don't be fooled by the 'temp' part; you're free to provide a starting 
path for all "temp" directories (including in your 'uploads' folder), 
and they're not deleted automatically, so you can keep them permanently 
or prune them as needed. If you don't care you can use gettempdir and 
it'll put the file in your OS's default temp folder (probably /tmp) and 
it'll be removed on reboot (or by you manually).






--
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 1.3 logging not working as I'd expect

2011-08-19 Thread Scott Danzig
I have Django 1.3 working with Python 2.7 and MySQL 5.5 on Mac OSX Lion...

I'm betting I'm missing something straight forward, but:

I have a simple Django app in development that uses a dictConfig setting 
simpler than the default in settings.py:

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d 
%(thread)d %(message)s'
},
},
'handlers': {
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'verbose'
},
'file':{
'level':'DEBUG',
'class':'logging.FileHandler',
'formatter': 'verbose',
'filename': 'testdjango.log',
},
},
'loggers': {
'testlogger': {
'handlers': ['console','file'],
'level': 'DEBUG',
'propagate': True,
   },
},
}


Then later in code that I know is run... (I tried in my app's views.py and 
also the backend).. I put something like this:

import logging
logger = logging.getLogger('testlogger')
logger.warn('hello')
logger.info('please appear')


And I just don't see it, neither in the console, nor the file.

I have also tried something like this:
import logging
logger = logging.getLogger('otherlogger')
hdlr = logging.FileHandler('newlogger.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr) 
logger.setLevel(logging.DEBUG)
logger.warn('In settings.py!')

And that doesn't work either, unless I put it right in settings.py.. in 
which case it appears 4 times, because, from what I understand, settings.py 
gets loaded that many times.  But then this doesn't work in the 
views.py/backend .. perhaps because the dictConfig gets loaded after 
settings.py is run?  I don't know.

I'm hoping for someone to give me a heads up about what I'm missing here. 
 Django's been pretty easy to deal with until I started to look into 
logging.

Thanks.

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



Random File Path

2011-08-19 Thread Ulisses Dias
Dear all,

I'm creating a server that will receive a file and will generate
an downloadable output. I would like to allow the user to come back
later to get the output and to access his own input, since it takes
some time to generate the output.

 So, my idea was to put the file in a folder whose name was
randomly generated, and to provide the folder name to the user, so, in
the future, he would be able to retrieve the files. However, I can't
generate the random folder name. My original idea was to make the
following model:

class upload_form(models.Model):
title  = models.CharField(max_length=50)
file   = models.FileField(upload_to="upload/%s" %
''.join(random.sample(string.ascii_lowercase + string.digits,16)))

However, django is generating the same random name all the time. Does
anybody has an idea of what to do?

-- 
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: Splitting models.py results in table rename?

2011-08-19 Thread Joshua Russo
Perfect! Thank you

-- 
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/-/NRyP256j0G4J.
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: Splitting models.py results in table rename?

2011-08-19 Thread Ramiro Morales
On Fri, Aug 19, 2011 at 11:42 PM, Joshua Russo  wrote:
> My models.py was getting too large so I tried to split it into
> /models
>   __init__.py
>   someLogicalGroupOfModels.py
>   andSoOn.py
> in the __init__.py I have
> from appName.models.someLogicalGroupOfModels import *
> from appName.models.andSoOn import *
> All of my imports still work but the queries are now looking for
> models_someTableName instead of appName_someTableName.
> I know I've done this before. Is there something I'm doing wrong?

Not wrong, you only need a small additional detail:

https://docs.djangoproject.com/en/1.3/ref/models/options/#app-label

-- 
Ramiro Morales

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



Splitting models.py results in table rename?

2011-08-19 Thread Joshua Russo
My models.py was getting too large so I tried to split it into

/models
  __init__.py
  someLogicalGroupOfModels.py
  andSoOn.py

in the __init__.py I have

from appName.models.someLogicalGroupOfModels import *
from appName.models.andSoOn import *

All of my imports still work but the queries are now looking for 
models_someTableName instead of appName_someTableName. 

I know I've done this before. Is there something I'm doing wrong?

-- 
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/-/wt_ebzcUYSYJ.
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: "app_index.html" = i want to be in admin...

2011-08-19 Thread Nan

> where should i change

https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance

> and where to put this file..?

https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types

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



Specific models without a database table

2011-08-19 Thread Kristofer Pettijohn
Hello, 


Is it possible to create specific models without a database table? 

Basically what I would like to do is create an email account management 
application that ties into my existing mail server and its API. I would like 
Django to have a Users model and keep track of users, a Domains model to keep 
track of the email domains for the user, but I don't want it to actually keep 
track of email addresses. Once the user is in the application, they will go 
into the "EmailAccount" model and I simply want the model to query my mail 
server via its SOAP API. So when they create/delete/edit email accounts, there 
will be form pages and simple validation done by Django, but the actual work 
will be done by connecting to the mail servers API and not a database. 


Is this possible? 


Thanks, 
Kris 

-- 
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: Possible interest in a webcast/presentation about Django site with 40mil+ rows of data??

2011-08-19 Thread Cal Leeming [Simplicity Media Ltd]
Hi all,

Okay, good news and bad news.

The bad news, is that the site/project which sparked this webcast to be
made, has had some legal complications and is being shut down - less than 1
month after being released :L

The good news, is that the webcast will still be going ahead.

For those of you that want to see the site it was related to, it's
http://www.iliketochan.com .

The site itself was a complete 4chan archive, dating back to 2010, peaking
at 50 million posts and 17 million images.

Particularly sad about this because so much time and effort went into the
site, but at the same time, it has been a great learning experience (both in
code and business). So being able to share that on the webcast will be of
some small comfort :)

Cal

On Thu, Aug 11, 2011 at 6:31 PM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> Last call on this guys:
>
>
> https://spreadsheets.google.com/a/foxwhisper.co.uk/spreadsheet/viewform?hl=en_US=dENPX3BMUUFMbi1CbElwV3BvOEdkNmc6MQ#gid=0
>
> If you want to register your attendance, please do so now.
>
> Thanks
>
> On Mon, Jul 25, 2011 at 2:00 PM, nicolas HERSOG wrote:
>
>> I won t be able to follow the live session but I can't wait to watch your
>> record on YT.
>>
>> Thx!
>>
>> On Mon, Jul 25, 2011 at 2:42 PM, Cal Leeming [Simplicity Media Ltd] <
>> cal.leem...@simplicitymedialtd.co.uk> wrote:
>>
>>> Second call for register your attendance on this webcast, if you haven't
>>> already done so.
>>>
>>> Thanks
>>>
>>> Cal
>>>
>>>
>>> On Tue, Jul 12, 2011 at 2:48 PM, Cal Leeming [Simplicity Media Ltd] <
>>> cal.leem...@simplicitymedialtd.co.uk> wrote:
>>>
 Hi all,

 Great response to this, 45 registered votes in total.

 The webcast will take place on Monday 29th August 2011 - (Minimum
 resolution 1920x1080)

 However, because the time zone results are almost split 50/50, I'm going
 to allow users to select from two time slots, if the results are still 
 split
 50/50, then I'll do both an afternoon and evening session.

 Please use this form to register your place.

 https://spreadsheets.google.com/a/foxwhisper.co.uk/spreadsheet/viewform?formkey=dENPX3BMUUFMbi1CbElwV3BvOEdkNmc6MQ

 Cal

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



"app_index.html" = i want to be in admin...

2011-08-19 Thread doniyor
hi there,

i have a litle problem in bringing my app to admin. the thing is, i
dont use models, so the talk about 'setting.py' would be wasty. what i
dont understand is how to override the app_index.html and where to put
it sothat my app can be seen in admin page..

i give the code of app_index.html

{% extends "admin/index.html" %}
{% load i18n %}
{% if not is_popup %}

{% block breadcrumbs %}

{% trans "HOME" %}
{% for app in app_list %}
{% blocktrans with app.name as name %} {{ name }} {% endblocktrans %}
{% endfor %}{% endblock %}

{% endif %}
{% block sidebar %}{% endblock %}

where should i change and where to put this file..?

best thanks,

doni

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



how to invalidate per-view cache?

2011-08-19 Thread galgal
I want to use per-view 
cache. 
I know how it's working, but where's the problem? How can I invalidate that 
cache? I must do it each time database records are changed. There is no info 
about how to do that:/

-- 
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/-/Xh1TgeV5M7AJ.
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 Test Corrupted Test Data

2011-08-19 Thread patjenk
As I understand it, the database should be reset between each test. To
me this means that unless the variable being examined is an attribute
of self, the tests shouldn't affect each other.

Could it be possible that there is a sqllite subtly that delays the
reset of the table count and it affects the outcome of the test in
this instance?

On Aug 19, 3:43 pm, bik...@gmail.com wrote:
> Could it be that the tests affect each other (when ran in a series)?
>
> Sent from my BlackBerry® from Vodafone
>
> -Original Message-
> From: dm03514 
>
> Sender: django-users@googlegroups.com
> Date: Fri, 19 Aug 2011 12:13:24
> To: Django users
> Reply-To: django-users@googlegroups.com
> Subject: Django Test Corrupted Test Data
>
> I have a test class that subclasses django.test.TestCase which has
> about 5 different tests in it. When I run my full test suite (using
> nose, and specifying sqlite as backend) there are a series of
> failures. When I go to debug the tests, running them individually,
> they pass fine.
>
> http://stackoverflow.com/questions/7126172/django-testrunner-incorrec...
>
> --
> 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 
> athttp://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: Dynamic Forms with Varying init Arguments

2011-08-19 Thread SixDegrees

OK, thanks. I was on the verge of rolling my own solution anyway.

Form models won't work for me; although the ID I want to pass is a primary
key to a table, I need to rummage around in the database and track down
several bits and pieces; there's not a simple correspondence to one
particular model in this case, sadly. At least I don't think so; I may give
it another look.


Wayne Smith-4 wrote:
> 
> On Aug 19, 1:58 pm, SixDegrees  wrote:
>> I'm no longer at the computer where my code resides. But "you are wanting
>> to
>> call formset_factory
>> and have it pass along a parameter to the Form that the formset
>> contains" is pretty much what I want to know how to do.
> 
> Well, the short answer is that you can't do that--formset_factory()
> does not accept kwargs.
> 
> Your other option is to basically write your own formset_factory().
> If you look at the source, you will see that it really doesn't do
> anything special--it's more of a convenience method that creates a
> basic FormSet.  You could also write your own Formset, with its own
> custom __init__ method, inherit from BaseFormSet, and pass that to the
> formset_factory() method.  Yeah, that's probably what I would do.
> 
> A good rule of thumb that I have found is that if you are trying to do
> something with Django, and it is either not possible or requires a
> good bit of hackery, then you are probably (although not always)
> "doing it wrong".  Most of Django is very flexible, but sometimes you
> just need to know where to look for the answer.  That's why I was
> inquiring about exactly what your code is doing and such--your use of
> a primary key makes me think (but doesn't guarantee) that you are
> using a form to represent an instance of a model, and if so, you want
> to be looking there.
> 
> Wayne
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Dynamic-Forms-with-Varying-init-Arguments-tp32296362p32298409.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-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 Not Populating AutoField

2011-08-19 Thread Landy Chapman


On Aug 19, 2:05 pm, Lee  wrote:
> Landy - thanks for that idea. Am I correct in understanding that
> setting a field to AutoField has no effect on save_model, and simply
> causes dbsync to add the sequence/nextval to the Postgres table?

I am not sure; On a droid phone so I can't look at the source code or
run tests.

> If so
> that is my problem, because I want to have one database schema that
> works across different DBMSes, and the sequence/nextval syntax is
> Postgres-specific so I have not been using dbsync.

Django abstracts this away.. If django is creating your tables, you
can trust it will do The Right Thing(tm)  for whatever DBMS you are
using.  If you're not the trusting type you can run this command to
find out what django would do to create your tables:
   django-admin.py sqlall

Then you can change the database_backend  in settings.py to find out
what the differences would be.

> I was hoping AutoField caused the *application* to manage the auto-
> incrementing primary key, not the database -- is there an easy way to
> do this in Django/Admin?
That is almost never a good idea (*maybe* there is an edge case I've
never seen).  It isn't easy to prevent collisions (two records with
same id). Imagine two users adding new records at the same time. Why
do that when the problem is already solved by your DBMS?

> Thanks very much for the help.
You're quite welcome!

-- 
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: Nested: transaction.commit_on_success and django 1.3

2011-08-19 Thread aledema


On 28 Lug, 11:57, Gelonida N  wrote:

> I'm asking as this snippet is already 3 years old.

you could try my snippet:

http://djangosnippets.org/snippets/2515/

-- 
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 Test Corrupted Test Data

2011-08-19 Thread bikkit
Could it be that the tests affect each other (when ran in a series)?

Sent from my BlackBerry® from Vodafone

-Original Message-
From: dm03514 
Sender: django-users@googlegroups.com
Date: Fri, 19 Aug 2011 12:13:24 
To: Django users
Reply-To: django-users@googlegroups.com
Subject: Django Test Corrupted Test Data

I have a test class that subclasses django.test.TestCase which has
about 5 different tests in it. When I run my full test suite (using
nose, and specifying sqlite as backend) there are a series of
failures. When I go to debug the tests, running them individually,
they pass fine.

http://stackoverflow.com/questions/7126172/django-testrunner-incorrect-query-counts-corrupted-data-general-mayhem

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



Django Test Corrupted Test Data

2011-08-19 Thread dm03514
I have a test class that subclasses django.test.TestCase which has
about 5 different tests in it. When I run my full test suite (using
nose, and specifying sqlite as backend) there are a series of
failures. When I go to debug the tests, running them individually,
they pass fine.

http://stackoverflow.com/questions/7126172/django-testrunner-incorrect-query-counts-corrupted-data-general-mayhem

-- 
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: Dynamic Forms with Varying init Arguments

2011-08-19 Thread wayne
On Aug 19, 1:58 pm, SixDegrees  wrote:
> I'm no longer at the computer where my code resides. But "you are wanting to
> call formset_factory
> and have it pass along a parameter to the Form that the formset
> contains" is pretty much what I want to know how to do.

Well, the short answer is that you can't do that--formset_factory()
does not accept kwargs.

Your other option is to basically write your own formset_factory().
If you look at the source, you will see that it really doesn't do
anything special--it's more of a convenience method that creates a
basic FormSet.  You could also write your own Formset, with its own
custom __init__ method, inherit from BaseFormSet, and pass that to the
formset_factory() method.  Yeah, that's probably what I would do.

A good rule of thumb that I have found is that if you are trying to do
something with Django, and it is either not possible or requires a
good bit of hackery, then you are probably (although not always)
"doing it wrong".  Most of Django is very flexible, but sometimes you
just need to know where to look for the answer.  That's why I was
inquiring about exactly what your code is doing and such--your use of
a primary key makes me think (but doesn't guarantee) that you are
using a form to represent an instance of a model, and if so, you want
to be looking there.

Wayne

-- 
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: Dynamic Forms with Varying init Arguments

2011-08-19 Thread SixDegrees

I'm no longer at the computer where my code resides. But "you are wanting to
call formset_factory
and have it pass along a parameter to the Form that the formset
contains" is pretty much what I want to know how to do.


Wayne Smith-4 wrote:
> 
> On Aug 19, 12:41 pm, SixDegrees  wrote:
>> The parameter in question is a primary key that is used to generate a
>> series
>> of fields within the form. It is passed to the form __init__ routine, and
>> can vary from one form to another. So, given a formset, I want to tell
>> the
>> formset "This is the parameter you should use when creating the next form
>> you create."
> 
> I think it might help if you could post a code snippet showing how you
> are creating the formset (not the __init__, but where you call the
> formset creation method) and the formset creation method itself (or
> just its name if you are using formset_factory or something else from
> Django).
> 
> If I understand you correctly, you are wanting to call formset_factory
> and have it pass along a parameter to the Form that the formset
> contains.  However, you talk about the parameter being a primary key,
> which would indicate to me that you are dealing with existing objects
> from models, in which case we should be talking about a ModelFormset.
> 
> Wayne
> 
> -- 
> 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.
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Dynamic-Forms-with-Varying-init-Arguments-tp32296362p32297690.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-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: Strange behavior in model.save()

2011-08-19 Thread David Jacquet
Yes,

it is the same thing.  What I wonder is if there is a standard or better way
of getting the same functionality as my full_save method?

Regards
David



2011/8/19 Yaşar Arabacı 

> I don't quite understand what you did there, but, it seems to me it is the
> same thing with your initial post.
>
> ref = getattr(self, f.name) -> you are getting a field here, this field is
> a empty descriptor, doesn't hold any data yet.
> ref.full_save(*args,*kwargs) -> you populated your field with data here by
> calling full_save on it
> setattr(self,f.name,ref) -> you are assigning this field to be a part of
> parent object, where you got it initially
>
> then you are saving the parent object.
>
>
>
>
>
> 2011/8/19 David Jacquet 
>
>>
>> Thanks Yaşar and Jani for your fast replies!
>>
>>
>> I understand that normally one would assign in the reverse order. However
>> I do not understand exactly what happens when I do
>> meeting.place = meeting.place
>> never in my programming experience have I seen an example when
>> x=x
>> really does something. Isn't this strange?
>>
>>
>> Anyway, the reason for me wanting to go around normal behavior is that I
>> have a quite complicated and nested datamodel. Then I offer an api where
>> people can post JSON object. The will posts will be heavily nested ojbects
>> and I do not want save it to db by rewriting the whole save-chain in my
>> code. I have solved this by creating the class AREM below. When I have a
>> dictionary d representing a class A (subclass to AREM) and I want it saved I
>> do:
>>
>> a = A().from_dict(d)
>> a.full_save()
>>
>> I have gotten it to work, but not before I added the (for me very strange)
>> row
>>
>> setattr(self, f.name, ref) #Without this everything collapses
>>
>> residing on the second most bottom row in the code below. The problem is
>> that I do not know what it does, nor if there is a more elegant, faster or
>> better way to do it.
>>
>> Best Regards
>> David
>>
>>
>>
>> #class AbstractRecursiveEnabledModel(models.Model):
>> class AREM(AMCS):
>> class Meta:
>> abstract = True
>>
>> def from_dict(self, d):
>> if not isinstance(d, dict):
>> return d
>> fl = self._meta.fields
>> for f in fl:
>> if d.has_key(f.name) and f.rel and d[f.name] is not None:
>> d[f.name] = f.rel.to().from_dict(d[f.name])
>> self.__init__(**d)
>> return self
>>
>> def full_save(self,*args, **kwargs):fl = self._meta.fields
>>
>> for f in fl:
>> if f.rel:
>> ref = getattr(self, f.name)
>> if ref is not None and ref.pk is None and ref is not
>> self:
>> ref.full_save(*args, **kwargs)
>> setattr(self, f.name, ref) #Without this everything
>> collapses
>> super(AREM, self).save(*args, **kwargs)
>>
>>
>>
>>
>>
>>
>>
>> On Fri, Aug 19, 2011 at 2:34 PM, Jani Tiainen  wrote:
>>
>>> On 08/19/2011 03:15 PM, Jacco wrote:
>>>
 I am having great difficulties in saving nested models in an easy
 way.


 #Two (almost) identical functions:
 def test1():
 place = Place(where='Paris')

>>>
>>> place is not saved, thus it does not have a primary key (id)
>>>
>>>
>>>  meeting = Meeting(place=place, when='2011-01-01')

>>>
>>> You assign non saved instance to a meeting. Probably what happened
>>> internally is that place.pk is copied to meeting.place_id.
>>>
>>>  place.save()

>>>
>>> You saved place. Changes in model are not reflected to referred model.
>>>
>>>  meeting.save()

>>>
>>> You save meeting with still (partially) stale place pk. thus resulting an
>>> exception.
>>>
>>>
>>>  def test2():
 place = Place(where='Paris')
 meeting = Meeting(place=place, when='2011-01-01')

 place.save()
 meeting.place = meeting.place  #BY setting meeting.place to
 itself, it works 

>>>
>>> You updated your meeting internal structure.
>>>
>>>  meeting.save()
 return meeting

 --



 - Running test1() results in crash "null value in column "place_id"
 violates not-null constraint"
 - Running test2() results in OK.
 - Only difference is the dummy line "meting.place = meeting.place".

 Could someone who really understands this explain what is going on?


>>> What's going on that you have done it incorrect order.
>>>
>>> place = Place(where='Paris')
>>> place.save() # Place saved, PK assigned.
>>>
>>>
>>> meeting = Meeting(place=place, when='2011-01-01')
>>> meeting.save() # Meeting saved with correct place.
>>>
>>> --
>>>
>>> Jani Tiainen
>>>
>>> --
>>> You received this message because you are subscribed to the Google 

Re: Best approach to handling different types of Users

2011-08-19 Thread DrBloodmoney
On Fri, Aug 19, 2011 at 9:27 AM, Andre Terra  wrote:
> Alright, do what you will. Whatever floats your boat..
>
> On Fri, Aug 19, 2011 at 5:12 AM, Matt Schinckel  wrote:
>>
>> On Friday, August 19, 2011 12:07:44 PM UTC+9:30, Andre Terra (airstrike)
>> wrote:
>>>
>>> Until you install some third party app that accesses
>>> User.objects.all() and then suddenly nothing works as it's supposed
>>> to.
>>
>> Why wouldn't it? The User subclasses will still appear in the
>> User.objects.all() queryset.
>>>
>>> You can access the User object from its related UserProfile instance
>>> and do everything you say from there instead of breaking the
>>> convention. Nobody's stopping you from writing an abstract
>>> BaseUserProfile model with an FK to User and custom UserProfile
>>> subclasses. I just don't see any advantages in going down that path.
>>
>>  As I said, 'at this stage', it all seems to be working out okay. I have
>> plenty of 3rd party apps, and even some of my own, that access User, and
>> they still work with sub-classes.
>>>
>>> Because how will you access every user if you ever need to? What if
>>> someone gets promoted? How will you separate view from model logic?
>>> Are you going to rewrite forms for every user class? That's probably
>>> going to be hard to maintain.
>>
>>  You can still access User.objects.all(). I even have a way to access the
>> sub-classes (downcasting) when fetching all users.
>>>
>>> FWIW, profiles are the canonical solution. They are also the only
>>> elegant solution, at least until the app loading branch lands on
>>> trunk, which should then allow you to register a different class as
>>> User. But that won't happen any time soon..
>>
>> See, I don't see them as an elegant solution. Having to do:
>>     user.get_profile().date_of_birth
>> instead of:
>>     user.date_of_birth
>> irks me every time I write the code. UserProfile has always felt to me
>> that it was a patchy way of extending User.
>> Matt.
>>

Not being able to define your own User model is easily my least
favorite thing about django. User.get_profile() is an antipattern.

I hope we get the ability to define our own User model makes it into
contrib.auth at some point (lazy loaded)

-- 
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: Strange behavior in model.save()

2011-08-19 Thread Yaşar Arabacı
I don't quite understand what you did there, but, it seems to me it is the
same thing with your initial post.

ref = getattr(self, f.name) -> you are getting a field here, this field is a
empty descriptor, doesn't hold any data yet.
ref.full_save(*args,*kwargs) -> you populated your field with data here by
calling full_save on it
setattr(self,f.name,ref) -> you are assigning this field to be a part of
parent object, where you got it initially

then you are saving the parent object.





2011/8/19 David Jacquet 

>
> Thanks Yaşar and Jani for your fast replies!
>
>
> I understand that normally one would assign in the reverse order. However I
> do not understand exactly what happens when I do
> meeting.place = meeting.place
> never in my programming experience have I seen an example when
> x=x
> really does something. Isn't this strange?
>
>
> Anyway, the reason for me wanting to go around normal behavior is that I
> have a quite complicated and nested datamodel. Then I offer an api where
> people can post JSON object. The will posts will be heavily nested ojbects
> and I do not want save it to db by rewriting the whole save-chain in my
> code. I have solved this by creating the class AREM below. When I have a
> dictionary d representing a class A (subclass to AREM) and I want it saved I
> do:
>
> a = A().from_dict(d)
> a.full_save()
>
> I have gotten it to work, but not before I added the (for me very strange)
> row
>
> setattr(self, f.name, ref) #Without this everything collapses
>
> residing on the second most bottom row in the code below. The problem is
> that I do not know what it does, nor if there is a more elegant, faster or
> better way to do it.
>
> Best Regards
> David
>
>
>
> #class AbstractRecursiveEnabledModel(models.Model):
> class AREM(AMCS):
> class Meta:
> abstract = True
>
> def from_dict(self, d):
> if not isinstance(d, dict):
> return d
> fl = self._meta.fields
> for f in fl:
> if d.has_key(f.name) and f.rel and d[f.name] is not None:
> d[f.name] = f.rel.to().from_dict(d[f.name])
> self.__init__(**d)
> return self
>
> def full_save(self,*args, **kwargs):fl = self._meta.fields
>
> for f in fl:
> if f.rel:
> ref = getattr(self, f.name)
> if ref is not None and ref.pk is None and ref is not self:
> ref.full_save(*args, **kwargs)
> setattr(self, f.name, ref) #Without this everything
> collapses
> super(AREM, self).save(*args, **kwargs)
>
>
>
>
>
>
>
> On Fri, Aug 19, 2011 at 2:34 PM, Jani Tiainen  wrote:
>
>> On 08/19/2011 03:15 PM, Jacco wrote:
>>
>>> I am having great difficulties in saving nested models in an easy
>>> way.
>>>
>>>
>>> #Two (almost) identical functions:
>>> def test1():
>>> place = Place(where='Paris')
>>>
>>
>> place is not saved, thus it does not have a primary key (id)
>>
>>
>>  meeting = Meeting(place=place, when='2011-01-01')
>>>
>>
>> You assign non saved instance to a meeting. Probably what happened
>> internally is that place.pk is copied to meeting.place_id.
>>
>>  place.save()
>>>
>>
>> You saved place. Changes in model are not reflected to referred model.
>>
>>  meeting.save()
>>>
>>
>> You save meeting with still (partially) stale place pk. thus resulting an
>> exception.
>>
>>
>>  def test2():
>>> place = Place(where='Paris')
>>> meeting = Meeting(place=place, when='2011-01-01')
>>>
>>> place.save()
>>> meeting.place = meeting.place  #BY setting meeting.place to
>>> itself, it works 
>>>
>>
>> You updated your meeting internal structure.
>>
>>  meeting.save()
>>> return meeting
>>>
>>> --
>>>
>>>
>>>
>>> - Running test1() results in crash "null value in column "place_id"
>>> violates not-null constraint"
>>> - Running test2() results in OK.
>>> - Only difference is the dummy line "meting.place = meeting.place".
>>>
>>> Could someone who really understands this explain what is going on?
>>>
>>>
>> What's going on that you have done it incorrect order.
>>
>> place = Place(where='Paris')
>> place.save() # Place saved, PK assigned.
>>
>>
>> meeting = Meeting(place=place, when='2011-01-01')
>> meeting.save() # Meeting saved with correct place.
>>
>> --
>>
>> 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-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
> 

Re: Initialization code that should only run under a web server

2011-08-19 Thread bruno desthuilliers
On 19 août, 16:15, Boaz Leskes  wrote:
> Hi,
>
> I have some computationally intensive initialization logic that
> should run when a new process is started up by the web server. Following
> advice on the web, I've imported the module with the initialization
> code from settings.py, which works perfectly as advertised. However,
> it has one side effect which is very cumbersome - the code runs with
> every manage command as well. Every syncdb (and migration as we use
> South) takes forever. This is a problem during deployment.

You may want to check sys.argv[0] (wild guess, but AFAICT this should
do the trick...)

-- 
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 Not Populating AutoField

2011-08-19 Thread Lee
Landy - thanks for that idea. Am I correct in understanding that
setting a field to AutoField has no effect on save_model, and simply
causes dbsync to add the sequence/nextval to the Postgres table? If so
that is my problem, because I want to have one database schema that
works across different DBMSes, and the sequence/nextval syntax is
Postgres-specific so I have not been using dbsync.

I was hoping AutoField caused the *application* to manage the auto-
incrementing primary key, not the database -- is there an easy way to
do this in Django/Admin?

Thanks very much for the help.

Lee

-- 
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: Dynamic Forms with Varying init Arguments

2011-08-19 Thread wayne
On Aug 19, 12:41 pm, SixDegrees  wrote:
> The parameter in question is a primary key that is used to generate a series
> of fields within the form. It is passed to the form __init__ routine, and
> can vary from one form to another. So, given a formset, I want to tell the
> formset "This is the parameter you should use when creating the next form
> you create."

I think it might help if you could post a code snippet showing how you
are creating the formset (not the __init__, but where you call the
formset creation method) and the formset creation method itself (or
just its name if you are using formset_factory or something else from
Django).

If I understand you correctly, you are wanting to call formset_factory
and have it pass along a parameter to the Form that the formset
contains.  However, you talk about the parameter being a primary key,
which would indicate to me that you are dealing with existing objects
from models, in which case we should be talking about a ModelFormset.

Wayne

-- 
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: Djangonaut is looking for a job

2011-08-19 Thread Andre Terra
http://djangogigs.com/
https://www.djangoproject.com/rss/community/jobs/

2011/8/19 Eugeny Belykh 

> hi))
> i think yes,we should keep  trying
>
>
> 2011/8/17 枯藤天涯 
>
>> hello,I am from China。And I am looking a job about python/django .Just
>> same as you .Remote (telecommuting) only.Can we find the job like
>> this?
>>
>> 2011/8/5 Eugeny Belykh :
>> > Hi everybody.I am Django newbee based in Russia. I am looking for a
>> > Django related job.Remote (telecommuting) only. 1 django-powered site
>> > in portfolio.Are there any vacancies?
>> >
>> > --
>> > 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.
>

-- 
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 Not Populating AutoField

2011-08-19 Thread Landy Chapman
Did you create the table using django?
Can you post the table definition in postgresql?

If you still have an empty database, you could try dropping the id
column and  do a django  dbsync

otherwise you may have to create a sequence and apply it to the id
field. Something along the lines of:

create sequence id_seq start 1 increment 1;
alter table xxx alter column id set default nextval('id_seq');

-- 
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: Dynamic Forms with Varying init Arguments

2011-08-19 Thread SixDegrees

The parameter in question is a primary key that is used to generate a series
of fields within the form. It is passed to the form __init__ routine, and
can vary from one form to another. So, given a formset, I want to tell the
formset "This is the parameter you should use when creating the next form
you create."


SixDegrees wrote:
> 
> I'm using formsets to implement a dynamic form as described 
> http://www.mancoosi.org/~abate/dynamic-forms-with-django here . However,
> the forms created by the formset want a parameter passed that determines
> the contents of the form during initialization. This parameter can be
> passed back through another form on the same page using Javascript, but I
> can't figure out how to tell the formset to create the next form using
> this parameter. How is this done?
> 
> As an alternative, I can create a new form manually. But there doesn't
> seem to be a way to add it to the formset.
> 
> I would much prefer to stay away from JavaScript and other client-side
> approaches, other than passing the single parameter used for
> initialization.
> 

-- 
View this message in context: 
http://old.nabble.com/Dynamic-Forms-with-Varying-init-Arguments-tp32296362p32297251.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-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: Djangonaut is looking for a job

2011-08-19 Thread Eugeny Belykh
hi))
i think yes,we should keep  trying


2011/8/17 枯藤天涯 

> hello,I am from China。And I am looking a job about python/django .Just
> same as you .Remote (telecommuting) only.Can we find the job like
> this?
>
> 2011/8/5 Eugeny Belykh :
> > Hi everybody.I am Django newbee based in Russia. I am looking for a
> > Django related job.Remote (telecommuting) only. 1 django-powered site
> > in portfolio.Are there any vacancies?
> >
> > --
> > 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: Django Not Populating AutoField

2011-08-19 Thread Lee
<>

Did so -- no effect. I even disabled my overridden save_model so I'm
back to out-of-the-box Admin setup -- no effect. This is with Postgres
and the psycopg2 driver. Is no one else seeing this problem?

On Aug 18, 5:32 pm, Shawn Milochik  wrote:
> As defined your id field doesn't differ from Django's default. Just get
> rid of your custom id field.

-- 
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: Dynamic Forms with Varying init Arguments

2011-08-19 Thread wayne
On Aug 19, 10:44 am, SixDegrees  wrote:
> I'm using formsets to implement a dynamic form as 
> describedhttp://www.mancoosi.org/~abate/dynamic-forms-with-djangohere . 
> However, the
> forms created by the formset want a parameter passed that determines the
> contents of the form during initialization.

What parameter is that?  You should be able to accomplish what you
describe without any Javascript, just like the code does at the link
you provide.

Wayne

-- 
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: Getting ForeignKey not to CASCADE, SET NULL not working (postgresql)

2011-08-19 Thread mike
thanks for the links.  I did come across those issues as well.  But
the
main issue is that no SET NULL contraint is being set on the
database ... Django does do it, but
if someone deletes an item using the cli, the database will not do the
right thing since
the sql being generated ignores the SET NULL constraint.

thanks again,

mike

On Aug 19, 10:53 am, Landy Chapman  wrote:
> Have a look:
>
> -http://old.nabble.com/Should-postgresql-cascade-after-truncate-td3188...
>
> -  https://code.djangoproject.com/ticket/11665
>
> http://groups.google.com/group/django-developers/browse_thread/thread...

-- 
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: Getting ForeignKey not to CASCADE, SET NULL not working (postgresql)

2011-08-19 Thread Landy Chapman
Have a look:

- http://old.nabble.com/Should-postgresql-cascade-after-truncate-td31886534.html

-  https://code.djangoproject.com/ticket/11665

http://groups.google.com/group/django-developers/browse_thread/thread/27fe52b8bd0ca105/49d5058a1594a428

-- 
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 reloader fails to watch all the project files

2011-08-19 Thread Bill Freeman
Does your urls.py in the app in question import the view, or are you
just referring to the view functions with strings?  I'm not sure whether
views.py is imported before the first time one of the urls is triggered
in this case, but it would be a cheap check to add the import.

On Thu, Aug 18, 2011 at 4:54 PM, rwman  wrote:
> Hi. I bumped into a problem with djnago autoreloader (using standard
> runserver command) recently - when i update my views.py file it does not
> reload the server automatically. (while it does, if i update my project's
> settings.py file)
> Looking at the code (django/utils/autoreload.py) - i discovered, that it
> watches sys.modules list(dict, actually). And after some debugging i found,
> that my app's views.py never gets into this list.
> i am no expert in python, and will appreciate any help in finding answers.
> Can anyone please tell me,
> - is it a bug? (or no - updating views.py should not trigger autoreload?)
> - how 'settings.py' appeared in the sys.modules?(what code makes it get in
> there) and why 'some_app.views.py' does not?
>
> --
> 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/-/SXecMqFIiQYJ.
> 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.



Dynamic Forms with Varying init Arguments

2011-08-19 Thread SixDegrees

I'm using formsets to implement a dynamic form as described 
http://www.mancoosi.org/~abate/dynamic-forms-with-django here . However, the
forms created by the formset want a parameter passed that determines the
contents of the form during initialization. This parameter can be passed
back through another form on the same page using Javascript, but I can't
figure out how to tell the formset to create the next form using this
parameter. How is this done?

As an alternative, I can create a new form manually. But there doesn't seem
to be a way to add it to the formset.

I would much prefer to stay away from JavaScript and other client-side
approaches, other than passing the single parameter used for initialization.
-- 
View this message in context: 
http://old.nabble.com/Dynamic-Forms-with-Varying-init-Arguments-tp32296362p32296362.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-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: modelForm has no _default_manager

2011-08-19 Thread Guillaume DE BURE
Thanks, I overlooked the documentation... Will check this!

Guillaume
Le 19 août 2011 14:49, "Daniel Roseman"  a écrit :
> On Friday, 19 August 2011 11:15:53 UTC+1, gdebure wrote:
>>
>> Hi Everyone,
>>
>> I've been discovering Django for a few weeks, and love it so far :)
>> However I am facing an issue with a modelForm. As I couldn't find my
>> answer through googling, I thought you might be able to help...
>>
>> == context ==
>> I have an object (called "Domain") that has an "owner" attribute that
>> links to a user. using guardian (http://packages.python.org/django-
>> guardian/ ), I would like to

>> automatically setup a per object
>> permission on this Domain for its Owner
>>
>> == code ==
>> Please see : http://pastebin.com/4Uf31Q52
>>
>> == error ==
>> Whenever I try to access the update page that should contain the Form,
>> I get the error:
>>
>> type object 'DomainForm' has no attribute '_default_manager'
>>
>> (Full traceback at http://dpaste.com/598065/)
>>
>> Please note that this does not seem to be the same as the
>> "AttributeError: 'str' object has no attribute '_default_manager'" for
>> which I saw many things on google, but that do not seem to apply to my
>> case.
>>
>> Thanks a lot for any guidance you may provide :)
>>
>> Guillaume
>
>
> You've simply put the form class as the `model` parameter in the URLconf.
> You need to use the `form_class` parameter instead.
> --
> DR.
>
> --
> 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/-/q-_GkaiJzxAJ.
> 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.



Using annotate() in a custom model manager

2011-08-19 Thread LaundroMat
Hi -

I have these models; with one custom manager.

class OrderByHighestScoreManager(models.Manager):
def get_query_set(self, *args, **kwargs):
qs = super(OrderByHighestValidationsManager,
self).get_query_set(*args, **kwargs)
return
qs.annotate(score=Count('votes__id'),).order_by('score')

class AbstractEntry(models.Model):
user = models.ForeignKey(User, null=True, blank=True)
last_modified = models.DateTimeField(auto_now=True)
objects = models.Manager()
order_by_votes = OrderByHighestValidationsManager()

class Entry(AbstractEntry):
creation_date = models.DateTimeField(auto_now_add=True)
votes = generic.GenericRelation(Vote)


I can't get the custom manager to work
This is OK:
Entry.objects.annotate(score=Count('votes__id'),).order_by('score')

This does not work:
Entry.order_by_votes.all()

The error I get is:
Error
Traceback (most recent call last):
  File "c:\Python27\Lib\unittest\case.py", line 318, in run
testMethod()
  File "C:\Data\Development\django_projects\oko\\apps\entries
\tests\model.py", line 111, in test_order_by_votes
self.assertEqual(list(Entry.order_by_votes.values_list('id',
flat=True)), [self.e1.id, self.e2.id])
  File "C:\Data\Development\django_projects\oko\lib\site-packages
\django\db\models\query.py", line 84, in __len__
self._result_cache.extend(self._iter)
  File "C:\Data\Development\django_projects\oko\lib\site-packages
\django\db\models\query.py", line 956, in iterator
for row in self.query.get_compiler(self.db).results_iter():
  File "C:\Data\Development\django_projects\oko\lib\site-packages
\django\db\models\sql\compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
  File "C:\Data\Development\django_projects\oko\lib\site-packages
\django\db\models\sql\compiler.py", line 725, in execute_sql
sql, params = self.as_sql()
  File "C:\Data\Development\django_projects\oko\lib\site-packages
\django\db\models\sql\compiler.py", line 60, in as_sql
ordering, ordering_group_by = self.get_ordering()
  File "C:\Data\Development\django_projects\oko\lib\site-packages
\django\db\models\sql\compiler.py", line 349, in get_ordering
self.query.model._meta, default_order=asc):
  File "C:\Data\Development\django_projects\oko\lib\site-packages
\django\db\models\sql\compiler.py", line 378, in find_ordering_name
opts, alias, False)
  File "C:\Data\Development\django_projects\oko\lib\site-packages
\django\db\models\sql\query.py", line 1238, in setup_joins
"Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'score' into field. Choices are:
creation_date, id, last_modified,  user, votes

=

What's going wrong here?

I would very much like to perform this sorting via a manager, or at
least a method accessible from within an Entry instance as several
templates will be using this special sorting (and I don't want to copy
this complex queryset over different views).

Thanks in advance!

-- 
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: Strange behavior in model.save()

2011-08-19 Thread David Jacquet
Thanks Yaşar and Jani for your fast replies!


I understand that normally one would assign in the reverse order. However I
do not understand exactly what happens when I do
meeting.place = meeting.place
never in my programming experience have I seen an example when
x=x
really does something. Isn't this strange?


Anyway, the reason for me wanting to go around normal behavior is that I
have a quite complicated and nested datamodel. Then I offer an api where
people can post JSON object. The will posts will be heavily nested ojbects
and I do not want save it to db by rewriting the whole save-chain in my
code. I have solved this by creating the class AREM below. When I have a
dictionary d representing a class A (subclass to AREM) and I want it saved I
do:

a = A().from_dict(d)
a.full_save()

I have gotten it to work, but not before I added the (for me very strange)
row

setattr(self, f.name, ref) #Without this everything collapses

residing on the second most bottom row in the code below. The problem is
that I do not know what it does, nor if there is a more elegant, faster or
better way to do it.

Best Regards
David



#class AbstractRecursiveEnabledModel(models.Model):
class AREM(AMCS):
class Meta:
abstract = True

def from_dict(self, d):
if not isinstance(d, dict):
return d
fl = self._meta.fields
for f in fl:
if d.has_key(f.name) and f.rel and d[f.name] is not None:
d[f.name] = f.rel.to().from_dict(d[f.name])
self.__init__(**d)
return self

def full_save(self,*args, **kwargs):fl = self._meta.fields

for f in fl:
if f.rel:
ref = getattr(self, f.name)
if ref is not None and ref.pk is None and ref is not self:
ref.full_save(*args, **kwargs)
setattr(self, f.name, ref) #Without this everything
collapses
super(AREM, self).save(*args, **kwargs)







On Fri, Aug 19, 2011 at 2:34 PM, Jani Tiainen  wrote:

> On 08/19/2011 03:15 PM, Jacco wrote:
>
>> I am having great difficulties in saving nested models in an easy
>> way.
>>
>>
>> #Two (almost) identical functions:
>> def test1():
>> place = Place(where='Paris')
>>
>
> place is not saved, thus it does not have a primary key (id)
>
>
>  meeting = Meeting(place=place, when='2011-01-01')
>>
>
> You assign non saved instance to a meeting. Probably what happened
> internally is that place.pk is copied to meeting.place_id.
>
>  place.save()
>>
>
> You saved place. Changes in model are not reflected to referred model.
>
>  meeting.save()
>>
>
> You save meeting with still (partially) stale place pk. thus resulting an
> exception.
>
>
>  def test2():
>> place = Place(where='Paris')
>> meeting = Meeting(place=place, when='2011-01-01')
>>
>> place.save()
>> meeting.place = meeting.place  #BY setting meeting.place to
>> itself, it works 
>>
>
> You updated your meeting internal structure.
>
>  meeting.save()
>> return meeting
>> --**--**
>> --**--**
>> --
>>
>>
>>
>> - Running test1() results in crash "null value in column "place_id"
>> violates not-null constraint"
>> - Running test2() results in OK.
>> - Only difference is the dummy line "meting.place = meeting.place".
>>
>> Could someone who really understands this explain what is going on?
>>
>>
> What's going on that you have done it incorrect order.
>
> place = Place(where='Paris')
> place.save() # Place saved, PK assigned.
>
>
> meeting = Meeting(place=place, when='2011-01-01')
> meeting.save() # Meeting saved with correct place.
>
> --
>
> 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-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> 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: Initialization code that should only run under a web server

2011-08-19 Thread Yaşar Arabacı
I didn't try this but might work. You can create a second manage.py called
for example manage2.py  file with following contents:

#!/usr/bin/env python
from django.core.management import execute_manager
import imp
try:
  imp.find_module('alternative_settings') # Assumed to be in the same
directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the
directory containing %r. It appears you've customized things.\nYou'll have
to run django-admin.py, passing it your settings module.\n" % __file__)
sys.exit(1)

import alternative_settings
if __name__ == "__main__":
  execute_manager(alternative_settings)

Then create an alternative_settings.py file, all the same but don't make
heavy calculations there.


2011/8/19 Boaz Leskes 

> Hi,
>
> I have some computationally intensive initialization logic that
> should
> run when a new process is started up by the web server. Following
> advice on the web, I've imported the module with the initialization
> code from settings.py, which works perfectly as advertised. However,
> it has one side effect which is very cumbersome - the code runs with
> every manage command as well. Every syncdb (and migration as we use
> South) takes forever. This is a problem during deployment.
>
> What's the best way to run initialization code only when it is
> executed under a server? (runserver & mod_wsgi) - is there any way to
> tell that a manage command is active at the moment and what it is? I
> could then not run the code for anything but runserver.
>
> Thanks,
> Boaz
>
> --
> 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.



Initialization code that should only run under a web server

2011-08-19 Thread Boaz Leskes
Hi,

I have some computationally intensive initialization logic that
should
run when a new process is started up by the web server. Following
advice on the web, I've imported the module with the initialization
code from settings.py, which works perfectly as advertised. However,
it has one side effect which is very cumbersome - the code runs with
every manage command as well. Every syncdb (and migration as we use
South) takes forever. This is a problem during deployment.

What's the best way to run initialization code only when it is
executed under a server? (runserver & mod_wsgi) - is there any way to
tell that a manage command is active at the moment and what it is? I
could then not run the code for anything but runserver.

Thanks,
Boaz

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



Getting ForeignKey not to CASCADE, SET NULL not working (postgresql)

2011-08-19 Thread mike
I can get the set null on a foreign key to work.

in my model I have this:

leaguteTypeId = models.ForeignKey(LeagueType,null=True,
db_column='leaguetype', on_delete=models.SET_NULL)


This is what is postgresql dumps:
ALTER TABLE ONLY league
ADD CONSTRAINT league_leaguetype_fkey
FOREIGN KEY (leaguetype) REFERENCES leaguetype(id) DEFERRABLE
INITIALLY DEFERRED;

This is what it should be:
ALTER TABLE League
ADD CONSTRAINT league_leaguetype_fkey
FOREIGN KEY (leaguetype) REFERENCES leaguetype (id)
ON UPDATE CASCADE
ON DELETE SET NULL

django version 1.3 postgresql 8.4
any ideas ?

thanks

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



Re: Best approach to handling different types of Users

2011-08-19 Thread Andre Terra
Alright, do what you will. Whatever floats your boat..

On Fri, Aug 19, 2011 at 5:12 AM, Matt Schinckel  wrote:

>
> On Friday, August 19, 2011 12:07:44 PM UTC+9:30, Andre Terra (airstrike)
> wrote:
>>
>> Until you install some third party app that accesses
>> User.objects.all() and then suddenly nothing works as it's supposed
>> to.
>>
>> Why wouldn't it? The User subclasses will still appear in the
> User.objects.all() queryset.
>
>> You can access the User object from its related UserProfile instance
>> and do everything you say from there instead of breaking the
>> convention. Nobody's stopping you from writing an abstract
>> BaseUserProfile model with an FK to User and custom UserProfile
>> subclasses. I just don't see any advantages in going down that path.
>>
>  As I said, 'at this stage', it all seems to be working out okay. I have
> plenty of 3rd party apps, and even some of my own, that access User, and
> they still work with sub-classes.
>
>> Because how will you access every user if you ever need to? What if
>> someone gets promoted? How will you separate view from model logic?
>> Are you going to rewrite forms for every user class? That's probably
>> going to be hard to maintain.
>>
>  You can still access User.objects.all(). I even have a way to access the
> sub-classes (downcasting) when fetching all users.
>
>> FWIW, profiles are the canonical solution. They are also the only
>> elegant solution, at least until the app loading branch lands on
>> trunk, which should then allow you to register a different class as
>> User. But that won't happen any time soon..
>>
> See, I don't see them as an elegant solution. Having to do:
>
> user.get_profile().date_of_birth
>
> instead of:
>
> user.date_of_birth
>
> irks me every time I write the code. UserProfile has always felt to me that
> it was a patchy way of extending User.
>
> Matt.
>
> --
> 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/-/-B-vk5gzPqcJ.
>
> 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: modelForm has no _default_manager

2011-08-19 Thread Daniel Roseman
On Friday, 19 August 2011 11:15:53 UTC+1, gdebure wrote:
>
> Hi Everyone, 
>
> I've been discovering Django for a few weeks, and love it so far :) 
> However I am facing an issue with a modelForm. As I couldn't find my 
> answer through googling, I thought you might be able to help... 
>
> == context == 
> I have an object (called "Domain") that has an "owner" attribute that 
> links to a user. using guardian (http://packages.python.org/django- 
> guardian/ ), I would like to 
> automatically setup a per object 
> permission on this Domain for its Owner 
>
> == code == 
> Please see : http://pastebin.com/4Uf31Q52 
>
> == error == 
> Whenever I try to access the update page that should contain the Form, 
> I get the error: 
>
> type object 'DomainForm' has no attribute '_default_manager' 
>
> (Full traceback at http://dpaste.com/598065/) 
>
> Please note that this does not seem to be the same as the 
> "AttributeError: 'str' object has no attribute '_default_manager'" for 
> which I saw many things on google, but that do not seem to apply to my 
> case. 
>
> Thanks a lot for any guidance you may provide :) 
>
> Guillaume


You've simply put the form class as the `model` parameter in the URLconf. 
You need to use the `form_class` parameter instead.
--
DR.

-- 
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/-/q-_GkaiJzxAJ.
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: Strange behavior in model.save()

2011-08-19 Thread Jani Tiainen

On 08/19/2011 03:15 PM, Jacco wrote:

I am having great difficulties in saving nested models in an easy
way.


#Two (almost) identical functions:
def test1():
 place = Place(where='Paris')


place is not saved, thus it does not have a primary key (id)


 meeting = Meeting(place=place, when='2011-01-01')


You assign non saved instance to a meeting. Probably what happened 
internally is that place.pk is copied to meeting.place_id.



 place.save()


You saved place. Changes in model are not reflected to referred model.


 meeting.save()


You save meeting with still (partially) stale place pk. thus resulting 
an exception.



def test2():
 place = Place(where='Paris')
 meeting = Meeting(place=place, when='2011-01-01')

 place.save()
 meeting.place = meeting.place  #BY setting meeting.place to
itself, it works 


You updated your meeting internal structure.

 meeting.save()
 return meeting
--



- Running test1() results in crash "null value in column "place_id"
violates not-null constraint"
- Running test2() results in OK.
- Only difference is the dummy line "meting.place = meeting.place".

Could someone who really understands this explain what is going on?



What's going on that you have done it incorrect order.

place = Place(where='Paris')
place.save() # Place saved, PK assigned.

meeting = Meeting(place=place, when='2011-01-01')
meeting.save() # Meeting saved with correct place.

--

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-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: Strange behavior in model.save()

2011-08-19 Thread Yaşar Arabacı
And your second function works because when you set  meeting.place =
meeting.place, unsaved place object gets changed with saved place object :)
Nice catch though.

19 Ağustos 2011 15:28 tarihinde Yaşar Arabacı  yazdı:

> It is because you are creating meeting object, before saving "place" in db.
> So place object doesn't have any id yet. So test 1 should be:
>
>place = Place(where='Paris')
>place.save()
>meeting = Meeting(place=place, when='2011-01-01')
>
>
>
>meeting.save()
>return meeting
> 2011/8/19 Jacco 
>
>> I am having great difficulties in saving nested models in an easy
>> way.
>>
>>
>> Consider the following Example :
>>
>> --
>> class Place(models.Model):
>>where   = models.CharField(max_length=10)
>> class Meeting(models.Model):
>>place = models.ForeignKey(Place)
>>when  = models.DateField()
>>
>> #Two (almost) identical functions:
>> def test1():
>>place = Place(where='Paris')
>>meeting = Meeting(place=place, when='2011-01-01')
>>
>>place.save()
>>
>>meeting.save()
>>return meeting
>>
>> def test2():
>>place = Place(where='Paris')
>>meeting = Meeting(place=place, when='2011-01-01')
>>
>>place.save()
>>meeting.place = meeting.place  #BY setting meeting.place to
>> itself, it works 
>>meeting.save()
>>return meeting
>>
>> --
>>
>>
>>
>> - Running test1() results in crash "null value in column "place_id"
>> violates not-null constraint"
>> - Running test2() results in OK.
>> - Only difference is the dummy line "meting.place = meeting.place".
>>
>> Could someone who really understands this explain what is going on?
>>
>> --
>> 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: Strange behavior in model.save()

2011-08-19 Thread Yaşar Arabacı
It is because you are creating meeting object, before saving "place" in db.
So place object doesn't have any id yet. So test 1 should be:

   place = Place(where='Paris')
   place.save()
   meeting = Meeting(place=place, when='2011-01-01')



   meeting.save()
   return meeting
2011/8/19 Jacco 

> I am having great difficulties in saving nested models in an easy
> way.
>
>
> Consider the following Example :
>
> --
> class Place(models.Model):
>where   = models.CharField(max_length=10)
> class Meeting(models.Model):
>place = models.ForeignKey(Place)
>when  = models.DateField()
>
> #Two (almost) identical functions:
> def test1():
>place = Place(where='Paris')
>meeting = Meeting(place=place, when='2011-01-01')
>
>place.save()
>
>meeting.save()
>return meeting
>
> def test2():
>place = Place(where='Paris')
>meeting = Meeting(place=place, when='2011-01-01')
>
>place.save()
>meeting.place = meeting.place  #BY setting meeting.place to
> itself, it works 
>meeting.save()
>return meeting
>
> --
>
>
>
> - Running test1() results in crash "null value in column "place_id"
> violates not-null constraint"
> - Running test2() results in OK.
> - Only difference is the dummy line "meting.place = meeting.place".
>
> Could someone who really understands this explain what is going on?
>
> --
> 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: Getting and modifying url parameters in template: howto?

2011-08-19 Thread Yaşar Arabacı
You can either send required information from your view to your template, or
do some javascript on the browser side.

2011/8/19 samuele.mattiuzzo 

> Yeah, i was thinking about that...
>
> A template tag like {% my_url   %}
>
> could be something like that...
>
> On Aug 18, 6:36 pm, Andre Terra  wrote:
> > Assuming I understood what you're trying to do, why not write a template
> tag
> > (more specifically, an inclusion tag)?
> >
> > Cheers,
> > AT
> >
> > On Thu, Aug 18, 2011 at 11:47 AM, samuele.mattiuzzo  >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > I'm not using haystack, since is strictly model-related. My solr
> > > instance isnt' bound to any model (since i don't use any backend DB to
> > > store my data)
> >
> > > i need something like get_full_path or get_absolute_url, but not
> > > modell-related in this case...
> >
> > > On 18 Ago, 16:37, Andre Terra  wrote:
> > > > Searching with Django =http://haystacksearch.org/
> >
> > > > Behold the power of pluggable apps.
> >
> > > > Cheers,
> > > > AT
> >
> > > > On Thu, Aug 18, 2011 at 11:34 AM, samuele.mattiuzzo <
> samum...@gmail.com
> > > >wrote:
> >
> > > > > Hi!
> > > > > I'm stuck with a problem... more confused than stuck, actually.
> >
> > > > > I have a search engine i'm working on, and we're using GET method
> to
> > > > > perform searches. In the listing page, i have my search results on
> the
> > > > > left and some filters on the right, something like google's filter.
> >
> > > > > my filters are all blabla
> >
> > > > > what i need to do, and i don't know how, is:
> >
> > > > > 1 - get url parameters
> > > > > 2 - for each filter modify the correct parameter
> >
> > > > > example:
> >
> > > > >www.mysite.com/?name=apple=now=male
> >
> > > > > for "name" filters:
> >
> > > > > new_val
> >
> > > > > i don't know what to look for, maybe the {{ url }} tag can help me,
> > > > > but i don't know how to get_and_modify a specific param :(
> >
> > > > > can anybody help me? thanks!
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Django users" group.
> > > > > To post to this group, send email to django-users@googlegroups.com
> .
> > > > > To unsubscribe from this group, send email to
> > > > > django-users+unsubscr...@googlegroups.com.
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/django-users?hl=en.
> >
> > > --
> > > 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.



Strange behavior in model.save()

2011-08-19 Thread Jacco
I am having great difficulties in saving nested models in an easy
way.


Consider the following Example :
--
class Place(models.Model):
where   = models.CharField(max_length=10)
class Meeting(models.Model):
place = models.ForeignKey(Place)
when  = models.DateField()

#Two (almost) identical functions:
def test1():
place = Place(where='Paris')
meeting = Meeting(place=place, when='2011-01-01')

place.save()

meeting.save()
return meeting

def test2():
place = Place(where='Paris')
meeting = Meeting(place=place, when='2011-01-01')

place.save()
meeting.place = meeting.place  #BY setting meeting.place to
itself, it works 
meeting.save()
return meeting
--



- Running test1() results in crash "null value in column "place_id"
violates not-null constraint"
- Running test2() results in OK.
- Only difference is the dummy line "meting.place = meeting.place".

Could someone who really understands this explain what is going on?

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



modelForm has no _default_manager

2011-08-19 Thread gdebure
Hi Everyone,

I've been discovering Django for a few weeks, and love it so far :)
However I am facing an issue with a modelForm. As I couldn't find my
answer through googling, I thought you might be able to help...

== context ==
I have an object (called "Domain") that has an "owner" attribute that
links to a user. using guardian (http://packages.python.org/django-
guardian/), I would like to automatically setup a per object
permission on this Domain for its Owner

== code ==
Please see : http://pastebin.com/4Uf31Q52

== error ==
Whenever I try to access the update page that should contain the Form,
I get the error:

type object 'DomainForm' has no attribute '_default_manager'

(Full traceback at http://dpaste.com/598065/)

Please note that this does not seem to be the same as the
"AttributeError: 'str' object has no attribute '_default_manager'" for
which I saw many things on google, but that do not seem to apply to my
case.

Thanks a lot for any guidance you may provide :)

Guillaume

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



Assign a variable from a template in a "global" way?

2011-08-19 Thread Forbairt
Hi All,

I'm using the code from 
http://www.soyoucode.com/2011/set-variable-django-template

from django import template

register = template.Library()

class SetVarNode(template.Node):

def __init__(self, var_name, var_value):
self.var_name = var_name
self.var_value = var_value

def render(self, context):
try:
value = template.Variable(self.var_value).resolve(context)
except template.VariableDoesNotExist:
value = ""
context[self.var_name] = value
return u""

def set_var(parser, token):
"""
{% set   =  %}
"""
parts = token.split_contents()
if len(parts) < 4:
raise template.TemplateSyntaxError("'set' tag must be of the
form:  {% set   =  %}")
return SetVarNode(parts[1], parts[3])

register.tag('set', set_var)

I've my main template base.html and in this I include config.html
where I load up the above custom templatetag set_var

{% load set_var %}
{% set iconsize = 50 %}

I then include another template file from base.html which would like
to make use of the variable I've assigned in the config.html

Now I can assign the variable in config.html and it works fine in this
context. I'm stuck with how to make it global though. Any help would
be appreciated. I'm new to python / django and I've been tearing my
hair out trying to figure out how to go about doing this.

Any help would be greatly appreciated
James

-- 
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: Getting and modifying url parameters in template: howto?

2011-08-19 Thread samuele.mattiuzzo
Yeah, i was thinking about that...

A template tag like {% my_url   %}

could be something like that...

On Aug 18, 6:36 pm, Andre Terra  wrote:
> Assuming I understood what you're trying to do, why not write a template tag
> (more specifically, an inclusion tag)?
>
> Cheers,
> AT
>
> On Thu, Aug 18, 2011 at 11:47 AM, samuele.mattiuzzo wrote:
>
>
>
>
>
>
>
> > I'm not using haystack, since is strictly model-related. My solr
> > instance isnt' bound to any model (since i don't use any backend DB to
> > store my data)
>
> > i need something like get_full_path or get_absolute_url, but not
> > modell-related in this case...
>
> > On 18 Ago, 16:37, Andre Terra  wrote:
> > > Searching with Django =http://haystacksearch.org/
>
> > > Behold the power of pluggable apps.
>
> > > Cheers,
> > > AT
>
> > > On Thu, Aug 18, 2011 at 11:34 AM, samuele.mattiuzzo  > >wrote:
>
> > > > Hi!
> > > > I'm stuck with a problem... more confused than stuck, actually.
>
> > > > I have a search engine i'm working on, and we're using GET method to
> > > > perform searches. In the listing page, i have my search results on the
> > > > left and some filters on the right, something like google's filter.
>
> > > > my filters are all blabla
>
> > > > what i need to do, and i don't know how, is:
>
> > > > 1 - get url parameters
> > > > 2 - for each filter modify the correct parameter
>
> > > > example:
>
> > > >www.mysite.com/?name=apple=now=male
>
> > > > for "name" filters:
>
> > > > new_val
>
> > > > i don't know what to look for, maybe the {{ url }} tag can help me,
> > > > but i don't know how to get_and_modify a specific param :(
>
> > > > can anybody help me? thanks!
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Django users" group.
> > > > To post to this group, send email to django-users@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > django-users+unsubscr...@googlegroups.com.
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/django-users?hl=en.
>
> > --
> > 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: Django admin site and DEBUG flag.

2011-08-19 Thread william ratcliff
Actually, you might want to just use the following:
http://betterthangrep.com/

to search through the entire project--this program has saved me a lot of
time!

William

On Fri, Aug 19, 2011 at 4:36 AM, Reinout van Rees wrote:

> On 19-08-11 10:27, KC LEE wrote:
>
>> urlpatterns = patterns('',
>>
>> (r'^$', 'accounts.views.front_page'),
>> url(r'social/', include('social_auth.urls')),
>>
>> (r'^admin/', include(admin.site.urls)),
>>
>> (r'^regions/', include('region.urls')),
>>
>> (r'^messages/', include('pimfy_messages.urls')**),
>> (r'^accounts/', include('accounts.urls')),
>> (r'^issue/', include('issue.urls')),
>> (r'^notification/', include('notification.urls')),
>>
>>
> Looks alright. Only noticeable thing: that 'social/' one is the only one
> called with url(). Might be worth a try to remove that url() call around it
> to let it match the rest. Shouldn't matter, but... ;-)
>
>
> You said that admin/* and admin/users/* and admin/groups/* *did* work?
> Which ones don't? If it is for instance /admin/issues/*, look at that issues
> app and see if there's an 'if settings.DEBUG' somewhere in there.
>
>
>
> Reinout
>
> --
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.**nl/
>
> "If you're not sure what to do, make something. -- Paul Graham"
>
> --
> 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+unsubscribe@**
> 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.



How to make pydev suport django specific syntax?

2011-08-19 Thread smith jack
for example, django have some dynamic mechanism, the code can be
processed wel by django, but pydev will just simply show some error
message,
how to make pydev deal with such dynamics?

-- 
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 admin site and DEBUG flag.

2011-08-19 Thread Reinout van Rees

On 19-08-11 10:27, KC LEE wrote:

urlpatterns = patterns('',

 (r'^$', 'accounts.views.front_page'),
 url(r'social/', include('social_auth.urls')),

 (r'^admin/', include(admin.site.urls)),

 (r'^regions/', include('region.urls')),

 (r'^messages/', include('pimfy_messages.urls')),
 (r'^accounts/', include('accounts.urls')),
 (r'^issue/', include('issue.urls')),
 (r'^notification/', include('notification.urls')),



Looks alright. Only noticeable thing: that 'social/' one is the only one 
called with url(). Might be worth a try to remove that url() call around 
it to let it match the rest. Shouldn't matter, but... ;-)



You said that admin/* and admin/users/* and admin/groups/* *did* work? 
Which ones don't? If it is for instance /admin/issues/*, look at that 
issues app and see if there's an 'if settings.DEBUG' somewhere in there.



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: 'dict' object has no attribute 'META'

2011-08-19 Thread MikeKJ

Thanks guys!  yeah the request parameter was missing, so much for parallel
monitor reading!
All I can say is that I write code better now,  thanks again

MJ

The first parameter to RequestContext should always be the request, not the 
context dict. I don't think that has ever been different - see for example 
the class as of four years ago:
https://code.djangoproject.com/browser/django/trunk/django/template/context.py?rev=6975#L96
--
DR.

-- 

-- 
View this message in context: 
http://old.nabble.com/%27dict%27-object-has-no-attribute-%27META%27-tp32288508p32293465.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-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 admin site and DEBUG flag.

2011-08-19 Thread KC LEE
My problem is identical to this,

https://groups.google.com/group/django-users/browse_thread/thread/62af38b39713f5e7/279df4fba31fd292

On Aug 19, 5:27 pm, KC LEE  wrote:
> My urls.py looks like this,
>
> # -*- coding: utf-8 -*-
>
> from django.conf.urls.defaults import *
> from django.conf import settings
> from django.views.generic.simple import direct_to_template
>
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
>
>     (r'^$', 'accounts.views.front_page'),
>     url(r'social/', include('social_auth.urls')),
>
>     (r'^admin/', include(admin.site.urls)),
>
>     (r'^regions/', include('region.urls')),
>
>     (r'^messages/', include('pimfy_messages.urls')),
>     (r'^accounts/', include('accounts.urls')),
>     (r'^issue/', include('issue.urls')),
>     (r'^notification/', include('notification.urls')),
>
>     (r'^password_forgot/$',
> 'django.contrib.auth.views.password_reset'),
>     (r'^password_forgot/done/$',
> 'django.contrib.auth.views.password_reset_done'),
>     (r'^password_reset/(?P[0-9A-Za-z]+)/(?P.+)/$',
> 'django.contrib.auth.views.password_reset_confirm'),
>     (r'^password_reset/done/$',
> 'django.contrib.auth.views.password_reset_complete'),
>
> )
>
> On Aug 19, 4:36 pm, Reinout van Rees  wrote:
>
>
>
>
>
>
>
> > On 19-08-11 05:28, KC LEE wrote:
>
> > > When I set DEBUG flag true, Django admin site works fine.
>
> > > But when I change it to false, it throws me the page not found in
> > > Django admin site (except main page of admin site, Groups page, and
> > > Users page)
>
> > This sounds like your urls.py has an "if settings.DEBUG:" around where
> > the admin site is mounted in your urls.
>
> > Reinout
>
> > --
> > Reinout van Rees                    http://reinout.vanrees.org/
> > rein...@vanrees.org            http://www.nelen-schuurmans.nl/
> > "If you're not sure what to do, make something. -- Paul Graham"

-- 
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 admin site and DEBUG flag.

2011-08-19 Thread KC LEE
My urls.py looks like this,

# -*- coding: utf-8 -*-

from django.conf.urls.defaults import *
from django.conf import settings
from django.views.generic.simple import direct_to_template

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

(r'^$', 'accounts.views.front_page'),
url(r'social/', include('social_auth.urls')),

(r'^admin/', include(admin.site.urls)),

(r'^regions/', include('region.urls')),

(r'^messages/', include('pimfy_messages.urls')),
(r'^accounts/', include('accounts.urls')),
(r'^issue/', include('issue.urls')),
(r'^notification/', include('notification.urls')),

(r'^password_forgot/$',
'django.contrib.auth.views.password_reset'),
(r'^password_forgot/done/$',
'django.contrib.auth.views.password_reset_done'),
(r'^password_reset/(?P[0-9A-Za-z]+)/(?P.+)/$',
'django.contrib.auth.views.password_reset_confirm'),
(r'^password_reset/done/$',
'django.contrib.auth.views.password_reset_complete'),


)





On Aug 19, 4:36 pm, Reinout van Rees  wrote:
> On 19-08-11 05:28, KC LEE wrote:
>
> > When I set DEBUG flag true, Django admin site works fine.
>
> > But when I change it to false, it throws me the page not found in
> > Django admin site (except main page of admin site, Groups page, and
> > Users page)
>
> This sounds like your urls.py has an "if settings.DEBUG:" around where
> the admin site is mounted in your urls.
>
> Reinout
>
> --
> Reinout van Rees                    http://reinout.vanrees.org/
> rein...@vanrees.org            http://www.nelen-schuurmans.nl/
> "If you're not sure what to do, make something. -- Paul Graham"

-- 
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: Best approach to handling different types of Users

2011-08-19 Thread Matt Schinckel

On Friday, August 19, 2011 12:07:44 PM UTC+9:30, Andre Terra (airstrike) 
wrote:
>
> Until you install some third party app that accesses
> User.objects.all() and then suddenly nothing works as it's supposed
> to.
>
> Why wouldn't it? The User subclasses will still appear in the 
User.objects.all() queryset. 

> You can access the User object from its related UserProfile instance
> and do everything you say from there instead of breaking the
> convention. Nobody's stopping you from writing an abstract
> BaseUserProfile model with an FK to User and custom UserProfile
> subclasses. I just don't see any advantages in going down that path.
>
 As I said, 'at this stage', it all seems to be working out okay. I have 
plenty of 3rd party apps, and even some of my own, that access User, and 
they still work with sub-classes.

> Because how will you access every user if you ever need to? What if
> someone gets promoted? How will you separate view from model logic?
> Are you going to rewrite forms for every user class? That's probably
> going to be hard to maintain.
>
 You can still access User.objects.all(). I even have a way to access the 
sub-classes (downcasting) when fetching all users.

> FWIW, profiles are the canonical solution. They are also the only
> elegant solution, at least until the app loading branch lands on
> trunk, which should then allow you to register a different class as
> User. But that won't happen any time soon..
>
See, I don't see them as an elegant solution. Having to do:

user.get_profile().date_of_birth 

instead of:

user.date_of_birth

irks me every time I write the code. UserProfile has always felt to me that 
it was a patchy way of extending User.

Matt.

-- 
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/-/-B-vk5gzPqcJ.
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: Using os.fork() in a Django view

2011-08-19 Thread Kevin
Thank you very much for your suggestions about using Celery.  I'll
definitely look into this one.  Originally I was trying to avoid using
os.fork(), but was unsure what to use.  I will also look into the
uWSGI information provided as well.  Overall I would prefer to make
the entire system modular, much like how Django works.  If you use
Apache, then use this backend, if you use Nginx, then use this one.
Having a similar system to how Django currently works will make it
easy for any current Django developer/deployment administrator to work
with this control panel system.  This also opens the door to third-
parties creating their own backends for custom solutions.  Also a
backend system for storing data would be nice as well, say store
configuration in a model, or fetch and store it using LDAP.  Other
plugins, may include similar ones to what cPanel has, such as DNS
management and such.  Database management would be very basic, as the
editing of data is handled nicely by each projects Django admin site.
Database management would have the ability to administer databases,
and perform exports and imports of data.  Another ability I would like
to be plugable would be how users transfer their applications to the
server, currently I do plan Subversion support, but say a user prefers
GIT, or even the archaic and insecure FTP?  FYI, I use Subversion over
SSH.

  My ultimate goal with this project would be to bring a cPanel like
experience to Django administration, to better widen it's support
among "cheap hosts", where PHP currently(and unfortunately)
dominates.  Does cPanel even support Django type applications?  I
don't want to try re-inventing a wheel here.  I will look further into
panels for hosting Django projects and see what comes up.

On Aug 19, 2:24 am, Roberto De Ioris  wrote:
> Il giorno 19/ago/2011, alle ore 08:46, Kevin ha scritto:
>
> > Hello everyone,
>
> > Here's the code I will be needing to run in a os.fork():
> > from django.core.management import setup_environ, call_command
> > import settings
> > setup_environ(settings)
> > call_command('', **kwargs)
>
> >  So this would be in a separate function and called from a view which
> > uses os.fork(), or should I place os.fork() in the same function as
> > this code.  Of course the sys.path will be re-written before any
> > imports are done.  I plan on integrating Virtualenv with this.  The
> > model in the management Django project will contain the directories
> > and such that point to the Virtualenv.
>
> >  If anybody is interesting in helping with such a project, I am very
> > much open to any help.  I hope that this project may open Django to a
> > wider world of users, if the command-line Django admin stuff can be
> > done through a nifty web interface.  I have a server which it can be
> > developed and tested on as well.
>
> IMHO, this is the wrong approach from a security/sysadmin point of view.
>
> All of your django instances will run under the same uid. bad: all of your 
> users will be able
> to destroy other instances.
>
> If you want to call a setuid after each fork() you have to run the django 
> panel as root. even badder.
>
> As a rule, do not allow users generating fork(). You will need to implement a 
> throttling system (and this could be a pita).
>
> Even if modern os are stronger against fork bombing, you can destroy a whole 
> server easily.
>
> The most secure approach would be enqueing the tasks (you can use celery, 
> uWSGI spooler, or a dedicated daemon or whatever you want)
> and execute one by one (this solves fork bombing problem). You will lose 
> real-time, but you will gain security.
>
> Each task should run as a specific uid, so for each customer run another 
> daemon waiting for event (it will really run manage.py and runfcgi for you).
>
> Lot of work to do, you should take in account that the uWSGI project is built 
> with this target in mind (ISPs), and has systems to easily administering 
> multi-uid environments:
>
> http://projects.unbit.it/uwsgi/wiki/Emperorhttp://projects.unbit.it/uwsgi/wiki/FastRouterhttp://projects.unbit.it/uwsgi/wiki/LinuxNamespacehttp://projects.unbit.it/uwsgi/wiki/UseCgroups
>
> the main idea (already used by more than 20 ISPs worldwide) is having the 
> "panel" generating config files (they can be even taken via http dynamically)
> After you have a user instance running, you could add an embedded app on it 
> to launch tasks (so it will be the user app itself executing processes)
>
> Another (rawer, but funny, used by rosti.cz) approach is this one:
>
> https://github.com/creckx/uWSGI-Manager
>
> You can even start from the ground and re-implement all of this concepts in 
> pure-python (in this case i suggest you to try gunicorn as it is more simple 
> to integrate [being in python]).
>
> Or you could follow the old-raw-way of dinamically generating apache 
> virtualhosts file for each customer and let mod_wsgi+daemon_mode do the hard 
> work.
>
> Well, returning to 

Re: Django admin site and DEBUG flag.

2011-08-19 Thread Reinout van Rees

On 19-08-11 05:28, KC LEE wrote:

When I set DEBUG flag true, Django admin site works fine.

But when I change it to false, it throws me the page not found in
Django admin site (except main page of admin site, Groups page, and
Users page)


This sounds like your urls.py has an "if settings.DEBUG:" around where 
the admin site is mounted in your urls.



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

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



Re: problem with a graph image in template

2011-08-19 Thread Reinout van Rees

On 19-08-11 04:03, smartaz wrote:

I think the error is in image.png GET, a python syntax error but I can
not think where (I do not know how to retrieve the trace of a 500
error in django, I installed django debug toolbar) it seems that
python can not write the file with the image ..the content type? ..I
don't understand, .this second view works when i ask an httpresponse
instead of the template


Ah! You're getting the 500 on the image, so you can't easily see the 
full 500 traceback in your browser as the html renders just fine.


Two options:

- Just go directly to the url of the image instead of to the html page 
that contains the img tag. Then you'll see the 500 traceback of your 
image itself. (Assuming DEBUG=True in your settings.py).


- Install firebug (or use chrome's/safari's build-in developer tools) 
and look at the various responses. There you can normally directly see 
the 500 error text.



Seeing the traceback ought to show you the problem.


Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: Using os.fork() in a Django view

2011-08-19 Thread Roberto De Ioris

Il giorno 19/ago/2011, alle ore 08:46, Kevin ha scritto:

> Hello everyone,
> 
> 
> Here's the code I will be needing to run in a os.fork():
> from django.core.management import setup_environ, call_command
> import settings
> setup_environ(settings)
> call_command('', **kwargs)
> 
>  So this would be in a separate function and called from a view which
> uses os.fork(), or should I place os.fork() in the same function as
> this code.  Of course the sys.path will be re-written before any
> imports are done.  I plan on integrating Virtualenv with this.  The
> model in the management Django project will contain the directories
> and such that point to the Virtualenv.
> 
>  If anybody is interesting in helping with such a project, I am very
> much open to any help.  I hope that this project may open Django to a
> wider world of users, if the command-line Django admin stuff can be
> done through a nifty web interface.  I have a server which it can be
> developed and tested on as well.
> 

IMHO, this is the wrong approach from a security/sysadmin point of view.

All of your django instances will run under the same uid. bad: all of your 
users will be able
to destroy other instances.

If you want to call a setuid after each fork() you have to run the django panel 
as root. even badder.

As a rule, do not allow users generating fork(). You will need to implement a 
throttling system (and this could be a pita).

Even if modern os are stronger against fork bombing, you can destroy a whole 
server easily.

The most secure approach would be enqueing the tasks (you can use celery, uWSGI 
spooler, or a dedicated daemon or whatever you want)
and execute one by one (this solves fork bombing problem). You will lose 
real-time, but you will gain security.

Each task should run as a specific uid, so for each customer run another daemon 
waiting for event (it will really run manage.py and runfcgi for you).

Lot of work to do, you should take in account that the uWSGI project is built 
with this target in mind (ISPs), and has systems to easily administering 
multi-uid environments:

http://projects.unbit.it/uwsgi/wiki/Emperor
http://projects.unbit.it/uwsgi/wiki/FastRouter
http://projects.unbit.it/uwsgi/wiki/LinuxNamespace
http://projects.unbit.it/uwsgi/wiki/UseCgroups

the main idea (already used by more than 20 ISPs worldwide) is having the 
"panel" generating config files (they can be even taken via http dynamically)
After you have a user instance running, you could add an embedded app on it to 
launch tasks (so it will be the user app itself executing processes)

Another (rawer, but funny, used by rosti.cz) approach is this one:

https://github.com/creckx/uWSGI-Manager

You can even start from the ground and re-implement all of this concepts in 
pure-python (in this case i suggest you to try gunicorn as it is more simple to 
integrate [being in python]).

Or you could follow the old-raw-way of dinamically generating apache 
virtualhosts file for each customer and let mod_wsgi+daemon_mode do the hard 
work.


Well, returning to the os.fork() problem, if you really need it, be sure that 
it will be the user slice/area/instance calling it (so you can limit with the 
various jailing technics) and not your main control panel.

--
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: Using os.fork() in a Django view

2011-08-19 Thread Russell Keith-Magee
On Fri, Aug 19, 2011 at 2:46 PM, Kevin  wrote:
> Hello everyone,
>
>  Firstly, I've been using Django for quiet sometime now and have
> created a few projects and many of my websites run it.  I am wanting
> to take my Django management to the next level, and need to use the
> os.fork() function, here's why.
>
>  I am planning on developing a web control panel for managing Django
> instances in Django itself.  It only makes sense to make the control
> panel in Django.  It will contain models for managing the actually
> instances themselves and which users have control to them, and what
> permissions these users have.  Features I plan on putting into the
> control panel will be native Subversion support, using the Python
> Subversion libraries.

Hi Kevin,

Firstly, you don't want to be doing this with os.fork(). Subversion
has good Python bindings, so you can invoke Subversion calls directly
from within Python. The same is true of many other system functions.

Secondly, you don't want to be doing this with os.fork(). Web requests
are designed to be short lived. Putting an expensive system call in
the middle of a web request is a certain way to resource starvation.

What you want to do instead is use a service like Celery. When the
user requests a system function, you create a Job, and put it on a
celery queue to be satisfied. Creating a job is a very quick
operation, which means you can return control to the web request, and
the request can be returned to the user. Then, you set up a mechanism
to check when the job has completed -- for example, polling via an
AJAX call to get the result of the job, and displaying the result on
the page that was served when you created the job. Your web requests
remain short lived, and you don't lock up your web server.

Lastly, before you embark on a grand project like this, I would
suggest having a long look for prior art. You're not the first person
that has described this exact problem on django-users; I'd be deeply
surprised if there isn't *something* out there that will do at least
some of what you're describing.

Yours,
Russ Magee %-)

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



Using os.fork() in a Django view

2011-08-19 Thread Kevin
Hello everyone,

  Firstly, I've been using Django for quiet sometime now and have
created a few projects and many of my websites run it.  I am wanting
to take my Django management to the next level, and need to use the
os.fork() function, here's why.

  I am planning on developing a web control panel for managing Django
instances in Django itself.  It only makes sense to make the control
panel in Django.  It will contain models for managing the actually
instances themselves and which users have control to them, and what
permissions these users have.  Features I plan on putting into the
control panel will be native Subversion support, using the Python
Subversion libraries.  This will allow projects to be versioned and
updated using Subversion rather than FTP/SFTP.  I currently use
Subversion in this manner already and it works wonderfully.  Other
features will include stopping and starting instances by use of
runfcgi management command.  I plan on using FastCGI support for
easier management and wider server support.  I currently use Nginx for
my website and it works nicely with Django's FastCGI server.  It will
allow database syncs and other tools normally supplied by manage.py.
I also plan on adding support for creating new projects and
associating it with an new Subversion repo.

  Now, the only hurdle I am currently trying to get past is the
ability to manage a Django site from within a different Django site.
I need to use Fork in order to make sure that the process uses the
settings.py from the other Django instance, and for it stays separate
from the Django control panel.  For example, a user could add some
malicious setting that could cause havoc when imported.  Process
separation is very important, and I would like some ideas on how I can
go about doing this to ensure a secure server.  Should I just spawn a
new Python process perhaps with a specific function to do the
management calls to be on the safe side?

Here's the code I will be needing to run in a os.fork():
from django.core.management import setup_environ, call_command
import settings
setup_environ(settings)
call_command('', **kwargs)

  So this would be in a separate function and called from a view which
uses os.fork(), or should I place os.fork() in the same function as
this code.  Of course the sys.path will be re-written before any
imports are done.  I plan on integrating Virtualenv with this.  The
model in the management Django project will contain the directories
and such that point to the Virtualenv.

  If anybody is interesting in helping with such a project, I am very
much open to any help.  I hope that this project may open Django to a
wider world of users, if the command-line Django admin stuff can be
done through a nifty web interface.  I have a server which it can be
developed and tested on as well.

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