Re: django images nginx and authentication
On Oct 15, 9:41 pm, ReneMarxiswrote: > Hello > > i'm faceing the following problem: i have some application for > creating image galleries (upload/change...). > Till now the images are served by an nginx webserver (and are > therefore open to everyone). The django app is running in apache with > wsgi. > > My problem is i need to restrict the image delivery only to persons > that are authorized to watch the images. Best would be to include > djangos authentication with nginx. > > Is there any way to accomplish this or any other hints? If you are using nginx as a front end proxy to Django application running in Apache/mod_wsgi, then have Django return X-Accel-Redirect header with location of static file as hosted by nginx. Then setup nginx with private URL namespace mapping to files. The X-Accel- Redirect will be allowed to access those private files but not direct requests to nginx. In other words, Django authenticates user and if allowed to access file, sends back that header to have nginx serve it up. Because Django is serving up the files direct, this will actually be quite efficient. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django images nginx and authentication
Many thanks. i will try that out. But sounds to be a good solution :) On 15 Okt., 15:00, tbackwrote: > Hi Rene, > > look at this:http://wiki.nginx.org/NginxHttpSecureDownload. I personally use > lighttpd and mod_secdownload and googled the above. > > It works like this: > Your django application and your image server(s) share a secret. > Your application takes the secret, the url and a timestamp to > generate a new url consisting of the original url, the timestamp and > a hash value. > > The image server than takes his secret, the timestamp and the url > to calculate the hash. If the timestamp is not older than your > specified period and the hash matches the submitted hash the user > is allowed to download the image. > > cheers tback > > On Oct 15, 12:41 pm, ReneMarxis wrote: > > > Hello > > > i'm faceing the following problem: i have some application for > > creating image galleries (upload/change...). > > Till now the images are served by an nginx webserver (and are > > therefore open to everyone). The django app is running in apache with > > wsgi. > > > My problem is i need to restrict the image delivery only to persons > > that are authorized to watch the images. Best would be to include > > djangos authentication with nginx. > > > Is there any way to accomplish this or any other hints? > > > _thanks rene --~--~-~--~~~---~--~~ 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: invalid sytax when naming url
On Thu, Oct 15, 2009 at 10:14 PM, Davidwrote: > > I can't figure out why this is invalid syntax... You can't pass a keyword argument to a tuple. It should read: url(r'^$', object_list, list_args, name='list'), -- Adam Olsen SendOutCards.com http://www.vimtips.org http://last.fm/user/synic --~--~-~--~~~---~--~~ 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: Converting namespaces to dictionaries for use in template context processors ...
Hey, so to follow up ... I wrote my own that seems to do the trick, my little project here is called Tycho, so the Tycho.globals.Config contains the stuff mentioned in my previous email: # ContextProcessors.py # # all Tycho context processors: import Tycho.globals.Config import types, copy def config(request): # convert Config and it's subclasses to nested dicts: configs_dict = { } filternames = (dir(__builtins__), '__module__', '__file__') def isconfig(e): if isinstance(e, types.IntType) or \ isinstance(e, types.LongType) or \ isinstance(e, types.FloatType) or \ isinstance(e, types.StringType): return True return False def convert(e): edict = { } for n in filter( lambda x: x not in filternames, dir(e) ): if isinstance(getattr(e, n), types.ClassType): edict[n] = convert( getattr(e, n) ) elif isconfig(getattr(e, n)) and \ n not in filternames: edict[n] = copy.copy(getattr(e, n)) return edict return convert(Tycho.globals.Config) if __name__ == '__main__': # simple dispatch: print str( config(None) ) ### ... seems to do the trick. -John On Thu, Oct 15, 2009 at 8:55 PM, jcwrote: > > Hey Django users, > > So I've got a python file in my django app that I'm using to store some > configs in (to be global across several django apps), it's basically looks > something like this: > > [ -- Contents of Config.py -- ] > VERSION = '0.1' > MEDIA_PREFIX = '/usr/local/dev-www/m/' > [ .. etc ...] > > class u: > "place to put user/login-specific configurations" > MAX_LENGTH = 64 > PASS_MIN_LENGTH = 10 > > [ ... and some other classes with the same sort of thing too ...] > > Within views themselves, these are easy to access, e.g., > Configs.u.MAX_LENGTH, but I'd like be able to easily pass EVERYTHING here to > templates. > > So I'm wondering ... is there some easy/prescribed way (perhaps provided by > django itsself) to be able to turn this into a set of nested dictionaries for > use by a context processor? So for example, I'd like to effectively end up > with: > > render_to_response('stuff.html', > { > 'config' : { > 'VERSION' : '0.1' > 'MEDIA_PREFIX' : '/usr/local/dev-www/m/' > # ... etc ... > > } > }) > > Thanks! > -John --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
invalid sytax when naming url
I can't figure out why this is invalid syntax... Here is my code: from cube.books.models import Listing from django.contrib import admin from django.conf.urls.defaults import * from django.views.generic.simple import direct_to_template from django.views.generic.list_detail import object_list admin.autodiscover() list_args = { 'queryset' : Listing.objects.all(), } urlpatterns = patterns('', (r'^$', object_list, list_args, name='list'), (r'^help/', direct_to_template, {'template' : 'help.html'}), (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), ) And My Error: ('invalid syntax', ('/home/david/project/cube/urls.py', 15, 41, "(r'^$', object_list, list_args, name='list'),\n")) Traceback: File "/var/lib/python-support/python2.6/django/core/handlers/base.py" in get_response 77. request.path_info) File "/var/lib/python-support/python2.6/django/core/urlresolvers.py" in resolve 179. for pattern in self.urlconf_module.urlpatterns: File "/var/lib/python-support/python2.6/django/core/urlresolvers.py" in _get_urlconf_module 198. self._urlconf_module = __import__ (self.urlconf_name, {}, {}, ['']) Any help? 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 -~--~~~~--~~--~--~---
Converting namespaces to dictionaries for use in template context processors ...
Hey Django users, So I've got a python file in my django app that I'm using to store some configs in (to be global across several django apps), it's basically looks something like this: [ -- Contents of Config.py -- ] VERSION = '0.1' MEDIA_PREFIX = '/usr/local/dev-www/m/' [ .. etc ...] class u: "place to put user/login-specific configurations" MAX_LENGTH = 64 PASS_MIN_LENGTH = 10 [ ... and some other classes with the same sort of thing too ...] Within views themselves, these are easy to access, e.g., Configs.u.MAX_LENGTH, but I'd like be able to easily pass EVERYTHING here to templates. So I'm wondering ... is there some easy/prescribed way (perhaps provided by django itsself) to be able to turn this into a set of nested dictionaries for use by a context processor? So for example, I'd like to effectively end up with: render_to_response('stuff.html', { 'config' : { 'VERSION' : '0.1' 'MEDIA_PREFIX' : '/usr/local/dev-www/m/' # ... etc ... } }) Thanks! -John --~--~-~--~~~---~--~~ 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: Upload Progress Bar
Well, John at fariviewcomputing ended up helping me out (Thanks again John!), and it all works fine now. Turns out nginx was grabbing the files during the upload, and only handing them to Apache at the end, so the progress bar didn't work. I took nginx out of the equation and it works great now. On Oct 15, 1:01 pm, mattimckwrote: > Sorry to drag up a really old topic, but I am having the same issue as > Pawel on the thread > athttp://groups.google.com/group/django-users/browse_thread/thread/738e > I've responded to that thread, but my message didn't seem to come up. > So, I apologise if this ends up here twice. > > Is Pawel still around? Was anyone able to help solve this problem? If > not, could anyone help? > > The basic question is that he was (as am I) trying to implement a > version of the upload progress bar > fromhttp://www.fairviewcomputing.com/blog/2008/10/21/ajax-upload-progress > All seems to be working ok (no errors from Django, and the empty > progress bar displays for a while during upload), except that the bar > doesn't move, and Javascript keeps returning "upload is null". > > I'm also getting the same value "null" being returned from the > upload_progress view in Django (which in turn is what the JS is > receiving at each interval it checks the view), although i'm using a > slightly different setup than Pawel (mod_wsgi instead of mod_python, > and jQuery instead of YUI). > > Any help would be massively and hugely appreciated. > > -Matt --~--~-~--~~~---~--~~ 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: Running Tornado instead of modwsgi apache
On Friday 16 Oct 2009 8:10:08 am djangou...@gmail.com wrote: > Blog post with tornado setup? :) http://www.djangosnippets.org/snippets/1748/ -- regards kg http://lawgon.livejournal.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: Running Tornado instead of modwsgi apache
Blog post with tornado setup? :) Kenneth Gonsalves wrote: On Friday 16 Oct 2009 4:16:26 am Graham Dumpleton wrote: > > > Are you certain that the web server is the performance bottleneck? In > > > my experience, it rarely is. > > > > That argument aside, can we get an answer? > > But what he states is very important and shouldn't just be ignored. > > Now, I am sure someone will respond about Tornado, but have you even > made an attempt to tune your Apache/mod_wsgi installation? > > Also be aware that the Tornado benchmarks are quite misleading. > Although they given an impression that it runs up to 4 times quicker > than Apache/mod_wsgi that is not actually true and it certainly > doesn't mean your full application stack is magically going to run 4 > times quicker. my two paise: I run a VPS with 5 django sites on it. RAM is 256. I was using more or less untweaked apache with mod_python. The only tweaking done was playing around a bit with prefork settings. Now the sites there are extremely low volume - if any of them get more than 10 visitors a day it is some thing to celebrate. But even at this volume, pages (simple pages) were taking upto 2 minutes to load. And once or twice when there were more than a 100 visitors to one site, the server would freeze. Top would show several apache instances hogging most of the memory. I shifted to nginx/tornado. No tweaking here. Just the default install. Page loads are under a couple of seconds (compared to minutes). The processes do not even show up in the top part of top. There fore my take is: for the low end of the market, the bottleneck is RAM and the webserver. At this end of the market there is not much point in spending time tweaking apache when much better performance can be expected without spending much time with nginx/tornado. My experience in another server shows that this is at least twice as fast as apache/mod_wsgi. I repeat - this is my experience for low end of the market. And my experience is empirical. -- regards kg http://lawgon.livejournal.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: Deadlock detected
On Oct 15, 2009, at 8:01 AM, Szymon wrote: > CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."postac_postacie" > x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x" What this is doing is acquiring a shared lock on the row where id = $1 (the parameter) on table postas_postacie (you probably could figure this out); this corresponds to application Postac, model class Postacie. I'd examine the use cases of those models to see if different view methods are acquiring locks in a different order and creating a circular dependency. -- -- Christophe Pettus x...@thebuild.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: Running Tornado instead of modwsgi apache
On Friday 16 Oct 2009 4:16:26 am Graham Dumpleton wrote: > > > Are you certain that the web server is the performance bottleneck? In > > > my experience, it rarely is. > > > > That argument aside, can we get an answer? > > But what he states is very important and shouldn't just be ignored. > > Now, I am sure someone will respond about Tornado, but have you even > made an attempt to tune your Apache/mod_wsgi installation? > > Also be aware that the Tornado benchmarks are quite misleading. > Although they given an impression that it runs up to 4 times quicker > than Apache/mod_wsgi that is not actually true and it certainly > doesn't mean your full application stack is magically going to run 4 > times quicker. my two paise: I run a VPS with 5 django sites on it. RAM is 256. I was using more or less untweaked apache with mod_python. The only tweaking done was playing around a bit with prefork settings. Now the sites there are extremely low volume - if any of them get more than 10 visitors a day it is some thing to celebrate. But even at this volume, pages (simple pages) were taking upto 2 minutes to load. And once or twice when there were more than a 100 visitors to one site, the server would freeze. Top would show several apache instances hogging most of the memory. I shifted to nginx/tornado. No tweaking here. Just the default install. Page loads are under a couple of seconds (compared to minutes). The processes do not even show up in the top part of top. There fore my take is: for the low end of the market, the bottleneck is RAM and the webserver. At this end of the market there is not much point in spending time tweaking apache when much better performance can be expected without spending much time with nginx/tornado. My experience in another server shows that this is at least twice as fast as apache/mod_wsgi. I repeat - this is my experience for low end of the market. And my experience is empirical. -- regards kg http://lawgon.livejournal.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: Middleware to replace @login_required SOLVED, + PCI Compliance
Ethan, Thanks for the feedback. I did create my own middleware, and it was ridiculously simple. I just looked at the django.middleware files and saw how easy it was. I only had to make exceptions for the pages pertaining to resetting a forgotten password (from django.contrib.auth.views) and the login page. I put them in the same middleware, because it was so simple. I would tend to agree that they should be separate, except that they're each handling one end of an 'if' block (logged in or not), and it might actually make more sense to the maintenance programmer to have them together. For the curious, here's my code. Also, for the wise and helpful who might find fatal flaws and will help me correct them: http://pastebin.com/f4ddc98b6 Incidentally, this is part of a larger effort to make contrib.auth PCI compliant. Since this was the last step in that effort, I'm planning to write up the whole thing, since I asked about how to do it and didn't get any answers. PCI compliance requires password expiration after 90 days (max), a minimum password length, letters and numbers in the password, and disallowing users to re-use old passwords for a minimum of the four most recently used. Shawn --~--~-~--~~~---~--~~ 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: Running Tornado instead of modwsgi apache
On Oct 16, 10:21 am, Antoni Aloywrote: > 2009/10/16 Graham Dumpleton : > > > On Oct 16, 4:59 am, Ramdas S wrote: > >> On Thu, Oct 15, 2009 at 11:11 PM, Christophe Pettus > >> wrote: > > >> > On Oct 15, 2009, at 10:36 AM, Ramdas S wrote: > > >> > > I am currently running all my sites on modwsgi apache! Though I > >> > > cannot complain that the performance is bad, I would like to have > >> > > more. > > >> > Are you certain that the web server is the performance bottleneck? In > >> > my experience, it rarely is. > > >> That argument aside, can we get an answer? > > > But what he states is very important and shouldn't just be ignored. > > I agree with Grahan if you're looking for performance first you have > to look at your own code, tune your database, then your web server and > then perhaps you have to consider other server options. > > In our case our reason to move from apache+wsgi configuration to a > ngnix + WSGI CherryPy/Tornado configuration not was performace but > resources. Even loosing some performance the relation between the > number of requests per second and the memory and CPU consumed in the > computer was good enougth to justify the change. What resources? Often this again comes down to issue of properly setting up Apache/mod_wsgi. If resources are limited, eg., memory, you should not for example be using embedded mode of mod_wsgi or mod_python. Read: http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html If you configure things properly with Apache/mod_wsgi, there is no reason why it should be any worse on resources than competing solutions. The problem is that most people just don't have a clue about how to setup Apache well, or don't actually even investigate how Apache/ mod_wsgi can be reconfigured to address such issues. Documentation is only useful when people read it. Mailing lists are also only useful if you actually go asking how to do things when you don't understand. Graham --~--~-~--~~~---~--~~ 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: When would you use Context instead of RequestContext?
You have a point. Then again, Django does have a wiki, which is a good place for suggestions to be annotated with a discussion of the pros and cons of a particular approach. On Oct 15, 6:13 pm, bruno desthuillierswrote: > > who is going to decide which are "best" practices ?-) --~--~-~--~~~---~--~~ 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: Running Tornado instead of modwsgi apache
2009/10/16 Graham Dumpleton: > > > > On Oct 16, 4:59 am, Ramdas S wrote: >> On Thu, Oct 15, 2009 at 11:11 PM, Christophe Pettus wrote: >> >> >> >> > On Oct 15, 2009, at 10:36 AM, Ramdas S wrote: >> >> > > I am currently running all my sites on modwsgi apache! Though I >> > > cannot complain that the performance is bad, I would like to have >> > > more. >> >> > Are you certain that the web server is the performance bottleneck? In >> > my experience, it rarely is. >> >> That argument aside, can we get an answer? > > But what he states is very important and shouldn't just be ignored. > I agree with Grahan if you're looking for performance first you have to look at your own code, tune your database, then your web server and then perhaps you have to consider other server options. In our case our reason to move from apache+wsgi configuration to a ngnix + WSGI CherryPy/Tornado configuration not was performace but resources. Even loosing some performance the relation between the number of requests per second and the memory and CPU consumed in the computer was good enougth to justify the change. -- Antoni Aloy López Blog: http://trespams.com Site: http://apsl.net --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Console output on dev server
When running the dev server, it shows a log of everything that happens (i.e. - GET & POST messages) in the console. Is there anyway to hide those log messages and only show errors (if they happen)? --~--~-~--~~~---~--~~ 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: Running Tornado instead of modwsgi apache
On Oct 16, 4:59 am, Ramdas Swrote: > On Thu, Oct 15, 2009 at 11:11 PM, Christophe Pettus wrote: > > > > > On Oct 15, 2009, at 10:36 AM, Ramdas S wrote: > > > > I am currently running all my sites on modwsgi apache! Though I > > > cannot complain that the performance is bad, I would like to have > > > more. > > > Are you certain that the web server is the performance bottleneck? In > > my experience, it rarely is. > > That argument aside, can we get an answer? But what he states is very important and shouldn't just be ignored. Now, I am sure someone will respond about Tornado, but have you even made an attempt to tune your Apache/mod_wsgi installation? Also be aware that the Tornado benchmarks are quite misleading. Although they given an impression that it runs up to 4 times quicker than Apache/mod_wsgi that is not actually true and it certainly doesn't mean your full application stack is magically going to run 4 times quicker. If you compare like applications on top, unlike what they did in comparing a minimal native hello world program with heavyweight Django (in comparison), you will get results which are quite similar. On MacOS X with an untuned Apache installation, Tornado is actually slower than Apache/mod_wsgi when comparing a Tornado hello world application with a WSGI hello world application. That all said, if you still want to believe their slanted benchmarks then that is fine. Just make sure you are choosing one hosting mechanism over another based on what you perceive is usability as far as ease of installation, configuration and management. It is quite pointless to make decisions on just benchmarks as no single benchmark will really give you the full picture and as other person pointed out the web server is usually never the bottleneck. Thus, chasing better performance, which likely will amount to less than a few percent difference in the context of the complete application stack, by shifting to another hosting mechanism is likely more to just waste time which you could spend on fixing up the performance of your application and database access. Graham --~--~-~--~~~---~--~~ 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 manage (for testserver) fixtures files when use django.contrib.auth
Are you looking for help on creating fixtures? If so, try this: http://docs.djangoproject.com/en/dev/howto/initial-data/#howto-initial-data If you're trying to add users using fixtures, then have a look here: http://groups.google.com/group/django-users/browse_thread/thread/c66f564797e64d47/35ab82234e8fe7c7?q=#35ab82234e8fe7c7 On Oct 15, 12:18 pm, Jacobianwrote: > I find very much, if exists a link with explain could you send me, > Thanks. > > P.D. Sorry, for my english. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Customizing form widget
I have a Category and SubCategory model. Each SubCategory belongs to a Category via a Foreign Key. (So each Category can have many SubCategories.) I have several places throughout my app where I show the list of SubCategories as part of some ModelForm. It renders like so: subcategory 1 subcategory 2 subcategory 3 ... Which is dandy, but I would like to customize this a bit by showing Categories as well in an , like so: subcategory 1 subcategory 2 subcategory 3 ... Any ideas on how I can make that happen? Thanks in advance for any help. --~--~-~--~~~---~--~~ 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: When would you use Context instead of RequestContext?
On 15 oct, 18:28, ringemupwrote: > I don't think I've seen the two-function technique used much, if at > all. To be true, I never saw it anywhere except in some of my own code. But I wish I'd seen it more often... Also and FWIW, the "rendering" part of the "two-fold" views is easily factorable as an higher order function. > I'd certainly find it beneficial if more of the pluggables I use > took that approach. > > I wonder if a central repository of information about best practices > would benefit the community? Probably - but who is going to decide which are "best" practices ?-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can't get css working
On 15 oct, 17:44, Davidwrote: > Thank you for the interesting discussion. > Still, my original problem is bothering me. The "interesting discussion" was actually a practical example of a setup that is known to work and really helps avoiding typos. Did you try to rewrite your code according to this example ? If yes, and it still fails, please make a tarball of your project and post it somewhere we can get it. > Any idea what I could do to narrow it down? Make sure you have 'DEBUG=True' in your settings.py and "django.core.context_processors.debug" listed in your TEMPLATE_CONTEXT_PROCESSORS, run the dev server and point your browser to "127.0.0.1:8000/media_site/style.css". You should get a debug page telling you whether the 404 comes from the dispatcher not being able to resolve the url, or if the url was resolved but the file not found. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django and SSL Deployment using mod_wsgi
Hey take a look at this http://www.howsthe.com/blog/2009/sep/20/djang-nginx-mod_wsgi-ssl/ Vitaly Babiy On Thu, Oct 15, 2009 at 5:30 PM, neri...@gmail.comwrote: > > I'm trying to do the same thing but I'm having problems getting nginx > to server over https. I removed all 443 references for apache and > added them to my nginx/sites-available/domain.com, so I have a > declaration for static content listening on port 80 and then another > for ssl on 443. I'm totally new to this so I'm a bit unsure what's > wrong, do I need to add some WSGI reference to the nginx config, is > there a ssl mod for nginx I need to enable? > > Thanks, > > Jason > > On Aug 31, 10:39 am, Francis wrote: > > We setup aNginxproxy in front ofApache/WSGI and gotNginxto handle > > theSSLcert and simply pass on a flag to WSGI if the connection was > > coming through http or https. > > > > Next you'll want aSSLmiddleware, we use: > http://www.djangosnippets.org/snippets/240/ > > > > Now its a matter of configuring which views you wantSSL(follow > > example in the middleware) > > > > On Aug 28, 11:04 pm, Vitaly Babiy wrote: > > > > > Hey guys, > > > What is the best way to deploy an app that uses mod_wsgi that some > parts of > > > it need to be behindSSL? > > > > > Thanks, > > > Vitaly Babiy > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django and SSL Deployment using mod_wsgi
I'm trying to do the same thing but I'm having problems getting nginx to server over https. I removed all 443 references for apache and added them to my nginx/sites-available/domain.com, so I have a declaration for static content listening on port 80 and then another for ssl on 443. I'm totally new to this so I'm a bit unsure what's wrong, do I need to add some WSGI reference to the nginx config, is there a ssl mod for nginx I need to enable? Thanks, Jason On Aug 31, 10:39 am, Franciswrote: > We setup aNginxproxy in front ofApache/WSGI and gotNginxto handle > theSSLcert and simply pass on a flag to WSGI if the connection was > coming through http or https. > > Next you'll want aSSLmiddleware, we > use:http://www.djangosnippets.org/snippets/240/ > > Now its a matter of configuring which views you wantSSL(follow > example in the middleware) > > On Aug 28, 11:04 pm, Vitaly Babiy wrote: > > > Hey guys, > > What is the best way to deploy an app that uses mod_wsgi that some parts of > > it need to be behindSSL? > > > Thanks, > > Vitaly Babiy --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
InLine Validation
hello, I'm somewhat new to Python->Django and I found a little problem. -> I have 2 classes <-- - PayForm class (models.Model): type = models.CharField (max_length = 1, choices = PAYFORMS_TYPES) weekendDays = models.BooleanField () models.BooleanField holydays = () dateTime = models.DateTimeField (default = datetime.datetime.now (), editable = False) DateMother class (datebase): day = models.CharField (max_length = 2, choices = DAYMONTH_DAYS) month = models.CharField (max_length = 2, choices = _DAYMONTH_MONTHS) payform = models.ForeignKey (PayForm, editable = False) -> Inline <-- - PayFormInLine class (admin.TabularInline): model = DateMother -> ModelAdmin <-- --- PayFormAdmin class (admin.ModelAdmin): inlines = [ PayFormInLine, ] for example if the form was the following Type: type1 WeekendDays: yes Holydays: yes Day Month 15, 05 30, 04 15, 06 ¿I do like to compare the values of Month (moth [0], month [1 ]...) ? Thank you. : -( :- ( : -( :- ( : -( :- ( BAD BAD BAD : -( :- ( : -( :- ( : - ( :- ( : -( :- ( : -( :- ( DateMotherFormset class (BaseInlineFormSet): def clean (self): cleaned_data = self.cleaned_data self.cleaned_data.get day = (day) month = self.cleaned_data.get ( "month") count = 0 for form in self.forms: if month [0] == '5 ': self._errors [ "month"] [0] = ErrorList ([ 'Error']) return cleaned_data : -( :- ( : -( :- ( : -( :- ( BAD BAD BAD : -( :- ( : -( :- ( : - ( :- ( : -( :- ( : -( :- ( --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
InLine Validation
hola, soy algo nuevo en Python-Django y me he encontrado con un pequeño problema. -> tengo 2 clases <- class PayForm(models.Model): type = models.CharField(max_length=1, choices=PAYFORMS_TYPES) weekendDays = models.BooleanField() holydays = models.BooleanField() dateTime = models.DateTimeField(default=datetime.datetime.now(), editable=False) class DateMother(DateBase): day = models.CharField(max_length=2, choices=HOLYDAYS_DAYS) month = models.CharField(max_length=2, choices=HOLYDAYS_MONTHS) payform = models.ForeignKey(PayForm, editable=False) -> Inline <- class PayFormInLine(admin.TabularInline): model = DateMother -> ModelAdmin <- class PayFormAdmin(admin.ModelAdmin): inlines = [ PayFormInLine, ] por ejemplo si el formulario fuera el siguiente Type: type1 WeekendDays: yes Holydays: yes Day Month 15, 05 30, 04 15, 06 como me hago para comparar los valores de Month(moth[0], month[1]...) Gracias. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can't get css working
thanks for your help! I just won't get it. The "GET /media_site/style.css HTTP/1.1" 404 2118 is triggered by the link-tag in the template. After it checks in the urls.py. The output is the same, whether I have the "static-stuff" configured or not. So I probabely can't tell whether the url wasn't found other the problem occured later on. Later it would try to find the file in the file system, in $PROJECT_DIR/media_site/style.css right? On 15 Okt., 21:38, Jim McGawwrote: > Sorry, David, didn't mean to hijack your discussion! > > Looking over your original code, is it possible you need to use the += > operator? So, you have your urlpatterns, and then you add one for the > static media below: > > urlpatterns = pattern('', > # patterns for site here > ) > > urlpatterns += patterns('' > (r'^media_site/(?P.*)$', 'django.views.static.serve', > {'document_root': settings.MEDIA_ROOT}), > ) > > This depends on how you have thing set up...you look like you have: > > patterns('', ... etc... ), which won't do anything. You need to add it > to the urlpatterns variable. > > By the way, breaking it out into two urlpatterns definitions might > seem silly, but it also allows you to conditionalize the use of local > static media in DEBUG mode, so it won't be used in production: > > urlpatterns = patterns('', > # etc. > ) > > if settings.DEBUG: > urlpatterns += patterns('' > (r'^media_site/(?P.*)$', 'django.views.static.serve', > {'document_root': settings.MEDIA_ROOT}), > ) --~--~-~--~~~---~--~~ 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: Middleware stored locally
I have an init.py, is the path the likely problem or is it something else? thanks, Andrew On 15 Oct, 02:07, BenWwrote: > I think every dir on the import path needs and __init__.py > > On Oct 14, 5:10 pm, When ideas fail wrote: > > > If i have a lib folder in my app what is the correct way to reference > > it in settings.py? > > > I've tried this > > > MIDDLEWARE_CLASSES = ( > > 'myapp.lib.django_authopenid.middleware.OpenIDMiddleware' > > # and > > 'myapp.django_authopenid.middleware.OpenIDMiddleware' > > ) > > > the file its in is > > > \Apache2.2\myapp\lib\django_authopenid > > > but I get a 500 Internal Server and the error log tells me the > > following: > > > [Thu Oct 15 00:56:39 2009] [error] [client 127.0.0.1] raise > > exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' > > % (mw_module, e) > > [Thu Oct 15 00:56:39 2009] [error] [client 127.0.0.1] > > ImproperlyConfigured: Error importing middleware > > abeona.django_authopenid.middleware: "No module named > > django_authopenid.middleware" > > > I'd appreciate any help > > > Thanks > > > Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can't get css working
Sorry, David, didn't mean to hijack your discussion! Looking over your original code, is it possible you need to use the += operator? So, you have your urlpatterns, and then you add one for the static media below: urlpatterns = pattern('', # patterns for site here ) urlpatterns += patterns('' (r'^media_site/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), ) This depends on how you have thing set up...you look like you have: patterns('', ... etc... ), which won't do anything. You need to add it to the urlpatterns variable. By the way, breaking it out into two urlpatterns definitions might seem silly, but it also allows you to conditionalize the use of local static media in DEBUG mode, so it won't be used in production: urlpatterns = patterns('', # etc. ) if settings.DEBUG: urlpatterns += patterns('' (r'^media_site/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), ) --~--~-~--~~~---~--~~ 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: Developer help appreciated: unicode() not returning SafeString correctly - possibly a bug?
Ah - ok, I see! My knowledge of the unicode area is lacking, so I hadn't actually realized we were overriding a built-in by defining __unicode__. Completely obvious now that you point it out of course. I don't need to be returning a string instead of unicode. I just inadvertantly ended up doing that due to the fact that my widget, in certain cases, does not need to provide an input and thus was not calling its super() method. I'm used to using strings rather than unicode, so the resulting widget was just rendering some html for display only, and my render() method was returning it as a string rather than as unicode. In all other cases where I've done this sort of thing, I think I at some point ended up concatenating my html onto the return value of the widget's super() method, or concatenating it with the return of render_to_string(), and both of those have the effect of turning it into unicode, so I just never noticed the problem. So possibly a silly question, but is it considered best practice to code all strings as unicode as you write them, or is it better to convert to unicode at the end? IE def render(self, name, value, attrs=None): rendered = u' blah blah blah ' rendered += u' blah blah blah ' return mark-safe(rendered) vs: def render(self, name, value, attrs=None): rendered = ' blah blah blah ' rendered += ' blah blah blah ' return mark_safe(unicode(rendered)) Or maybe it doesn't matter at all, just curious if there is some benefit to one versus the other. I do recognize that what I'm doing above is ugly and that the html should go into the template, and eventually I will move it there. Sometimes it's just easier to live in python when debugging and not have the added complexity of the template. Ok, thanks for your response, that clarified a lot. Margie On Oct 14, 10:21 pm, Karen Traceywrote: > On Wed, Oct 14, 2009 at 6:25 PM, Margie Roginski > wrote: > > > > > Eventually I end up in the force_unicode() function at code that looks > > like this: > > > if hasattr(s, '__unicode__'): > > s = unicode(s) > > > The call to unicode(s) has resulted in my render function getting > > called, and as far as I can tell, unicode(s) should simply return the > > value that my render function returned. I would expect the resulting > > 's' to be a SafeString. However, if I look at the type of s after > > unicode(s) has been called, it's type is now rather > > than > > Python absolutely positively no exceptions requires that unicode(x) returns > unicode. If your implementation of __unicode__ does not return unicode, > then Python will attempt to coerce it to unicode. SafeString inherits from > str, and str is a type that can be coerced to unicode, so that is what > Python does. (If an implementation of __unicode__ returns something that is > neither unicode nor can be coerced to unicode, an exception will be > raised.) > > > This seems to result in the mark_safe() that I did in my render > > function not having the intended effect. > > > I have anlayzed this code to death, and I absolutely cannot figure out > > why the value being returned by my render function would be changing > > from SafeString to unicode. > > Because Python forces the return value from a unicode() call to be of type > unicode, so it coerces the SafeString to unicode. > > Note that if in my render() function I have a unicode string rather> than a > normal string, I don't see this issue. I can obviously work > > around this, but would like to know if this seems like a bug that I > > should post. Perhaps it is a python bug even? That's hard to > > believe, but I guess it's possible. > > If you call mark_safe on a unicode type, you get SafeUnicode instead of > SafeString. Since SafeUnicode inherits from unicode, no conversion is > needed and the safeness property is maintained through the calls. Why do > you want to be returning strings instead of unicode from your widget's > render()? > > Karen --~--~-~--~~~---~--~~ 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: Running Tornado instead of modwsgi apache
On Thu, Oct 15, 2009 at 11:11 PM, Christophe Pettuswrote: > > > On Oct 15, 2009, at 10:36 AM, Ramdas S wrote: > > > I am currently running all my sites on modwsgi apache! Though I > > cannot complain that the performance is bad, I would like to have > > more. > > Are you certain that the web server is the performance bottleneck? In > my experience, it rarely is. > That argument aside, can we get an answer? > > -- > -- Christophe Pettus >x...@thebuild.com > > > > > -- Ramdas S +91 9342 583 065 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin Settings
Creating a function off the model worked great! --- On Wed, 10/14/09, Bayuadjiwrote: > From: Bayuadji > Subject: Re: Admin Settings > To: django-users@googlegroups.com > Date: Wednesday, October 14, 2009, 11:52 PM > > or create a function that return > object.foreign_key.field1. > then use the function in list_display > > cheers. > -djibon- > > On 10/14/09, justquick > wrote: > > > > try using 'foreign_key__field1' instead > > > > On Oct 14, 12:04 pm, freeav8r > wrote: > >> Is it possible to do something like this: > >> > >> class MyModelAdmin(admin.ModelAdmin): > >> list_display = (‘field1’, field2’, > ‘foreign_key’, > >> ‘foreign_key.field1’, foreign_key.field2’,) > >> > >> admin.site.register(MyModel, MyModelAdmin) > >> > >> ‘foreign_key’ works just fine, but > ‘foreign_key.field1’ and > >> ‘foreign_key.field2’ error out. Any > suggestions? > > > > > > > > -- > -- > http://www.tumbletooth.org > my linkedin profile : http://www.linkedin.com/in/bayuadji > -- > > > > --~--~-~--~~~---~--~~ 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: Running Tornado instead of modwsgi apache
On Oct 15, 2009, at 10:36 AM, Ramdas S wrote: > I am currently running all my sites on modwsgi apache! Though I > cannot complain that the performance is bad, I would like to have > more. Are you certain that the web server is the performance bottleneck? In my experience, it rarely is. -- -- Christophe Pettus x...@thebuild.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 -~--~~~~--~~--~--~---
Running Tornado instead of modwsgi apache
I am currently running all my sites on modwsgi apache! Though I cannot complain that the performance is bad, I would like to have more. I have been reading on the web on different peopl's experience and suggestions, on migrating to Tornado with Nginx or Lighty serving the static files I seen both good and bad! How much of performance gain can you expect? What is the groups official recommendation? Thanks -- Ramdas S +91 9342 583 065 --~--~-~--~~~---~--~~ 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 manage (for testserver) fixtures files when use django.contrib.auth
I find very much, if exists a link with explain could you send me, Thanks. P.D. Sorry, for my english. --~--~-~--~~~---~--~~ 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: Middleware to replace @login_required
On Thu, Oct 15, 2009 at 12:24 PM, Shawn Milochikwrote: > > Middleware question: > > If 100% of an apps views require a logged-in user except for the login > page, does it makes sense to have middleware check the URL and > redirect to the login page rather than putting the @login_required > decorator over all the views? > This is what I do, yeah. It's a nice way to "decorate" your site when your auth requirement isn't so fine grained. We have an AuthRequirementMiddleware that you might find useful -- though it may be just as easy to rewrite. :) It lets you specify path prefixes (in settings.py) that are exempt from the auth check. It sounds like you might want to invert that logic. Release: http://pypi.python.org/pypi/djangohelpers Forkable trunk: http://github.com/ccnmtl/djangohelpers I have to ensure that users' passwords expire, and to do that I need > to check the user's profile on each page load and redirect to the > password change page if it has. > I tried doing this within a context processor, but redirection doesn't > work from there. I was told on the IRC channel that I should be using > middleware. > > If that's the case, doesn't it makes sense to just handle the (nearly > identical) task of @login_required in the same middleware? > I'd keep them in separate middlewares for cleaner organization and futureproofing, but YMMV. egj --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
DRY: max length not taken from Model.field when using ModelForm
Hi All, It seems the max_lenght from the model definition is not respected thoughout the form that's created when using Modelform. company_name = models.CharField(max_length=75) Is this correct or am I missing something? And while violating DRY is the Modelform definition the best place to put this? It does seem to work for the form fields' label, which is taken from the model fields' verbose name. Thanx for any light on the subject Regards, Gerard. -- self.url = www.gerardjp.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: When would you use Context instead of RequestContext?
I don't think I've seen the two-function technique used much, if at all. I'd certainly find it beneficial if more of the pluggables I use took that approach. I wonder if a central repository of information about best practices would benefit the community? On Oct 15, 3:40 am, bruno desthuillierswrote: > > Is using RequestContext best practice for apps meant to be pluggable? > > As a general rule, yes. FWIW and while we're at it, another best > practice for pluggable apps would be, whenever possible, to write "two- > folds" views - that is, split the view into two functions, one that do > the job and returns a RequestContext, and the other one - the > "official" view - that calls on the first and takes of the rendering > etc. --~--~-~--~~~---~--~~ 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: Embedding multiple images in html email
> Can't you include the link and source within the html code of the email? The problem then becomes that many email programs no longer display remote images inline unless the email comes from a trusted source. It was a popular way to add tracking bugs to HTML emails, so MUAs began to disable the functionality. To get around it, you have to include the image in the HTML-email itself as a named attachment, and then reference it with as described at[1] Don't forget that some folks fly with HTML email turned off or from mobile devices that may not support HTML email, so they will only see the plain-text version which you'll want to include. The images and HTML version will likely appear merely as attachments. -tim [1] http://code.activestate.com/recipes/473810/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Middleware to replace @login_required
Middleware question: If 100% of an apps views require a logged-in user except for the login page, does it makes sense to have middleware check the URL and redirect to the login page rather than putting the @login_required decorator over all the views? I have to ensure that users' passwords expire, and to do that I need to check the user's profile on each page load and redirect to the password change page if it has. I tried doing this within a context processor, but redirection doesn't work from there. I was told on the IRC channel that I should be using middleware. If that's the case, doesn't it makes sense to just handle the (nearly identical) task of @login_required in the same middleware? Thanks, Shawn --~--~-~--~~~---~--~~ 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: Embedding multiple images in html email
Can't you include the link and source within the html code of the email? for example, as a snippet: . . . html = """\ blah blah blah http://blah-blah-blah.com;>http://blah-blah-blah.com/media/img/blah-blah-whatver-image.png; width=100%> Blah-whatever-your-message-here """ # Record the MIME types of both parts - text/plain and text/html. part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, in this case # the HTML message, is best and preferred. msg.attach(part1) msg.attach(part2) s = smtplib.SMTP(blah-blah-whatever-MY_SMTP_SERVER) # sendmail function takes 3 arguments: sender's address, recipient's address # and message to send - here it is sent as one string. s.sendmail(me, myRecipient, msg.as_string()) s.quit() . . . Since it is html, you can embed as many images as you want? On Thu, Oct 15, 2009 at 5:30 AM, Muhammed Abadwrote: > > As the topic says, can I embed multiple images in an html email > template so the recipient does not have to download them? > > I know this might be a silly request, but a client has asked me to do > this for him and Im absolutely stumped. > > The closest to a solution I have come to is this : > http://www.djangosnippets.org/snippets/1507/ > > If someone else can get this to work, please let me know. > > Any other solution are welcome. > > Thanks in advance. > > M. > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can't get css working
Thank you for the interesting discussion. Still, my original problem is bothering me. Any idea what I could do to narrow it down? --~--~-~--~~~---~--~~ 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: Multi-db support
Jeff Bell wrote: > My problem occurs during larger queries - I get 'Too many connections' > error. If I run these queries through django's default manager they > are handled fine. Can anyone point me in the right direction, maybe > the source code where django handles this. I'm pretty sure I need to > close the connection in my MultiDBManager but not sure how to > accomplish this. > If you mean something based on MultiDBManager here: http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/ I think it makes an awful lot of DatabaseWrappers as-is. I _think_ (but could be wrong), that seriously lowers connection reuse, so you end up with a lot of dangling connections. Here's something further pared down I'm currently testing with django 1.1.1 to tide us over until true multi-db for our own simple multi-postgresql-database case. It "seems to work", though doesn't address a bunch of stuff true multi-db would cover - I just needed (okay, wanted) read-only access to an extra database through django orm, but you could probably add Eric's _insert. I also only use processes not threads, with mod_wsgi daemon mode. Doing it this way, you should probably consider an altconnection1.close() sometimes (it won't happen implicitly sometimes unlike the main connection), but it's only using one extra DatabaseWrapper instance per extra database. from django.conf import settings from django.db import backend altconnection1 = backend.DatabaseWrapper( 'DATABASE_HOST': settings.DATABASE_HOST, 'DATABASE_NAME': "altdb1", 'DATABASE_OPTIONS': settings.DATABASE_OPTIONS, 'DATABASE_PASSWORD': '', 'DATABASE_PORT': '', 'DATABASE_USER': settings.DATABASE_USER, 'TIME_ZONE': settings.TIME_ZONE, }) class ExtDBManager(models.Manager): def __init__(self, connection, *args, **kwargs): self.connection = connection super(ExtDBManager, self).__init__(*args, **kwargs) def get_query_set(self): qs = super(ExtDBManager, self).get_query_set() qs.query.connection = self.connection return qs class MyModel1(models.Model): class Meta: managed = False db_table = 'table1' objects = ExtDBManager(altconnection1) ... class MyModel2(models.Model): class Meta: managed = False db_table = 'table2' objects = ExtDBManager(altconnection1) ... --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Deadlock detected
Hello, Sometimes Django (on higher loads) throws exception: TransactionRollbackError: deadlock detected DETAIL: Process 58214 waits for ShareLock on transaction 121403425; blocked by process 58200. Process 58200 waits for ShareLock on transaction 121403482; blocked by process 58214. HINT: See server log for query details. CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."postac_postacie" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x" Any suggestions? Apache + mod_wsgi + Postgres. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Cannot create notification records in management.py
Hi, I'm using django notification. I've installed django-messages, that tries to add records for into the notification_noticetype table. Here is the management.py from django.db.models import get_models, signals from django.conf import settings from django.utils.translation import ugettext_noop as _ if "app.notification" in settings.INSTALLED_APPS: from trunk.app.notification.models import models def create_notice_types(app, created_models, verbosity, **kwargs): notification.create_notice_type("messages_received", _ ("Message Received"), _("you have received a message"), default=2) notification.create_notice_type("messages_sent", _("Message Sent"), _("you have sent a message"), default=1) notification.create_notice_type("messages_replied", _("Message Replied"), _("you have replied to a message"), default=1) notification.create_notice_type("messages_reply_received", _ ("Reply Received"), _("you have received a reply to a message"), default=2) notification.create_notice_type("messages_deleted", _("Message Deleted"), _("you have deleted a message"), default=1) notification.create_notice_type("messages_recovered", _ ("Message Recovered"), _("you have undeleted a message"), default=1) signals.post_syncdb.connect(create_notice_types, sender=notification) else: print "Skipping creation of NoticeTypes as notification app not found" Django founds the notification app but it seems that this line signals.post_syncdb.connect(create_notice_types, sender=notification) doesn't get executed. I googled but didn't found anything. Has anyone ever encountered this issue? I'm running on Python2.5 and Django 1.1.1 Thanks, Simone. --~--~-~--~~~---~--~~ 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: ModelAdmin.save_model Not being called
The problem was that I was overriding the save_model method on the InlineAdmin instead of on the ModelAdmin itself. Now is being called... Cheers. and thanks! On Oct 15, 11:16 am, ekawrote: > DR: > > Yes your are right. My bad... still my one is not being called. > > Here is the code: > > class LocatedItemStackedInline(generic.GenericStackedInline): > template = "admin/location_app/located_items/stacked.html" > model = LocatedItem > extra = 1 > form = MyModelForm > raw_id_fields = ('location',) > > def save_model(self, request, obj, form, change): > import ipdb;ipdb.set_trace() > super(LocatedItemStackedInline, self).save_model(request, obj, > form, change) > > def save_form(self, request, form, change): > import ipdb;ipdb.set_trace() > super(LocatedItemStackedInline, self).save_form(request, form, > change) > > On Oct 15, 11:13 am, Daniel Roseman wrote: > > > On Oct 15, 2:58 pm, eka wrote: > > > > Hi all > > > > I need to override the ModelAdmin save_model and I found out that is > > > not being called. I checked the documentation where it says how to use > > > it and the searched around the code to see if there is a call to that > > > method and can't find any call to save_model anywhere in all Django > > > src (versions 1.0 and 1.1). > > > >http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#django.contri... > > > > Any clue? Is this not implemented? Bug? Or I'm missing something? > > > > Regards > > > > Esteban (eka) > > > I don't know where you're looking, but save_model is called from > > add_view, change_view and changelist_view in contrib.admin.options. > > -- > > DR. --~--~-~--~~~---~--~~ 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: ModelAdmin.save_model Not being called
DR: Yes your are right. My bad... still my one is not being called. Here is the code: class LocatedItemStackedInline(generic.GenericStackedInline): template = "admin/location_app/located_items/stacked.html" model = LocatedItem extra = 1 form = MyModelForm raw_id_fields = ('location',) def save_model(self, request, obj, form, change): import ipdb;ipdb.set_trace() super(LocatedItemStackedInline, self).save_model(request, obj, form, change) def save_form(self, request, form, change): import ipdb;ipdb.set_trace() super(LocatedItemStackedInline, self).save_form(request, form, change) On Oct 15, 11:13 am, Daniel Rosemanwrote: > On Oct 15, 2:58 pm, eka wrote: > > > Hi all > > > I need to override the ModelAdmin save_model and I found out that is > > not being called. I checked the documentation where it says how to use > > it and the searched around the code to see if there is a call to that > > method and can't find any call to save_model anywhere in all Django > > src (versions 1.0 and 1.1). > > >http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#django.contri... > > > Any clue? Is this not implemented? Bug? Or I'm missing something? > > > Regards > > > Esteban (eka) > > I don't know where you're looking, but save_model is called from > add_view, change_view and changelist_view in contrib.admin.options. > -- > DR. --~--~-~--~~~---~--~~ 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: ModelAdmin.save_model Not being called
Is this what you were looking for? def save_model(self, request, obj, form, change): """ Given a model instance save it to the database. """ obj.save() It is in contrib.admin.options: -- Peter --~--~-~--~~~---~--~~ 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: ModelAdmin.save_model Not being called
On Oct 15, 2:58 pm, ekawrote: > Hi all > > I need to override the ModelAdmin save_model and I found out that is > not being called. I checked the documentation where it says how to use > it and the searched around the code to see if there is a call to that > method and can't find any call to save_model anywhere in all Django > src (versions 1.0 and 1.1). > > http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#django.contri... > > Any clue? Is this not implemented? Bug? Or I'm missing something? > > Regards > > Esteban (eka) I don't know where you're looking, but save_model is called from add_view, change_view and changelist_view in contrib.admin.options. -- DR. --~--~-~--~~~---~--~~ 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: ModelAdmin.save_model Not being called
Also overriding the Model.save is not an option since I need to use the request object that is passed to the save_model method cause I have some stuff in the request I need to use. Any clue? On Oct 15, 11:07 am, ekawrote: > But is there any reason why I can't use that one? Is documented :P > > On Oct 15, 11:05 am, Bayuadji wrote: > > > Hi, > > > You could override save on Model instead. > > > -djibon- > > > On 10/15/09, eka wrote: > > > > Hi all > > > > I need to override the ModelAdmin save_model and I found out that is > > > not being called. I checked the documentation where it says how to use > > > it and the searched around the code to see if there is a call to that > > > method and can't find any call to save_model anywhere in all Django > > > src (versions 1.0 and 1.1). > > > >http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#django.contri... > > > > Any clue? Is this not implemented? Bug? Or I'm missing something? > > > > Regards > > > > Esteban (eka) > > > -- > > --http://www.tumbletooth.org > > my linkedin profile :http://www.linkedin.com/in/bayuadji > > -- --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Bug #6138
This fix for this bug has been commited and is in revision 11624. As I 'own' the bug should I chnage the status to 'fixed'? Presently no-one has done that. -- Peter --~--~-~--~~~---~--~~ 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: ModelAdmin.save_model Not being called
But is there any reason why I can't use that one? Is documented :P On Oct 15, 11:05 am, Bayuadjiwrote: > Hi, > > You could override save on Model instead. > > -djibon- > > On 10/15/09, eka wrote: > > > > > > > Hi all > > > I need to override the ModelAdmin save_model and I found out that is > > not being called. I checked the documentation where it says how to use > > it and the searched around the code to see if there is a call to that > > method and can't find any call to save_model anywhere in all Django > > src (versions 1.0 and 1.1). > > >http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#django.contri... > > > Any clue? Is this not implemented? Bug? Or I'm missing something? > > > Regards > > > Esteban (eka) > > -- > --http://www.tumbletooth.org > my linkedin profile :http://www.linkedin.com/in/bayuadji > -- --~--~-~--~~~---~--~~ 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: displaying tree data in admin
Thank you, Daniel, I'm trying to use this: http://magicrebirth.wordpress.com/2009/08/18/django-admin-and-mptt-2/ On Oct 15, 12:09 pm, Daniel Rosemanwrote: > On Oct 15, 8:16 am, ev wrote: > > > May be there were developers solutions? Where should I look for? > > Look at the django-mptt project. It implements an efficient algorithm > for tree access, and also has some useful libraries that help with > displaying trees. You might be able to use one of them. > > Alternatively, you could represent the tree simply by making > __unicode__ prefix a series of dashes equal to the level of the > element: > > def __unicode__(self): > return u"%s %s" % ((u'-' * self.level), self.name) > > This would show the elements like this: > root > -level1 > --level2 > ---level3 > > etc. > -- > DR. --~--~-~--~~~---~--~~ 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: ModelAdmin.save_model Not being called
Hi, You could override save on Model instead. -djibon- On 10/15/09, ekawrote: > > Hi all > > I need to override the ModelAdmin save_model and I found out that is > not being called. I checked the documentation where it says how to use > it and the searched around the code to see if there is a call to that > method and can't find any call to save_model anywhere in all Django > src (versions 1.0 and 1.1). > > http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model > > Any clue? Is this not implemented? Bug? Or I'm missing something? > > Regards > > Esteban (eka) > > > -- -- http://www.tumbletooth.org my linkedin profile : http://www.linkedin.com/in/bayuadji -- --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ModelAdmin.save_model Not being called
Hi all I need to override the ModelAdmin save_model and I found out that is not being called. I checked the documentation where it says how to use it and the searched around the code to see if there is a call to that method and can't find any call to save_model anywhere in all Django src (versions 1.0 and 1.1). http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model Any clue? Is this not implemented? Bug? Or I'm missing something? Regards Esteban (eka) --~--~-~--~~~---~--~~ 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: Generic View update_object with foreign key.
-- Sent from my Palm Unknown BvgfgfDavodM wrote: Hello all, Im just getting started with Django so apologies if this is a silly question. I have worked through the 4 tutorials and built the Poll application. I am now trying to add a page to edit polls using a generic view. My aim is to be able to edit polls in the same way as in the admin view, i.e editing the question and the foreign keyed choices. I have managed to implement the generic update_object and can happily edit the main data for the poll but am getting stuck with editing the foreign key values. >From reading the documentation I think I need to pass 'form_class' : MyPollForm instead of 'model' : Poll. Where MyPollForm is a model form for poll with an inline formset for choices. pre> class ChoiceInline(???): class Meta: model = Choice class MyPollForm(ModelForm): class Meta: model = Poll /pre> Am I going about this the right way? If so what does choice inline need to inherit from and how do I add it to MyPollForm? Thanks in advance, Dave --~--~-~--~~~---~--~~ 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: question about foreign key
Hi jul, if there is a chance that the country doesn't exist you have to check that before. Have a look at get_or_create: http://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-create-kwargs Cheers, Till On Oct 15, 1:51 pm, julwrote: > Hi, > > I've got the two models Country and Restaurant shown below. Is there a > way to directly set a country by instanciating a restaurant with a > Country instance? Something like: > > r=Restaurant(name='whatever', country=Country(name='newcountry')) > r.save() > > which returns "Column 'country_id' cannot be null" > > Or do I have to previously check if the country exists, and creating > it if it doesn't? > > Thanks > jul --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django images nginx and authentication
Hi Rene, look at this: http://wiki.nginx.org/NginxHttpSecureDownload. I personally use lighttpd and mod_secdownload and googled the above. It works like this: Your django application and your image server(s) share a secret. Your application takes the secret, the url and a timestamp to generate a new url consisting of the original url, the timestamp and a hash value. The image server than takes his secret, the timestamp and the url to calculate the hash. If the timestamp is not older than your specified period and the hash matches the submitted hash the user is allowed to download the image. cheers tback On Oct 15, 12:41 pm, ReneMarxiswrote: > Hello > > i'm faceing the following problem: i have some application for > creating image galleries (upload/change...). > Till now the images are served by an nginx webserver (and are > therefore open to everyone). The django app is running in apache with > wsgi. > > My problem is i need to restrict the image delivery only to persons > that are authorized to watch the images. Best would be to include > djangos authentication with nginx. > > Is there any way to accomplish this or any other hints? > > _thanks rene --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django images nginx and authentication
Hi, it seems that my first post didn't go through. I'm personally using lighttpd with mod_secdownload. But google just gave me this this: http://wiki.nginx.org/NginxHttpSecureDownload I'm pretty sure it will serve your needs. cheers, tback On Oct 15, 12:41 pm, ReneMarxiswrote: > Hello > > My problem is i need to restrict the image delivery only to persons > that are authorized to watch the images. Best would be to include > djangos authentication with nginx. > > Is there any way to accomplish this or any other hints? > > _thanks rene --~--~-~--~~~---~--~~ 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: question about foreign key
On Oct 15, 1:46 pm, bruno desthuillierswrote: > On 15 oct, 13:51, jul wrote: > > > Hi, > > > I've got the two models Country and Restaurant shown below. Is there a > > way to directly set a country by instanciating a restaurant with a > > Country instance? Something like: > > > r=Restaurant(name='whatever', country=Country(name='newcountry')) > > r.save() > > > which returns "Column 'country_id' cannot be null" > > Indeed - the Country instance only exists in memory by that time. > > > Or do I have to previously check if the country exists, and creating > > it if it doesn't? > > You may want to read about the Queryset.get_or_create > method:http://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-cre... > > In your above exemple, this would be used like: > > r=Restaurant(name='whatever', country=Country.objects.get_or_create > (name='newcountry')[0]) > r.save() Worth pointing out that you need the [0] there because get_or_create returns a tuple of (item, created) where created is a boolean showing whether or not the item was actually created. -- DR. --~--~-~--~~~---~--~~ 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: When would you use Context instead of RequestContext?
On Thu, Oct 15, 2009 at 9:01 PM, wiswaudwrote: > > If i'm not mistaken, RequestContext, through context_processors.auth, > will call request.user.get_and_delete_messages() and put in the > messages to the user in the context. That's fine and dandy, except > that in most modern applications, you have client-side code that will > be calling server-side partial templates; for example, to refresh the > contents of a message div. If you use RequestContext in such views, > you'll lose the messages, unless you make sure to somehow send those > back to the client as well, and have client-side code that checks for > that. It's strange you should raise that issue, because as of about 24 hours ago, it isn't the case any more. Luke Plant checked in some changes to trunk that make the retrieval of messages by RequestContext both lazy and memoized, so they won't be retrieved unless you explicitly request them, and they will be preserved for the length of the request once retrieved. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: When would you use Context instead of RequestContext?
If i'm not mistaken, RequestContext, through context_processors.auth, will call request.user.get_and_delete_messages() and put in the messages to the user in the context. That's fine and dandy, except that in most modern applications, you have client-side code that will be calling server-side partial templates; for example, to refresh the contents of a message div. If you use RequestContext in such views, you'll lose the messages, unless you make sure to somehow send those back to the client as well, and have client-side code that checks for that. Of course in that case, you might want to disable context_processors.auth, fill in the user context variable yourself, and have a special call/view for messages so that your js code makes a separate call for messages. I'm not saying using Context for partials is the solution here, i'm just saying that's something to watch out for, as the messages are lost if you're not careful. On Oct 15, 3:40 am, bruno desthuillierswrote: > On 14 oct, 19:44, Nan wrote: > > > So it's basically just an issue of optimization? > > > Is using RequestContext best practice for apps meant to be pluggable? > > As a general rule, yes. FWIW and while we're at it, another best > practice for pluggable apps would be, whenever possible, to write "two- > folds" views - that is, split the view into two functions, one that do > the job and returns a RequestContext, and the other one - the > "official" view - that calls on the first and takes of the rendering > etc. --~--~-~--~~~---~--~~ 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: question about foreign key
On 15 oct, 13:51, julwrote: > Hi, > > I've got the two models Country and Restaurant shown below. Is there a > way to directly set a country by instanciating a restaurant with a > Country instance? Something like: > > r=Restaurant(name='whatever', country=Country(name='newcountry')) > r.save() > > which returns "Column 'country_id' cannot be null" Indeed - the Country instance only exists in memory by that time. > Or do I have to previously check if the country exists, and creating > it if it doesn't? You may want to read about the Queryset.get_or_create method: http://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-create-kwargs In your above exemple, this would be used like: r=Restaurant(name='whatever', country=Country.objects.get_or_create (name='newcountry')[0]) r.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 -~--~~~~--~~--~--~---
Embedding multiple images in html email
As the topic says, can I embed multiple images in an html email template so the recipient does not have to download them? I know this might be a silly request, but a client has asked me to do this for him and Im absolutely stumped. The closest to a solution I have come to is this : http://www.djangosnippets.org/snippets/1507/ If someone else can get this to work, please let me know. Any other solution are welcome. Thanks in advance. M. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
question about foreign key
Hi, I've got the two models Country and Restaurant shown below. Is there a way to directly set a country by instanciating a restaurant with a Country instance? Something like: r=Restaurant(name='whatever', country=Country(name='newcountry')) r.save() which returns "Column 'country_id' cannot be null" Or do I have to previously check if the country exists, and creating it if it doesn't? Thanks jul class Country(models.Model): name = models.CharField(max_length=100, unique=True) class Restaurant(models.Model): name = models.CharField(max_length=100) country=models.ForeignKey(Country) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Generic View update_object with foreign key.
Hello all, Im just getting started with Django so apologies if this is a silly question. I have worked through the 4 tutorials and built the Poll application. I am now trying to add a page to edit polls using a generic view. My aim is to be able to edit polls in the same way as in the admin view, i.e editing the question and the foreign keyed choices. I have managed to implement the generic update_object and can happily edit the main data for the poll but am getting stuck with editing the foreign key values. >From reading the documentation I think I need to pass 'form_class' : MyPollForm instead of 'model' : Poll. Where MyPollForm is a model form for poll with an inline formset for choices. class ChoiceInline(???): class Meta: model = Choice class MyPollForm(ModelForm): class Meta: model = Poll Am I going about this the right way? If so what does choice inline need to inherit from and how do I add it to MyPollForm? Thanks in advance, Dave --~--~-~--~~~---~--~~ 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, insert into a foreign key produces unusual 'invalid keyword argument' error
Hi, im using django 1.0+mysql I get an unexpected error: "'event' is an invalid keyword argument for this function" I get using a django view which used to work for moving data into the mysql db by saving a foreign key instance of 'Event' in 'Category'. 1. The model is: class Event (models.Model): added = models.DateTimeField() addedBy = models.IntegerField() contact = models.CharField(max_length=100) email = models.CharField(max_length=100) phoneBH = models.CharField(max_length=30) phoneAH = models.CharField(max_length=30) phoneFax = models.CharField(max_length=30) phoneM = models.CharField(max_length=30) url = models.CharField(max_length=100) title = models.CharField(max_length=100) description = models.TextField() def __unicode__(self): return u"%s %s %s %s %s %s %s %s %s %s %s %s"%(self.added, self.addedBy, self.contact, self.email, self.phoneBH, self.phoneAH, self.phoneFax, self.phoneM, self.url, self.title, self.cost, self.description) class Category (models.Model): event = models.ForeignKey(Event) name = models.CharField(max_length=40) def __unicode__(self): return u"%s"%(self.name) 2. The piece of code which produces the error in the view: >> events_category = Category(name=new_event_tag, event=events_event) events_category.save() #note events_event is just a saved instance of Event() 3. The behaviour of the error is such that if i rename the 'Category' model to something else eg: 'Category2', drop the table and then syncdb and run it again then i dont get the error. However if it is called 'Category' then for some reason it does not work. Of course the downside here is id have to go through and rename all usage of the Category model in my views to the new class which with my project will take a long time. 4. here is the error, its the usual sort of thing you get trying to insert the wrong variable name into the model only it is the correct name. I am familiar with what django docs say about the error and it should be recognising the Foreign key 'event' being in Category but it doesnt! I just hope im forgetting something easy - Request Method: GET Request URL:http://127.0.0.1:8000/admin/eventmigrate/ Exception Type: TypeError Exception Value: 'event' is an invalid keyword argument for this function Exception Location: /var/lib/python-support/python2.5/django/db/models/base.py in __init__, line 265 Python Executable: /usr/bin/python Python Version: 2.5.2 - 5. I have a feeling something is wrong with mysql or django manage.py is not building the table properly... any troubleshooting advice would go a long way to helping me :) In addition here is what "python manage.py inspectdb" says about Category: - class EventsCategory(models.Model): id = models.IntegerField(primary_key=True) event_id = models.IntegerField() name = models.CharField(max_length=120) class Meta: db_table = u'events_category' cheers ---sam --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
unable to see SQL even after DEBUG=True in settings
Here is what is happening. >>> from django.db import connection >>> from mysite import settings >>> settings.DEBUG True >>> connection.queries [] I have run the app such that it has executed number of db queries and I know for sure there must be some sql. But still I don't see any in connection.queries. what am I doing wrong? thanks, Indu --~--~-~--~~~---~--~~ 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: questions about model attribute permissions set in django admin
Hi Allen, it looks like there is a 'pain in the ass' solution to your needs: http://stackoverflow.com/questions/1336382/how-can-i-modify-django-to-create-view-permission Cheers Eesti --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
django images nginx and authentication
Hello i'm faceing the following problem: i have some application for creating image galleries (upload/change...). Till now the images are served by an nginx webserver (and are therefore open to everyone). The django app is running in apache with wsgi. My problem is i need to restrict the image delivery only to persons that are authorized to watch the images. Best would be to include djangos authentication with nginx. Is there any way to accomplish this or any other hints? _thanks rene --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django project layout - authentication
Correction: We have a class 'LDAPBackend' with an authenticate function. Then in the view we use 'authenticate' from django.contrib.auth and if that returns None, we call the 'authenticate' bound to 'LDAPBackend'. Does it make sense to have a separate app just for one class? I assume the answer is no. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: [django-tagging] machinetags with namespaces and values, a ready-to-use branch
2009/10/15 Gregor Müllegger: > Hi django-users, > > in the last week i took a quick look over the django-tagging issue tracker and > found the interesting issue #14 "Support for machine tags". This seems to be > the oldest unclosed issue for django-tagging. This thrilled me so much that i > wanted to give it a try and developed a django-tagging branch with support for > namespaces and values. > Great work; this should come in handy for my next project. I wish I had gotten my earlier hacks up to scratch and made them public; I had some of this functionality implemented. Serves me right for being distracted with other projects :) I haven't looked at your code yet (I will soon), but I'm just curious if your changes have had any impact on performance? I remember that when I set out to implement some of this code, I had issues with it being efficient when there are larger sets of tags, including excessive database calls, or excessive data parsing. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django project layout - authentication
Hi I'm writing a web interface where users (in groups with different rights) can login and view and edit db entries. At the moment the login functionality is in myproject/ auth.py The authenticate method in auth.py checks the Users table and if that fails it tries ldap authentication. Now my question: Would it be better to make a separate app called 'auth' or is it ok to just leave it in the auth.py? It's not much code but then again dividing the project into many apps seems not like a bad idea either. Thanks for your help. --n --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
complete a form from auth_user
Hello i need to put in the forms.ChoiceField the value of the django uath_user table i can do it? how can import the table in the forms.py file Thanks luca --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can't get css working
Hi Bruno, Nice tips you got. thanks :) -djibon- On 10/15/09, bruno desthuillierswrote: > > On 14 oct, 19:34, David wrote: >> Thanks JIm, didn't solve my problem, but always good to learn some >> best practices. Any particular reason why >> {'document_root' : os.path.join(settings.CURRENT_PATH,"media_site") }) >> is better than >> {'document_root': settings.MEDIA_ROOT} >> in settings.py? > > Obviously none, except a failure to spot this repetition, I'd say !-) > > Here's what we usually do here for dev settings - as DRY as possible: > > ## settings.py > import os > > # typical default dev server setting > DEV_SERVER=True > PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) > PROJECT_URL = 'http://127.0.0.1:8000' > > # easier to use the same componant for URL and PATH > MEDIA_DIR = "site_media" > > # the MEDIA_ROOT must end with a path separator AFAICT > MEDIA_ROOT = os.path.join(PROJECT_PATH, MEDIA_DIR) + os.path.sep > > # use the fully qualified URL > # NB : we don't use os.path.join here - it's an url, not a system path > MEDIA_URL = "%s/%s/" % (PROJECT_URL, MEDIA_DIR) > > # don't forget the media processor for {{ MEDIA_URL }} in the > templates > TEMPLATE_CONTEXT_PROCESSORS = ( > # > "django.core.context_processors.media", > # > ) > > > ## urls.py > from django.conf.urls.defaults import * > from django.conf import settings > > urlpatterns = patterns( > '', > # urls here > ) > > if settings.get("DEV_SERVER", False): > urlpatterns += patterns( > '', > # static stuff > (r'^%s/(?P.*)$' % settings.MEDIA_DIR, > 'django.views.static.serve', > {'document_root': settings.MEDIA_ROOT} > ), > ) > > > ## base.html > > > > > > {% block title %}My project's title{% endblock %} > > > > > etc > > > > > This WorksForUs(tm) so far - as long as the dev server's user has read > access on MEDIA_ROOT and it's content of course !-) > > HTH > > > > -- -- http://www.tumbletooth.org my linkedin profile : http://www.linkedin.com/in/bayuadji -- --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can't get css working
On 14 oct, 19:34, Davidwrote: > Thanks JIm, didn't solve my problem, but always good to learn some > best practices. Any particular reason why > {'document_root' : os.path.join(settings.CURRENT_PATH,"media_site") }) > is better than > {'document_root': settings.MEDIA_ROOT} > in settings.py? Obviously none, except a failure to spot this repetition, I'd say !-) Here's what we usually do here for dev settings - as DRY as possible: ## settings.py import os # typical default dev server setting DEV_SERVER=True PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) PROJECT_URL = 'http://127.0.0.1:8000' # easier to use the same componant for URL and PATH MEDIA_DIR = "site_media" # the MEDIA_ROOT must end with a path separator AFAICT MEDIA_ROOT = os.path.join(PROJECT_PATH, MEDIA_DIR) + os.path.sep # use the fully qualified URL # NB : we don't use os.path.join here - it's an url, not a system path MEDIA_URL = "%s/%s/" % (PROJECT_URL, MEDIA_DIR) # don't forget the media processor for {{ MEDIA_URL }} in the templates TEMPLATE_CONTEXT_PROCESSORS = ( # "django.core.context_processors.media", # ) ## urls.py from django.conf.urls.defaults import * from django.conf import settings urlpatterns = patterns( '', # urls here ) if settings.get("DEV_SERVER", False): urlpatterns += patterns( '', # static stuff (r'^%s/(?P.*)$' % settings.MEDIA_DIR, 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT} ), ) ## base.html {% block title %}My project's title{% endblock %} etc This WorksForUs(tm) so far - as long as the dev server's user has read access on MEDIA_ROOT and it's content of course !-) HTH --~--~-~--~~~---~--~~ 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: First tutorial - Not off to a good start :(
On 14 Oct 20:27, AndrewXHill wrote: > > Glad you found a solution. I think though that you could have also > just removed the .py, not add 'python', so your command would have > been, > > $ django-admin startproject mysite Quite correct - the debian/ubuntu packages have django-admin, not django-admin.py on the path, as that binary is copied to /usr/bin and the policy says that binaries in there should not include the extension. Thanks, -- Brett Parker --~--~-~--~~~---~--~~ 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: displaying tree data in admin
On Oct 15, 8:16 am, evwrote: > May be there were developers solutions? Where should I look for? > Look at the django-mptt project. It implements an efficient algorithm for tree access, and also has some useful libraries that help with displaying trees. You might be able to use one of them. Alternatively, you could represent the tree simply by making __unicode__ prefix a series of dashes equal to the level of the element: def __unicode__(self): return u"%s %s" % ((u'-' * self.level), self.name) This would show the elements like this: root -level1 --level2 ---level3 etc. -- DR. --~--~-~--~~~---~--~~ 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: When would you use Context instead of RequestContext?
On 14 oct, 19:44, Nanwrote: > So it's basically just an issue of optimization? > > Is using RequestContext best practice for apps meant to be pluggable? > As a general rule, yes. FWIW and while we're at it, another best practice for pluggable apps would be, whenever possible, to write "two- folds" views - that is, split the view into two functions, one that do the job and returns a RequestContext, and the other one - the "official" view - that calls on the first and takes of the rendering etc. --~--~-~--~~~---~--~~ 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: displaying tree data in admin
May be there were developers solutions? Where should I look for? On Oct 15, 9:18 am, Михаил Лукинwrote: > There is no sucj feature in admin interface > > On Wed, Oct 14, 2009 at 9:18 PM, ev wrote: > > > I've created model Structure referenced to itself and filled it with > > my data. > > > class Structure(models.Model): > > parent=models.ForeignKey('self', blank=True, null=True, > > related_name='child_set') > > title=models.CharField(max_length=100) > > > Default admin interface shows my data as a plain list. What should I > > do to see my data in a tree? > > -- > regards, > Mihail --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---