Re: ANN: PyMySQL 0.3

2010-09-29 Thread Bo Shi
The following patch to your application's manage.py will allow you to
use pymysql without patching Django.

 #!/usr/bin/env python
+try:
+import pymysql
+pymysql.install_as_MySQLdb()
+except ImportError:
+pass
+

On Sep 10, 12:25 pm, Andy  wrote:
> On Sep 10, 11:18 am, Andy Dustman  wrote:
>
> > Uh, no.
>
> > MySQLdb releases the GIL on any blocking call, so other threads can run.
>
> > Django is *not* asynchronous. It's threaded.
>
> The default Django behavior is threaded.
>
> But it can be made to run in async mode, where socket communication
> doesn't block. That way one Django thread can serve multiple users
> concurrently.
>
> Check out gevent for details.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: manage.py test without using a database?

2009-01-05 Thread Bo Shi

Thanks Russell, the former works great (I was hoping, in my infinite
laziness, that there was an undocumented command line switch :-P).

Regards,
Bo

On Jan 1, 1:50 am, "Russell Keith-Magee" 
wrote:
> On Wed, Dec 31, 2008 at 7:08 AM, Bo Shi  wrote:
>
> > Hi,
>
> > One of our django applications does not use django's ORM.  Is there a
> > way to run
>
> > ./manage.py test my_app
>
> > Such that it does not perform test database setup?
>
> There are two ways that you could do this.
>
> The first would be to define a custom test runner that skipped the
> database setup phase. django/test/simple/run_tests() will give you a
> model for what needs to be in a test runner; take a copy of this
> method (removing the database setup portions) and follow the
> instructions in [1]
>
> The second approach would be to define a dummy database backend that
> didn't complain about a database not being defined.
> django/db/backends/dummy gives you a starting point for this.
>
> Either way, you will need to make changes to your settings file.
> Neither of these approaches will fall in to the "if I'm only testing
> my_app, don't bother setting up the database, otherwise set up the
> database as normal" category.
>
> [1]http://docs.djangoproject.com/en/dev/topics/testing/#using-different-...
>
> 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
-~--~~~~--~~--~--~---



manage.py test without using a database?

2008-12-30 Thread Bo Shi

Hi,

One of our django applications does not use django's ORM.  Is there a
way to run

./manage.py test my_app

Such that it does not perform test database setup?


Thanks,
Bo
--~--~-~--~~~---~--~~
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 HTTP header data in templates

2007-01-22 Thread Bo Shi

I think request.META is what you're looking for, i.e.:

   referrer = request.META.get('HTTP_REFERER', '/')

On Jan 22, 9:39 am, "Andy Dustman" <[EMAIL PROTECTED]> wrote:
> I have a 404 page that I would like to display some of the HTTP
> headers (particularly HTTP_REFERER) in so that user receiving the
> error can make a usable report. Is there some way at getting at this
> information in a template without having to have your view return a
> HttpResponseNotFound object? I'm using get_object_or_404() but the
> same problem applies with generic views.
>
> --
> Patriotism means to stand by the country. It does
> not mean to stand by the president. -- T. Roosevelt
>
> This message has been scanned for memes and
> dangerous content by MindScanner, and is
> believed to be unclean.


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



sqlite3, QuerySet.extra() and order_by() inconsistencies between Python versions

2007-01-12 Thread Bo Shi

Hi -

Has anyone else observed differences between the behavior of order_by
between Python 2.3 and 2.4?  Under 2.3, the following code drops many
items in thread_list when using order_by():

...
extra_last_updated = """
SELECT date FROM forum_post
WHERE forum_post.thread_id = forum_thread.id
ORDER BY date DESC LIMIT 1
"""

thread_list = thread_list.extra(
select = {
# ...
#'last_updated': extra_last_updated,  # bug:
http://code.djangoproject.com/ticket/2210
'date': extra_last_updated,
'last_poster': extra_last_poster,
#},)
},).order_by('-csticky', '-date')

The above works as expected in a mod_python setup with Python 2.4 but
not Python 2.3 (Debian Sarge vs. Etch).  The pysqlite versions I'm
using are identical in both setups.  Of course, I haven't controlled
for a lot of other factors, but maybe someone has observed this before?


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



Strange admin sqlite3 read error

2006-09-13 Thread Bo Shi

Hi All -

