Re: test client vs jinja?

2021-02-10 Thread Roy Smith
Hmmm, it's not doing the templates quite right.  assertTemplateUsed() 
doesn't work, but I can get around that easy enough:

-self.assertTemplateUsed(response, 'spi/sock-info.dtl')
+
+self.assertEqual(response.templates, ['spi/sock-info.jinja'])

On Wednesday, February 10, 2021 at 9:32:31 PM UTC-5 Roy Smith wrote:

> I've gotten back to playing with this.  What I've ended up doing is 
> monkey-patching render to send the signal django.test.Client is expecting 
> from the template backend.  Paraphrasing my (python 3.7) code:
>
> from unittest.mock import patch
> from django.test.signals import template_rendered
> from django.shortcuts import render
>
> class TimelineViewTest(TestCase):
> @patch('spi.views.render')
> def test_context_includes_tag_list(self, mock_render):
>
> def render_patch(request, template, context):
> template_rendered.send(sender=self, template=template, 
> context=context)
> return render(request, template, context)
>
> mock_render.side_effect = render_patch
>
> At least doing it this way puts all the weird stuff in my test code.  I 
> didn't have to touch anything in my production view code (or in either 
> django or jinja).
> On Thursday, February 4, 2021 at 7:29:23 PM UTC-5 Roy Smith wrote:
>
>> I started my current project using native django templates and now I'm 
>> converting to jinja2. For the most part, it has gone smoothly. 
>>
>> The surprising roadblock was that this broke all my unit tests. The issue 
>> is that django.template.backends.jinja2.Jinja2 doesn't populate 
>> response.context. 
>>
>> One thought I had was to patch django.shortcuts.render() with 
>> unittest.mock. That didn't work out so well. 
>>
>> Where I seem to be heading now is to have each of my View subclasses have 
>> a build_context() static method, put most of the logic in that, and then I 
>> can call that directly in my unit tests. This seems to be workable, but 
>> it's kind of ugly that I need to alter my production code to make it 
>> testable. 
>>
>> Any wisdom from people who have gone through this would be appreciated. 
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f8e6204-6231-4fa8-b462-04e54efd0e95n%40googlegroups.com.


Re: test client vs jinja?

2021-02-10 Thread Roy Smith
I've gotten back to playing with this.  What I've ended up doing is 
monkey-patching render to send the signal django.test.Client is expecting 
from the template backend.  Paraphrasing my (python 3.7) code:

from unittest.mock import patch
from django.test.signals import template_rendered
from django.shortcuts import render

class TimelineViewTest(TestCase):
@patch('spi.views.render')
def test_context_includes_tag_list(self, mock_render):

def render_patch(request, template, context):
template_rendered.send(sender=self, template=template, 
context=context)
return render(request, template, context)

mock_render.side_effect = render_patch

At least doing it this way puts all the weird stuff in my test code.  I 
didn't have to touch anything in my production view code (or in either 
django or jinja).
On Thursday, February 4, 2021 at 7:29:23 PM UTC-5 Roy Smith wrote:

> I started my current project using native django templates and now I'm 
> converting to jinja2. For the most part, it has gone smoothly. 
>
> The surprising roadblock was that this broke all my unit tests. The issue 
> is that django.template.backends.jinja2.Jinja2 doesn't populate 
> response.context.
>
> One thought I had was to patch django.shortcuts.render() with 
> unittest.mock. That didn't work out so well.
>
> Where I seem to be heading now is to have each of my View subclasses have 
> a build_context() static method, put most of the logic in that, and then I 
> can call that directly in my unit tests. This seems to be workable, but 
> it's kind of ugly that I need to alter my production code to make it 
> testable.
>
> Any wisdom from people who have gone through this would be appreciated.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b228c0ca-e7d4-4a0f-8649-859961864163n%40googlegroups.com.


Re: test client vs jinja?

2021-02-10 Thread Roy Smith
It's a known problem.  See https://code.djangoproject.com/ticket/24622.  In 
short, the django template code has hooks to populate these values in the 
test client's response.  The jinja folks (understandably) don't want to add 
the same hooks.
On Friday, February 5, 2021 at 1:37:10 AM UTC-5 Benny M wrote:

> Hi Roy,
>
> I haven’t been through this personally, but it strikes me as odd that the 
> test can’t read the request context. On the surface it would stand to 
> reason that if the test can’t read it, then the page wouldn’t render on 
> browser request. Can you post an example of one of your failing tests and 
> the accompanying failure result?
>
> Benny

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5187a80f-f03f-4400-8b61-3e9cf9467dc5n%40googlegroups.com.


test client vs jinja?

2021-02-04 Thread Roy Smith
I started my current project using native django templates and now I'm 
converting to jinja2.  For the most part, it has gone smoothly.  

The surprising roadblock was that this broke all my unit tests.   The issue is 
that django.template.backends.jinja2.Jinja2 doesn't populate response.context.

One thought I had was to patch django.shortcuts.render() with unittest.mock.  
That didn't work out so well.

Where I seem to be heading now is to have each of my View subclasses have a 
build_context() static method, put most of the logic in that, and then I can 
call that directly in my unit tests.  This seems to be workable, but it's kind 
of ugly that I need to alter my production code to make it testable.

Any wisdom from people who have gone through this would be appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/70A8C0DD-5C8D-4A30-89A5-A7F50A454DAB%40panix.com.


Getting staticfiles to find subdirectories?

2021-01-14 Thread Roy Smith
I'm running django 2.2.

My static directory has a subdirectory which I want to deploy, but as far as I 
can tell, staticfiles only finds files in the top-level static directory.  is 
there any way to make it recurse and find everything below the static 
directory, and keep the same directory structure in the deployed static area?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9049E14D-4365-48F4-8CF4-01A84CDF2BF4%40panix.com.


Re: forms.ChoiceField calls choices callback twice?

2020-08-27 Thread Roy Smith
Hmmm, maybe related to https://code.djangoproject.com/ticket/26665 ?

On Thursday, August 27, 2020 at 5:29:39 PM UTC-4 Roy Smith wrote:

> I'm running:
>
> Python 3.7
> Django 2.2
> Debian 4.9
>
> If I configure a forms ChoiceField with a callback function for choices, 
> it gets called twice each time I render the form:
>
> from unittest import TestCase
> from django import forms
>
> def callback():
> print("callback")
> return [('foo', 'bar')]
>
> class MyForm(forms.Form):
> f = forms.ChoiceField(choices=callback)
>
>
> class FormTest(TestCase):
> MyForm().as_p()
>
>
>
> prints:
>
> ./manage.py test spi.test_f
> callback
> callback
> System check identified no issues (0 silenced).
>
> --
> Ran 0 tests in 0.000s
>
> OK
>
>
> Is this a known issue?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/24a524a6-5c47-42f7-ba63-37c77b09da34n%40googlegroups.com.


forms.ChoiceField calls choices callback twice?

2020-08-27 Thread Roy Smith
I'm running:

Python 3.7
Django 2.2
Debian 4.9

If I configure a forms ChoiceField with a callback function for choices, it 
gets called twice each time I render the form:

> from unittest import TestCase
> from django import forms
> 
> def callback():
> print("callback")
> return [('foo', 'bar')]
> 
> class MyForm(forms.Form):
> f = forms.ChoiceField(choices=callback)
> 
> 
> class FormTest(TestCase):
> MyForm().as_p()


prints:

> ./manage.py test spi.test_f
> callback
> callback
> System check identified no issues (0 silenced).
> 
> --
> Ran 0 tests in 0.000s
> 
> OK

Is this a known issue?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D7AA7EED-1D58-4A8C-A931-A6653D390135%40panix.com.


Re: social_django.models.UserSocialAuth.DoesNotExist in unit test

