Re: 4 beginner's questions

2007-07-21 Thread Stefan Matthias Aust

2007/7/21, Tim Chase <[EMAIL PROTECTED]>:

> I believe you're looking for the word "arbitrary".

Yes. Thanks. Geeks should however take into consideration that a
"random access file" isn't called an "arbitrary access file" ;)

-- 
Stefan Matthias Aust

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



Re: 4 beginner's questions

2007-07-21 Thread Tim Chase

>>> Let's assume you have users who are allowed to assign nick names to
>>> theirselves and still all thoses nick names must be different. This is
>>> want I call a random ID.
>>>
>> If a user assigns it, it is not random, by any definition of random I
>> can think of.
> 
> From the server's point of view it is random - IMHO - because the
> server cannot guess it and users don't know the choices of other
> users. Perhaps there's a better English word, I'd call it "zufällig".

I believe you're looking for the word "arbitrary".  In non-geek
circles, the word "random" works as well, but among geeks,
"random" has a more mathematically precise definition that tends
to be assumed.  In your case, you want a "unique arbitrary
(user-defined) id/nickname".

But heck, your English beats the pants of any skills *I* have in
a foreign language. :)

-tim





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



Re: 4 beginner's questions

2007-07-21 Thread Stefan Matthias Aust

2007/7/21, Nis Jørgensen <[EMAIL PROTECTED]>:
>
> Stefan Matthias Aust skrev:
> >
> > Let's assume you have users who are allowed to assign nick names to
> > theirselves and still all thoses nick names must be different. This is
> > want I call a random ID.
> >
> If a user assigns it, it is not random, by any definition of random I
> can think of.

From the server's point of view it is random - IMHO - because the
server cannot guess it and users don't know the choices of other
users. Perhaps there's a better English word, I'd call it "zufällig".

> I do see the use case for random unique values - for instance to give
> each object a url without making it possible for a visitor to retrieve
> all the objects.

That would be another use case. Yet another would be to use random IDs
to not but a bias on some objects - that is you don't want to reveal
whether some object was entered before another object.

-- 
Stefan Matthias Aust // Truth until paradox

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



Re: 4 beginner's questions

2007-07-21 Thread Nis Jørgensen

Stefan Matthias Aust skrev:
>
> Let's assume you have users who are allowed to assign nick names to
> theirselves and still all thoses nick names must be different. This is
> want I call a random ID.
>   
If a user assigns it, it is not random, by any definition of random I
can think of.

I do see the use case for random unique values - for instance to give
each object a url without making it possible for a visitor to retrieve
all the objects. Very weak security of course, but some kind of security
still.

Nis




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



Re: 4 beginner's questions

2007-07-21 Thread Stefan Matthias Aust

2007/7/19, Collin Grady <[EMAIL PROTECTED]>:

> However, it seems like a poor solution to spam INSERTS until you get a
> valid ID. Why exactly do you need a random ID?

Let's assume you have users who are allowed to assign nick names to
theirselves and still all thoses nick names must be different. This is
want I call a random ID.

-- 
Stefan Matthias Aust

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



Re: 4 beginner's questions

2007-07-19 Thread Carl Karsten

Stefan Matthias Aust wrote:
> Carl, Jeremy,
> 
> Thanks for your answers.
> 
> Carl wrote:
> 
>> I just made this.  it should answer most of 1 and 2.
>> http://code.djangoproject.com/wiki/DatabaseReset
> 
> Somehow, it seems to me that there should be a standard utility
> function to initialize the system for command line tools. I saw your
> "nifty trick" twice and I used a similar approach.

I vote for ./manage.py -runscript myscript.py
which apparently has been shot down in the past.

> 
> Your migrate.py script seems to be very specific to your
> mysql-specific use case.

yes, but only for reading.  The writes into django db are all via the django db 
api.

The page is boarder line wiki worthy, but I got tired of pasting the same 3 
files into dpaste.com :)

Carl K

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



Re: 4 beginner's questions

2007-07-19 Thread Stefan Matthias Aust

Carl, Jeremy,

