Re: Tutorial confusion: flat project layout with django 1.3.1

2011-10-16 Thread Kirill Spitsin
On Sun, Oct 16, 2011 at 07:27:42PM -0700, garyrob wrote:
> I'm having a strange problem.
> 
> When I run
> 
>   django-admin startproject mysite
> 
> I get a directory structure that is flat in the sense that there is no inner 
> mysite directory -- the manage.py and urls.py files are at the same level.
> 
> But Part 1 of the django tutorial 
> (https://docs.djangoproject.com/en/dev/intro/tutorial01/) shows a directory 
> structure with an inner mysite, such that manage.py is at the top layer and 
> urls.py is in the inner mysite. And it also says:
...

You are reading tutorial for development version of Django, and
startproject default layout was recently changed [1].  Tutorial for
1.3 is here: https://docs.djangoproject.com/en/1.3/intro/tutorial01/

[1] https://code.djangoproject.com/changeset/16964

-- 
Kirill Spitsin

-- 
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: ALL CAPS input and Sentence case

2011-07-26 Thread Kirill Spitsin
On Tue, Jul 26, 2011 at 07:19:46PM +0300, Kirill Spitsin wrote:
> On Tue, Jul 26, 2011 at 08:48:24AM -0700, christian.posta wrote:
> > For user input, I would like to format what they enter into 'sentence
> > case'
> > Example, if they input ALL CAPS for a description, I want to lowercase
> > that, but according to sentence rules (first word in sentence upper
> > case, rest lowercase up to the period).
> > 
> > I was hoping something like this exists as a convenience function/
> > module, but if not i guess i'll have to write it myself.
> 
> >>> 'ALL CAPS. aNd MixED.'.title()
> 'All Caps. And Mixed.'

Or, sorry, I've read your question carelessly.

You can try this code, seems to do what you want:
http://mail.python.org/pipermail/tutor/2004-September/031859.html

-- 
Kirill Spitsin

-- 
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: ALL CAPS input and Sentence case

2011-07-26 Thread Kirill Spitsin
On Tue, Jul 26, 2011 at 08:48:24AM -0700, christian.posta wrote:
> For user input, I would like to format what they enter into 'sentence
> case'
> Example, if they input ALL CAPS for a description, I want to lowercase
> that, but according to sentence rules (first word in sentence upper
> case, rest lowercase up to the period).
> 
> I was hoping something like this exists as a convenience function/
> module, but if not i guess i'll have to write it myself.

>>> 'ALL CAPS. aNd MixED.'.title()
'All Caps. And Mixed.'

-- 
Kirill Spitsin

-- 
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: Database doubt

2011-07-26 Thread Kirill Spitsin
On Tue, Jul 26, 2011 at 04:50:27AM -0700, vaibhav agarwal wrote:
> Hey,
> 
> I am coding in django for the first time and I had this doubt about
> database.At the start of coding , you are not sure of all the fields
> in the models of your site. So you end up making a few fields and
> proceed . But if at some other time , you might realise that you have
> to add a new field . In such a case syncdb does not change the table
> ( maybe deleting or adding fields ) . What  should I be doing in such
> a case ?

Use South [1]_, it addresses exactly this task.

.. [1] http://south.aeracode.org/

-- 
Kirill Spitsin

-- 
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: Need help intercepting SQL

2011-07-11 Thread Kirill Spitsin
On Sun, Jul 10, 2011 at 02:41:59PM -0700, Eric B wrote:
> Our web site uses Django 1.2.  We're adding a layer to our MySQL
> database called dbShards for fragmentation (sharding).  I need to
> prepend instructive SQL comments (/* ... */) to UPDATE statements in
> certain situations.  What's the best way to intercept the raw SQL sent
> to the database?

You can override django.db.models.sql.compiler.SQLUpdateCompiler.as_sql()
method [1], and then make a custom database backend, which would point to
your modified compiler ([2], [3]).  Or you could monkey-patch Django's compiler.
Feels somewhat hackish, but should work :).

.. [1] 
https://code.djangoproject.com/browser/django/branches/releases/1.2.X/django/db/models/sql/compiler.py#L812
.. [2] 
https://code.djangoproject.com/browser/django/branches/releases/1.2.X/django/db/backends/__init__.py#L106
.. [3] 
https://code.djangoproject.com/browser/django/branches/releases/1.2.X/django/db/backends/__init__.py#L280

