DB Api, OR queries?

2005-09-02 Thread Milton

Is it possible to do the following using the DB API or would I be
better off running a manual sql query? from the docs it appears you can
only do AND queries?

select * from table where col='value' or col='value2'

It's a simplified example. My goal is to be able to do keyword matching
using "contains" across currently active stories in the database.



Re: limit_choices_to users in a specific group

2005-09-02 Thread scottpierce

Well, I gave up.  I had hoped it would be a little cleaner but this
works:

def _getTeachers():
   u = users.get_list(
 tables=['auth_users_groups','auth_groups'],
 where=["auth_groups.name = 'teacher'",
"auth_users_groups.group_id = auth_groups.id",
"auth_users_groups.user_id = auth_users.id"])
   return tuple([(y[0:2],y) for y in [str(x) for x in u]])

def _getStudents():
   s =  users.get_list(
 tables=['auth_users_groups','auth_groups'],
 where=["auth_groups.name = 'student'",
"auth_users_groups.group_id = auth_groups.id",
"auth_users_groups.user_id = auth_users.id"])
   return tuple([(y[0:2],y) for y in [str(x) for x in s]])

# Create your models here.
class Assignment(meta.Model):
   id = meta.AutoField('ID', primary_key=True)
   assigner = meta.ForeignKey(User, choices=_getTeachers(),
verbose_name="user making assignment")
   assignee = meta.ForeignKey(User, choices=_getStudents(),
verbose_name="user receiving assignment")



Re: extending admin interface

2005-09-02 Thread scottpierce

Post the code after making the recommended changes.



Re: MySQL problem

2005-09-02 Thread Eugene Lazutkin

Hmm. connection_timeout is 5. Might be the problem. Or not.


"Eugene Lazutkin" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> Simon,
>
> Thank you for good suggestion. I checked the variable. It's value is 
> 28800. I am sure that none of my queries takes 8 hours to complete.
>
> Most probably Django keeps connections open between requests (make sense 
> for performance). That connection is closed after 8 hours but Django (?) 
> assumes it is still open and breaks when query is unsuccessful. Am I 
> right?
>
> This problem is compounded (possibly) with related problems. I use FCGI 
> method outlined here: http://wiki.dreamhost.com/index.php/Django. It looks 
> like after exception I have a dead process in memory, which I have to kill 
> manually using "kill -9". Otherwise it is going to be here forever. Well, 
> most probably it is a problem of fcgi.py.
>
> Anyway, number of python2.3 processes grows until I hit some predefined 
> limit => system tries to kill these processes => they don't care (should 
> be killed with -9) => they are still around => web site dies, until I log 
> in to shoot the undead processes down.
>
> Any help is appreciated.
>
> Thanks,
>
> Eugene
>
> PS: I wish more providers allowed to use mod_python and PostgreSQL...
>
>
> "GrumpySimon" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>>
>> This error often occurs when MySQL times out because the query's taking
>> too long.
>>
>> At a guess this would be at the MySQL end of things - try running this
>> command at the mysql prompt:
>>
>> SHOW VARIABLES LIKE 'wait_timeout';
>>
>> You should get something like this:
>> +---+--+
>> | Variable_name | Value |
>> +---+--+
>> | wait_timeout  | 28800   |
>> +---+---+
>> 1 row in set (0.00 sec)
>>
>>
>> Where Value is the number of seconds. You can override this by issuing
>> this command:
>> set wait_timeout = $largernumber
>>
>> More reasons for this error are here:
>> http://dev.mysql.com/doc/mysql/en/gone-away.html
>>
>> --Simon
>>
>>
>
>
>
> 





Re: MySQL problem

2005-09-02 Thread Eugene Lazutkin

Simon,

Thank you for good suggestion. I checked the variable. It's value is 28800. 
I am sure that none of my queries takes 8 hours to complete.

Most probably Django keeps connections open between requests (make sense for 
performance). That connection is closed after 8 hours but Django (?) assumes 
it is still open and breaks when query is unsuccessful. Am I right?