2020-08-05 Thread Roy Smith
I got this figured out.  It turns out I had a dependency on social_auth in an 
entirely different part of my code where I execute

reqeust.user.social_auth.get(provider='mediawiki').extra_data['access_token']

regardless of what auth backend was actually used.



> On Aug 4, 2020, at 10:08 PM, Roy Smith  wrote:
> 
> I have both model and social backends configured in settings.py:
> 
>> AUTHENTICATION_BACKENDS = (
>> 'django.contrib.auth.backends.ModelBackend',
>> 'social_core.backends.mediawiki.MediaWiki',
>> )
> 
> 
> When I run this test:
> 
>> from django.test import TestCase, Client
>> from django.contrib.auth.models import User
>> 
>> 
>> class UserActivitiesViewTest(TestCase):
>> def test_mainspace_title_contains_colon(self):
>> user_fred = User.objects.create_user('Fred', 'f...@example.com 
>> <mailto:f...@example.com>', 'password')
>> client = Client()
>> client.force_login(user_fred, 
>> backend='django.contrib.auth.backends.ModelBackend')
>> response = client.get('/spi/spi-user-activities/Foo', {'count': 10, 
>> 'main': 1}, follow=True)
> 
> 
> The view that's being tested is:
> 
>> class UserActivitiesView(LoginRequiredMixin, View):
>> def get(self, request, user_name):
>>   .
> 
> 
> I get a social_django.models.UserSocialAuth.DoesNotExist exception in the 
> client.get() call.  Why is it doing any kind of query on UserSocialAuth if 
> I'm telling force_login() to use ModelBackend?
> 
> I'm running django 2.2, python 3.7
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D27D0026-FE0A-4F41-B408-130264105A3C%40panix.com.


social_django.models.UserSocialAuth.DoesNotExist in unit test

2020-08-04 Thread Roy Smith
I have both model and social backends configured in settings.py:

> AUTHENTICATION_BACKENDS = (
> 'django.contrib.auth.backends.ModelBackend',
> 'social_core.backends.mediawiki.MediaWiki',
> )


When I run this test:

> from django.test import TestCase, Client
> from django.contrib.auth.models import User
> 
> 
> class UserActivitiesViewTest(TestCase):
> def test_mainspace_title_contains_colon(self):
> user_fred = User.objects.create_user('Fred', 'f...@example.com', 
> 'password')
> client = Client()
> client.force_login(user_fred, 
> backend='django.contrib.auth.backends.ModelBackend')
> response = client.get('/spi/spi-user-activities/Foo', {'count': 10, 
> 'main': 1}, follow=True)


The view that's being tested is:

> class UserActivitiesView(LoginRequiredMixin, View):
> def get(self, request, user_name):
>   .


I get a social_django.models.UserSocialAuth.DoesNotExist exception in the 
client.get() call.  Why is it doing any kind of query on UserSocialAuth if I'm 
telling force_login() to use ModelBackend?

I'm running django 2.2, python 3.7

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/F63F152D-91BE-41DA-A13D-F54D1D708AD8%40panix.com.


Re: How to configure a DatagramHandler for logging?

2020-06-28 Thread Roy Smith
Oh, never mind.  It turns out  'logging.handlers.DatagramHandler' is exactly 
what you need, I just didn't get all the pieces wired up right.


> On Jun 28, 2020, at 9:20 PM, Roy Smith  wrote:
> 
>  'logging.handlers.DatagramHandler',

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/19745158-E9B0-43D9-9892-1ECF8E570B66%40panix.com.


Re: How to configure a DatagramHandler for logging?

2020-06-28 Thread Roy Smith
Correction, the line that says 'logging.handlers.DatagramHandler', really reads 
'logging.DatagramHandler' in the code I'm running.  The 
logging.handlers.DatagramHandler was just something I tried to see what it 
would do.



> On Jun 28, 2020, at 9:17 PM, Roy Smith  wrote:
> 
> Python 3.7.3
> Django 2.2.13
> Debian Linux
> 
> I'm trying to configure a DatagramHandler for logging.  My LOGGING config is:
> 
> LOGGING = {
> 'version': 1,
> 'disable_existing_loggers': False,
> 'handlers': {
> 'file': {
> 'level': 'DEBUG',
> 'class': 'logging.FileHandler',
> 'filename': os.path.join(LOG_DIR, 'django.log'),
> },
> 'netcat': {
> 'level': 'DEBUG',
> 'class': 'logging.handlers.DatagramHandler',
> 'host': 'x',
> 'port': 23001,
> },
> },
> 'loggers': {
> 'django': {
> 'handlers': ['file'],
> 'level': 'DEBUG',
> 'propagate': True,
> },
> },
> }
> 
> When django starts, I get:
> 
> AttributeError: module 'logging' has no attribute 'DatagramHandler'
> 
> Sure enough, if I look in.../lib/python3.7/logging/__init__.py, there is no 
> DatagramHandler.  So what am I supposed to do?
> 
> I suspect this is more of a Python question than a Django question, but I 
> figured I'd start here and work my way up :-)
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/0AE03550-BE78-48A0-A42F-D5A05FF9D42D%40panix.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/77CAEE05-D836-4FF1-A653-A7389B7B06CE%40panix.com.


How to configure a DatagramHandler for logging?

2020-06-28 Thread Roy Smith
Python 3.7.3
Django 2.2.13
Debian Linux

I'm trying to configure a DatagramHandler for logging.  My LOGGING config is:

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(LOG_DIR, 'django.log'),
},
'netcat': {
'level': 'DEBUG',
'class': 'logging.handlers.DatagramHandler',
'host': 'x',
'port': 23001,
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}

When django starts, I get:

AttributeError: module 'logging' has no attribute 'DatagramHandler'

Sure enough, if I look in.../lib/python3.7/logging/__init__.py, there is no 
DatagramHandler.  So what am I supposed to do?

I suspect this is more of a Python question than a Django question, but I 
figured I'd start here and work my way up :-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0AE03550-BE78-48A0-A42F-D5A05FF9D42D%40panix.com.


Re: Problem with google calendar on ancient django version

2014-12-23 Thread Roy Smith
Heh, I figured it out (a good night's sleep helped).  I've got Privacy Badger 
installed.  Disabling that lets the the file load properly :-)

I guess for completeness, the answers to my questions are:

1) Probably not

2) No clue

3) "Will not fix -- working as designed" :-)

4) No


On Dec 22, 2014, at 9:02 PM, Roy Smith wrote:

> I'm in the process of incrementally upgrading a site running some ancient 
> software (django 1.3.1 and django-cms 2.2).  I've got a development version 
> of the site running django-cms 2.3.8 (and still django 1.3.1) for testing.  
> The plan is to get it up to modern versions of both, but one step at a time.  
> One oddity is see in the newer site, my google calendar is missing some of 
> the icons.   The problem is that
> 
> https://calendar.google.com/googlecalendar/images/combined_v22.png
> 
> (a bunch of sprited images) is failing to load on the 2.3.8 site, with 
> "net::ERR_BLOCKED_BY_CLIENT" showing in the javascript console.  The referrer 
> URL for that is
> 
> https://www.google.com/calendar/static/7f25774200d4fe9fa8584b21c00791ffe
> 
> so it's clear this is some kind of cross-domain problem.  The questions are:
> 
> 1) Has anybody else seen this?
> 
> 2) Why did changing the django-cms version change how this behaves?
> 
> 3) Is this fixed in later django-cms versions?
> 
> 4) Is this fundamentally a bug in Google calendar, i.e. I should be reporting 
> it to them?
> 
> --
> Roy Smith
> r...@panix.com
> 


--
Roy Smith
r...@panix.com



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/005A9097-03FF-4C96-9E93-39A253C36FA9%40panix.com.
For more options, visit https://groups.google.com/d/optout.


