Re: test client vs jinja?

2021-02-10 Thread Roy Smith
ednesday, 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)

Re: test client vs jinja?

2021-02-10 Thread Roy Smith
bruary 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 > i

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

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.

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 struc

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, &

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',

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,

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

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 mes

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 Smi

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', 'cla

Re: Problem with google calendar on ancient django version

2014-12-23 Thread Roy Smith
) 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 t

Problem with google calendar on ancient django version

2014-12-22 Thread Roy Smith
s 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 use

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 fak

Get size of cached item?

2013-08-16 Thread Roy Smith
ckling 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

Atomic test/set/get using django cache API?

2013-05-14 Thread Roy Smith
ted. 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 e

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,

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 da

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

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

editable option for model field?

2012-06-04 Thread Roy Smith
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" g

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 becau

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

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 ImageV

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,

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:

Overriding an admin widget?

2012-04-25 Thread Roy Smith
ionAdmin) 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)

Adding context data to a TemplateView?

2012-04-22 Thread Roy Smith
ut 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 emai

AutoFields must have primary_key=True?

2012-04-16 Thread Roy Smith
> 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

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 becaus

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

2012-04-10 Thread Roy Smith
"pk": 9, "model": "contenttypes.contenttype", "fields": { "model": "gallery", "name": "gallery", "app_label": "photologue" } }, but that's the only entry fo

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 name

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 = {

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 n

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 defaul

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

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 pla

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 t

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 Ser

Re: HttpResponseRedirect adds hostname?

2011-08-23 Thread Roy Smith
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/grou

HttpResponseRedirect adds hostname?

2011-08-23 Thread Roy Smith
n 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

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

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

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.

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

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_excepti

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 d

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 ""? -

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]

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,

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 D

Re: authentication not working using test client

2011-04-26 Thread Roy Smith
N_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: > >

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(

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 Sm

Rendering a template from inside a templatetag?

2011-04-07 Thread Roy Smith
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@googlegroup

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 th

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

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 t

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('/'

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

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

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

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

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/stati

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 pr

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 p

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