Re: Global objects
On Tue, Jun 30, 2009 at 12:14 AM, diogobaederwrote: > > Oops... sorry... silly error... :-P > > Now, I'm passing the RequestContext instance correctly, but I get a > different error: > http://dpaste.com/61430/ > > Is it because I'm passing None as the second argument for > render_to_response? I have no data here, besides the context processor > data... > > Thanks again! > > Diogo > > > > On Jun 30, 12:47 am, Alex Gaynor wrote: > > On Mon, Jun 29, 2009 at 10:43 PM, diogobaeder > wrote: > > > > > Alex, > > > > > I'm trying to use the context processors, but I'm getting the > > > following error: > > >http://dpaste.com/61410/ > > > > > Any idea of what it might be? > > > > > Thanks! > > > > > Diogo > > > > > On Jun 26, 11:56 am, diogobaeder wrote: > > > > Thanks, Alex, I'll give a look at these TEMPLATE_CONTEXT_PROCESSORS > to > > > > see if they solve my problem... thanks a lot! :-) > > > > > > Diogo > > > > > > On Jun 26, 12:44 am, Alex Gaynor wrote: > > > > > > > On Thu, Jun 25, 2009 at 10:42 PM, diogobaeder < > diogobae...@gmail.com> > > > wrote: > > > > > > > > Let me explain myself better: I have some menus in my site, and > they > > > > > > appear all along the front-end pages. One of these menus must > have a > > > > > > list ofobjects. > > > > > > > > Considering that I have a "base.html" that has these menus, how > can I > > > > > > pass theobjectsto it, without having to fetch theobjectsin each > > > > > > view of the site? > > > > > > > > Thanks! > > > > > > > > Diogo > > > > > > > > On Jun 25, 8:39 pm, Diogo Baeder wrote: > > > > > > > Hi, > > > > > > > > > I'm trying to set up aglobalmodel object list, to populate a > part > > > of a > > > > > > > menu in my site. How can I do it? How can I instantiate the > model > > > object > > > > > > > list, so that it is available to all the views? > > > > > > > > > Thanks! > > > > > > > > > Diogo > > > > > > > See my answer in this thread: > > >http://groups.google.com/group/django-users/browse_frm/thread/1656392. > .. > > > > > same techniques should work for you. > > > > > > > Alex > > > > > > > -- > > > > > "I disapprove of what you say, but I will defend to the death your > > > right to > > > > > say it." --Voltaire > > > > > "The people's good is the highest law."--Cicero > > > > You're passing RequestCOntext. WHat you need to do is pass > > RequestCOntext(request). > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > I don't believe so. There looks to be an issue with your TEMPLATE_CONTEXT_PROCESSORS settings. Is everything in their a string pythonpath to a callable? Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Global objects
Oops... sorry... silly error... :-P Now, I'm passing the RequestContext instance correctly, but I get a different error: http://dpaste.com/61430/ Is it because I'm passing None as the second argument for render_to_response? I have no data here, besides the context processor data... Thanks again! Diogo On Jun 30, 12:47 am, Alex Gaynorwrote: > On Mon, Jun 29, 2009 at 10:43 PM, diogobaeder wrote: > > > Alex, > > > I'm trying to use the context processors, but I'm getting the > > following error: > >http://dpaste.com/61410/ > > > Any idea of what it might be? > > > Thanks! > > > Diogo > > > On Jun 26, 11:56 am, diogobaeder wrote: > > > Thanks, Alex, I'll give a look at these TEMPLATE_CONTEXT_PROCESSORS to > > > see if they solve my problem... thanks a lot! :-) > > > > Diogo > > > > On Jun 26, 12:44 am, Alex Gaynor wrote: > > > > > On Thu, Jun 25, 2009 at 10:42 PM, diogobaeder > > wrote: > > > > > > Let me explain myself better: I have some menus in my site, and they > > > > > appear all along the front-end pages. One of these menus must have a > > > > > list ofobjects. > > > > > > Considering that I have a "base.html" that has these menus, how can I > > > > > pass theobjectsto it, without having to fetch theobjectsin each > > > > > view of the site? > > > > > > Thanks! > > > > > > Diogo > > > > > > On Jun 25, 8:39 pm, Diogo Baeder wrote: > > > > > > Hi, > > > > > > > I'm trying to set up aglobalmodel object list, to populate a part > > of a > > > > > > menu in my site. How can I do it? How can I instantiate the model > > object > > > > > > list, so that it is available to all the views? > > > > > > > Thanks! > > > > > > > Diogo > > > > > See my answer in this thread: > >http://groups.google.com/group/django-users/browse_frm/thread/1656392... > > > > same techniques should work for you. > > > > > Alex > > > > > -- > > > > "I disapprove of what you say, but I will defend to the death your > > right to > > > > say it." --Voltaire > > > > "The people's good is the highest law."--Cicero > > You're passing RequestCOntext. WHat you need to do is pass > RequestCOntext(request). > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: serving a static file via nginx requiring authentication from django
On 6/28/09 10:20 PM, Annie wrote: > I'm trying to this to work: users can download their files from their > account page from a url like this: > http://example.com/account/download/a1234565789asedga-2/ > for which django processes the authentication and then passes along > the info to nginx to serve the file. [...] > Here are the relevant bits of code: > > # part of the views.py > > def download_file(request, dlkey=None, ftype=None): > if request.user.is_authenticated(): > try: > k = Ebook.objects.select_related().filter > (ftype__exact=ftype).filter > (book__orderdetail__dlkey__exact=dlkey).filter > (book__orderdetail__medium__exact='E')[:1] > for e in k: > ebook = e.ebook > filename = os.path.join(PROTECTED_DIR, os.path.basename > (ebook)) > response = HttpResponse() > response['X-Accel-Redirect'] = ebook > response['Content-Disposition'] = > "attachment;filename=" + ebook > return response > except Exception: > raise Http404 > > > # part of the nginx configuration for the domain: > > location ^~ /account/download/ { > include /etc/nginx/ > fastcgi_params_django; > fastcgi_pass127.0.0.1:1024; > alias /home/me/web/example.com/ > public/media/books/; > } > > location ^~ /media/books/ { > root/home/me/web/example.com/ > public; > internal; > } [...] > [1] http://wiki.nginx.org/NginxXSendfile I think the answer's in that document, actually. The value of X-Accel-Redirect should be your internal location's URL ('/media/books/') plus your filename (os.path.basename(ebook), in your view). Nginx will deliver /home/me/web/example.com/public/media/books/ebook-basename.pdf. 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: Global objects
On Mon, Jun 29, 2009 at 10:43 PM, diogobaederwrote: > > Alex, > > I'm trying to use the context processors, but I'm getting the > following error: > http://dpaste.com/61410/ > > Any idea of what it might be? > > Thanks! > > Diogo > > > > On Jun 26, 11:56 am, diogobaeder wrote: > > Thanks, Alex, I'll give a look at these TEMPLATE_CONTEXT_PROCESSORS to > > see if they solve my problem... thanks a lot! :-) > > > > Diogo > > > > On Jun 26, 12:44 am, Alex Gaynor wrote: > > > > > On Thu, Jun 25, 2009 at 10:42 PM, diogobaeder > wrote: > > > > > > Let me explain myself better: I have some menus in my site, and they > > > > appear all along the front-end pages. One of these menus must have a > > > > list ofobjects. > > > > > > Considering that I have a "base.html" that has these menus, how can I > > > > pass theobjectsto it, without having to fetch theobjectsin each > > > > view of the site? > > > > > > Thanks! > > > > > > Diogo > > > > > > On Jun 25, 8:39 pm, Diogo Baeder wrote: > > > > > Hi, > > > > > > > I'm trying to set up aglobalmodel object list, to populate a part > of a > > > > > menu in my site. How can I do it? How can I instantiate the model > object > > > > > list, so that it is available to all the views? > > > > > > > Thanks! > > > > > > > Diogo > > > > > See my answer in this thread: > http://groups.google.com/group/django-users/browse_frm/thread/1656392... > > > same techniques should work for you. > > > > > Alex > > > > > -- > > > "I disapprove of what you say, but I will defend to the death your > right to > > > say it." --Voltaire > > > "The people's good is the highest law."--Cicero > > > You're passing RequestCOntext. WHat you need to do is pass RequestCOntext(request). Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Global objects
Alex, I'm trying to use the context processors, but I'm getting the following error: http://dpaste.com/61410/ Any idea of what it might be? Thanks! Diogo On Jun 26, 11:56 am, diogobaederwrote: > Thanks, Alex, I'll give a look at these TEMPLATE_CONTEXT_PROCESSORS to > see if they solve my problem... thanks a lot! :-) > > Diogo > > On Jun 26, 12:44 am, Alex Gaynor wrote: > > > On Thu, Jun 25, 2009 at 10:42 PM, diogobaeder wrote: > > > > Let me explain myself better: I have some menus in my site, and they > > > appear all along the front-end pages. One of these menus must have a > > > list ofobjects. > > > > Considering that I have a "base.html" that has these menus, how can I > > > pass theobjectsto it, without having to fetch theobjectsin each > > > view of the site? > > > > Thanks! > > > > Diogo > > > > On Jun 25, 8:39 pm, Diogo Baeder wrote: > > > > Hi, > > > > > I'm trying to set up aglobalmodel object list, to populate a part of a > > > > menu in my site. How can I do it? How can I instantiate the model object > > > > list, so that it is available to all the views? > > > > > Thanks! > > > > > Diogo > > > See my answer in this > > thread:http://groups.google.com/group/django-users/browse_frm/thread/1656392... > > same techniques should work for you. > > > Alex > > > -- > > "I disapprove of what you say, but I will defend to the death your right to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
orbited tutorial .. wsgi instead of mod_python shouldn't matter?
http://darkporter.com/?p=7 --~--~-~--~~~---~--~~ 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: for the thousandth time... No module named django.core.handlers.modpython
On Jun 30, 12:12 pm, Rama Vadakattuwrote: > As the error is with import please try to do this > > Just open a python shell and try do the import More to the point, do it with the exact version that mod_python was compiled against and run the test as the same user that Apache runs as. This is because mod_python may be using a different Python installation if there is more than one installed and because Apache runs as a different user. There is no point therefore doing this as yourself as that doesn't reflect how it will run. You also need to ensure PYTHONPATH is not set in environment of shell you run test as, as that wouldn't normally be set for Apache/ mod_python. > >>> import django.core.handlers.modpython > > if it works fine then we are sure that modpython is present on the > python path and the problem is not with import .. Ahh, no. The mod_python package is different. This is showing that Django itself is present for that version of Python. The ImportError specifically indicates that it can't even import top level 'django' module. Graham > On Jun 30, 3:31 am, garagefan wrote: > > > > >http://kennethdavid.net/admin > > > error page: > > > MOD_PYTHON ERROR > > > ProcessId: 9659 > > Interpreter: 'kennethdavid.net' > > > ServerName: 'kennethdavid.net' > > DocumentRoot: '/home/kdwadmin' > > > URI: '/admin' > > Location: '/' > > Directory: None > > Filename: '/home/kdwadmin/admin' > > PathInfo: '' > > > Phase: 'PythonHandler' > > Handler: 'django.core.handlers.modpython' > > > Traceback (most recent call last): > > > File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line > > 1537, in HandlerDispatch > > default=default_handler, arg=req, silent=hlist.silent) > > > File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line > > 1202, in _process_target > > module = import_module(module_name, path=path) > > > File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line > > 304, in import_module > > return __import__(module_name, {}, {}, ['*']) > > > ImportError: No module named django.core.handlers.modpython > > > I know i know, this has been asked a million times... i've looked at > > the answers and i've checked things... > > > both mod_python and django live in my site packages directory. I've > > set apache as the group and gave it RWX privileges. i've also insured > > that the path from site packages to the modpython.py does in fact go > > through django/core/handlers/modpython > > > at this point, i'm not sure what else to check. > > > my virtual host setup looks like this: > > > NameVirtualHost kennethdavid.net:80 > > > > > ServerName kennethdavid.net > > ServerAliaswww.kennethdavid.net > > DocumentRoot /home/kdwadmin > > > > > SetHandler python-program > > PythonHandler django.core.handlers.modpython > > SetEnv DJANGO_SETTINGS_MODULE kdnet.settings > > PythonPath "['/home/kdwadmin', '/home/kdwadmin/kdnet'] > > + sys.path" > > PythonDebug On > > > > > > > obviously it works because its getting to mod_python and getting sick. > > > thanks guys and gals --~--~-~--~~~---~--~~ 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: rollback transaction without an exception when transaction is tied to http requests
So, using automatic transaction management, there is no way to cause a transaction rollback without the user seeing the exception... stink... thanks for your help! On Jun 30, 3:07 am, Karen Traceywrote: > On Sun, Jun 28, 2009 at 11:14 PM, sico wrote: > > > [snip] > > > However, I am still curious if there is a way to tell django to not > > commit the transaction without the user seeing an exception > > Yes and no: I tried to describe that in my previous answer. Yes, you can > arrange to have the transaction be rolled back instead of being committed, > and you can avoid having exceptions reflected to the user. But no, there is > no setting to tell Django to automatically rollback on error and not > propagate the exception resulting from the error: your code must do that. > > First you have to use manual transaction management, so that you control > when the updates get committed. If you use the default autocommit behavior > you cannot roll back already completed updates as they will be automatically > committed as they are executed. > > Then you need to be aware, in your code, of what statements might raise > exceptions. You must write your code to explicitly handle the cases where > exceptions may be raised and "do the right thing" instead of having them > just propagate up and be reported as server errors. > > 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: for the thousandth time... No module named django.core.handlers.modpython
As the error is with import please try to do this Just open a python shell and try do the import >>> import django.core.handlers.modpython if it works fine then we are sure that modpython is present on the python path and the problem is not with import .. On Jun 30, 3:31 am, garagefanwrote: > http://kennethdavid.net/admin > > error page: > > MOD_PYTHON ERROR > > ProcessId: 9659 > Interpreter: 'kennethdavid.net' > > ServerName: 'kennethdavid.net' > DocumentRoot: '/home/kdwadmin' > > URI: '/admin' > Location: '/' > Directory: None > Filename: '/home/kdwadmin/admin' > PathInfo: '' > > Phase: 'PythonHandler' > Handler: 'django.core.handlers.modpython' > > Traceback (most recent call last): > > File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line > 1537, in HandlerDispatch > default=default_handler, arg=req, silent=hlist.silent) > > File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line > 1202, in _process_target > module = import_module(module_name, path=path) > > File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line > 304, in import_module > return __import__(module_name, {}, {}, ['*']) > > ImportError: No module named django.core.handlers.modpython > > I know i know, this has been asked a million times... i've looked at > the answers and i've checked things... > > both mod_python and django live in my site packages directory. I've > set apache as the group and gave it RWX privileges. i've also insured > that the path from site packages to the modpython.py does in fact go > through django/core/handlers/modpython > > at this point, i'm not sure what else to check. > > my virtual host setup looks like this: > > NameVirtualHost kennethdavid.net:80 > > > ServerName kennethdavid.net > ServerAliaswww.kennethdavid.net > DocumentRoot /home/kdwadmin > > > SetHandler python-program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE kdnet.settings > PythonPath "['/home/kdwadmin', '/home/kdwadmin/kdnet'] > + sys.path" > PythonDebug On > > > > obviously it works because its getting to mod_python and getting sick. > > thanks guys and gals --~--~-~--~~~---~--~~ 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 1.0.2 Thread safety
There should be a little warning in the 1.0.2 docs or on http://code.djangoproject.com/wiki/DjangoSpecifications/Core/Threading that it is *not* thread safe. I've hit http://code.djangoproject.com/ticket/10470 on production, applied the patches manually. Please make sure you apply both http://code.djangoproject.com/changeset/10036 and http://code.djangoproject.com/changeset/10040, the first one contains a bug which will deadlock the server. --~--~-~--~~~---~--~~ 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: ModelMultipleChoiceField - when is queryset updated?
Also this behavior is different from ModelChoiceField - which DOES seem to update immediately if an instance is added to the model. I'm using version 1.0.2 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 -~--~~~~--~~--~--~---
Re: Installation on XP
FloridaShark wrote: > I'd like to find and install Django in Windows XP. > Need help please, new to Python GUI environments. > Thanks My Installation quite simple - download latest python installation from python.org because i`m using SVN version, - Im Install Tortoise SVN - get the SVN version and put in a directory - Setup PYTHONPATH for directory that hold the django SVN - i'm using notepad++ for coding *i think i`ts leighweight and simple enough for beginner For installation just follow the documentation iyank4 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ModelMultipleChoiceField - when is queryset updated?
I had this: disciplines = forms.ModelMultipleChoiceField(queryset = Discipline.objects.all()) But if new Disciplines are created during runtime they do not appear on the list when a new form is rendered. There doesn't seem to be a mention of that fact in the documentation. So is it correct that to get a current list you must do the following: disciplines = forms.ModelMultipleChoiceField(queryset = None) def __init__(self, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) self.fields['disciplines'].queryset = Discipline.objects.all() 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 -~--~~~~--~~--~--~---
ModelForm for Object with ManyToManyField does not validate
Article model has MM field to Authors. Editing an Article 123 would than be: >>> f = ArticleForm( instance=Article.objects.get(id=123) ) But than: >>> f.is_valid() False >>> f.data {} >>> f._errors {} >>> f.is_bound False Closer look at the form object "author" field: >>> f.fields['author'].required True Why is Author field ignored when populating form with instance that has valid Author entry? Since Author field is required it is obvious that form does not validate. --~--~-~--~~~---~--~~ 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: Setting up TinyMCE with django-grappelli?
Thanks! On Jun 29, 12:52 am, patrickkwrote: > hi chris, > > the question abouttinymceis answered/discussed at the grappelli > google-code issue-list. > > you might want to ask your question about the filebrowser setup at the > filebrowser google-group:http://groups.google.com/group/djangofilebrowser > > please not that you should give more details. your questions are too > abstract to really help. > what _exactly_ is your problem? > what did you try to solve it? > what´s your setup? > > concerningTinyMCE, you should take a look at > this:http://code.google.com/p/django-tinymce/ > > thanks, > patrick > > On 28 Jun., 21:49, odonnell wrote: > > > > > Can anyone give me some help with this? > > > On Jun 26, 3:27 pm, odonnell wrote: > > > > Also, I'm trying to set up django-filebrowser, made by the same people > > > who make django-grappelli, and there's some stuff on that Google Code > > > wiki aboutTinyMCEthat's totally confused me. > > > > I want Grappelli, FileBrowser, andTinyMCEall working nicely. Right > > > now, I have Grappelli set up. If anyone can help me with the other two > > > installations, that would be greatly appreciated. --~--~-~--~~~---~--~~ 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: Installation on XP
one more thing follow the example/tutorial in the django book v2 exactly,, no shortcuts,,, On Jun 29, 5:32 pm, dartdogwrote: > It is very doable but lots of stuff, I'm still working it out,, I > suggest Eclipse... with Pydev for the python env,, It can support > Django as well but that gets more tricky I hope to get it all > documented shortly... my travails are somewhat documented on my blog > ,http://tombrander.wordpress.comwhile a lot about Google app engine > most applies to this (plain Django) as well,,, I think It may save you > "some" trial and error. I'm currently working through some other > issues and plan to document as well, once I get figured out!! > > On Jun 29, 4:16 pm, FloridaShark wrote: > > > I'd like to find and install Django in Windows XP. > > Need help please, new to Python GUI environments. > > 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 -~--~~~~--~~--~--~---
Re: switching menu items on and off - dynamic urls?
I was afraid of middleware too, but it's really not bad at all. Just remember that the URL patterns are only processed once. On Jun 27, 7:41 am, Kenneth Gonsalveswrote: > On Friday 26 June 2009 21:19:30 Rajesh D wrote: > > > > > > I have a conference management application. It has a list of menu items > > > on the lefthand side. These menus are created by a templatetag from a > > > list of menus in views.py. At various stages of the conference, menu > > > items have to be enabled or disabled. For example, 'submit talk' has to > > > be hidden after the last date for talk submission is over. At present I > > > am doing this by commenting out the menu item in views.py and commenting > > > out the corresponding url inurls.py. But this involves the admins > > > delving into code, which is not a good thing as there is no guarantee > > > that the admins will be programmers. The menu items can be put in a > > > model, and have a boolean field 'activate'. That is not a problem. But if > > > the url is not commented out inurls.py, there is nothing to prevent the > > >userfrom directly typing in the url. So is there some way where these > > >urlscan also be stored in a model so that the admin just has to set > > > 'activate' to false and the menu will not appear and the url will not be > > > available for theuserto directly type it in? > > > You could use custom middleware code to set request.urlconf[1] from a > > function that dynamically puts together the menuURLsbasedon your > > model's activate flag. > > > For an example of dynamically constructing URL patterns at run time, > > see Django Admin's sites.AdminSite.get_urls method[2]. Note that this > > admin method isn't called per request but the examply is still useful > > to understand how simple it is to return a custom URL pattern list. > > The key is to wire that function into the custom middleware mentioned > > above. > > thanks for the detailed reply, but I am terrified of going any where near > middleware. I compromised by making a decorator that checks whether the menu > item is enabled when ever a view function is called from that menu. Works for > me (am fighting a deadline). > -- > regards > kghttp://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: Installation on XP
It is very doable but lots of stuff, I'm still working it out,, I suggest Eclipse... with Pydev for the python env,, It can support Django as well but that gets more tricky I hope to get it all documented shortly... my travails are somewhat documented on my blog , http://tombrander.wordpress.com while a lot about Google app engine most applies to this (plain Django) as well,,, I think It may save you "some" trial and error. I'm currently working through some other issues and plan to document as well, once I get figured out!! On Jun 29, 4:16 pm, FloridaSharkwrote: > I'd like to find and install Django in Windows XP. > Need help please, new to Python GUI environments. > 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 -~--~~~~--~~--~--~---
for the thousandth time... No module named django.core.handlers.modpython
http://kennethdavid.net/admin error page: MOD_PYTHON ERROR ProcessId: 9659 Interpreter:'kennethdavid.net' ServerName: 'kennethdavid.net' DocumentRoot: '/home/kdwadmin' URI:'/admin' Location: '/' Directory: None Filename: '/home/kdwadmin/admin' PathInfo: '' Phase: 'PythonHandler' Handler:'django.core.handlers.modpython' Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1202, in _process_target module = import_module(module_name, path=path) File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 304, in import_module return __import__(module_name, {}, {}, ['*']) ImportError: No module named django.core.handlers.modpython I know i know, this has been asked a million times... i've looked at the answers and i've checked things... both mod_python and django live in my site packages directory. I've set apache as the group and gave it RWX privileges. i've also insured that the path from site packages to the modpython.py does in fact go through django/core/handlers/modpython at this point, i'm not sure what else to check. my virtual host setup looks like this: NameVirtualHost kennethdavid.net:80 ServerName kennethdavid.net ServerAlias www.kennethdavid.net DocumentRoot /home/kdwadmin SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE kdnet.settings PythonPath "['/home/kdwadmin', '/home/kdwadmin/kdnet'] + sys.path" PythonDebug On obviously it works because its getting to mod_python and getting sick. thanks guys and gals --~--~-~--~~~---~--~~ 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: Trying to understand Django and Python from a C++ perspective
Yea, I'm not wanting to use stuff.objects, but I'm wanting to pull some of the same voodoo, probably not safe for a python novice like myself :-) On Jun 29, 5:24 pm, Alex Gaynorwrote: > On Mon, Jun 29, 2009 at 5:19 PM, Mark Jones wrote: > > > I can't seem to reason out why/how this works. > > > I have a class Named Stuff > > > I can say Stuff.objects.filter(.) and that will return valid set > > of data. > > > What I can't understand is what exactly is objects, and why is it I > > can call it with Stuff.objects, but I can't call it with stuff.objects > > (an instance of Stuff). > > > >>> dir(Stuff) shows me 'objects' > > >>> dir(stuff) shows me 'objects' > > > >>> type(Stuff.objects) > > > > >>> type(stuff.objects) > > Traceback (most recent call last): > > File "", line 1, in > > File "...manager.py", line 151, in __get__ > > AttributeError: Manager isn't accessible via Stuff instances > > > What is the python Magic going on here to make this possible? > > > I'm asking because I want to make something like 'objects' in that it > > doesn't need an instance, but it is scoped within the model of Stuff. > > > My background is C++ and these look like methods/objects that are > > static to the class, not part of the instances. I just can't figure > > out how to declare and instantiate them in python. > > Django uses an advanced python feature called descriptors in order to > prevent you from accessing a manager (which is what "objects" is) from an > instance. My understanding of the reason for this is somewhat conceptual: > asking for all the objects that are "Stuff"s makes sense, but asking for all > the objects that are "some object" doesn't make as much sense. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Trying to understand Django and Python from a C++ perspective
On Mon, Jun 29, 2009 at 5:19 PM, Mark Joneswrote: > > I can't seem to reason out why/how this works. > > I have a class Named Stuff > > I can say Stuff.objects.filter(.) and that will return valid set > of data. > > What I can't understand is what exactly is objects, and why is it I > can call it with Stuff.objects, but I can't call it with stuff.objects > (an instance of Stuff). > > >>> dir(Stuff) shows me 'objects' > >>> dir(stuff) shows me 'objects' > > >>> type(Stuff.objects) > > >>> type(stuff.objects) > Traceback (most recent call last): > File "", line 1, in > File "...manager.py", line 151, in __get__ > AttributeError: Manager isn't accessible via Stuff instances > > What is the python Magic going on here to make this possible? > > I'm asking because I want to make something like 'objects' in that it > doesn't need an instance, but it is scoped within the model of Stuff. > > My background is C++ and these look like methods/objects that are > static to the class, not part of the instances. I just can't figure > out how to declare and instantiate them in python. > > > Django uses an advanced python feature called descriptors in order to prevent you from accessing a manager (which is what "objects" is) from an instance. My understanding of the reason for this is somewhat conceptual: asking for all the objects that are "Stuff"s makes sense, but asking for all the objects that are "some object" doesn't make as much sense. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Trying to understand Django and Python from a C++ perspective
I can't seem to reason out why/how this works. I have a class Named Stuff I can say Stuff.objects.filter(.) and that will return valid set of data. What I can't understand is what exactly is objects, and why is it I can call it with Stuff.objects, but I can't call it with stuff.objects (an instance of Stuff). >>> dir(Stuff) shows me 'objects' >>> dir(stuff) shows me 'objects' >>> type(Stuff.objects) >>> type(stuff.objects) Traceback (most recent call last): File "", line 1, in File "...manager.py", line 151, in __get__ AttributeError: Manager isn't accessible via Stuff instances What is the python Magic going on here to make this possible? I'm asking because I want to make something like 'objects' in that it doesn't need an instance, but it is scoped within the model of Stuff. My background is C++ and these look like methods/objects that are static to the class, not part of the instances. I just can't figure out how to declare and instantiate them in python. --~--~-~--~~~---~--~~ 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: Custom templatetags for loading objects
On Mon, Jun 29, 2009 at 11:20 PM, Justin Lillywrote: > > This is likely exactly what you're looking for: > > > http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/ > > -justin > > Thanks Justin. This is really good. Regards, -- Join Scrum8.com. http://scrum8.com/member/jpartogi/ http://scrum8.com/blog/jpartogi/ http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Installation on XP
I'd like to find and install Django in Windows XP. Need help please, new to Python GUI environments. 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 -~--~~~~--~~--~--~---
Model for Video Mashup
I want to create a web application that access videos from many different websites such as YouTube, Google Video, etc. The app should be able to store all the necessary information that would later allow the site to access a particular video. For instance, if the user inputs the URL http://www.youtube.com/watch?v=dMH0bHeiRNg, the application should be able to store all the information needed to play the video and play it later. My problem is that I am new to web programming and I am having trouble creating an effective model for the web app. As it stands, I have a Video model that has a ForeignKey to a VideoHost model. The VideoHost contains a hostname for a video hosting site, a field that stores the regex necessary to extract some kind of identifier from the URL, and some other information that pertains to accessing a video from that particular host. The more I work with this model, however, the more I find it hard to use and too inflexible. I don't mean to ask anyone to come up with a complete model for me. I gave the details of the project so that my situation would be better understood. All I am asking is if anyone can recommend a better model pattern that I could use for a mashup of this sort. Thanks in advance! --~--~-~--~~~---~--~~ 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 unicode model pickle problem
I wouldn't consider myself an expert with Unicdoe, but I do know that pickle and cPickle use ASCII for serialization. If you have utf-8 characters stored as attributes in the object you're pickling, that could cause the codec error. On Jun 22, 10:15 pm, Rodrigo Ceawrote: > I am having trouble pickling, and then saving to the DB, django models > with Unicode text in them. The site is for Spanish speakers, so we > need our ñs, és and ös. > > I implemented an unlimited undo feature for a Django site, using this > PickleField snippet: > > http://www.djangosnippets.org/snippets/513/. > > I created a model that holds each object's state at a certain > datetime, like so: > > from fields import PickledObjectField > > class UndoRecord(models.Model): > user = models.ForeignKey(User) > pickle = PickledObjectField() > date = models.DateTimeField(auto_now_add=True) > > and then in my views, whenever a user changes something, I save an > UndoRecord like so: > > undo = UndoRecord(user=request.user, pickle=obj) > undo.save() > > This works fine, except when the object that I am saving has non-ASCII > characters in it, which case I get a lovely: > > DjangoUnicodeDecodeError: 'utf8' codec can't decode bytes in position > 372-373: invalid data. You passed in "crbml_core.models\nMusico\np1\n > (tRp2\n(dp3\nS'foto'\np4\nccopy_reg\n_reconstructor\np5\n > (cdjango.db.models.fields.files\nImageFieldFile\np6\nc__builtin__ > \nobject\np7\nNtRp8\n > (dp9\nS'_committed'\np10\nI01\nsS'_file'\np11\nNsS'name'\np12\nVuploads/ > musicos/235470296_54ae5af3e9_o.jpg > \np13\nsS'closed'\np14\nI00\nsbsS'user_id'\np15\nNsS'visible'\np16\nI1\nsS' > influencias'\np17\nVFaith > No More\np18\nsS'nombre'\np19\nV\xd1\xed\xfa\xf6\np20\nsS'id'\np21\nL2L > \nsb." () > > I have been trying to fix this using the approach show > here:http://www.mail-archive.com/django-users@googlegroups.com/msg67883.html, > but no such luck. > > Unicode errors are my particular achilles' heel, so any help is much > appreciated. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Internal redirect
Hi, I've have a multilingual site where each languaje runs under one diferente "folder": www.site.com/en/ and www.site.com/es/. Everything works perfectly fine, but now I want that the user see the english version on the root path. How can I do this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 -~--~~~~--~~--~--~---
Trying to get static media to serve from Django in Debug on windows
The doc here give an example: http://docs.djangoproject.com/en/dev/howto/static-files/ Which looks like so: if settings.DEBUG: urlpatterns += patterns('', (r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}), ) So I put this in my Main urls file if settings.DEBUG: urlpatterns += patterns('', (r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': r'^/django_yaba/media'}), ) My full path on windows is: C:\Users\DadLaptop\Documents\E1workspace\django_yabba\src\django_yaba \media The app still can't find any media?? css..etc All suggestions appreciated --~--~-~--~~~---~--~~ 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: Password-protecting PDF downloads?
2009/6/29 Rajesh Dhawan: > > > > bax...@gretschpages.com wrote: >> This is probably more of a python question, but here goes: Can anyone >> point me to a method of dynamically attaching a password to a PDF and >> protecting the file before it's downloaded? Take a look at http://blog.kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/ to port to Django or http://www.djangosnippets.org/snippets/491/ On this way you can control who has the rights to download a file without password protecting it. Hope it helps! -- 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 -~--~~~~--~~--~--~---
changing apache mod python
Hi all, I made an mistake of upgrading ubuntu to the last version. This new version is running python 2.6 and it has also install the mod python for apache linked to this python version. All my code is running django 0.96 with python 2.5. Now, the developments don't work. It says I have the following error: MOD_PYTHON ERROR ProcessId: 5225 Interpreter:'x' ServerName: '' DocumentRoot: '/htdocs' URI:'/' Location: '/' Directory: None Filename: '/htdocs' PathInfo: '/' Phase: 'PythonHandler' Handler:'django.core.handlers.modpython' At the end, it says I have an error importing a module. does anybody know how to go back to the 2.5 python module? or how can I resolve this problem? thank you very much, best regards, Miguel --~--~-~--~~~---~--~~ 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: Strange behavior with ModelForm and saving
StackOverflow to the rescue: http://stackoverflow.com/questions/1059831/strange-behavior-with-modelform-and-saving On Jun 29, 2:43 pm, Huuuzewrote: > This problem is very strange and I'm hoping someone can help me. For > the sake of argument, I have a Author model with ForeignKey > relationship to the Book model. When I display an author, I would > like to have a ChoiceField that ONLY displays the books associated > with that author. As such, I override the AuthorForm.__init__() > method and I create a List of choices (tuples) based upon a query that > filters books based upon the author ID. The tuple is a composite of > the book ID and the book name (i.e., (1, 'Moby Dick')). Those > "choices" are then assigned to the ModelForm's choices attribute. > > When the form renders in the template, the ChoiceField is properly > displayed, listing only those books associated with that author. > > This is where things get weird. > > When I save the form, I receive a ValueError (Cannot assign > "u'1'":Author.book" must be a Book instance). This error makes sense > due to the FK relationship. However, if I add a "print" statement to > the code, make no other changes, and then save the record, it works. > The ValueError magically disappears. I've tried this a number of > times, ensuring I haven't inadvertently made another change, and it > works each time. > > Does anyone know what's going on here? --~--~-~--~~~---~--~~ 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: no module name xxxx error
my directory and subdirectories looks like this ronproject | rondata | ronapp The __init__.py file is in both the rondata and the ronapp folders. When I run manage.py runserver I get "Error: No module name rondata" I also tried to run manage.py inspectdb because my app is based on a legacy database. I get the same error message. This is puzzling because just a few days ago I create this app and was cleaning up the tables in the database and ran manage.py syncdb when I got the error. I can run my other apps when no problem. On Jun 29, 2:21 pm, Steve Howellwrote: > On Jun 29, 11:13 am, nixon66 wrote: > > > Steve, > > > The is a __init__.py > > Ok, you need to provide a little more detail then. Can you tell us > what your subdirectory structure looks like, and have you put > __init__.py's in enclosing folders? > > Sometimes modules fail to import due to syntax errors in the modules > themselves. > > Do you have a more specific error message? Have you verified no typos > in the import statement itself? Can you import the module from a > manage.py shell? --~--~-~--~~~---~--~~ 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 2 Level Navigation
I am currently writing a navigation system for a new site. It consists of a top level horizontal dropdown nav at the top of all the pages, along with a secondary subnav on the child pages. I have a good system working for the top level nav with DRY urls and css highlighting of the active page. The challenge I am having now is I see duplication for my sub level nav. Here is an example of the dpaste http://dpaste.com/61199/ Should I refactor the code to place my menu items into a python list and build my navs dynamically? Is there another easier way? This list would comprise of url entries ( objects from urls.py ) with an added label (i.e. 'My Friends') that will be listed hierarchically. Basically, I want to be able to pass in a list object (nav) to my templates and use the template looping constructs to dynamically build my menu system. Does anyone out there think this is the right/wrong approach? Any feedback would be greatly appreciated. --~--~-~--~~~---~--~~ 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: no module name xxxx error
On Jun 29, 11:05 am, nixon66wrote: > I'm getting an error no module name x. I've create all the > directories and I can see them, but I keep getting this error and > can't understand why. Any ideas. Not sure why this is happening since > it did not happen when I've created other apps. There are many reasons why modules cannot be found, but the most likely gotcha is that you forgot to create __init__.py. If __init__.py is already there, then you can help others help you by listing the things you've verified already (PYTHONPATH, 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: Redirect to html file
> Hi! If I have some html file somewhere (i.e. /var/file), how to > redirect user to it? It is not a template and not in a template > folder. Thanks :) "Redirect" probably isn't the word you wanted there. If you really meant "How do I make my view function display the contents of an arbitrary HTML file?", the answer is: def showvarfile(request): return HttpResponse(open('/var/file').read()) As you can see, it's your own Python code reading the file's contents and sending it back to the browser. So this works even if '/var/file' isn't in a directory that your webserver is serving. That comes with some caveats, of course -- it's usually not the best way to do things, and is not as efficient as just letting the webserver serve it -- but I think that's what you were asking for... --~--~-~--~~~---~--~~ 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: no module name xxxx error
This is an __init__.py in the folder On Jun 29, 2:08 pm, Alex Gaynorwrote: > On Mon, Jun 29, 2009 at 1:05 PM, nixon66 wrote: > > > I'm getting an error no module name x. I've create all the > > directories and I can see them, but I keep getting this error and > > can't understand why. Any ideas. Not sure why this is happening since > > it did not happen when I've created other apps. > > Did you forget to create an __init__.py in the folder? Python needs this to > recognize the folder as a module. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: no module name xxxx error
Steve, The is a __init__.py On Jun 29, 2:09 pm, Steve Howellwrote: > On Jun 29, 11:05 am, nixon66 wrote: > > > I'm getting an error no module name x. I've create all the > > directories and I can see them, but I keep getting this error and > > can't understand why. Any ideas. Not sure why this is happening since > > it did not happen when I've created other apps. > > There are many reasons why modules cannot be found, but the most > likely gotcha is that you forgot to create __init__.py. > > If __init__.py is already there, then you can help others help you by > listing the things you've verified already (PYTHONPATH, 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 -~--~~~~--~~--~--~---
Strange behavior with ModelForm and saving
This problem is very strange and I'm hoping someone can help me. For the sake of argument, I have a Author model with ForeignKey relationship to the Book model. When I display an author, I would like to have a ChoiceField that ONLY displays the books associated with that author. As such, I override the AuthorForm.__init__() method and I create a List of choices (tuples) based upon a query that filters books based upon the author ID. The tuple is a composite of the book ID and the book name (i.e., (1, 'Moby Dick')). Those "choices" are then assigned to the ModelForm's choices attribute. When the form renders in the template, the ChoiceField is properly displayed, listing only those books associated with that author. This is where things get weird. When I save the form, I receive a ValueError (Cannot assign "u'1'":Author.book" must be a Book instance). This error makes sense due to the FK relationship. However, if I add a "print" statement to the code, make no other changes, and then save the record, it works. The ValueError magically disappears. I've tried this a number of times, ensuring I haven't inadvertently made another change, and it works each time. Does anyone know what's going on here? --~--~-~--~~~---~--~~ 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: Arbitrary HTTP CONNECT attempts on Django dev server
For those unfamiliar with what DMZ means. < http://en.wikipedia.org/wiki/DMZ_(computing) > On Jun 29, 7:27 am, Richard Sheborawrote: > yes. with no firewall protection in your case. that is what the dmz setting > of a router is supposed to do. Toodle-looo creecode --~--~-~--~~~---~--~~ 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: no module name xxxx error
This is an _init__.py in the folder On Jun 29, 2:08 pm, Alex Gaynorwrote: > On Mon, Jun 29, 2009 at 1:05 PM, nixon66 wrote: > > > I'm getting an error no module name x. I've create all the > > directories and I can see them, but I keep getting this error and > > can't understand why. Any ideas. Not sure why this is happening since > > it did not happen when I've created other apps. > > Did you forget to create an __init__.py in the folder? Python needs this to > recognize the folder as a module. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: import a variable form views to forms
Thanks Dan. I´ve tried that but it doesnt work, there are no errors but the form doesnt display in the page. > > I think you just have to call it like this: > > form = ComentForm(request.POST, user_choices_list=children) > > I've not done it passing the POST data too, only passing in a kwarg. > > Hope this helps > > Radez --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
get_or_create() returns "no such savepoint" error
Hi, I have created a management command that populates some tables in a Postgres database, and I use the handy get_or_create() method in db/ models/query.py. I tried running a command recently where I had inadvertently left some foreign key references dangling around, but instead of a useful error, I instead got the obscure error "no such savepoint." The code catches the original exception that would have helped me realize my own error, and instead raises a new exception about "no such savepoint." Here is the code with get_or_create() that obscures the error: except IntegrityError, e: transaction.savepoint_rollback(sid) In order to see actual errors, I think I need to something with management commands that allows the savepoint to be rolled back. Has anybody encountered this before? I've skimmed some long threads pertaining to Django/psycopg/Postgres interactions with respect to setting up transaction management, but I have to admit that most of the discussion has been over my head. Thanks, Steve P.S. Here is the entire method for get_or_create(), for more context: def get_or_create(self, **kwargs): """ Looks up an object with the given kwargs, creating one if necessary. Returns a tuple of (object, created), where created is a boolean specifying whether an object was created. """ assert kwargs, \ 'get_or_create() must be passed at least one keyword argument' defaults = kwargs.pop('defaults', {}) try: return self.get(**kwargs), False except self.model.DoesNotExist: try: params = dict([(k, v) for k, v in kwargs.items() if '__' not in k]) params.update(defaults) obj = self.model(**params) sid = transaction.savepoint() obj.save(force_insert=True) transaction.savepoint_commit(sid) return obj, True except IntegrityError, e: transaction.savepoint_rollback(sid) try: return self.get(**kwargs), False except self.model.DoesNotExist: raise e --~--~-~--~~~---~--~~ 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: no module name xxxx error
On Jun 29, 11:13 am, nixon66wrote: > Steve, > > The is a __init__.py > Ok, you need to provide a little more detail then. Can you tell us what your subdirectory structure looks like, and have you put __init__.py's in enclosing folders? Sometimes modules fail to import due to syntax errors in the modules themselves. Do you have a more specific error message? Have you verified no typos in the import statement itself? Can you import the module from a manage.py shell? --~--~-~--~~~---~--~~ 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: no module name xxxx error
On Mon, Jun 29, 2009 at 1:05 PM, nixon66wrote: > > I'm getting an error no module name x. I've create all the > directories and I can see them, but I keep getting this error and > can't understand why. Any ideas. Not sure why this is happening since > it did not happen when I've created other apps. > > > Did you forget to create an __init__.py in the folder? Python needs this to recognize the folder as a module. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
no module name xxxx error
I'm getting an error no module name x. I've create all the directories and I can see them, but I keep getting this error and can't understand why. Any ideas. Not sure why this is happening since it did not happen when I've created other apps. --~--~-~--~~~---~--~~ 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: import a variable form views to forms
On 06/29/2009 10:48 AM, ariest wrote: > Sorry, this is the actual code: > > views.py > > def parent(request): > user = request.user > key = user.get_profile().link > p = Parent.objects.get(pk = key) > children = p.children.all() > if request.method == 'POST': > form = ComentForm(request.POST, children???) > if form.is_valid(): > cd = form.cleaned_data > c = Coments(from=cd['from'], comentario=cd['coment']) > c.save() > return render_to_response('sent.html', locals()) > else: > form = ComentForm(children???) > return render_to_response('parent.html', locals()) > > forms.py > > class ComentForm(forms.Form): > def __init__(self, user_choices_list, *args, **kwargs): > super(ComentForm, self).__init__(*args, **kwargs) > self.fields['from'].choices = user_choices_list > from = forms.ChoiceField() > coment = forms.CharField(widget=forms.Textarea, label='Coment') > > > I think you just have to call it like this: form = ComentForm(request.POST, user_choices_list=children) I've not done it passing the POST data too, only passing in a kwarg. Hope this helps Radez --~--~-~--~~~---~--~~ 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: import a variable form views to forms
On Mon, Jun 29, 2009 at 12:04 PM, ariestwrote: > > Nobody? > > > > Please try to be patient. This is an all volunteer mailing list and it's only been 2 hours. Many people are at work or otherwise occupied and thus unable to reply. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Handling a reusable form in multiple views
Perfect. I actually realized soon after posting that option 1 would work well for this scenario, but option 2 would be a good future enhancement. Thanks for your help. On Jun 29, 11:56 am, Rajesh Dhawanwrote: > delinowrote: > > Rajesh, > > > Thanks for your response. If I post the form to a dedicated view that > > works fine, but how do I handle validation properly in this approach. > > Say the user enters invalid data, do I now need to redirect them back > > to the original page and then display these errors? That seems like it > > will be a headache as well. Note that this form is a reusable form > > that gets displayed within most templates so it's just a little > > section of the page. If I now enter invalid data and post the form, > > it's going to post to a different view that will then see the form is > > invalid and then what?? > > Option 1: Send your invalid form to a simple template that knows how > to display the form and its errors. > > Option 2: Post your form via AJAX -- you should still implement Option > 1 for people that have turned off Javascript > > -RD --~--~-~--~~~---~--~~ 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: import a variable form views to forms
Nobody? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Ordering of ManyToManyField using a field of the intermediate table
Hi, I have a couple of models like: class Album(models.Model): title = models.CharField(max_length=255) class Image(models.Model): image = models.ImageField(upload_to='images/') albums = models.ManyToManyField(Album, blank=True) the schema of the intermediate table is, of course: `id` int(11) NOT NULL auto_increment, `image_id` int(11) NOT NULL, `album_id` int(11) NOT NULL, Is it possible to order album.image_set with respect to the ID field of the intermediate table? I'd like to do this so i can efficiently sort images in the order they were added to the album. Thank you! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting started with django
1.visit www.djangoproject.com . they have the best documentation 2. try experimenting with stuff. for example you can try developing a website using django. 3. you can search code.google.com or sourceforge.net for some django projects and look at the source code. cheers On Mon, Jun 29, 2009 at 7:09 PM, Rajesh Dhawanwrote: > >> I have some basic of python(functional part and also very basic of oop >> part), but don't have other knowledge. I would like to start with >> django. So, what more is required to getting started with django so >> that i can grasp all the concept and can be proficient with django. >> Also is there any way to develop my skills? > > Start with the "First Steps" section documented here: > http://docs.djangoproject.com/en/dev/ > > -RD > > > > -- Mugisha Moses P.O. Box 1420 Kampala, Uganda http://appfrica.org skype name : mossplix twitter: @mugisha --~--~-~--~~~---~--~~ 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: Uploaded File Array
BarakatX2 wrote: > When I do: > > print type(f) > > It outputs: > > > > Also when I try to get the filename using the name property of > UploadedFile, it says: > > 'str' object has no attribute 'name' > > When I just print f it shows: > > ëPNG Try something like this code: for fname, fvalue in request.FILES.iteritems(): print fname # This is the submitted file name print type(fvalue) # This is the file object -RD --~--~-~--~~~---~--~~ 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: Is it possible to access foreign-keyed properties using values_list()?
huu...@gmail.com wrote: > I stand corrected. However, I should've been more explicit. I > created a method that combines multiple fields on the Author model. > For example: > > def Author(models.Model): > first_name = models.CharField() > last_name = models.CharField() > > def get_full_name(self): >return self.first_name + ' ' + self.last_name > > I've tried to access "author__get_full_name" but have not been > successful. The values_list method takes field names that are actually database model fields. `get_full_name` is not a DB field. So you can't use it directly in the values list. But you can get the first_name and last_name fields and post process them to generate the full_name in Python. -RD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting started with django
> I have some basic of python(functional part and also very basic of oop > part), but don't have other knowledge. I would like to start with > django. So, what more is required to getting started with django so > that i can grasp all the concept and can be proficient with django. > Also is there any way to develop my skills? Start with the "First Steps" section documented here: http://docs.djangoproject.com/en/dev/ -RD --~--~-~--~~~---~--~~ 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: Is it possible to access foreign-keyed properties using values_list()?
I stand corrected. However, I should've been more explicit. I created a method that combines multiple fields on the Author model. For example: def Author(models.Model): first_name = models.CharField() last_name = models.CharField() def get_full_name(self): return self.first_name + ' ' + self.last_name I've tried to access "author__get_full_name" but have not been successful. On Jun 29, 10:46 am, Karen Traceywrote: > On Mon, Jun 29, 2009 at 10:27 AM, huu...@gmail.com wrote: > > > I'd like to use values_list() to populate a choices attribute. > > However, I need to access some foreign-keyed properties to properly > > display the information. > > > For example: > > > >> Books.objects.values_list('id', 'author__name') > > > Currently, it doesn't appear to be working. > > It works for me: > > Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > (InteractiveConsole)>>> from crossword.models import Puzzles > >>> Puzzles.objects.values_list('date', 'publisher__editor')[22] > > (datetime.date(2009, 6, 24), u'Rich Norris/Joyce Nichols Lewis') > > What do you get? What were you expecting instead? > > 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: Password-protecting PDF downloads?
bax...@gretschpages.com wrote: > This is probably more of a python question, but here goes: Can anyone > point me to a method of dynamically attaching a password to a PDF and > protecting the file before it's downloaded? The pyPDF library supports PDF encryption. There are probably others like it. http://pybrary.net/pyPdf/ --~--~-~--~~~---~--~~ 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: Uploaded File Array
When I do: print type(f) It outputs: Also when I try to get the filename using the name property of UploadedFile, it says: 'str' object has no attribute 'name' When I just print f it shows: ëPNG On Jun 29, 10:48 am, Rajesh Dwrote: > On Jun 29, 11:05 am, BarakatX2 wrote: > > > I have a form that allows a dynamic number of files to be uploaded. On > > the Django side, if I print the request.FILES it is described as: > > > > png)>, , > > ]}> > > > But when I try to access the files like this: > > > for f in files['rqFiles']: > > > Then f is a string with some ascii characters including the file > > extension. Shouldn't it be an InMemoryUploadedFile? > > Yes. How are you checking that it is not? If you just print "f", you > will see the name of the file but its type would be correct. > > > How should I be > > accessing files['rqFiles']? > > Go through this > doc:http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handli... > > On each of your files, you could use the f.chunks() method described > in the example in the above doc. > > -RD --~--~-~--~~~---~--~~ 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: add other field for django admin user
> Suppose I have UserPref with attribute phone and detail > Is it possible to add UserPref.phone and UserPref.detil in edit form > in django user admin? You can provide a custom form that has your additional fields and knows how to save them. See: http://docs.djangoproject.com/en/dev//ref/contrib/admin/#modeladmin-options -RD --~--~-~--~~~---~--~~ 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: Handling a reusable form in multiple views
delino wrote: > Rajesh, > > Thanks for your response. If I post the form to a dedicated view that > works fine, but how do I handle validation properly in this approach. > Say the user enters invalid data, do I now need to redirect them back > to the original page and then display these errors? That seems like it > will be a headache as well. Note that this form is a reusable form > that gets displayed within most templates so it's just a little > section of the page. If I now enter invalid data and post the form, > it's going to post to a different view that will then see the form is > invalid and then what?? Option 1: Send your invalid form to a simple template that knows how to display the form and its errors. Option 2: Post your form via AJAX -- you should still implement Option 1 for people that have turned off Javascript -RD --~--~-~--~~~---~--~~ 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: http://www.djangobook.com/en/2.0/chapter03/
oh 0k. thanks dude! I was about to declare that myself. Thanks! On Jun 29, 11:45 pm, Alex Gaynorwrote: > On Mon, Jun 29, 2009 at 10:39 AM, djangonoob wrote: > > > Hi all, > > i am following the tutorial on the link in the subject, > >http://www.djangobook.com/en/2.0/chapter03/ > > and i ran into some trouble. > > > > > from django.conf.urls.defaults import * > > from mysite.views import hello, current_datetime, hours_ahead > > > urlpatterns = patterns('', > > (r'^hello/$', hello), > > (r'^time/$', current_datetime), > > (r'^time/plus/(\d{1,2})/$', hours_ahead), > > ) > > > > > I followed th instructions and than i ran into an erro which states : > > 'tuple' object is not callable > > > Here's a complete error message: > > *** > > Request Method: GET > > Request URL: http://localhost:8000/time/plus/3/ > > Exception Type: TypeError > > Exception Value: > > > 'tuple' object is not callable > > > Exception Location: /home/eugene/public_html/django/mysite/../mysite/ > > urls.py in , line 21 > > Python Executable: /usr/bin/python > > Python Version: 2.6.2 > > Python Path: ['/home/eugene/public_html/django/mysite', '/usr/lib/ > > python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib- > > tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/ > > usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/ > > Numeric', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/ > > dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/ > > lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/ > > python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2- > > unicode', '/usr/local/lib/python2.6/dist-packages'] > > Server time: Mon, 29 Jun 2009 10:31:46 -0500 > > > *** > > > Here are my code: > > > views.py : > > * > > from django.http import Http404, HttpResponse > > import datetime > > > def hello(request): > > return HttpResponse("hello world") > > > def current_datetime(request): > > now = datetime.datetime.now() > > html = "It is now %s." % now > > return HttpResponse(html) > > > def home(request): > > return HttpResponse("This is a home page") > > > def hours_ahead(request, offset): > > try: > > offset = int(offset) > > except ValueError: > > raise Http404() > > dt = datetime.datetime.now() + datetime.timedelta(hours=offset) > > html = "In %s hour(s), it will be %s." % > > (offset, dt) > > return HttpResponse(html) > > > * > > > urls.py > > * > > from django.conf.urls.defaults import * > > from mysite.views import hello, home, current_datetime, hours_ahead > > > urlpatterns = patterns('', > > > ('^hello/$', hello), > > ('^$', home), > > ('^time/$', current_datetime) > > (r'^time/plus/(\d{1,2})/$', hours_ahead), > > > ) > > *** > > > Any idea where did i go wrong? > > > Why did i receive a 'tuple' object is not callable errors? > > > Best Regards, > > EUgene > > If you look you are misisng a comma after one of the lines in your URLconf > (the 2nd URL). That's what causes this issue. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Uploaded File Array
On Jun 29, 11:05 am, BarakatX2wrote: > I have a form that allows a dynamic number of files to be uploaded. On > the Django side, if I print the request.FILES it is described as: > > png)>, , > ]}> > > But when I try to access the files like this: > > for f in files['rqFiles']: > > Then f is a string with some ascii characters including the file > extension. Shouldn't it be an InMemoryUploadedFile? Yes. How are you checking that it is not? If you just print "f", you will see the name of the file but its type would be correct. > How should I be > accessing files['rqFiles']? Go through this doc: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files On each of your files, you could use the f.chunks() method described in the example in the above doc. -RD --~--~-~--~~~---~--~~ 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: http://www.djangobook.com/en/2.0/chapter03/
On Mon, Jun 29, 2009 at 10:39 AM, djangonoobwrote: > > Hi all, > i am following the tutorial on the link in the subject, > http://www.djangobook.com/en/2.0/chapter03/ > and i ran into some trouble. > > > from django.conf.urls.defaults import * > from mysite.views import hello, current_datetime, hours_ahead > > urlpatterns = patterns('', >(r'^hello/$', hello), >(r'^time/$', current_datetime), >(r'^time/plus/(\d{1,2})/$', hours_ahead), > ) > > > I followed th instructions and than i ran into an erro which states : > 'tuple' object is not callable > > Here's a complete error message: > *** > Request Method: GET > Request URL:http://localhost:8000/time/plus/3/ > Exception Type: TypeError > Exception Value: > > 'tuple' object is not callable > > Exception Location: /home/eugene/public_html/django/mysite/../mysite/ > urls.py in , line 21 > Python Executable: /usr/bin/python > Python Version: 2.6.2 > Python Path:['/home/eugene/public_html/django/mysite', '/usr/lib/ > python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib- > tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/ > usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/ > Numeric', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/ > dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/ > lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/ > python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2- > unicode', '/usr/local/lib/python2.6/dist-packages'] > Server time:Mon, 29 Jun 2009 10:31:46 -0500 > > *** > > Here are my code: > > > views.py : > * > from django.http import Http404, HttpResponse > import datetime > > def hello(request): >return HttpResponse("hello world") > > def current_datetime(request): >now = datetime.datetime.now() >html = "It is now %s." % now >return HttpResponse(html) > > def home(request): >return HttpResponse("This is a home page") > > def hours_ahead(request, offset): >try: >offset = int(offset) >except ValueError: >raise Http404() >dt = datetime.datetime.now() + datetime.timedelta(hours=offset) >html = "In %s hour(s), it will be %s." % > (offset, dt) >return HttpResponse(html) > > * > > urls.py > * > from django.conf.urls.defaults import * > from mysite.views import hello, home, current_datetime, hours_ahead > > urlpatterns = patterns('', > >('^hello/$', hello), >('^$', home), >('^time/$', current_datetime) >(r'^time/plus/(\d{1,2})/$', hours_ahead), > > ) > *** > > Any idea where did i go wrong? > > Why did i receive a 'tuple' object is not callable errors? > > Best Regards, > EUgene > > > > If you look you are misisng a comma after one of the lines in your URLconf (the 2nd URL). That's what causes this issue. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: http://www.djangobook.com/en/2.0/chapter03/
Hi all, i am following the tutorial on the link in the subject, http://www.djangobook.com/en/2.0/chapter03/ and i ran into some trouble. from django.conf.urls.defaults import * from mysite.views import hello, current_datetime, hours_ahead urlpatterns = patterns('', (r'^hello/$', hello), (r'^time/$', current_datetime), (r'^time/plus/(\d{1,2})/$', hours_ahead), ) I followed th instructions and than i ran into an erro which states : 'tuple' object is not callable Here's a complete error message: *** Request Method: GET Request URL:http://localhost:8000/time/plus/3/ Exception Type: TypeError Exception Value: 'tuple' object is not callable Exception Location: /home/eugene/public_html/django/mysite/../mysite/ urls.py in , line 21 Python Executable: /usr/bin/python Python Version: 2.6.2 Python Path:['/home/eugene/public_html/django/mysite', '/usr/lib/ python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib- tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/ usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/ Numeric', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/ dist-packages/gst-0.10', '/var/lib/python-support/python2.6', '/usr/ lib/python2.6/dist-packages/gtk-2.0', '/var/lib/python-support/ python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2- unicode', '/usr/local/lib/python2.6/dist-packages'] Server time:Mon, 29 Jun 2009 10:31:46 -0500 *** Here are my code: views.py : * from django.http import Http404, HttpResponse import datetime def hello(request): return HttpResponse("hello world") def current_datetime(request): now = datetime.datetime.now() html = "It is now %s." % now return HttpResponse(html) def home(request): return HttpResponse("This is a home page") def hours_ahead(request, offset): try: offset = int(offset) except ValueError: raise Http404() dt = datetime.datetime.now() + datetime.timedelta(hours=offset) html = "In %s hour(s), it will be %s." % (offset, dt) return HttpResponse(html) * urls.py * from django.conf.urls.defaults import * from mysite.views import hello, home, current_datetime, hours_ahead urlpatterns = patterns('', ('^hello/$', hello), ('^$', home), ('^time/$', current_datetime) (r'^time/plus/(\d{1,2})/$', hours_ahead), ) *** Any idea where did i go wrong? Why did i receive a 'tuple' object is not callable errors? Best Regards, EUgene --~--~-~--~~~---~--~~ 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: Handling a reusable form in multiple views
Rajesh, Thanks for your response. If I post the form to a dedicated view that works fine, but how do I handle validation properly in this approach. Say the user enters invalid data, do I now need to redirect them back to the original page and then display these errors? That seems like it will be a headache as well. Note that this form is a reusable form that gets displayed within most templates so it's just a little section of the page. If I now enter invalid data and post the form, it's going to post to a different view that will then see the form is invalid and then what?? Thanks, Delino On Jun 25, 5:02 pm, Rajesh Dwrote: > On Jun 25, 4:43 pm,delino wrote: > > > > > Hi, > > > I have a simple scenario using Django 0.96 and am looking for a > > cleaner solution than what I currently have: > > > I want to include a simple submission form (a few simple fields) on > > most pages of my site. I have the form action set to '.' so that > > validation can be done in place and errors displayed to the user. I am > > currently checking for the POST and either handling it or creating a > > new form in each of these views and then passing the form to each of > > my templates, e.g. > > > def example_page(request): > > if request.method == 'POST': > > form = SubmitMeForm(request.POST) > > if form.is_valid(): > > # do your thing > > return HttpResponseRedirect('/done/') > > else: > > form = SubmitMeForm() > > > variables = RequestContext(request, { > > 'submitMeForm': form, > > }) > > return render_to_response('somePage.html', variables) > > > I have 2 issues with this: > > > 1 - I have to include this code in each and every view that represents > > a page that has this template. There has to be a simpler way of doing > > it. > > > 2 - What if one of these pages has another Django form in it? I now > > have to handle the fact that the POST could have resulted from this > > form OR the other one. How would I do that? > > You could add your form to your request context using a context > processor under a key other than 'form' (so it doesn't clash with > forms defined by your other views). This way, your context processor > will make this form available globally. Secondly, instead of posting > this common form to '.', post it to a dedicated view that only knows > how to process this common form. > > -RD > > > > > TIA > > --delino --~--~-~--~~~---~--~~ 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: rollback transaction without an exception when transaction is tied to http requests
On Sun, Jun 28, 2009 at 11:14 PM, sicowrote: > > [snip] > > However, I am still curious if there is a way to tell django to not > commit the transaction without the user seeing an exception > > Yes and no: I tried to describe that in my previous answer. Yes, you can arrange to have the transaction be rolled back instead of being committed, and you can avoid having exceptions reflected to the user. But no, there is no setting to tell Django to automatically rollback on error and not propagate the exception resulting from the error: your code must do that. First you have to use manual transaction management, so that you control when the updates get committed. If you use the default autocommit behavior you cannot roll back already completed updates as they will be automatically committed as they are executed. Then you need to be aware, in your code, of what statements might raise exceptions. You must write your code to explicitly handle the cases where exceptions may be raised and "do the right thing" instead of having them just propagate up and be reported as server errors. 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 -~--~~~~--~~--~--~---
Uploaded File Array
I have a form that allows a dynamic number of files to be uploaded. On the Django side, if I print the request.FILES it is described as: , , ]}> But when I try to access the files like this: for f in files['rqFiles']: Then f is a string with some ascii characters including the file extension. Shouldn't it be an InMemoryUploadedFile? How should I be accessing files['rqFiles']? Thanks 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: import a variable form views to forms
Sorry, this is the actual code: views.py def parent(request): user = request.user key = user.get_profile().link p = Parent.objects.get(pk = key) children = p.children.all() if request.method == 'POST': form = ComentForm(request.POST, children???) if form.is_valid(): cd = form.cleaned_data c = Coments(from=cd['from'], comentario=cd['coment']) c.save() return render_to_response('sent.html', locals()) else: form = ComentForm(children???) return render_to_response('parent.html', locals()) forms.py class ComentForm(forms.Form): def __init__(self, user_choices_list, *args, **kwargs): super(ComentForm, self).__init__(*args, **kwargs) self.fields['from'].choices = user_choices_list from = forms.ChoiceField() coment = forms.CharField(widget=forms.Textarea, label='Coment') --~--~-~--~~~---~--~~ 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: Is it possible to access foreign-keyed properties using values_list()?
On Mon, Jun 29, 2009 at 10:27 AM, huu...@gmail.comwrote: > > I'd like to use values_list() to populate a choices attribute. > However, I need to access some foreign-keyed properties to properly > display the information. > > For example: > > >> Books.objects.values_list('id', 'author__name') > > Currently, it doesn't appear to be working. It works for me: Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from crossword.models import Puzzles >>> Puzzles.objects.values_list('date', 'publisher__editor')[22] (datetime.date(2009, 6, 24), u'Rich Norris/Joyce Nichols Lewis') What do you get? What were you expecting instead? 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: Arbitrary HTTP CONNECT attempts on Django dev server
yes. with no firewall protection in your case. that is what the dmz setting of a router is supposed to do. On 6/29/09, chefsmartwrote: > > > Hi, > > Thanks for your descriptive answer. > > I'm starting the development server with python manage.py runserver > 192.168.1.110:8000 > > This is so that the Django app can be accessed from other machines on > the (home) network for testing. At the time these messages were > displayed on the server console, no other computers were running in > the network. However, my machine is in the DMZ. So at that point of > time the network had only me, and the (broadband) router itself. > > In this setup, is my computer accessible from outside the local > network? > > Regards, > CM > > On Jun 28, 8:17 pm, Karen Tracey wrote: > > > On Sun, Jun 28, 2009 at 9:11 AM, chefsmart > wrote: > > > > > I'm seeing a lot of the following in my Django development server > > > window lately: - > > > > > [28/Jun/2009 18:33:42] "CONNECT mail.burst.idv.tw:25 HTTP/1.0" 500 > > > 41555 > > > > > Has anyone else seen this messages? What is this exactly? Is my > > > computer infected with some malware? > > > > > I would have been easy if it were a GET, POST, PUT or DELETE. But > > > CONNECT? > > > > > I know I'm not making much sense, but I am puzzled where this request > > > is coming from! > > > > Something is trying to use your development server as a proxy to set up a > > tunnel to some host named mail.burst.idv.tw, port number 25 (a mail > server > > port). > > > > What command line arguments are you using to start your development > server? > > Specifically are you setting it up to listen on all interfaces, or just > the > > default localhost? If you are listening only on localhost, then the > > requests are coming from some program running on your machine. If that's > > the case then I'd suspect your computer has been infected with something. > > > > If on the other hand you've specified 0.0.0.0 as the IP address for the > dev > > server to listen on, then the request could be coming from anywhere that > can > > reach your machine. So -- what other machines have the ability to > connect > > to your machine? > > > > If it's open to the whole Internet, then these requests could be coming > from > > anywhere and it's probably not worth trying to track them down. The dev > > server is not creating the requested tunnel (it's actually running into > an > > exception and returning a 500 server error...from a little experimenting > I > > think the 500 error is due to ticket #10834) so no great harm done in > this > > particular case. > > > > But if you do have a dev server open to the Internet, you might want to > > rethink that -- see the note here: > http://docs.djangoproject.com/en/dev/ref/django-admin/#runserver > > > > "DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through > > security audits..." > > > > While this particular possibly malicious request isn't causing anything > too > > bad to happen, the dev server really has not been checked to ensure that > it > > can't be fooled into doing something it shouldn't be doing. It's really > not > > a good idea to have one open to the Internet at large. > > > > If on the other hand your machine is only accessible from a limited > number > > of other machines that you "trust", it looks like one of them might be > > infected with something. In that case you might want to add some > additional > > logging in basehttp.py to report the client address and port since the > > existing log message doesn't include that information. If you change the > > log_message routine in django/core/servers/basehttp.py to be: > > > > def log_message(self, format, *args): > > # Don't bother logging requests for admin images or the favicon. > > if self.path.startswith(self.admin_media_prefix) or self.path == > > '/favicon.ico': > > return > > client_host = self.client_address[0] > > client_port = self.client_address[1] > > sys.stderr.write("[%s] Client %s:%d: %s\n" % > > (self.log_date_time_string(), client_host, client_port, format % args)) > > > > then you'll have the IP address of the machine that is sending the > requests. > > > > Karen > > > -- Thanks, Richard Shebora Information in this transmission is privileged and confidential. It is intended for the use of the individual or entity named above. Any review, dissemination, disclosure, alteration, printing, circulation or transmission of this email or it's attachments is prohibited and unlawful. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email
Is it possible to access foreign-keyed properties using values_list()?
I'd like to use values_list() to populate a choices attribute. However, I need to access some foreign-keyed properties to properly display the information. For example: >> Books.objects.values_list('id', 'author__name') Currently, it doesn't appear to be working. --~--~-~--~~~---~--~~ 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: regex problem in django
On Jun 29, 2:57 pm, Joruwrote: > Still doesn't work even I remove wrap function :( So it seems your regex is incorrect, the problem is not related to Django. If you paste your code here I can have a look, but I still think you'd be better off reading a bit more about regular expressions yourself. The last link I posted wasn't very useful for learning because it is just a reference, there is a proper tutorial on regular expressions with Python here: http://www.amk.ca/python/howto/regex/ James --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
import a variable form views to forms
Hello, I want to use a objects list in a ChoiceField of a form that I have in forms.py but I dont know how to do it. views.py def parent(request): user = request.user key = user.get_profile().link p = Parent.objects.get(pk = key) children = p.children.all() if request.method == 'POST': form = ComentForm(request.POST, children???) if form.is_valid(): cd = form.cleaned_data c = Coments(from=cd['from'], comentario=cd['coment']) c.save() return render_to_response('sent.html', locals()) else: form = ComentForm(user_choices_list=lista_maestras) return render_to_response('parent.html', locals()) forms.py class ComentForm(forms.Form): def __init__(self, user_choices_list, *args, **kwargs): super(ComentForm, self).__init__(*args, **kwargs) self.fields['from'].choices = user_choices_list from = forms.ChoiceField() coment = forms.CharField(widget=forms.Textarea, label='Coment') --~--~-~--~~~---~--~~ 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: Redirect to html file
On Mon, Jun 29, 2009 at 6:11 AM, Daniel Rosemanwrote: > > On Jun 29, 9:23 am, alecs wrote: > > Hi! If I have some html file somewhere (i.e. /var/file), how to > > redirect user to it? It is not a template and not in a template > > folder. Thanks :) > > It needs to be somewhere the webserver can see it. Ideally you'd put > in the same place as the rest of your static content (CSS, JS), then > you can use the MEDIA_URL setting to access it. > -- > DR. > > > Alternatively you could just render it using a direct to template generic view, since just about any static HTML is a valid template file. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
add other field for django admin user
Hi, Suppose I have UserPref with attribute phone and detail Is it possible to add UserPref.phone and UserPref.detil in edit form in django user admin? --~--~-~--~~~---~--~~ 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: regex problem in django
Still doesn't work even I remove wrap function :( On Jun 29, 7:35 pm, James Gregorywrote: > On Jun 29, 1:05 pm, Joru wrote: > > > I'm sorry for my typo > > the string var suppose to be like this > > str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n > > So every match string "wr:" should had "+" in front of it line > > the one that confuse me is that my function work in django/python > > shell, but thisregexdoesn't work well if i called it from views.py > > of my django app > > So the problem that I faced is that, how come when using django/python > > shell. myregexwork but not if I put in on my views.py > > Any hint? > > I may be wrong, but I suspect there is a difference between the input > string/code you are using in the shell, and the input string/code you > are using in the view. What happens if make a new empty Python script > and cut and paste in your code (removing the wrap function from > Django). Does it work then? > > James --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Password-protecting PDF downloads?
This is probably more of a python question, but here goes: Can anyone point me to a method of dynamically attaching a password to a PDF and protecting the file before it's downloaded? --~--~-~--~~~---~--~~ 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: Custom templatetags for loading objects
This is likely exactly what you're looking for: http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/ -justin On Mon, Jun 29, 2009 at 9:16 AM, Joshua Partogiwrote: > Dear all, > Currently I want to make a custom templatetags for loading objects to be > looped over. Is there any reference that I should be reading? > Kind regards, > > -- > Join Scrum8.com. > > http://scrum8.com/member/jpartogi/ > http://scrum8.com/blog/jpartogi/ > http://twitter.com/scrum8 > > > > -- Justin Lilly Python/Django Developer http://justinlilly.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 -~--~~~~--~~--~--~---
Custom templatetags for loading objects
Dear all, Currently I want to make a custom templatetags for loading objects to be looped over. Is there any reference that I should be reading? Kind regards, -- Join Scrum8.com. http://scrum8.com/member/jpartogi/ http://scrum8.com/blog/jpartogi/ http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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: subdomains cookie problem
Hi Raja This looks great. Thanks for helping out. Stepehn On Jun 29, 9:17 pm, Rajawrote: > Setup thecookie.domain attribute value to '.mydomain.com' (The first > dot is important) and all hosts in that domain will get thecookie. > > -- Raja > > On Jun 29, 4:01 pm, Stephen Cheng wrote: > > > Yes, I check thecookievalue in view or in middleware class. > > > Just give example, eg, I want the browser to remember online user's > > city, so next time when they typewww.mydomain.com, it will be > > diverted to cityx.mydomain.com. > > > Now the problem is that: > > 1. When I setup acookievarible cityname=city5 in > > city1.mydomain.com (in a view), I expect in my middleware class to > > redirect to city5.mydomain.com if thesubdomainname is www, but the > > citynamecookievar is none and the cityanme=city5 exists only in > >subdomaincity1.mydomain.com > > 2. I tried to diagnose the problem and found that I have to setup > > the samecookievar in each of separatesubdomainview, which is not > > acceptable. > > > Hope this clarify things. > > > Thanks, > > > Stephen > > > On Jun 29, 7:36 pm, Raja wrote: > > > > Just checking, Are you submitting back to the server before checking > > > for thecookievalue ? Cookies are sent only when the request reaches > > > the server. > > > > -- Raja > > > > On Jun 29, 9:21 am, Stephen Cheng wrote: > > > > > Hi > > > > > I am facing a problem in DEV server that I really have no idea how to > > > > resolve, which is related tocookievariable for subdomains. > > > > > I use wildcard subdomains, eg. sub1.abc.com, sub2.abc.com, > > > > sub3.abc.com and all sub domains point to one running instance of > > > > django app. > > > > > The problem is that I hope the cookievar will be available for all > > > > subdomains but it seems django doesn't support(correct me if I am > > > > wrong) > > > > > eg, I setup cookieabc="abc" in sub1.abc.com, however cookieabc=None > > > > when accessing sub1.abc.com in the same view. I tried to enable > > > > SESSION_COOKIE_DOMAIN, but it doesn't work. > > > > > I have no idea how to resolve this. Any idea? > > > > > Thanks, > > > > > Stephen --~--~-~--~~~---~--~~ 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: regex problem in django
On Jun 29, 1:05 pm, Joruwrote: > I'm sorry for my typo > the string var suppose to be like this > str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n > So every match string "wr:" should had "+" in front of it line > the one that confuse me is that my function work in django/python > shell, but this regex doesn't work well if i called it from views.py > of my django app > So the problem that I faced is that, how come when using django/python > shell. my regex work but not if I put in on my views.py > Any hint? I may be wrong, but I suspect there is a difference between the input string/code you are using in the shell, and the input string/code you are using in the view. What happens if make a new empty Python script and cut and paste in your code (removing the wrap function from Django). Does it work then? James --~--~-~--~~~---~--~~ 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: Get Users' Groups
Thanks :) And where can I see the whole Group Documentation? All the fields we have available (and their names), etc... On 25 Jun, 18:02, Daniel Rosemanwrote: > On Jun 25, 2:45 pm, Gil Sousa wrote: > > > Hi! > > > I searched on documentation but I didn't see anything related with > > managing users' groups, I want to do something like a "staff page" and > > for that I need to get a list of groups, I need to get the NAME of > > each group and I need to get the list of members of each group. How > > can I do this? > > > I am using the User and Group django Models. > > > Thanks! > > It's just a normal ManyToMany relationship between user and group. So > you can do: > > {% for group in groups %} > {{ group.name }} - {{ group.user_set.all }} > {% endfor %} > -- > 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: regex problem in django
I'm sorry for my typo the string var suppose to be like this str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n So every match string "wr:" should had "+" in front of it line the one that confuse me is that my function work in django/python shell, but this regex doesn't work well if i called it from views.py of my django app So the problem that I faced is that, how come when using django/python shell. my regex work but not if I put in on my views.py Any hint? On Jun 29, 5:49 pm, James Gregorywrote: > On Jun 29, 11:19 am, Joru wrote: > > > ah, I just want to match in the end of line only > > so change the rule "wr$" would get what I want? > > > > Square brackets are for character groups, not literal strings. "wr:" > > > is just a string so it should be "wr:", not "[wr:]". Also, you want to > > > match the beginning of the line, not the end, so it should be > > > something like "^wr:", not "wr$". Unless I've missed something. > > When you split your test string on newlines you get: > > "wr:" > " one bunny" > " two bunny" > " wr: three bunny" > > In the first line "wr:" is at both the beginning and end of the > string, as it is the whole string. The next two lines do not feature > "wr:" at all. On the last line "wr:" is at neither the beginning nor > the end of the string - it has " " in front, and " three bunny" > afterwards. Depending on what you want to do you might want to call > strip() on each line, in which case the 4th line would become "wr: > three bunny", making wr: the beginning of the line. It depends what > you want to do, and anyway I can't write your program for you. > > Essentially, you just need to spend some time reading a bit more about > regular expressions:http://docs.python.org/library/re.html > > James --~--~-~--~~~---~--~~ 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: Linking css file to the template
On Jun 29, 12:33 pm, atikwrote: > I am working on a simple django project. I have tried to link the css > file, but it's not working. If i run the html template directly, then > it's ok. but if i run the server, then its not working. What to do? Read the documentation: http://docs.djangoproject.com/en/dev/howto/static-files/ And also read this: http://catb.org/esr/faqs/smart-questions.html -- 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 -~--~~~~--~~--~--~---
Linking css file to the template
I am working on a simple django project. I have tried to link the css file, but it's not working. If i run the html template directly, then it's ok. but if i run the server, then its not working. What to do? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is IP address caching built into the Django Framework?
On Jun 29, 8:13 am, Vladimir Shulyakwrote: > > You can't rely on just the IP. If you do then you will have problems > > where large numbers of people sit behind a single IP, as will be case > > where corporate firewall is used, or where proxies or other gateway or > > NAT solution are used by ISPs. > > That's right, try to use cookie check instead of IP check. > Except cookies are very easy to fake it depends on how serious you want your voting to be; whether you could tolerate a little hacking or not. http://stackoverflow.com/questions/1042580/best-way-to-store-views-of-an-topic/ Is a discussion on this in mysql/php but the general principles are the same. Basically, IP addr is the only thing it's really hard to play around with - user-agent, cookie, everything else is fakable with ease. But if you use IP addr only then 2 people sharing the same IP address (different computers on the same broadband connection, etc) can only vote once. It's a problem. --~--~-~--~~~---~--~~ 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-profile-images
Hey guys, Anybody know the type of object "user" in {% profile_image user 64x64 %} 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 -~--~~~~--~~--~--~---
Re: subdomains cookie problem
Setup the cookie.domain attribute value to '.mydomain.com' (The first dot is important) and all hosts in that domain will get the cookie. -- Raja On Jun 29, 4:01 pm, Stephen Chengwrote: > Yes, I check the cookie value in view or in middleware class. > > Just give example, eg, I want the browser to remember online user's > city, so next time when they typewww.mydomain.com, it will be > diverted to cityx.mydomain.com. > > Now the problem is that: > 1. When I setup a cookie varible cityname=city5 in > city1.mydomain.com (in a view), I expect in my middleware class to > redirect to city5.mydomain.com if the subdomain name is www, but the > cityname cookie var is none and the cityanme=city5 exists only in > subdomain city1.mydomain.com > 2. I tried to diagnose the problem and found that I have to setup > the same cookie var in each of separate subdomain view, which is not > acceptable. > > Hope this clarify things. > > Thanks, > > Stephen > > On Jun 29, 7:36 pm, Raja wrote: > > > Just checking, Are you submitting back to the server before checking > > for the cookie value ? Cookies are sent only when the request reaches > > the server. > > > -- Raja > > > On Jun 29, 9:21 am, Stephen Cheng wrote: > > > > Hi > > > > I am facing a problem in DEV server that I really have no idea how to > > > resolve, which is related to cookie variable for subdomains. > > > > I use wildcard subdomains, eg. sub1.abc.com, sub2.abc.com, > > > sub3.abc.com and all sub domains point to one running instance of > > > django app. > > > > The problem is that I hope the cookievar will be available for all > > > subdomains but it seems django doesn't support(correct me if I am > > > wrong) > > > > eg, I setup cookieabc="abc" in sub1.abc.com, however cookieabc=None > > > when accessing sub1.abc.com in the same view. I tried to enable > > > SESSION_COOKIE_DOMAIN, but it doesn't work. > > > > I have no idea how to resolve this. Any idea? > > > > Thanks, > > > > Stephen --~--~-~--~~~---~--~~ 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: Base view class ?
"In my experience the biggest benefit of class-based views are when you are doing a bunch of similar stuff that's just a tiny bit different, for which you can just subclass the view class for the bits you need to change" Yap ... that's exactly why I'm looking for a class-based views. thank you Daniel On Mon, Jun 29, 2009 at 1:09 PM, Justin Lillywrote: > > It's also worth noting that you _can_ use a class for a view. Views > just have to be python callables. For more info on this, check out > Marty Alchin's Pro Django and the python doc's for __call__. > > In my experience the biggest benefit of class-based views are when you > are doing a bunch of similar stuff that's just a tiny bit different, > for which you can just subclass the view class for the bits you need > to change. > > Hope that helps. > > -justin > > > > On Jun 29, 2009, at 6:28 AM, Raja wrote: > >> >> You could use decorators (following the Decorator pattern) to do pre/ >> post interceptors. For e.g. >> http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.decorators.login_required >> shows a login_required decorator to make sure that those views can >> only be accessed after logging in. >> >> -- Raja >> >> >> On Jun 29, 3:16 pm, Daniel Guryca wrote: >>> OK >>> As I have said I'm coming from java so it's not so easy to change my >>> mind to a totally different approach. >>> >>> But I'm still curious if there is any before or after interceptor >>> in django. >>> Or how to implement one using a django style. >>> >>> Thank you >>> Daniel >>> >>> On Mon, Jun 29, 2009 at 12:05 PM, James >>> Gregory wrote: >>> On Jun 29, 10:59 am, Daniel Guryca wrote: > Hi, >>> > I'm very new to django and python .. coming from java world. >>> > I really like django structure (apps, ...) but I do not > understand how > one can create some base class where all general methods same for > all > views could be put. > You know I can see that views.py is only a module I would rather > expect class in it and all methods part of this class. Then this > class > could extend my BaseViewClass. >>> > Is something like before and after interceptors possible in > django ? > Then I would not need any base class. >>> > Thank you. > Cheers > Daniel >>> A class is just a collection of methods and data. In Django views do not have any data, because that is fetched from the model. So where is the advantage of having your methods part of a class rather than just functions which are part of the module? It would just mean you would have to add one extra layer of indentation to everything. If you want, think of the views.py module as being a class with no data members. >>> James >> > > > > > --~--~-~--~~~---~--~~ 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: Sharing a development site cheaply (free as in beer?)
> Currently GAE only supports django 0.96. Besides that, there are several > django features that is not available on GAE such as: session middleware and > django model which in effect django admin and django auth is not runnable on > it too. But it's quite worth it for your needs I reckon. Um, it supports 1.0 and 1.1 with this project, and as far as I know also support session middleware and django users (but not groups). http://code.google.com/p/app-engine-patch/ Tim ^,^ --~--~-~--~~~---~--~~ 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: Redirect to html file
On Jun 29, 9:23 am, alecswrote: > Hi! If I have some html file somewhere (i.e. /var/file), how to > redirect user to it? It is not a template and not in a template > folder. Thanks :) It needs to be somewhere the webserver can see it. Ideally you'd put in the same place as the rest of your static content (CSS, JS), then you can use the MEDIA_URL setting to access it. -- 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: Base view class ?
It's also worth noting that you _can_ use a class for a view. Views just have to be python callables. For more info on this, check out Marty Alchin's Pro Django and the python doc's for __call__. In my experience the biggest benefit of class-based views are when you are doing a bunch of similar stuff that's just a tiny bit different, for which you can just subclass the view class for the bits you need to change. Hope that helps. -justin On Jun 29, 2009, at 6:28 AM, Rajawrote: > > You could use decorators (following the Decorator pattern) to do pre/ > post interceptors. For e.g. > http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.decorators.login_required > shows a login_required decorator to make sure that those views can > only be accessed after logging in. > > -- Raja > > > On Jun 29, 3:16 pm, Daniel Guryca wrote: >> OK >> As I have said I'm coming from java so it's not so easy to change my >> mind to a totally different approach. >> >> But I'm still curious if there is any before or after interceptor >> in django. >> Or how to implement one using a django style. >> >> Thank you >> Daniel >> >> On Mon, Jun 29, 2009 at 12:05 PM, James >> Gregory wrote: >> >>> On Jun 29, 10:59 am, Daniel Guryca wrote: Hi, >> I'm very new to django and python .. coming from java world. >> I really like django structure (apps, ...) but I do not understand how one can create some base class where all general methods same for all views could be put. You know I can see that views.py is only a module I would rather expect class in it and all methods part of this class. Then this class could extend my BaseViewClass. >> Is something like before and after interceptors possible in django ? Then I would not need any base class. >> Thank you. Cheers Daniel >> >>> A class is just a collection of methods and data. In Django views do >>> not have any data, because that is fetched from the model. So >>> where is >>> the advantage of having your methods part of a class rather than >>> just >>> functions which are part of the module? It would just mean you would >>> have to add one extra layer of indentation to everything. If you >>> want, >>> think of the views.py module as being a class with no data members. >> >>> James > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Redirect to html file
Hi! If I have some html file somewhere (i.e. /var/file), how to redirect user to it? It is not a template and not in a template folder. 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 -~--~~~~--~~--~--~---
Re: subdomains cookie problem
Yes, I check the cookie value in view or in middleware class. Just give example, eg, I want the browser to remember online user's city, so next time when they type www.mydomain.com, it will be diverted to cityx.mydomain.com. Now the problem is that: 1. When I setup a cookie varible cityname=city5 in city1.mydomain.com (in a view), I expect in my middleware class to redirect to city5.mydomain.com if the subdomain name is www, but the cityname cookie var is none and the cityanme=city5 exists only in subdomain city1.mydomain.com 2. I tried to diagnose the problem and found that I have to setup the same cookie var in each of separate subdomain view, which is not acceptable. Hope this clarify things. Thanks, Stephen On Jun 29, 7:36 pm, Rajawrote: > Just checking, Are you submitting back to the server before checking > for the cookie value ? Cookies are sent only when the request reaches > the server. > > -- Raja > > On Jun 29, 9:21 am, Stephen Cheng wrote: > > > Hi > > > I am facing a problem in DEV server that I really have no idea how to > > resolve, which is related to cookie variable for subdomains. > > > I use wildcard subdomains, eg. sub1.abc.com, sub2.abc.com, > > sub3.abc.com and all sub domains point to one running instance of > > django app. > > > The problem is that I hope the cookievar will be available for all > > subdomains but it seems django doesn't support(correct me if I am > > wrong) > > > eg, I setup cookieabc="abc" in sub1.abc.com, however cookieabc=None > > when accessing sub1.abc.com in the same view. I tried to enable > > SESSION_COOKIE_DOMAIN, but it doesn't work. > > > I have no idea how to resolve this. Any idea? > > > Thanks, > > > Stephen --~--~-~--~~~---~--~~ 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: About django.root
can you try PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) in your django settings.py file? cheers On Sun, Jun 28, 2009 at 7:09 PM, Frank Abelwrote: > > Hi all, > > I'm using mod_python and have "PythonOption django.root" set. > > My question is, how can I access that var (my site deploy path prefix) > so in case that my app change of location all URLs that my app generate > ("get_absolute_url" models method, etc.) have the new location? > > Cheers > Frank Abel > > > -- Mugisha Moses P.O. Box 1420 Kampala, Uganda http://appfrica.org skype name : mossplix twitter: @mugisha --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Getting started with django
I have some basic of python(functional part and also very basic of oop part), but don't have other knowledge. I would like to start with django. So, what more is required to getting started with django so that i can grasp all the concept and can be proficient with django. Also is there any way to develop my skills? --~--~-~--~~~---~--~~ 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: regex problem in django
On Jun 29, 11:19 am, Joruwrote: > ah, I just want to match in the end of line only > so change the rule "wr$" would get what I want? > > > Square brackets are for character groups, not literal strings. "wr:" > > is just a string so it should be "wr:", not "[wr:]". Also, you want to > > match the beginning of the line, not the end, so it should be > > something like "^wr:", not "wr$". Unless I've missed something. When you split your test string on newlines you get: "wr:" " one bunny" " two bunny" " wr: three bunny" In the first line "wr:" is at both the beginning and end of the string, as it is the whole string. The next two lines do not feature "wr:" at all. On the last line "wr:" is at neither the beginning nor the end of the string - it has " " in front, and " three bunny" afterwards. Depending on what you want to do you might want to call strip() on each line, in which case the 4th line would become "wr: three bunny", making wr: the beginning of the line. It depends what you want to do, and anyway I can't write your program for you. Essentially, you just need to spend some time reading a bit more about regular expressions: http://docs.python.org/library/re.html James --~--~-~--~~~---~--~~ 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: Base view class ?
You could use decorators (following the Decorator pattern) to do pre/ post interceptors. For e.g. http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.decorators.login_required shows a login_required decorator to make sure that those views can only be accessed after logging in. -- Raja On Jun 29, 3:16 pm, Daniel Gurycawrote: > OK > As I have said I'm coming from java so it's not so easy to change my > mind to a totally different approach. > > But I'm still curious if there is any before or after interceptor in django. > Or how to implement one using a django style. > > Thank you > Daniel > > On Mon, Jun 29, 2009 at 12:05 PM, James Gregory wrote: > > > On Jun 29, 10:59 am, Daniel Guryca wrote: > >> Hi, > > >> I'm very new to django and python .. coming from java world. > > >> I really like django structure (apps, ...) but I do not understand how > >> one can create some base class where all general methods same for all > >> views could be put. > >> You know I can see that views.py is only a module I would rather > >> expect class in it and all methods part of this class. Then this class > >> could extend my BaseViewClass. > > >> Is something like before and after interceptors possible in django ? > >> Then I would not need any base class. > > >> Thank you. > >> Cheers > >> Daniel > > > A class is just a collection of methods and data. In Django views do > > not have any data, because that is fetched from the model. So where is > > the advantage of having your methods part of a class rather than just > > functions which are part of the module? It would just mean you would > > have to add one extra layer of indentation to everything. If you want, > > think of the views.py module as being a class with no data members. > > > James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help using the django queries API to select columns from multiple tables
Hi Daniel Thank you very much for your help. The reasons why the foreign key is in the other table is because an event can have multiple locations, its unusual however the Aviation industry has an event which will fly from location A to B. Yes it seems counter-intuitive at first glance. The other reason is If do move the foreign key to the Events table then i cant get the admin.py to work. The admin has to be able to edit all the fields (in effect see columns from multiple tables using inlines) from the same page: in admin.py: class LocationInline(admin.StackedInline): model=Location extra = 0 class EventAdmin(admin.ModelAdmin): inlines = [PeriodInline, LocationInline, InviteGroupInline, CategoryInline,] list_display = ('added','title','email',) list_per_page = 50 list_filter = ('added','start','end',) search_fields = ('contact', 'email', 'phoneBH', 'phoneAH', 'phoneFax', 'phoneM', 'url','title','description') admin.site.register(Event, EventAdmin) Nevertheless if there is no way to make the foreign key relationship work with the current schema then I will move it as you have suggested. Do you know how to build the admin.py to circumvent this issue? On Mon, Jun 29, 2009 at 6:51 PM, Daniel Rosemanwrote: > > On Jun 29, 4:57 am, Sam Walters wrote: > > Hi > > I am using django 1.0 to redevelop a website. > > I have readhttp://docs.djangoproject.com/en/1.0/topics/db/queries/andcant > > work out how to do my query except using raw sql. It would be great to be > > able to use the django query api so i can stack queries more easily. > > > > Just one working example would be enough for me to be able to figure out > the > > rest of the syntax i need. > > In this case the model is using a ForeignKey relationship between two > > tables, thus is a one to many relationship. > > > > the model.py code exists here:http://pastebin.com/m7ddf3bb8 > > > > the views.py code exists here:http://pastebin.com/m78daa247 > > > > I would like to be able to replace the customer sql cursor.generate > methods. > > > > Any help would be appreciated and allow me to discover a lot more about > > django queries. > > You don't need to explicitly join the tables - that's the whole point > of having a foreignkey field in the model. However, there is one > problem. It seems like your foreign key is on the wrong model. Surely > each event has a single location, but a location can have many events? > In which case, the FK should be from event to location. > > class Event (models.Model): > >location = models.ForeignKey(Event) > > Now, you can get the events like this: > > events = Event.objects.filter(start__gte=datetime.datetime.now > ()).select_related() > > and iterate through in your template: > > {% for event in events %} >{{ event.title }} - {{ event.location.name }} > {% endfor %} > > The select_related() on the initial query is optional, but will get > all the joined location data in one query and so cut down on database > access. > -- > 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: regex problem in django
ah, I just want to match in the end of line only so change the rule "wr$" would get what I want? On Jun 29, 4:56 pm, James Gregorywrote: > On Jun 29, 10:49 am, Joru wrote: > > > > > I mean None not null > > When I print rgx always None, that mean theregexeval never match > > The expected output result would be > > > +wr:> one bunny > > > two bunny > > > + wr: three bunny > > > Because everytime foundregexrules r'[wr:]$' then should add + in > > beginning of line > > > On Jun 29, 4:31 pm, James Gregory wrote: > > > > On Jun 29, 10:05 am, Joru wrote: > > > > > I still can't solve this > > > > Anyone had answer on this? > > > > > On Jun 26, 7:39 pm, Joru wrote: > > > > > > Hi, > > > > > > I experience some weirdness regarding usingregexwith django > > > > > I have following function in utils.py > > > > > > from django.utils.text import wrap > > > > > import re > > > > > > str = "wr: \n one bunny \n two bunny \n wr: three bunny \n > > > > > def do_regex(text): > > > > > lines = wrap(text, 55).split('\n') > > > > > for i, line in enumerate(lines): > > > > > cmp = re.compile(r'[wr:]$') > > > > > rgx = cmp.search(line) > > > > > if rgx: > > > > > line = "+%s" % line > > > > > lines[i] = line > > > > > else : > > > > > lines[i] = ">%s" % line > > > > > return '\n'.join(lines) > > > > > do_regex(str) > > > > > > when calling do_regex() from views.py, I always get rgx null while > > > > > when I use django shell rgx will have value when match toregexthat I > > > > > declare in cmp var > > > > > How to fix myregexso it can work inside views.py? > > > > I copied and pasted your code (with an added speech mark to close str) > > > into a controller function, and it works for me: > > > > Django version 1.1 beta 1, using settings 'pilchard.settings' > > > Development server is running athttp://127.0.0.1:8000/ > > > Quit the server with CTRL-BREAK.>wr: > > > > one bunny > > > > two bunny > > > > wr: three bunny > > > > [29/Jun/2009 10:29:45] "GET / HTTP/1.1" 200 2285 > > > > What do you mean by "get rgx null"? What exactly is null? Where? > > > > James > > Square brackets are for character groups, not literal strings. "wr:" > is just a string so it should be "wr:", not "[wr:]". Also, you want to > match the beginning of the line, not the end, so it should be > something like "^wr:", not "wr$". Unless I've missed something. > > James > James --~--~-~--~~~---~--~~ 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: Base view class ?
OK As I have said I'm coming from java so it's not so easy to change my mind to a totally different approach. But I'm still curious if there is any before or after interceptor in django. Or how to implement one using a django style. Thank you Daniel On Mon, Jun 29, 2009 at 12:05 PM, James Gregorywrote: > > > > On Jun 29, 10:59 am, Daniel Guryca wrote: >> Hi, >> >> I'm very new to django and python .. coming from java world. >> >> I really like django structure (apps, ...) but I do not understand how >> one can create some base class where all general methods same for all >> views could be put. >> You know I can see that views.py is only a module I would rather >> expect class in it and all methods part of this class. Then this class >> could extend my BaseViewClass. >> >> Is something like before and after interceptors possible in django ? >> Then I would not need any base class. >> >> Thank you. >> Cheers >> Daniel > > A class is just a collection of methods and data. In Django views do > not have any data, because that is fetched from the model. So where is > the advantage of having your methods part of a class rather than just > functions which are part of the module? It would just mean you would > have to add one extra layer of indentation to everything. If you want, > think of the views.py module as being a class with no data members. > > James > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---