Problem with google calendar on ancient django version

2014-12-22 Thread Roy Smith
I'm in the process of incrementally upgrading a site running some ancient 
software (django 1.3.1 and django-cms 2.2).  I've got a development version of 
the site running django-cms 2.3.8 (and still django 1.3.1) for testing.  The 
plan is to get it up to modern versions of both, but one step at a time.  One 
oddity is see in the newer site, my google calendar is missing some of the 
icons.   The problem is that

https://calendar.google.com/googlecalendar/images/combined_v22.png

(a bunch of sprited images) is failing to load on the 2.3.8 site, with 
"net::ERR_BLOCKED_BY_CLIENT" showing in the javascript console.  The referrer 
URL for that is

https://www.google.com/calendar/static/7f25774200d4fe9fa8584b21c00791ffe

so it's clear this is some kind of cross-domain problem.  The questions are:

1) Has anybody else seen this?

2) Why did changing the django-cms version change how this behaves?

3) Is this fixed in later django-cms versions?

4) Is this fundamentally a bug in Google calendar, i.e. I should be reporting 
it to them?

--
Roy Smith
r...@panix.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2FFD57A2-8E18-406A-8F02-A1D176B21B41%40panix.com.
For more options, visit https://groups.google.com/d/optout.


Finding gunicorn worker number inside django app?

2013-11-16 Thread Roy Smith
I'm running django (1.4) with gunicorn (0.17.4) and gevent.  I want to have 
the gunicorn worker number available inside of django, so I can include it 
in log messages and statsd data for tracking purposes.

What I'm doing right now is I put a pre_request hook in my gunicorn config 
file which fakes a HTTP header

def pre_request(worker, req):
   req.headers.append(("X-SONGZA-WORKER", str(worker.age)))

This works, but it seems kind of hacky.  It's also messy because I need to 
process it for every request.  It would be cleaner to do this in 
post_fork(), but I don't see how to communicate any information from the 
worker object available in pre_fork() to something that's visible inside 
django.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fca39909-631e-4558-b835-bcbff0b1b468%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Get size of cached item?

2013-08-16 Thread Roy Smith
I'm trying to log some statistics on the sizes of objects I store in memcache, 
for a specific set of keys.  What I'm doing now is pickling the data in my 
application code, and logging len() of the picked string.  This is wasteful 
because the cache machinery is just going to do the pickling all over again.  
Is there any way to find out how much memory each object I store is going to 
use without this extra overhead?

---
Roy Smith
r...@panix.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Atomic test/set/get using django cache API?

2013-05-14 Thread Roy Smith
I want to do an atomic "test and set if doesn't exist" on a cache key using the 
django API.  So far, that's easy.; cache.add() gives me exactly that.

But, if the key does exist, I also want to get the current value.  All add() 
gives me back is a flag saying if the key existed.  Is there a way to also get 
the value, inside the atomic perimeter?

--
Roy Smith
r...@panix.com

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




Why does BaseHandler::handle_uncaught_exception() not always log?

2012-10-24 Thread Roy Smith
In core/handlers/base.py, handle_uncaught_exception() does:

if settings.DEBUG:
from django.views import debug
return debug.technical_500_response(request, *exc_info)

logger.error('Internal Server Error: %s' % request.path,
exc_info=exc_info,
extra={
'status_code': 500,
'request':request
}
)

Wouldn't it make more sense to always log the exception?  As it stands now, 
it's an either/or deal.  If DEBUG, produce the debug page and don't log. 
 If not DEBUG, log and produce a normal 500 page.

I ended up writing my own process_exception() middleware to log stack 
traces for all uncaught exceptions.  This was fine in development, but in 
production, with DEBUG = False, I get *two* stacks in my log files for 
every exception (one from my hander, another from the code above).  This 
all seems silly.  It would be so much simpler (and obvious) if 
handle_uncaught_exception() always logged, regardless of which flavor of 
response it's going to produce.

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



Customizing session id strings?

2012-08-16 Thread Roy Smith
We're using django.contrib.sessions.backends.cache.  We use mongodb for our 
datastore, so we don't use the django model/database support at all.

The standard django session machinery generates 32-character hex strings 
(128 bits) for session ids.  We store the session_id in many places in our 
database (and index many collections on it), so shorter ids would be a big 
win.  Mongo uses 96-bits for its object ids.  I figure we don't need any 
more than that.  Base-64 encoding gives 16 characters.

So, the question is, is there any hook to allow us to generate our own 
session_ids for django.contrib.sessions.backends.cache to use?  I'm tempted 
to just subclass sessions.backends.cache and override 
_get_new_session_key(), but overriding underscore-prepended things sounds a 
little funky.

BTW, looking at base.py, why does it go to all the weird md5/pid/time 
stuff?  Why not just call uuid() and be done with it?

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



Admin actions -- short_description as doc string?

2012-07-04 Thread Roy Smith
I'm just staring to explore admin actions.  I'm surprised to see that you have 
to set the description by doing:

my_action_function.short_description = "blah"

wouldn't it be cleaner to just declare a doc string for the action function and 
have short_description grabbed from there?

--
Roy Smith
r...@panix.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.



Monitoring cache usage?

2012-06-20 Thread Roy Smith
What tools exist to monitor django's cache usage?  I'd like to see things like 
number of keys stored, total amount of memory used, hit rates broken down by 
key prefix, that sort of thing.

We're using django.core.cache.backends.memcached.MemcachedCache.

---
Roy Smith
r...@panix.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.



editable option for model field?

2012-06-04 Thread Roy Smith
The description of editable says:

> If False, the field will not be editable in the admin or via forms 
> automatically generated from the model class.

To me, this sounds like it will be shown in the admin, just not as an editable 
field (i.e. readonly).  However, when I try setting it to False, my field it 
omitted entirely from the admin.

What's the intent of editable?  Is this a bug, or is the description in the 
docs just misleading?

--
Roy Smith
r...@panix.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.



Tools for extending the admin?

2012-05-01 Thread Roy Smith
I'm working on a site which makes extensive use of admin, and we're 
starting to look at extending/customizing it.  I am aware of 
django-admin-tools and django-grappelli.  Are there other projects I should 
be looking at for admin extension/customization ideas?

-- 
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/-/p7epaDJinI4J.
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: Edit-once object in admin?

2012-04-28 Thread Roy Smith


On Saturday, April 28, 2012 10:35:40 AM UTC-4, Shawn Milochik wrote:
>
> Override the save() method to raise an exception if "self.id is not 
> None." 
>