This problem is compounded (possibly) with related problems. I use FCGI 
method outlined here: http://wiki.dreamhost.com/index.php/Django. It looks 
like after exception I have a dead process in memory, which I have to kill 
manually using "kill -9". Otherwise it is going to be here forever. Well, 
most probably it is a problem of fcgi.py.

Anyway, number of python2.3 processes grows until I hit some predefined 
limit => system tries to kill these processes => they don't care (should be 
killed with -9) => they are still around => web site dies, until I log in to 
shoot the undead processes down.

Any help is appreciated.

Thanks,

Eugene

PS: I wish more providers allowed to use mod_python and PostgreSQL...


"GrumpySimon" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> This error often occurs when MySQL times out because the query's taking
> too long.
>
> At a guess this would be at the MySQL end of things - try running this
> command at the mysql prompt:
>
> SHOW VARIABLES LIKE 'wait_timeout';
>
> You should get something like this:
> +---+--+
> | Variable_name | Value |
> +---+--+
> | wait_timeout  | 28800   |
> +---+---+
> 1 row in set (0.00 sec)
>
>
> Where Value is the number of seconds. You can override this by issuing
> this command:
> set wait_timeout = $largernumber
>
> More reasons for this error are here:
> http://dev.mysql.com/doc/mysql/en/gone-away.html
>
> --Simon
>
> 





Re: MySQL problem

2005-09-02 Thread GrumpySimon

This error often occurs when MySQL times out because the query's taking
too long.

At a guess this would be at the MySQL end of things - try running this
command at the mysql prompt:

SHOW VARIABLES LIKE 'wait_timeout';

You should get something like this:
+---+--+
| Variable_name | Value |
+---+--+
| wait_timeout  | 28800   |
+---+---+
1 row in set (0.00 sec)


Where Value is the number of seconds. You can override this by issuing
this command:
set wait_timeout = $largernumber

More reasons for this error are here:
http://dev.mysql.com/doc/mysql/en/gone-away.html

--Simon



Re: Ticket reports

2005-09-02 Thread Jeremy Dunck

On 9/2/05, Jeremy Dunck <[EMAIL PROTECTED]> wrote:
> Sorry, from here[1], I see that Trac admins can add reports to the
> list of ones supplied with the software.

I should point out that I don't know if Trac is smart about SQL
injection, which may make parameterization dangerous.


Re: Ticket reports

2005-09-02 Thread Jeremy Dunck

On 9/2/05, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
> 
> On 9/1/05, Jeremy Dunck <[EMAIL PROTECTED]> wrote:
> > Can we get a report which takes wildcards for ticket summary and 
> > description?
> >
> > With a small number of active tickets, it's not such an issue, but
> > it's at 160 and climbing slowly.
> 
> What do you mean?

Sorry, from here[1], I see that Trac admins can add reports to the
list of ones supplied with the software.

I also see that reports can be parameterized, so that a like clause
could be used on fields.  This could be used find issues which include
the text "DB", for example.

I'm asking that a report be added which supports parameterization and
uses that parameter to find issues including that text in the summary
and description fields.