The background:
I'm using SVN trunk with sqlite3, and can't access the admin page due
to a write-error on the database ("OperationalError: attempt to write a
readonly database").  I've attempted a number of permissions changes
(even doing a temporary chmod 777) on the database file with no luck.

Any thoughts on what's going on?

My urls.py looks like

urlpatterns = patterns('',
# Uncomment this for admin:
(r'^dicom/admin/', include('django.contrib.admin.urls')),

(r'^dicom/help/$', 'dnl_db.dindex.views.help'),
...



The error:
Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
result = object(req)

  File
"/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py",
line 163, in handler
return ModPythonHandler()(req)

  File
"/usr/lib/python2.3/site-packages/django/core/handlers/modpython.py",
line 140, in __call__
response = middleware_method(request, response)

  File
"/usr/lib/python2.3/site-packages/django/contrib/sessions/middleware.py",
line 89, in process_response
datetime.datetime.now() +
datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))

  File
"/usr/lib/python2.3/site-packages/django/contrib/sessions/models.py",
line 29, in save
s.save()

  File "/usr/lib/python2.3/site-packages/django/db/models/base.py",
line 204, in save
','.join(placeholders)), db_values)

  File "/usr/lib/python2.3/site-packages/django/db/backends/util.py",
line 12, in execute
return self.cursor.execute(sql, params)

  File
"/usr/lib/python2.3/site-packages/django/db/backends/sqlite3/base.py",
line 80, in execute
return Database.Cursor.execute(self, query, params)

OperationalError: attempt to write a readonly database


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



Admin "Page Not Found" Part 2

2006-06-14 Thread Bo Shi

This is a continuation of the following thread:

http://groups.google.com/group/django-users/browse_thread/thread/13a94a5ac9b5ff8a/f6fbcdd419ddf89e?q=page+not+found&rnum=1#f6fbcdd419ddf89e

I'm experiencing the same problem; I've fiddled with permissions
(superuser/explicitly setting all permissions, etc) and this does not
seem to be the issue.

=== 404 when I try to edit a question after saving
class Question(models.Model):
question = models.CharField(maxlength = 200)

class BinaryQuestion(Question):
class Admin:
list_display = ('question',)



=== works fine
class Question(models.Model):
question = models.CharField(maxlength = 200)

class BinaryQuestion(models.Model): # < no inheritance
question = models.CharField(maxlength = 200)
class Admin:
list_display = ('question',)
===


I'm quite befuddled.

bs


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



Re: Puzzling META.unique_together issue

2006-03-03 Thread Bo Shi

Sorry - some edit_inline, etc. got cut off in the paste.


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



Puzzling META.unique_together issue

2006-03-03 Thread Bo Shi

Hi, three models that concern this issue are Photo, Tag, and PhotoTag.
Tag represents the model for all tags:

class PhotoTag( meta.Model ):
tid = meta.ForeignKey( Tag, core = True )
pid = meta.ForeignKey( Photo, core = True, verbose_name = "Photo
Tag", edit_

class META:
# following prevents identical tags on photo TODO: doesn't work
unique_together = ( ( "tid", "pid" ), )


Results in the following exception.  Is unique_together not allowed on
ForeignKeys?  If so, can anyone suggest a workaround?


  File "/usr/lib/python2.3/site-packages/django/core/meta/__init__.py",
line 259,
 in get_manipulator_fields
fields.extend(f.get_manipulator_fields(self.opts, manipulator,
change, name_p
refix=prefix, rel=True))

  File "/usr/lib/python2.3/site-packages/django/core/meta/fields.py",
line 254, i
n get_manipulator_fields
params['validator_list'].append(getattr(manipulator, 'isUnique%s' %
'_'.join(
field_name_list)))

AttributeError: PhotoManipulatorAdd instance has no attribute
'isUniquetid_pid'


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



Re: File Upload Issue

2005-10-16 Thread Bo Shi

Hey Nesh,

Moving the rename logic to _pre_save() would be the best way of doing
things but I have a problem where I rename the uploaded file into one
based on it's primary key.  While in _pre_save(), self.id is None, so
is there a way to access the value that will become the primary key?

Bo



File Upload Issue

2005-10-15 Thread Bo Shi

Hi All,

I've been playing with FileField and file uploading.

I do have a problem that I can't seem to solve;  when a file gets
uploaded, it is placed in the media directory under some random
filename the client was using.  I would like to normalize this filename
so that

foo.txt

is saved on the server as

MEDIA_ROOT/text/username_fileid.txt

I have tried combining _post_save() and os.rename(...) to some limited
success but am not able to reset my FileField to the new file path (my
assumption is that using save() inside _post_save() causes infinite
recursion, no?).  Clearly said strategy is an ugly hack with some major
problems.

Is there an elegant way to do this?

Regards,
Bo