But, that still doesn't tell the admin interface to *show* the fields as 
read-only (which is really what I'm interested in).  If I raise an 
exception in save(), the admin interface will let somebody edit the fields 
and then give some sort of error when the click the Save button. 

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



Edit-once object in admin?

2012-04-28 Thread Roy Smith
I've got a model that looks something like this:

class Image(Model):
name = CharField(max_length=40)

class ImageVersion(Model):
image = ForeignKey(Image)
upload_date = DateTimeField(auto_now_add=True)
data = ImageField(upload_to="images/learncms")

I want all the data in an ImageVersion to be read-only once it is created. 
 The idea is that the active version of an image is always the latest one, 
and the only way to change an image is to upload a new version.  Existing 
versions can never be changed.  How can I implement this in the admin?

-- 
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/-/8S3EkzfiiBwJ.
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: Overriding an admin widget?

2012-04-25 Thread Roy Smith
Oh, I see what's going on.  I marked the field as readonly.  Apparently the 
widget only gets created if the field is editable (I guess that makes sense).



On Apr 25, 2012, at 1:28 PM, Roy Smith wrote:

> Ooops, forgot to mention, I'm using django 1.4.
> 
> 
> On Apr 25, 2012, at 12:51 PM, Roy Smith wrote:
> 
>> I'm trying to get the admin to give me a thumbnail for an ImageForm.  
>> Following the suggestion at http://djangosnippets.org/snippets/1580/, I've 
>> got the following code:
>> 
>> from django import forms
>> from django.contrib import admin
>> from django.db import models
>> from django.utils.safestring import mark_safe
>> 
>> class AdminImageWidget(forms.FileInput):
>> def __init__(self, attrs={}):
>> assert 0
>> super(AdminImageWidget, self).__init__(attrs)
>> 
>> def render(self, name, value, attrs=None):
>> output = []
>> if value and hasattr(value, "url"):
>> output.append((''
>>' '
>>% (value.url, value.url)))
>> output.append(super(AdminImageWidget, self).render(name, value, 
>> attrs))
>> return mark_safe(u''.join(output))
>> 
>> class ImageVersionAdmin(admin.ModelAdmin):
>> readonly_fields = ('image',
>>'data')
>> formfield_overrides = {
>> models.ImageField: {'widget': AdminImageWidget,
>> 'label': 'My Label',},
>> }
>> 
>> admin.site.register(ImageVersion, ImageVersionAdmin)
>> 
>> The problem is, I'm still getting the standard admin display.  I stuck the 
>> "assert 0" in AdminImageWidget.__init__() just to prove that it's never 
>> being called.  What magic am I missing?
>> 
>> My model looks like:
>> 
>> class ImageVersion(Model):
>> image = ForeignKey(Image)
>> data = ImageField(upload_to="images/foo")
>> 
>> ---
>> Roy Smith
>> r...@panix.com
>> 
>> 
>> 
> 
> 
> ---
> Roy Smith
> r...@panix.com
> 
> 
> 


---
Roy Smith
r...@panix.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: Overriding an admin widget?

2012-04-25 Thread Roy Smith
Ooops, forgot to mention, I'm using django 1.4.


On Apr 25, 2012, at 12:51 PM, Roy Smith wrote:

> I'm trying to get the admin to give me a thumbnail for an ImageForm.  
> Following the suggestion at http://djangosnippets.org/snippets/1580/, I've 
> got the following code:
> 
> from django import forms
> from django.contrib import admin
> from django.db import models
> from django.utils.safestring import mark_safe
> 
> class AdminImageWidget(forms.FileInput):
> def __init__(self, attrs={}):
> assert 0
> super(AdminImageWidget, self).__init__(attrs)
> 
> def render(self, name, value, attrs=None):
> output = []
> if value and hasattr(value, "url"):
> output.append((''
>' '
>% (value.url, value.url)))
> output.append(super(AdminImageWidget, self).render(name, value, 
> attrs))
> return mark_safe(u''.join(output))
> 
> class ImageVersionAdmin(admin.ModelAdmin):
> readonly_fields = ('image',
>'data')
> formfield_overrides = {
> models.ImageField: {'widget': AdminImageWidget,
> 'label': 'My Label',},
> }
> 
> admin.site.register(ImageVersion, ImageVersionAdmin)
> 
> The problem is, I'm still getting the standard admin display.  I stuck the 
> "assert 0" in AdminImageWidget.__init__() just to prove that it's never being 
> called.  What magic am I missing?
> 
> My model looks like:
> 
> class ImageVersion(Model):
> image = ForeignKey(Image)
> data = ImageField(upload_to="images/foo")
> 
> ---
> Roy Smith
> r...@panix.com
> 
> 
> 


---
Roy Smith
r...@panix.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.



Overriding an admin widget?

2012-04-25 Thread Roy Smith
I'm trying to get the admin to give me a thumbnail for an ImageForm.  Following 
the suggestion at http://djangosnippets.org/snippets/1580/, I've got the 
following code:

from django import forms
from django.contrib import admin
from django.db import models
from django.utils.safestring import mark_safe

class AdminImageWidget(forms.FileInput):
def __init__(self, attrs={}):
assert 0
super(AdminImageWidget, self).__init__(attrs)

def render(self, name, value, attrs=None):
output = []
if value and hasattr(value, "url"):
output.append((''
   ' '
   % (value.url, value.url)))
output.append(super(AdminImageWidget, self).render(name, value, attrs))
return mark_safe(u''.join(output))

class ImageVersionAdmin(admin.ModelAdmin):
readonly_fields = ('image',
   'data')
formfield_overrides = {
models.ImageField: {'widget': AdminImageWidget,
'label': 'My Label',},
}

admin.site.register(ImageVersion, ImageVersionAdmin)

The problem is, I'm still getting the standard admin display.  I stuck the 
"assert 0" in AdminImageWidget.__init__() just to prove that it's never being 
called.  What magic am I missing?

My model looks like:

class ImageVersion(Model):
image = ForeignKey(Image)
data = ImageField(upload_to="images/foo")

---
Roy Smith
r...@panix.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.



Adding context data to a TemplateView?

2012-04-22 Thread Roy Smith
I'm using a generic TemplateView (django-1.4), but I want to be able to add 
something to the context.  Is that possible?

The docs at 
https://docs.djangoproject.com/en/1.4/topics/generic-views/#adding-extra-context
 talk about "an extra optional parameter, extra_context", but I don't get what 
they're trying to explain.  I tried the obvious:

url(r'^about$',
TemplateView.as_view(template_name='legal_ipsum/about.html',
 extra_context={'pagename': 'about'})
),

in my urls.py file, but that just raises: "TemplateView() received an invalid 
keyword 'extra_context'".  What am I missing here?

--
Roy Smith
r...@panix.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.



AutoFields must have primary_key=True?

2012-04-16 Thread Roy Smith
I need an integer field which generates increasing integers.  But I don't want 
it to be my primary key.  In fact, it can't be, because I want the ability to 
manually reset it to something else.  The auto-increment is just a default 
value.

If I do:

> class Image(Model):
> serial = AutoField()

I get an error when I do syncdb or schemamigration:

> AssertionError: AutoFields must have primary_key=True.

Is this a bug?

---
Roy Smith
r...@panix.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.



Building composite keys?

2012-04-16 Thread Roy Smith
I've got a model in django 1.4:

class Image(Model):
serial = AutoField(primary_key=True)
version = IntegerField(default=1)

I want (serial, version) to be unique.  Is there a way to express that in the 
model layer?

---
Roy Smith
r...@panix.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.



Migrating a database from Django 1.1/postgress to 1.3/MySQL

2012-04-10 Thread Roy Smith
I've got an old site running Django 1.1 with a postgress backend.  I'm moving 
it to Django 1.3, with MySQL.  I dumped all the old data with:

$ python manage.py dumpdata --indent 2 > materia-dump.2012-04-06.json

I created a brand new MySQL database and ran syncdb, then tried to import the 
data with

$ python manage.py loaddata materia-dump.2012-04-06.json

But I get complaints about duplicate keys:

> Problem installing fixture '/home/roy/materia-dump.2012-04-06.json': 
> Traceback (most recent call last):
>   File 
> "/usr/lib/pymodules/python2.6/django/core/management/commands/loaddata.py", 
> line 174, in handle
> obj.save(using=using)
>   File "/usr/lib/pymodules/python2.6/django/core/serializers/base.py", line 
> 165, in save
> models.Model.save_base(self.object, using=using, raw=True)
>   File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 526, in 
> save_base
> rows = manager.using(using).filter(pk=pk_val)._update(values)
>   File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 491, in 
> _update
> return query.get_compiler(self.db).execute_sql(None)
>   File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 
> 869, in execute_sql
> cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
>   File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 
> 735, in execute_sql
> cursor.execute(sql, params)
>   File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line 34, in 
> execute
> return self.cursor.execute(sql, params)
>   File "/usr/lib/pymodules/python2.6/django/db/backends/mysql/base.py", line 
> 86, in execute
> return self.cursor.execute(query, args)
>   File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
> self.errorhandler(self, exc, value)
>   File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in 
> defaulterrorhandler
> raise errorclass, errorvalue
> IntegrityError: (1062, "Duplicate entry 'photologue-gallery' for key 
> 'app_label'")


Looking at the json output, I don't see any duplicates.  I've got:

  {
"pk": 9,
"model": "contenttypes.contenttype",
"fields": {
  "model": "gallery",
  "name": "gallery",
  "app_label": "photologue"
}
  },

but that's the only entry for name = "gallery", app_label = "photologue".  Any 
idea what I'm doing wrong?


---
Roy Smith
r...@panix.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: How to install django-mce?

2012-04-09 Thread Roy Smith


On Sunday, April 8, 2012 4:34:26 PM UTC-4, Roy Smith wrote:
>
> I'm trying to install django-tinymce 1.5.1b2 into a django-1.3 site.  The 
> installation instructions say:
>
> "Copy the jscripts/tiny_mce directory from the TinyMCE distribution into 
> a directory named js in your media root. You can override the location in 
> your settings (see below)."
>
> But there is no such directory. There are:
>
> ./media/tiny_mce/plugins/preview/jscripts
> ./static/tiny_mce/plugins/preview/jscripts
>
> directories, but no tiny_mce directory under those.  Even odder, the media 
> and static trees look like identical copies of each other.  Also, it seems 
> like the javascript files should go under my static directory, not my media 
> directory.  I'm guessing the installation directions predate django 1.3 and 
> collectstatic?
>
> So, what exactly am I supposed to install where?
>

On Sunday, April 8, 2012 4:34:26 PM UTC-4, Roy Smith wrote:
>
> I'm trying to install django-tinymce 1.5.1b2 into a django-1.3 site.  The 
> installation instructions say:
>
> "Copy the jscripts/tiny_mce directory from the TinyMCE distribution into 
> a directory named js in your media root. You can override the location in 
> your settings (see below)."
>
> But there is no such directory. There are:
>
> ./media/tiny_mce/plugins/preview/jscripts
> ./static/tiny_mce/plugins/preview/jscripts
>
> directories, but no tiny_mce directory under those.  Even odder, the media 
> and static trees look like identical copies of each other.  Also, it seems 
> like the javascript files should go under my static directory, not my media 
> directory.  I'm guessing the installation directions predate django 1.3 and 
> collectstatic?
>
> So, what exactly am I supposed to install where?
>

On Sunday, April 8, 2012 4:34:26 PM UTC-4, Roy Smith wrote:
>
> I'm trying to install django-tinymce 1.5.1b2 into a django-1.3 site.  The 
> installation instructions say:
>
> "Copy the jscripts/tiny_mce directory from the TinyMCE distribution into 
> a directory named js in your media root. You can override the location in 
> your settings (see below)."
>
> But there is no such directory. There are:
>
> ./media/tiny_mce/plugins/preview/jscripts
> ./static/tiny_mce/plugins/preview/jscripts
>
> directories, but no tiny_mce directory under those.  Even odder, the media 
> and static trees look like identical copies of each other.  Also, it seems 
> like the javascript files should go under my static directory, not my media 
> directory.  I'm guessing the installation directions predate django 1.3 and 
> collectstatic?
>
> So, what exactly am I supposed to install where?
>

On Sunday, April 8, 2012 4:34:26 PM UTC-4, Roy Smith wrote:
>
> I'm trying to install django-tinymce 1.5.1b2 into a django-1.3 site.  The 
> installation instructions say:
>
> "Copy the jscripts/tiny_mce directory from the TinyMCE distribution into 
> a directory named js in your media root. You can override the location in 
> your settings (see below)."
>
> But there is no such directory. There are:
>
> ./media/tiny_mce/plugins/preview/jscripts
> ./static/tiny_mce/plugins/preview/jscripts
>
> directories, but no tiny_mce directory under those.  Even odder, the media 
> and static trees look like identical copies of each other.  Also, it seems 
> like the javascript files should go under my static directory, not my media 
> directory.  I'm guessing the installation directions predate django 1.3 and 
> collectstatic?
>
> So, what exactly am I supposed to install where?
>

On Sunday, April 8, 2012 4:34:26 PM UTC-4, Roy Smith wrote:
>
> I'm trying to install django-tinymce 1.5.1b2 into a django-1.3 site.  The 
> installation instructions say:
>
> "Copy the jscripts/tiny_mce directory from the TinyMCE distribution into 
> a directory named js in your media root. You can override the location in 
> your settings (see below)."
>
> But there is no such directory. There are:
>
> ./media/tiny_mce/plugins/preview/jscripts
> ./static/tiny_mce/plugins/preview/jscripts
>
> directories, but no tiny_mce directory under those.  Even odder, the media 
> and static trees look like identical copies of each other.  Also, it seems 
> like the javascript files should go under my static directory, not my media 
> directory.  I'm guessing the installation directions predate django 1.3 and 
> collectstatic?
>
> So, what exactly am I supposed to install where?
>

-- 
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/-/yTiCOtVcr9cJ.
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 to install django-mce?

2012-04-09 Thread Roy Smith

>
> docs are little out of date but should work.
> http://django-tinymce.readthedocs.org/en/latest/installation.html
>

Thanks for the help.  The critical item was, "If you are using 
django-staticfiles you can skip this step".  I added 'tinymce' to 
INSTALLED_APPS, set

TINYMCE_DEFAULT_CONFIG = {
"width": "100%",
"height": "400px",
"theme": "advanced",
"relative_urls": False,
}

and ran manage.py collectstatic.  Works like a charm.  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/-/BuRatx8fOEUJ.
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 install django-mce?

2012-04-08 Thread Roy Smith
I'm trying to install django-tinymce 1.5.1b2 into a django-1.3 site.  The 
installation instructions say:

"Copy the jscripts/tiny_mce directory from the TinyMCE distribution into a 
directory named js in your media root. You can override the location in 
your settings (see below)."

But there is no such directory. There are:

./media/tiny_mce/plugins/preview/jscripts
./static/tiny_mce/plugins/preview/jscripts

directories, but no tiny_mce directory under those.  Even odder, the media 
and static trees look like identical copies of each other.  Also, it seems 
like the javascript files should go under my static directory, not my media 
directory.  I'm guessing the installation directions predate django 1.3 and 
collectstatic?

So, what exactly am I supposed to install where?

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



Why does django default to Chicago time?

2012-02-15 Thread Roy Smith
In the default settings.py file, the timezone is set to:

TIME_ZONE = 'America/Chicago'

Why?  Wouldn't None (to match the server's time zone) be a more sane 
default?  Even setting it to UTC would be more reasonable than setting it 
to any specific timezone, but surely going with the system default is the 
best of all.

-- 
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/-/_kKC8BMhA-kJ.
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.



STATIC_ROOT confusion

2011-10-07 Thread Roy Smith
I'm mystified why django (under runserver) is not finding my static
files.  I'm running django-1.3.1.  The relevant parts of my
settings.py file are:

STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
STATIC_URL = '/static/'

I have a file in my static directory, a file named foo.  If I do a GET
on http://localhost:8000/static/foo, I get an 404 with the message,
"'foo' could not be found".

I have commented django.contrib.staticfiles out of my settings.py
file.  For now, I just want to drop my static files manually into my
static directory.

-- 
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: Help me understand the django.request logger

2011-09-22 Thread Roy Smith
Ugh, I got it figured out.  I totally misunderstood what the docs were
saying.  I was thinking that somehow the django.request logger
magically found the request object and stuck it into the context.
That's not what it was saying at all.  All the quote from the docs
really means is that all the places inside of django where
django.request is used, the request is explicitly passed in as part of
extra.

Sigh.

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



Help me understand the django.request logger

2011-09-22 Thread Roy Smith
I'm running django 1.3, python 2.6.  I'm trying to write a custom
formatter for the django.request logger.  I need to log one of the
headers from the HTTP request.  The documentation for django.request
(https://docs.djangoproject.com/en/1.3/topics/logging/) says:

Messages to this logger have the following extra context:

status_code: The HTTP response code associated with the request.
request: The request object that generated the logging message.

It's not entirely clear what "extra context" means, but I'm assuming
the record passed to my format() method will include those
attributes.  It doesn't.  My formatter looks like:

class UniqueRequestIdFormatter(logging.Formatter):
def format(self, record):
record.message = record.msg % record.args
record.asctime = self.formatTime(record)
format = '%(asctime)s: %(name)s %(levelname)s %(funcName)s %
(message)s'
pprint.pprint(record.__dict__)
return format % record.__dict__

When I log something to this, it prints:

{'args': (),
 'asctime': '2011-09-22 14:54:53,755',
 'created': 1316717693.7554641,
 'exc_info': None,
 'exc_text': None,
 'filename': 'views.py',
 'funcName': 'listen_content',
 'levelname': 'DEBUG',
 'levelno': 10,
 'lineno': 253,
 'message': u"slug = 'essential-motown-hits-songza'",
 'module': 'views',
 'msecs': 755.46407699584961,
 'msg': u"slug = 'essential-motown-hits-songza'",
 'name': 'django.request',
 'pathname': '/home/roy/src/default/djsite/djfront/views.py',
 'process': 18113,
 'processName': 'MainProcess',
 'relativeCreated': 16236.304044723511,
 'thread': 48007945393920,
 'threadName': 'Dummy-1'}

How do I get access to the request object?

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



Mongo prints traceback directly to stderr?

2011-08-29 Thread Roy Smith
We've got an application which does lots of AJAX calls and sometimes
(intentionally) abandons the TCP connection before getting a
response.  These result in django dumping a stack trace to stderr (see
example below).

The question is, why does this get written directly to stderr?  It
happens in ServerHandler:

from traceback import print_exception
stderr = self.get_stderr()
print_exception(
exc_info[0], exc_info[1], exc_info[2],
self.traceback_limit, stderr
)

wouldn't it make more sense to write this to some logger, where we can
then control whether it gets printed or not?  In our case, it's
perfectly normal and we'd like to completely ignore it.



 example stack dump -
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 284, in run
self.finish_response()
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 324, in finish_response
self.write(data)
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 403, in write
self.send_headers()
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 467, in send_headers
self.send_preamble()
  File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 385, in send_preamble
'Date: %s\r\n' % http_date()
  File "/usr/lib/python2.6/socket.py", line 300, in write
self.flush()
  File "/usr/lib/python2.6/socket.py", line 286, in flush
self._sock.sendall(buffer)
error: [Errno 32] Broken pipe

-- 
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: HttpResponseRedirect adds hostname?

2011-08-23 Thread Roy Smith
Thanks for the explanation.  We ended up re-arranging which pieces were 
listening on which ports so the nginx front end is on port 80.  Reading the 
nginx docs, it seems like we might have been able to make our current set up do 
what we wanted, but shuffling the ports was easier :-)

Regarding:

> The munging is I think being done by whatever web
> server you're using (Apache? Nginx? It's hard to tell from your
> description; you just say "Django on port 9200"), 