I think this query would do something like I want (not tested, since I
don't have an install of trac handy):

SELECT id AS ticket, status, severity, priority, owner, 
   time as created, summary FROM ticket 
  WHERE status IN ('new', 'assigned', 'reopened')
  AND (summary like '$in_summary' or description like '$in_description')
  ORDER BY priority, time

[1]
http://code.djangoproject.com/wiki/TracReports


Re: MySQL problem

2005-09-02 Thread Eugene Lazutkin

(1, 2, 1, 'gamma', 2)

Note: the latest Python they have is 2.3. That's what I use.

"Adrian Holovaty" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

On 9/2/05, Eugene Lazutkin <[EMAIL PROTECTED]> wrote:
> I host my Django app on Dreamhost. They provide MySQL. I am getting a 
> weird
> MySQL-related error on regular basis: "OperationalError: (2013, 'Lost
> connection to MySQL server during query')".
> [..]
> Can it be Django's problem? One possibility is Django sets some timeout
> property on MySQL connection, which is too small. Or default timeout is 
> too
> small. Maybe some code should check that connection is alive and
> re-establish it, if it is dead.

Hey Eugene,

Django doesn't do any sort of timeout, so I suspect it's an error with
MySQLdb, the Python MySQL bindings. Which version of MySQLdb is
Dreamhost using? To find that out, do this:

"""
import MySQLdb
print MySQLdb.version_info
"""

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org





Re: Ticket reports

2005-09-02 Thread Adrian Holovaty

On 9/1/05, Jeremy Dunck <[EMAIL PROTECTED]> wrote:
> Can we get a report which takes wildcards for ticket summary and description?
> 
> With a small number of active tickets, it's not such an issue, but
> it's at 160 and climbing slowly.

What do you mean?

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Re: MySQL problem

2005-09-02 Thread Adrian Holovaty

On 9/2/05, Eugene Lazutkin <[EMAIL PROTECTED]> wrote:
> I host my Django app on Dreamhost. They provide MySQL. I am getting a weird
> MySQL-related error on regular basis: "OperationalError: (2013, 'Lost
> connection to MySQL server during query')".
> [..]
> Can it be Django's problem? One possibility is Django sets some timeout
> property on MySQL connection, which is too small. Or default timeout is too
> small. Maybe some code should check that connection is alive and
> re-establish it, if it is dead.

Hey Eugene,

Django doesn't do any sort of timeout, so I suspect it's an error with
MySQLdb, the Python MySQL bindings. Which version of MySQLdb is
Dreamhost using? To find that out, do this:

"""
import MySQLdb
print MySQLdb.version_info
"""

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


MySQL problem

2005-09-02 Thread Eugene Lazutkin

Hello,

I host my Django app on Dreamhost. They provide MySQL. I am getting a weird 
MySQL-related error on regular basis: "OperationalError: (2013, 'Lost 
connection to MySQL server during query')". Typical traceback is at the end 
of this message.

Typically it happens when I do 1st-2nd access to my app after long pause 
(~hour or so). Usually it works fine after that until I stop using it for 
several hours. It may be Dreamhost's problem (e.g., network connection is 
flakey) but I cannot believe it went unnoticed for so long.

Can it be Django's problem? One possibility is Django sets some timeout 
property on MySQL connection, which is too small. Or default timeout is too 
small. Maybe some code should check that connection is alive and 
re-establish it, if it is dead.

Another possibility is I am doing something wrong. Well, the app works fine 
locally without any hiccups. It works as expected after first "lost 
connection" error(s). I don't use any raw SQL.

I am at loss. I appreciate any ideas.

Thanks,

Eugene

===
  File "/home/myname/djsrc/django/core/handlers/base.py", line 64, in 
get_response
response = callback(request, **param_dict)

  File "/home/myname/djsrc/django/views/generic/date_based.py", line 49, in 
archive_index
return HttpResponse(t.render(c))

  File "/home/myname/djsrc/django/core/template.py", line 115, in render
return self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/template_loader.py", line 97, in 
render
return compiled_parent.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 115, in render
return self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/template_loader.py", line 97, in 
render
return compiled_parent.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 115, in render
return self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/template_loader.py", line 54, in 
render
result = self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/defaulttags.py", line 107, in render
nodelist.append(node.render(context))

  File "/home/myname/djp/home/apps/blog/templatetags/blog.py", line 99, in 
render
context['info']  = template.Template(INFO_TEMPLATE).render(context)

  File "/home/myname/djsrc/django/core/template.py", line 115, in render
return self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/template.py", line 470, in render
output = resolve_variable_with_filters(self.var_string, context)

  File "/home/myname/djsrc/django/core/template.py", line 411, in 
resolve_variable_with_filters
obj = resolve_variable(var, context)

  File "/home/myname/djsrc/django/core/template.py", line 389, in 