Thanks for your answers.

Carl wrote:

> I just made this.  it should answer most of 1 and 2.
> http://code.djangoproject.com/wiki/DatabaseReset

Somehow, it seems to me that there should be a standard utility
function to initialize the system for command line tools. I saw your
"nifty trick" twice and I used a similar approach.

Your migrate.py script seems to be very specific to your
mysql-specific use case.

Jeremy wrote:

> > What's the recommended way to access models from outside of views?

> What you have is pretty good, but do this, too, in order to make sure
> all models are loaded (so that descriptors for relationships are
> contributed to reverse models: [...]

Thanks, I changed my code.

> > 3) I need to create an object with a unique random id -
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/163604

Oh, it's not creating the ID, my question was whether I can safely
assume that I will always get an IntegrityError (and nothing else) and
whether just inserting stuff and catching errors is the recommended
Pythonic way.

-- 
Stefan Matthias Aust // Truth until paradox

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



Re: 4 beginner's questions

2007-07-19 Thread Jeremy Dunck

On 7/19/07, Stefan Matthias Aust <[EMAIL PROTECTED]> wrote:
> 1) It is important for me to recreate my environment from scratch
> (that is, from the VCS). I'd like to have a working application after
> calling "syncdb". For my own application, I've create an initial_data
> fixture. But I'd like to recreate users and permissions, too.

If you don't mind calling manage.py loaddata a few more times, yes.

The parameter there is the name of the fixture, *not* the name of an app.
http://www.djangoproject.com/documentation/django-admin/#loaddata-fixture-fixture
Fixtures in other dirs:
http://www.djangoproject.com/documentation/settings/#fixture-dirs

...
> it seems that
> "syncdb" always asks for an admin account on the console. Can I
> somehow suppress that question? Instead, I'd like to load some saved
> fixture.

--noinput
http://www.djangoproject.com/documentation/django-admin/#noinput

> What's the recommended way to access models from outside of views?
>

What you have is pretty good, but do this, too, in order to make sure
all models are loaded (so that descriptors for relationships are
contributed to reverse models:

from django.db.models import get_models
get_models()


> 3) I need to create an object with a unique random id -

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/163604

> "is enforced at the database level" but it unfortunately
> does not describe what happens if the constraint is violated. Will
> this always raise an IntegrityError?

Yes.  It just doesn't let you insert dupes; there is no id-generation
fallback (unless it's an autofield).

... Leaving #4 unanswered; your understanding seems correct.

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



Re: 4 beginner's questions

2007-07-19 Thread Carl Karsten

Stefan Matthias Aust wrote:
> Hi,
> 
> Coming from a Java background, I introduced Django in my company for a
> new web application. So far, we made great progress and web
> development suddenly was fun again. Unfortunately, it feels like all
> time I save because of Django, is spent on searching for an IDE (I
> still haven't found something really usable), reading the doc and
> solving trivial Python problems. I hope this will get better once I
> have more experience with Python.
> 
> I've a few questions regarding Django I'd like to ask in this and future 
> mails.
> 
> 1) It is important for me to recreate my environment from scratch
> (that is, from the VCS). I'd like to have a working application after
> calling "syncdb". For my own application, I've create an initial_data
> fixture. But I'd like to recreate users and permissions, too.
> 
> Is this possible?
> 
> I looked into django/core/management.py and it seems that "load_data"
> simple enumerates the installed application so if I want to create a
> fixture for "auth", the initial_data file must be located inside the
> django installation. This isn't an option. Furthermore, it seems that
> "syncdb" always asks for an admin account on the console. Can I
> somehow suppress that question? Instead, I'd like to load some saved
> fixture.
> 
> 2) I'd like to run batch application against our database
> (periodically using cron). Of course, I'd like to use the same
> database abstraction as Django uses, so I tried to find a way to
> initialize the system.
> 
> What's the recommended way to access models from outside of views?
> 
> I came up with these lines (conveniently located inside the project folder):
> 
>  #!/usr/bin/env python
>  ...
>  if __name__ == '__main__':
>from django.core.management import setup_environ
>import settings
>PROJECT_DIRECTORY = setup_environ(settings)
> 
>from demo.models import Demo
>d = Demo.objects.get(...)
>...
>d.save()
> 