it's the built-in runserver for testing, gunicorn in production.


On Aug 23, 2011, at 5:03 PM, Jacob Kaplan-Moss wrote:

> On Tue, Aug 23, 2011 at 4:01 PM, Jacob Kaplan-Moss <ja...@jacobian.org> wrote:
>> However, I believe it's not actually Django doing the rewriting.
> 
> Scratch that: I'm wrong. Actually, Django *is* doing the re-writing:
> see 
> https://code.djangoproject.com/browser/django/trunk/django/http/utils.py#L11.
> 
> Still, the point stands that it's necessary -- standards and all that
> -- and that you should be fixing it in your proxy layer.
> 
> Jacob
> 
> -- 
> 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.
> 


---
Roy Smith
r...@panix.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.



HttpResponseRedirect adds hostname?

2011-08-23 Thread Roy Smith
I've got a view which does returns HttpResponseRedirect('/').  When I look at 
the HTTP traffic in tcpdump, I can see that the location header has had the 
hostname added:

Location: http://gilbert.lic.songza.com/

Why does it do this?  It seems like it should just take the string I passed it 
and stick that into the header, no?

The problem is that we've got a complicated setup with django (on port 9200) 
and apache (on port 80) both behind nginx (on port 9300).  When I redirect to 
'/', my browser sees the absolute URL and ends up going to the apache server on 
port 80 (which is the wrong place; the nginx config would route to the django 
side).