resolve_variable
current = current()

  File "/home/myname/djsrc/django/utils/functional.py", line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + 
morekwargs.items()))

  File "/home/myname/djsrc/django/core/meta/__init__.py", line 873, in 
method_get_many_to_one
retrieved_obj = mod.get_object(**{'%s__exact' % 
field_with_rel.rel.field_name: val})

  File "/home/myname/djsrc/django/utils/functional.py", line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + 
morekwargs.items()))

  File "/home/myname/djsrc/django/core/meta/__init__.py", line 1080, in 
function_get_object
obj_list = function_get_list(opts, klass, **kwargs)

  File "/home/myname/djsrc/django/core/meta/__init__.py", line 1120, in 
function_get_list
return list(function_get_iterator(opts, klass, **kwargs))

  File "/home/myname/djsrc/django/core/meta/__init__.py", line 1103, in 
function_get_iterator
cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " or 
"") + ",".join(select) + sql, params)

  File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line 137, in 
execute
self.errorhandler(self, exc, value)

  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 33, 
in defaulterrorhandler
raise errorclass, errorvalue

OperationalError: (2013, 'Lost connection to MySQL server during query')

===





Re: Caching error: object has no attribute '_cache_middleware_set_cache'

2005-09-02 Thread Adrian Holovaty

On 9/2/05, Number one <[EMAIL PROTECTED]> wrote:
> It worked! All pages show up perfectly now. I just copied the settings
> from the documentation on the djangoproject.com.
> 
> Is this an bug? Because, according to the documentation it shouldn't
> matter where you put the CacheMiddleware entry.

Sweet. Nope, it's not a bug -- CacheMiddleware needs to be the first
entry in MIDDLEWARE_CLASSES, because middleware is applied in order.

I've updated the docs to explain this. Thanks for pointing it out!

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Re: Caching error: object has no attribute '_cache_middleware_set_cache'

2005-09-02 Thread Number one

Adrian,

It worked! All pages show up perfectly now. I just copied the settings
from the documentation on the djangoproject.com.

Is this an bug? Because, according to the documentation it shouldn't
matter where you put the CacheMiddleware entry.

Thanks very much for your quick response!

Berry.



Re: Caching error: object has no attribute '_cache_middleware_set_cache'

2005-09-02 Thread Adrian Holovaty

On 9/2/05, Number one <[EMAIL PROTECTED]> wrote:
> I got the following error when I activate caching:
> [...]
> MIDDLEWARE_CLASSES = (
> "django.middleware.common.CommonMiddleware",
> "django.middleware.cache.CacheMiddleware",
> )

Try making CacheMiddleware the first entry in MIDDLEWARE_CLASSES, and
let us know what happens.

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


Caching error: object has no attribute '_cache_middleware_set_cache'

2005-09-02 Thread Number one

I got the following error when I activate caching:
--
Mod_python error: "PythonHandler django.core.handlers.modpython"
Traceback (most recent call last):
  File "/usr/lib64/python2.3/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
result = object(req)
  File
"/usr/lib64/python2.3/site-packages/django/core/handlers/modpython.py",
line 164, in handler
return ModPythonHandler()(req)
  File
"/usr/lib64/python2.3/site-packages/django/core/handlers/modpython.py",
line 145, in __call__
response = middleware_method(request, response)
  File "/usr/lib64/python2.3/site-packages/django/middleware/cache.py",
line 78, in process_response
if request._cache_middleware_set_cache:
AttributeError: 'ModPythonRequest' object has no attribute
'_cache_middleware_set_cache'
--

It does not occur on all my pages, but only on a particular set. When I
deactivate caching the same pages show up just fine.

It also happens when I access a page that does not exist (a bad URL).
Normally this would generate a Http404, but when I activate caching the
error occurs.