-- 
Kirill Spitsin

-- 
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: How do I access a field's verbose_name?

2011-06-20 Thread Kirill Spitsin
On Mon, Jun 20, 2011 at 08:54:14AM -0700, Jeff Blaine wrote:
> I'd like to make use of a field's verbose_name in some code instead of
> duplicating that sort of info.  Can someone show me how?

>>> SomeModel._meta.get_field(field_name).verbose_name

-- 
Kirill Spitsin

-- 
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: Confusion about DJANGO_SETTINGS_MODULE

2011-06-02 Thread Kirill Spitsin
On Thu, Jun 02, 2011 at 05:29:01AM -0700, Kann wrote:
> Thanks Oscar, I read the page already, but am still not totally
> understood. The page said the value of DJANGO_SETTINGS_MODULE should
> be "Python path syntax", e.g.  mysite.settings. What exactly is
> "Python path syntax"? Would it be ok if I just provide the value as a
> file name? Perhaps, "new_setting.py"?

"new_setting"

And i would recommend you read this part of python tutorial:

http://docs.python.org/tutorial/modules.html

-- 
Kirill Spitsin

-- 
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: spawning threads within test cases in django test framework

2011-06-01 Thread Kirill Spitsin
On Tue, May 31, 2011 at 02:01:00PM -0700, Brian wrote:
> I've got a django app with a periodically scheduled background task that 
> updates the database. I've written a bunch of tests for its principal class 
> that are run as part of the django unit test framework. I want to convert 
> the class to do its work using multiple threads, but I'm having trouble 
> getting the tests to run against the multi-threaded version.
> 
> I've tried sqlite3 and postgres as back-ends, but to no avail. Is there a 
> problem where the testing framework uses transactions to rollback any 
> changes from one test to the next and so the evolving state of the database 
> in that transaction is hidden from the other threads? 

Right.

> Can the database connection (and hence transaction) be shared between
> the threads? Has anyone encountered this problem before? (And,
> ideally, came up with a really neat solution...)

Try to use TransactionTestCase instead of TestCase (and don't use
in-memory SQLite datebase).

-- 
Kirill Spitsin

-- 
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: save out a test database?

2011-06-01 Thread Kirill Spitsin
On Wed, Jun 01, 2011 at 11:59:28AM -0700, Margie Roginski wrote:
> That's a good pointer, thanks.  However I'm still confused about how I
> can actually dump out the data from my test run?  For example, say I
> have a particular test and I want to dump the data at some certain
> point.  I can put in pdb.set_trace() in the code to stop at the
> appropriate point, but what do I call from that point to create the
> mydata.json file that then gets loaded with the command
> 
>   django-admin.py testserver mydata.json

>>> from django.core.serializers import serialize
>>> queryset1 = Model1.objects.filter(...)
>>> queryset2 = Model2.objects.filter(...)
>>> fixture = serialize('json', list(queryset1) + list(queryset2))
>>> f = open('mydate.json', 'w')
>>> f.write(fixture)
>>> f.close()

-- 
Kirill Spitsin

-- 
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 DATETIME_FORMAT Localization

2011-05-31 Thread Kirill Spitsin
On Wed, May 25, 2011 at 10:46:30AM -0700, jrs_66 wrote:
> How can I do something like strptime(request.POST["start-date"],
> mycurrent_DATETIME_FORMAT)... There's got to be an undocumented way of
> referencing the constant currently being used?

I guess you need `django.utils.formats.date_format` function.

-- 
Kirill Spitsin

-- 
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: Can I perform an "alter table" to remove a "not null" constraint?

2011-05-31 Thread Kirill Spitsin
On Mon, May 30, 2011 at 09:52:27PM -0700, Gchorn wrote:
> It seems as though the default in Django when creating tables is to
> place a constraint that doesn't allow null values (contrary to what
> I've learned is the default for SQL in general).  I have a model which
> has a date attribute, and which I now want to be able to hold null
> values, but when I tried doing this by adding 'null = True' and 'blank
> = True' to the model's field options, Django generates a