It seems like a django bug that the string I pass HttpResponseRedirect is 
modified before generating the location header.  What do you guys think?


---
Roy Smith
r...@panix.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.



HttpRequest.META['SERVER_PORT'] is a string?

2011-08-02 Thread Roy Smith
I'm running django 1.3.  If I access HttpRequest.META['SERVER_PORT'],
I get back a string (i.e. "80").  I was expecting an integer.  Is this
a bug (in which case I'll open a ticket to fix it) or it it
intentional that it's returning a string (in which case I'll open a
ticket to document it better).

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



Unique usernames for Users?

2011-06-18 Thread Roy Smith
I assume that User.username is constrained to be unique, but I don't
actually see that stated anywhere.  Is it?  And, assuming it is, what
happens when you call create_user() with a username that's already
taken?  Is all this documented somewhere and I'm just not finding 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.



MongoDB with django?

2011-06-16 Thread Roy Smith
I'm exploring packages to use MongoDB with django.  So far, I've
found:

* DjanMon (https://github.com/mdirolf/djanMon/)
* Mongoengine (http://mongoengine.org)
* MongoKIT
* Mango
* Pymongo-bongo
* Mongodb-engine (https://github.com/django-mongodb-engine/mongodb-
engine)
* Django-nonrel (http://www.allbuttonspressed.com/projects/django-
nonrel)
* Django MongoDB Engine (http://django-mongodb.org)

Are there any major players I've missed?

-- 
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 to catch and log exceptions?

2011-06-14 Thread Roy Smith
Exactly what I was looking for.  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.



How to catch and log exceptions?

2011-06-14 Thread Roy Smith
I want to catch any exceptions thrown in my views (or anywhere else, I
suppose) and log a full stack trace.  I know I can write middleware
which implements process_exception(), but that just gets me the naked
exception object, not a full stack dump.  I'm assuming that by the
time my process_exception() method gets called, it's too late to call
sys.exc_info().  Or is it?

I can't use the default DEBUG mechanism which displays the stack trace
in the browser.  For one thing, I want the information in the log.
For another, most of my routes are AJAX calls, so there's nowhere to
display 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.



Passing cookies around?

2011-06-09 Thread Roy Smith
We're using django as a front end to a pre-existing web site
implemented in PHP.  The PHP code has a vaguely RESTful interface,
where you can make HTTP calls on it and get back JSON-ized data.  The
django layer sits in front of that and talks directly to the browser.
We're not using any models in django; just using the views to render
django templates using the data from the PHP back end.

Authentication on the original site was via session cookies maintained
in the browser.  We're trying to figure out how to make the django
layer deal with authentication.  My thought is that it shouldn't.  It
should be entirely stateless, and just transparently pass cookie
headers back and forth between the browser and the PHP back end.
Probably by using some middleware to do this.

Has anybody done anything like this before?  Am I heading off into
weeds?

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



Accessing template name inside a template?

2011-06-06 Thread Roy Smith
For diagnostic purposes, I want every one of my templates to emit an
HTML comment showing the template name.  I was doing fine just
dropping "", etc, in each template, until the first
time I renamed a template and forgot to update the comment :-)

Any way to automate this process so I can 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: Confused about uploading files (Cannot force both insert and updating in model saving)

2011-06-06 Thread Roy Smith

> >    if form.is_valid():
> >             f = request.FILES['file']
> >             data_set = DataSet()
> >             data_set.save('foo', f)
>
> I suspect this is the problem: you create an empty instnce of DataSet
> and then call its save method. model.save has three optional arguments
> [1], in this case you call it with force_insert='foo', force_update=f.
>
> Both f and 'foo' evaluate to True, which is an obvious conflict.

Ah, yes, of course.  I was mixing up model.save() and
model.FileField.save().  Thanks for setting me straight.  What I
wanted was this:

if form.is_valid():
f = request.FILES['file']
data_set = DataSet(file=f)
data_set.save()

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



Confused about uploading files (Cannot force both insert and updating in model saving)

2011-06-05 Thread Roy Smith
I'm trying to figure out how to upload a file.  I've got a model that
looks like:

class DataSet(models.Model):
file = models.FileField(upload_to='data/%Y/%m/%d')

and my view method is:

def create_data_set(request):
if request.method == 'POST':
form = DataSetForm(request.POST,
   request.FILES)
if form.is_valid():
f = request.FILES['file']
data_set = DataSet()
data_set.save('foo', f)
return HttpResponseRedirect("/")
print "invalid"
else:
form = DataSetForm()
ctx = {'form': form}
ctx.update(csrf(request))
return render_to_response('chart/data_set.html', ctx)

with a form

class DataSetForm(forms.Form):
file = forms.FileField()

When I execute this, I get a form containing a file picker (so far, so
good), but when I submit the form I get a mysterious error (below).
What am I doing wrong?


Environment:


Request Method: POST
Request URL: http://localhost:8000/dataset/create

Django Version: 1.3
Python Version: 2.6.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'chart']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/Users/roy/lib/webchart/lib/python2.6/site-packages/Django-1.3-
py2.6.egg/django/core/handlers/base.py" in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)
File "/Users/roy/WebChart/chart/views.py" in create_data_set
  27. data_set.save('foo', f, False)
File "/Users/roy/lib/webchart/lib/python2.6/site-packages/Django-1.3-
py2.6.egg/django/db/models/base.py" in save
  459. raise ValueError("Cannot force both insert and
updating in model saving.")

Exception Type: ValueError at /dataset/create
Exception Value: Cannot force both insert and updating in model
saving.

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



No style sheets with DEBUG = False?

2011-05-30 Thread Roy Smith
If I set:

DEBUG = False

in my settings.py file, my site runs and produces the correct HTML,
but there's no style sheets loaded.  Even stranger, if I save the HTML
generated each way into files and compare them, they're identical!

Any clue what might be causing the style sheets not to load with DEBUG
= False?

-- 
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: authentication not working using test client

2011-04-26 Thread Roy Smith
I figured it out.  When I first set up my settings.py file, I did:

AUTHENTICATION_BACKENDS = (
'socialregistration.auth.FacebookAuth',
)

which breaks (well, omits) the default authentication module that 
client.login() depends on.  I needed to do:

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'socialregistration.auth.FacebookAuth',
)


On Apr 26, 2011, at 12:56 PM, Roy Smith wrote:

> I've got a test case that essentially looks like this:
> 
> --
> from django.test import TestCase
> from django.test.client import Client
> from django.contrib.auth.models import User
> 
> class ApiTest(TestCase):
>def test_login(self):
>username = 'foo'
>email = 'f...@example.com'
>password = 'secret'
>user = User.objects.create_user(username, mail,
> password=password)
>assert user.username == username
>assert user.is_active
>client = Client()
>assert client.login(username=username, password=password)  #
> this assertion fails
> --
> 
> When I run it, the client.login() assertion fails.  Any idea what I
> might be doing wrong?
> 
> -- 
> 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.
> 


---
Roy Smith
r...@panix.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.



authentication not working using test client

2011-04-26 Thread Roy Smith
I've got a test case that essentially looks like this:

--
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User

class ApiTest(TestCase):
def test_login(self):
username = 'foo'
email = 'f...@example.com'
password = 'secret'
user = User.objects.create_user(username, mail,
password=password)
assert user.username == username
assert user.is_active
client = Client()
assert client.login(username=username, password=password)  #
this assertion fails
--

When I run it, the client.login() assertion fails.  Any idea what I
might be doing wrong?

-- 
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: Rendering a template from inside a templatetag? (never mind)

2011-04-07 Thread Roy Smith
Do-oh!  All I needed to do was

t = template.loader.get_template('collage/item-component.html')
return t.render(context)




On Apr 7, 2011, at 11:14 PM, Roy Smith wrote:

>   You can't call render_to_response() from inside a tag.  Or can you?


--
Roy Smith
r...@panix.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.



Rendering a template from inside a templatetag?

2011-04-07 Thread Roy Smith
I've just written my first template tag (w/ django-1.3).  The idea is to 
produce the HTML for a UI component which can get embedded in other templates.  
The top-level template is items.html (attached).  My tag is item_html, defined 
in collage_extras.py (also attached).

This works, but what I really want my render() function to do is render another 
template (as opposed to embedding HTML in the python code).  It's not clear how 
to do this.  You can't call render_to_response() from inside a tag.  Or can you?


{% include "collage/header.html" %}

{% load collage_extras %}

{{num_items}} Items:

{% for item in items %}
  {% item_html item %}
{% endfor %}


{% include "collage/footer.html" %}
from django import template

register = template.Library()

def do_item_html(parser, token):
try:
tag_name, item = token.split_contents()
except ValueError:
tag_name = token.contents.split()[0]
raise template.TemplateSyntaxError("%r tag requires a single argument" % tag_name)
return ItemHtmlNode(item)

class ItemHtmlNode(template.Node):
def __init__(self, item):
self.item = template.Variable(item)

def render(self, context):
my_item = self.item.resolve(context)
return '%s%s' % (my_item.id,
  my_item.title)
  

register.tag('item_html', do_item_html)



--
Roy Smith
r...@panix.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: unique identifier to distinguish an instance

2011-04-06 Thread Roy Smith
On Wed, 2011-04-06 at 15:13 -0700, Tony wrote:
> so I have two models, A and B.  B has a foreignkey relationship in it
> from A (To be clear because I know I dont explain it that well, one A
> has many Bs).  for each group of Bs each A is connected with, I want
> there to be a way to mark one of the Bs as unique from the rest of
> them.

Without knowing anything about your application, it sounds like your
data model really should have two different relationships.  There's a
1:1 relationship selecting the "unique" B for a given A, and then
there's an additional 1:N relationship, selecting the "non-unique" B's
for a given A.


-- 
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: Rendering read-only forms?

2011-04-06 Thread Roy Smith
On Wed, 2011-04-06 at 12:51 -0700, Mike Ramirez wrote:

> the form widgets accept a key word arguement of "attrs"[1] which takes a 
> dictionary that has the key as the option and the value is the options fale. 
> i.e.: attrs={'readonly': 'true'}. These are added to the field when it's 
> rendered to html. 

Thanks.  I had just discovered that when I read your mail.  Good to know
I was on the right track!  I ended up with two forms, and use the
appropriate one in each view.

class ItemForm(forms.Form):
url = forms.URLField()
title = forms.CharField()
text = forms.CharField(required=False)

class ReadOnlyItemForm(forms.Form):
ro_text_widget = forms.TextInput(attrs={'disabled': 'disabled'})
url = forms.URLField(widget=ro_text_widget)
title = forms.CharField(widget=ro_text_widget)
text = forms.CharField(widget=ro_text_widget, required=False)



Minor nit: of these three only the second and third are valid HTML.





It's been a long time since I've started a web project from ground zero.
I've decided to take advantage of that and be fanatical about all HTML
validating.  We'll see how long that lasts :-)

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



Rendering read-only forms?

2011-04-06 Thread Roy Smith
I want to display an object in exactly the same style as an existing
template that looks like this:


{% csrf_token %}

{{form}}




except that I want all the fields to be read-only.  It's easy enough
to not include the submit button, but I also want to add
readonly="true" attributes to all the  tags.  Is there any way
to do this, sort of some javascript which edits the DOM?

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



form.errors is not a dictionary?

2011-04-05 Thread Roy Smith
I'm using django-1.3 .  I have a view with the following code:

def item_create(request):
if request.method == 'POST':
form = ItemForm(request.POST)
if form.is_valid():
url = form.cleaned_data['url']
item.save()
return HttpResponseRedirect('/')
else:
print form.errors

when I submit the form, I expected that form.errors would print out as
a dict, as documented in 
http://docs.djangoproject.com/en/1.3/ref/forms/api/#using-forms-to-validate-data.
Instead, I'm getting a hunk of HTML:


Django version 1.3, using settings 'soco-site.settings'
Development server is running at http://0.0.0.0:7626/
Quit the server with CONTROL-C.
date_addedThis
field is required.user_idThis field is required.
[05/Apr/2011 16:36:32] "POST /item/create/ HTTP/1.1" 200 718

Is my understanding wrong, or is this a bug?

-- 
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: Johnny Cache on Django 1.3

2011-04-04 Thread Roy Smith
Weird choice of name for this project.  Should have been
"djohnny-cache" :-)