I just made this.  it should answer most of 1 and 2.
http://code.djangoproject.com/wiki/DatabaseReset

> 3) I need to create an object with a unique random id - and I would
> prefer not to use the database specific SQL layer. What's the best way
> to do it? My naive approach is to declare the id field unique and
> simply try to insert objects until I get no error. The documentation
> says [unique] "is enforced at the database level" but it unfortunately
> does not describe what happens if the constraint is violated. Will
> this always raise an IntegrityError?
> 

Why a unique _random_ id.  seems odd.  knowing the use case might help.

> 4) I'd like to specify the file name of an uploaded file. Right now,
> the original filename is kept and I think, this could cause problems
> if two people upload a file with the same name at the same time.
> 
> I tried to understand the file upload process in the Django source but
> there was too much meta magic for my brain. However, it seems that the
> current documentation doesn't tell the whole story. It seems, that
> there is a save_FOO_file() in addition to the documentation tree
> get_FOO_xxx methods... My guess is that manipulators.py is responsible
> for saving the uploaded file. ... Wait, I think, _save_FIELD_file()
> will eventually save the file and yes, that while loop is obviously
> not threadsafe! So I need to set the filename myself. But how?
> 

good Q  hopfully someone can answer it. :)

Carl K

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



4 beginner's questions

2007-07-19 Thread Stefan Matthias Aust

Hi,

Coming from a Java background, I introduced Django in my company for a
new web application. So far, we made great progress and web
development suddenly was fun again. Unfortunately, it feels like all
time I save because of Django, is spent on searching for an IDE (I
still haven't found something really usable), reading the doc and
solving trivial Python problems. I hope this will get better once I
have more experience with Python.

I've a few questions regarding Django I'd like to ask in this and future mails.

1) It is important for me to recreate my environment from scratch
(that is, from the VCS). I'd like to have a working application after
calling "syncdb". For my own application, I've create an initial_data
fixture. But I'd like to recreate users and permissions, too.

Is this possible?

I looked into django/core/management.py and it seems that "load_data"
simple enumerates the installed application so if I want to create a
fixture for "auth", the initial_data file must be located inside the
django installation. This isn't an option. Furthermore, it seems that
"syncdb" always asks for an admin account on the console. Can I
somehow suppress that question? Instead, I'd like to load some saved
fixture.

2) I'd like to run batch application against our database
(periodically using cron). Of course, I'd like to use the same
database abstraction as Django uses, so I tried to find a way to
initialize the system.

What's the recommended way to access models from outside of views?

I came up with these lines (conveniently located inside the project folder):

 #!/usr/bin/env python
 ...
 if __name__ == '__main__':
   from django.core.management import setup_environ
   import settings
   PROJECT_DIRECTORY = setup_environ(settings)

   from demo.models import Demo
   d = Demo.objects.get(...)
   ...
   d.save()

3) I need to create an object with a unique random id - and I would
prefer not to use the database specific SQL layer. What's the best way
to do it? My naive approach is to declare the id field unique and
simply try to insert objects until I get no error. The documentation
says [unique] "is enforced at the database level" but it unfortunately
does not describe what happens if the constraint is violated. Will
this always raise an IntegrityError?

4) I'd like to specify the file name of an uploaded file. Right now,
the original filename is kept and I think, this could cause problems
if two people upload a file with the same name at the same time.

I tried to understand the file upload process in the Django source but
there was too much meta magic for my brain. However, it seems that the
current documentation doesn't tell the whole story. It seems, that
there is a save_FOO_file() in addition to the documentation tree
get_FOO_xxx methods... My guess is that manipulators.py is responsible
for saving the uploaded file. ... Wait, I think, _save_FIELD_file()
will eventually save the file and yes, that while loop is obviously
not threadsafe! So I need to set the filename myself. But how?

-- 
Stefan Matthias Aust

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