Use South (http://south.aeracode.org/).

Or you can run ./manage.py dbshell, and ALTER TABLE yourself, for
example, for PostgreSQL::

ALTER TABLE  ALTER COLUMN  DROP NOT NULL;

-- 
Kirill Spitsin

-- 
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: setlang using AJAX

2011-05-30 Thread Kirill Spitsin
On Mon, May 30, 2011 at 08:03:46AM -0700, Luca Casagrande wrote:
> Thank you very much, for your help and your code.
> The problem is that the POST request is missing the csrf_token and so
> I have got a 403 Error.

https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#ajax

-- 
Kirill Spitsin

-- 
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: admin ordering for NULL fields

2011-05-27 Thread Kirill Spitsin
On Fri, May 27, 2011 at 12:35:26AM -0700, Dennis Schmidt wrote:
> In the admin panel I set a (descending) ordering on a model's date
> field. That's fine of course. Now, the "problem" is, that this field
> may be NULL in some cases and I want these items to appear at the
> beginning of the list. They appear at the very end. If I set the
> ordering to ASCENDING, then they do appear at the beginning but the
> rest of the order is, of course, not how I want it.
> 
> So I couldn't find something in the documentation how I could achieve
> what I want. Any tips, hints?

http://www.mail-archive.com/django-users@googlegroups.com/msg64668.html

-- 
Kirill Spitsin

-- 
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 model manager "live" object issues

2011-05-19 Thread Kirill Spitsin
On Wed, May 18, 2011 at 11:45:46PM -0700, James Hargreaves wrote:
...
> Firstly, when I query for LIVE objects in my view via
> Article.live.all() if I refresh the page repeatedly I can see (in
> MYSQL logs) the same database query being made with exactly the same
> date in the where clause - ie - the datetime.datetime.now() is being
> evaluated at compile time rather than runtime. I need the date to be
> evaluated at runtime.

I can't reproduce such behavior.  `.get_query_set()` is evaluted when
queryset is returned from manager, so, maybe, you cache queryset
somewhere in your view?

> Secondly, when I use the articles_set method on the Category object
> this appears to work correctly - the datetime used in the query
> changes each time the query is run - again I can see this in the logs.
> However, I am not quite sure why this works, since I don't have
> anything in my code to say that the articles_set query should return
> LIVE entries only!?

The first manager defined on model is interepted as "default manager".
You probably want to put line with `live` manager after `objects`
manager in `Article` declaration.

> Finally, why is none of this being cached?

Not quite so, QuerySet has a cache [1].

.. [1] 
http://docs.djangoproject.com/en/1.3/topics/db/queries/#caching-and-querysets

-- 
Kirill Spitsin

-- 
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: Built-in login form via inclusion tag

2011-05-19 Thread Kirill Spitsin
> On 13 Maj, 14:55, Gabe  wrote:
...
> > It seems like it don`t know enything about form variable. How can I
> > give it to it via inclusion tag?

You should return template context with `form` variable::

from django.contrib.auth.forms import AuthenticationForm

@register.inclusion_tag("you_template.html")
def login_tag():
form = AuthenticationForm()
return {"form": form,}

-- 
Kirill Spitsin

-- 
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: Where does SessionMiddleware load the session object from the SessionStore backend?

2011-05-12 Thread Kirill Spitsin
On Thu, May 12, 2011 at 03:39:39PM -0700, Andy wrote:
> Thanks. I did notice the load() method.
> 
> But can you tell me where is that method called?

session[key]:

SessionBase.__getitem__(key):
return self._session[key]
http://code.djangoproject.com/browser/django/trunk/django/contrib/sessions/backends/base.py#L46

SessionBase._session is a property, with getter SessionBase._get_session():
http://code.djangoproject.com/browser/django/trunk/django/contrib/sessions/backends/base.py#L168

and in _get_session() SessionBase.load() is called.

-- 
Kirill Spitsin

-- 
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: Where does SessionMiddleware load the session object from the SessionStore backend?

2011-05-12 Thread Kirill Spitsin
On Thu, May 12, 2011 at 01:58:07PM -0700, Andy wrote:
...
> So basically SessionStore just creates a new instance without trying
> to look up in the database to see whether that session already exists
> or not. But shouldn't that be the whole point of session -- for every
> request Django needs to look up in the session database to see if the
> session is already there? I'm guess at someplace this database lookup
> takes place but I can't find it.
> 
> Can you tell me where can i find it? Or did I misunderstand how
> session work in Django?

Django loads session from store lazily, after first access to session,
in `SessionStore.load()` method.  For example:

https://code.djangoproject.com/browser/django/trunk/django/contrib/sessions/backends/db.py#L16

-- 
Kirill Spitsin

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