On Mon, 2011-04-04 at 13:13 -0700, Charlie Offenbacher wrote:
> I read the docs (and the issues in their bug tracker), but my
> impression was that the main incompatibility with Django 1.3 is
> transactions, which we're not using.
> 
> Thanks for the reply,
> ~Charlie
> 
> On Apr 4, 4:24 am, Daniel Hilton  wrote:
> > On 4 April 2011 08:16, Charlie Offenbacher
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >  wrote:
> > > Hi everyone!
> >
> > > I'm try to install johnny-cache on Django 1.3. I literally followed
> > > the instructions here (http://packages.python.org/johnny-cache/#)
> > > exactly, using the memcached version.
> >
> > > Evverything runs okay, but nothing gets cached at all when I telnet to
> > > memcached. When I used cache-machine, that worked fine, so I know my
> > > memcached installation works.
> >
> > > Any suggestions on how to debug this problem?
> >
> > > Thanks for your time!!
> > > ~Charlie
> >
> > > --
> > > 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.
> >
> > If you read the docs (http://packages.python.org/johnny-cache/) on
> > pypi  there is a reference to the incompatibility and the cause of the
> > problem.
> >
> > Cheers,
> > Dan
> >
> > --
> > Dan Hilton
> > www.twitter.com/danhiltonwww.DanHilton.co.uk
> > 
> 


-- 
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 with ROOT_URLCONF

2011-04-03 Thread Roy Smith
On Apr 3, 4:58 pm, Shawn Milochik  wrote:
> In short, it has to be on your PYTHONPATH or in the local directory.

OK, then I'm still not getting how this works.  The full path to my
setting and urls files are:

/Users/roy/s7/soco/soco-site/settings.py
/Users/roy/s7/soco/soco-site/urls.py

If I have in that settings file:

ROOT_URLCONF = 'soco-site.urls'

and start up my server from the soco-site directory, it finds the urls
file.  How?  If I print out sys.path from inside settings.py, it
includes /Users/roy/S7/soco/soco-site, but not /Users/roy/S7/soco.
Even stranger, "soco-site" is not a valid module name.  If I do
something like "import soco-site.urls", I (as expected) get a syntax
error.  So what's the process that gets from the string 'soco-
site.urls' to a valid module import?  Is django handing the string
'soco-site.urls' directly to imp.loadmodule(), or something like that,
or is it parsing the string in django application code and doing
something magic with 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: Confusion with ROOT_URLCONF

2011-04-03 Thread Roy Smith
On Apr 3, 2:55 pm, andy  wrote:
> Well I'm guess you don't have to. Both ROOT_URLCONF = "foo.urls" and
> ROOT_URLCONF = "urls" seem to work fine.

Interesting, I just tried it that way, and sure enough it does work.
I had simply been following the examples in the tutorial, which showed
the foo.urls form.  Perhaps it once had to be that way in an older
version and the docs just never got updated?

Now I'm curious how it works both ways.

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



Confusion with ROOT_URLCONF

2011-04-03 Thread Roy Smith
I don't understand how ROOT_URLCONF is declared in settings.py.  If I
put all my apps (and my settings.py file) in a directory "foo", I'm
supposed to do:

ROOT_URLCONF = "foo.urls"

This seems counter-intuitive to me.  When I run my app (by running
"python manage.py runserver"), I'm already in the "foo" directory.
>From there, shouldn't you just need to do "import urls", not "import
foo.urls"?  Is the server doing a "cd .." at some point before it
starts running my code?

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



Problems with serving static files

2011-02-23 Thread Roy Smith
I'm running r15624, OSX-10.6.5, Python-2.6.1

In my top-level urls.py, I have:

# Serve static
files
(r'^static/(?P.*)$',
 'django.views.static.serve',
 {'document_root': '/Users/roy/dev/try.django/mysite/static',
  'show_indexes': True}),

If I go to http://localhost:8000/static/, I see a listing of my only
static file:

Index of /
site.css

but when I click on the site.css link, I get a 404 ('site.css' could
not be found).  Any ideas what might be going wrong?

-- 
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 getting called twice for each GET

2010-11-28 Thread Roy Smith
I've been playing around with django, building a toy app just to get
the feel of it.  I've been going nuts trying to figure out why my
index method has been getting called in all sort of places I didn't
expect.  I finally figured it out and thought I would share this with
the group (hopefully to prevent other django newbies from making the
same mistake).

I had a catch-all url defined:

urlpatterns = patterns('',
(r'^db/query/mn_id/', 'db.views.query_nm_id'),
(r'^db', 'db.views.index'),
(r'', 'db.views.index'),
)

I was seeing index() being called twice when I did a GET on "/db", and
if I did a GET on "/db/query/mn_id", I'd see query_mn_id() get called,
followed by a call to index().  It turns out the second GET in both
cases was my browser (Chrome on OSX) asking for "/favicon"!  Duh.

The clue that set me on the right path was that if I reloaded the page
with the "Reload this page" button, I got the behavior described
above, but if I navigated my history with the back and forward arrows,
I didn't get the extra call to index().I little sleuthing with
tcpdump showed what was going on, and logging request.get_full_path()
in each view method verified this.

What's really weird is that the /favicon GET isn't logged by
development server (python manage.py runserver).  For example,
runserver prints just:

[28/Nov/2010 09:36:57] "GET /db/query/ HTTP/1.1" 200 5

but I see in my application log:

DEBUG:root:/db/query/
DEBUG:root:/favicon.ico

Why don't both requests get printed?

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



Accessing multiple databases from a single django app?

2010-11-26 Thread Roy Smith
I want my application to be able to access two different mysql
databases (with different credentials, running on two different
servers).  One is a large data collection which I'll be accessing read-
only.  The other is read-write, and will be the one which manages the
site (account creation, user preferences, etc).  Is there a way to do
this?

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



How do I recover my password on the django website?

2010-08-08 Thread Roy Smith
I'm trying to submit a ticket to http://code.djangoproject.com/ and
need to login.  I must have created an account long ago because it
says my email address is already in use, but I have long since
forgotten my username and password.  I don't see any mechanism to
recover them.

My apologies if this is off-topic for this list.

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