The settings I use are the following:
#CacheMiddleware settings
CACHE_MIDDLEWARE_SECONDS = 60 * 60 * 1 # 1 hour
CACHE_MIDDLEWARE_KEY_PREFIX = 'mydjangocache'
CACHE_MIDDLEWARE_GZIP = True

MIDDLEWARE_CLASSES = (
"django.middleware.common.CommonMiddleware",
"django.middleware.cache.CacheMiddleware",
)

Anybody any ideas how I can resolve this issue?

Thanks.



Re: multiple model files

2005-09-02 Thread Maniac


Adrian Holovaty wrote:


"django-admin.py sql" shows SQL statements for the given model module.
So if your models are split across multiple modules, you'll have to do
each one at a time.
 

Ah! That's why... The confusion is caused by django-admin.py saying in 
--help that 'sql' command requires 'app', not 'module'.

Filed: http://code.djangoproject.com/ticket/454


Re: multiple model files

2005-09-02 Thread Adrian Holovaty

On 9/2/05, asrenzo <[EMAIL PROTECTED]> wrote:
> I tried to do what's written in the doc (or in this group) to split my
> Poll.py model into several sub-files. I changed the __init__.py of my
> app to look for all other files.
> 
> __ALL__ = ['Poll', 'Choices']
> 
> but a django-admin sql Poll only shows sql statments for Poll model.
> And this even if I save a __ALL__ = [] into __init__.py.

"django-admin.py sql" shows SQL statements for the given model module.
So if your models are split across multiple modules, you'll have to do
each one at a time.

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org


multiple model files

2005-09-02 Thread asrenzo

Hi,

I tried to do what's written in the doc (or in this group) to split my
Poll.py model into several sub-files. I changed the __init__.py of my
app to look for all other files.

__ALL__ = ['Poll', 'Choices']

but a django-admin sql Poll only shows sql statments for Poll model.
And this even if I save a __ALL__ = [] into __init__.py.

Is there something I missed ?

Regards,

Laurent.

PS : I use latest snapshot from svn.



Re: datetime field / form output

2005-09-02 Thread HBTaylor

I'm sorry to respond with a "me, too" instead of a solution, but I
believe your problem and mine may be related. In
http://groups.google.com/group/django-users/browse_thread/thread/f1219e342a8c89f0
(with a title of "selected" for ForeignKey field?), I have a ForeignKey
field. When I use a Generic View to update an existing object, the
SELECT for the ForeignKey is correctly rendered, but the existing value
is not selected. Is that what you see, or is there some other problem
with the SELECT tag?

If you are seeing the same thing, I might feel more comfortable knowing
that it isn't just my syntax. I might try to dig in and see where that
is happening in the view and see if there is a problem or something
we've both omitted.

H.B.



datetime field / form output

2005-09-02 Thread deltabps

Hi.

What am I doing wrong, I do not get form-values filled in properly when
editing objects.

It works for (as far as I can see) everything, except datetime fields
and foreign keys.

Thanks for support


I have a model, that contains the following:

--- cut ---
class Case(meta.Model):
customer = meta.ForeignKey(Customer)
opened = meta.DateTimeField()
reason = meta.CharField(maxlength=50)
description = meta.TextField()
--- cut ---

when I output the thing with a generic view (like this):

--- cut ---
(r'^updatecase/(?P\d+)/?$',
'django.views.generic.create_update.u
pdate_object', dict(case_dict, post_save_redirect="/support/"))
--- cut ---

and the cases_form.html:

--- cut ---
Customer:
{% if form.customer.errors %}*** {{ form.customer.errors|join:", " }}{%
endif %}
{{ form.customer }}

Description:
{% if form.description.errors %}*** {{ form.description.errors|join:",
" }}{% endif %}
{{ form.reason }}

Opened at Date:
{% if form.opened_date.errors %}*** {{ form.opened_date.errors|join:",
" }}{% endif %}
{{ form.opened_date }}
--- cut ---



Re: Admin login Problem (not the one in the FAQ)

2005-09-02 Thread Boffbowsh

or md5 -s 'password'