Re: apache authentication using Django on windows
Matt wrote on 11/05/08 16:26: > Hi, > > I have Django running on Apache 2.2 on windows. I am attempting to > use django authentification to secure an apache folder using this > configuration: > > > > AuthType Basic > AuthName "mysite.com" > AuthUserFile /dev/null > AuthBasicAuthoritative Off > Require valid-user > PythonPath "['E:/Software/django'] + sys.path" > SetEnv DJANGO_SETTINGS_MODULE testproject.settings > PythonOption DJANGO_SETTINGS_MODULE testproject.settings > PythonAuthenHandler django.contrib.auth.handlers.modpython > > > However, it complains that it cannot find /dev/null. Is there > something I can use instead of /dev/null for use on windows? > The equivalent of /dev/null on windows is NUL. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Highlight current active page
Alex Rades wrote on 09/30/08 09:03: > Hi, > what kind of pattern do you use to add a class attribute to the > current page being viewed? > I mean the usual: > > > Home > Products > FAQ > contact us > > > I have this snipped of html defined in the base template and all pages > inherit from it. > Currently I'm using this templatetag: > > http://gnuvince.wordpress.com/2007/09/14/a-django-template-tag-for-the-current-active-page/ > > while it's very useful, I don't like it too much, so I'm asking you > what is the best practice here. > I usually do that through a css switch on the body tag. e.g. base template: - Home Products FAQ contact us css: - #section-home #nav-home a, #section-products #nav-products a, #section-faq #nav-faq a, #section-contact #nav-contact a { background-color: blue; } products template: - {% block section %}products{% endblock %} faq template: - {% block section %}faq{% endblock %} hth Cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ldapauth and TLS
Daniele Procida wrote on 10/16/08 20:43: > On Thu, Oct 16, 2008, Dj Gilcrease <[EMAIL PROTECTED]> wrote: > >> LDAP_OPTIONS = 'ldap.OPT_X_TLS_DEMAND: True' >> should be >> LDAP_OPTIONS = {ldap.OPT_X_TLS_DEMAND: True} > > Sdly, that immediately crashes the server: > > Traceback (most recent call last): > File "manage.py", line 4, in > import settings # Assumed to be in the same directory. > File "/home/daniele/testmedic/settings.py", line 95, in > LDAP_OPTIONS = {ldap.OPT_X_TLS_DEMAND: True} > NameError: name 'ldap' is not defined import ldap LDAP_OPTIONS = {ldap.OPT_X_TLS_DEMAND: True} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django authorization of apache
Robin Becker wrote on 06/28/07 16:13: > I see from this documentation > > http://www.djangoproject.com/documentation/apache_auth/#configuring-apache > > that it is conceptually possible to configure apache authorization using > django. > > However, we have recently decided to de-couple django from mod_python by > using > fastcgi. This is because we wish to allow our django apps to use which ever > python might be appropriate and not restrict to the one for which we have > compiled apache+mod_python. > > Is there any way to have mod_python stuck on Python-2.4 with the controlling > django app use Python-2.5 and do configuration for apache. The only way I can > think of is to create a stub project which runs the auth only. > > I know that theoretically we can advance the apache, but that implies > re-installing wikis etc etc etc and when Python-2.6 comes out and the boss > wants > to use new feature X we'll go through the whole process again. > > Alternatively is there a way to do the reverse ie get django to use a > database > controlled by apache? You could directly access the database using something like mod_auth_mysql or the like. But the way django stores passwords may be 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django authorization of apache
Robin Becker wrote on 06/28/07 19:44: > Steven Armstrong wrote: >> Robin Becker wrote on 06/28/07 16:13: >>> I see from this documentation >>> >>> http://www.djangoproject.com/documentation/apache_auth/#configuring-apache >>> >>> that it is conceptually possible to configure apache authorization using >>> django. >>> >>> However, we have recently decided to de-couple django from mod_python by >>> using >>> fastcgi. This is because we wish to allow our django apps to use which ever >>> python might be appropriate and not restrict to the one for which we have >>> compiled apache+mod_python. >>> >>> Is there any way to have mod_python stuck on Python-2.4 with the >>> controlling >>> django app use Python-2.5 and do configuration for apache. The only way I >>> can >>> think of is to create a stub project which runs the auth only. >>> >>> I know that theoretically we can advance the apache, but that implies >>> re-installing wikis etc etc etc and when Python-2.6 comes out and the boss >>> wants >>> to use new feature X we'll go through the whole process again. >>> >>> Alternatively is there a way to do the reverse ie get django to use a >>> database >>> controlled by apache? >> You could directly access the database using something like >> mod_auth_mysql or the like. But the way django stores passwords may be a >> problem. > yes it seems harder than setting up a dummy project. > > On the other hand our current scheme uses require group xxx and I cannot seem > to > get validation done that way. > > I have this in a .htaccess file > > AuthType basic > AuthName "djauth test" > Require valid-user > Require group XXX > SetEnv DJANGO_SETTINGS_MODULE djauth.settings > PythonOption DJANGO_SETTINGS_MODULE djauth.settings > PythonAuthenHandler django.contrib.auth.handlers.modpython > > > I see the request for a user, but the validation seems to ignore the Require > Group clause entirely. I don't think the 'Require group' stuff will work. Guess you'll have to write your own auth handler based on django.contrib.auth.handlers.modpython. You could then pass the groups, or whatever else you need, to the handler using PythonOption directives. e.g. AuthType basic AuthName "djauth test" Require valid-user SetEnv DJANGO_SETTINGS_MODULE djauth.settings PythonOption DjangoGroups XXX group2 group3 PythonAuthenHandler path.to.my.auth.handler Have a look at django.contrib.auth.handlers.modpython. Should be easy to do. Good luck. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Open Linux Router
westymatt wrote on 07/27/07 06:41: > Yeah its the webserver for olr not the public site. The django server > seems like a good start, just add ssl and logging ect, and lots of > security enhancements Maybe the standalone WSGI server of CherryPie already does what you need? http://www.cherrypy.org/wiki/CherryPyDownload --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Dynamic OR queries
Chris Hoeppner wrote on 08/25/07 18:40: > Hi there! > > I was just wondering how to dynamically "or" together an indetermined > quantity of Q objects. They're constructed from a string like q=a+b+c, > which would get stiched together as "(Q(field=a) | Q(field=b) | > Q(field=c))". Any clue on how to do it with unknown parameters? It will > need to work with a+b, just like a+b+c+d+e+f+g+h... You get it :) from django.db.models import Q fields = 'a+b+c+d+e'.split('+') query = Q(field=fields.pop(0)) for field_value in fields: query = query | Q(field=field_value) mylist = MyModel.objects.filter(query) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django for non-web apps
Jeff Anderson wrote on 01/21/08 09:30: > Derek Anderson wrote: >> hey all, >> >> i'm prob. not the first to do this, but i don't know of anyone else >> who has so i thought i'd mention it. >> >> i've used django's database and ORM layers as the backend to a new >> pygtk app. (all over a sqlite db) it has worked wonders and allowed >> me to focus my time on the UI, not writing reams of file parsing >> code. i recommend anyone else starting a new app to consider it. >> >> the app itself is prob. of limited audience. (it's an itunes-like >> management app for research papers) if you're working on a phd you >> might want to give it a whirl, but otherwise i expect your reaction to >> be like "yeah, neat, but, wtf?" :) >> >> anyway, link: http://gpapers.org/ >> >> ttyl, >> derek >> >> >> > I actually started a thread along the same line a few weeks ago. We use > django at work for our print script that handles the accounting and > balance tracking. It works well. > > Jeff Anderson > Hi Jeff Seem to have missed your other post so I'll just chime in here. I've also written a print server backend/filter for CUPS based on tea4cups [1] that does accounting and IP based access control. We're also using django for all sort of system administration tasks at the university where I work. e.g for managing the CUPS/Samba servers from the django admin, maintaining install profiles for unattended Gentoo linux installations and such. django makes it dead simple to create both web interfaces as well as command line tools. So much nicer then the perlisch tools we used to have. loving it :) Cheers Steven [1] http://www.pykota.com/software/tea4cups --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django for non-web apps
Derek Anderson wrote on 01/21/08 09:12: > hey all, > > i'm prob. not the first to do this, but i don't know of anyone else who > has so i thought i'd mention it. > > i've used django's database and ORM layers as the backend to a new pygtk > app. (all over a sqlite db) it has worked wonders and allowed me to > focus my time on the UI, not writing reams of file parsing code. i > recommend anyone else starting a new app to consider it. > > the app itself is prob. of limited audience. (it's an itunes-like > management app for research papers) if you're working on a phd you > might want to give it a whirl, but otherwise i expect your reaction to > be like "yeah, neat, but, wtf?" :) > > anyway, link: http://gpapers.org/ > Looks interesting, will give it a shot. May I ask why you are using deseb instead of django-evolution [1]? Pros, cons? [1] http://code.google.com/p/django-evolution/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: considering django for The Freesound Project, some (de)constructive critisism
James Bennett wrote on 01/21/08 18:26: > On Jan 21, 2008 10:22 AM, Bram - Smartelectronix > <[EMAIL PROTECTED]> wrote: [...] > >> 3. finegrained permissions. "I only want my friends to be able to edit >> my tags." Again people seem to be working on this, but nothing seems to >> be making it into trunk. Does anyone have a good soliution for this >> particular problem, or is it still really a matter of "roll your own"? > > I keep meaning to write a blog entry on how easy it is to do this in > newforms-admin; all the ugly hacks people have come up with to try to > do this just go away. Christian Joergensen has written a nice article on his blog which among other things also shows a possible solution for this [1] [1] http://www.technobabble.dk/2008/jan/06/filtering-foreign-key-choices-newforms-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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django for non-web apps
dlc wrote on 01/22/08 00:40: > How does authentication work? > > I want to build apps with both web and CLI interfaces, with nearly > 100% overlap in functionality between the two interfaces. I'm a CLI > snob but I also need GUI to "sell" my projects to the rest of the > team. We use LDAP/Kerberos for both unix and webapp authentication. So the usernames/passwords are the same throughout the system. In the CLI wrappers I just get the current username from the system and load a django User from the database based on that. Works good enough for us as we just use the tools in our trusted sysadmin group. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: *Idea-Share* How to secure auth
Ravi Kumar wrote on 01/31/08 06:45: > Hi, > I have developed a Django project with 3 apps. Now, I have to implement > authentication for 2 apps, while one app will be public without any > authentication. > But I don't want to run two virtual servers with HTTP and HTTPS differently. > The condition is, when a page requiring authentication, it should forward to > Login page with very secure implementation (quite afraid of wire sniffer > dogs in my network). I should have used HTTPS but i already put the problem. > How how can I proceed? Can i have SSL/HTTPS just for login authentication > anyway, else all other page just check user is_authenticated and serves the > pages on plain. > Maybe, If i could not make the question clear, please let me know, I will > revise it. Maybe something like this in your apache config? RedirectMatch permanent /(login|securepage) https://www.example.com/$1/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: *Idea-Share* How to secure auth
Ravi Kumar wrote on 01/31/08 12:07: > On Jan 31, 2008 2:49 PM, Steven Armstrong <[EMAIL PROTECTED]> wrote: > >> Maybe something like this in your apache config? >> >> RedirectMatch permanent /(login|securepage) https://www.example.com/$1/ >> >> > One idea is to redirect user login to HTTPS in same django apps but in > different apache virtual than HTTP (80). This way two django instances would > be running, that is why I don't want to use that method. If you want http and https you will need two virtual hosts. There is no way around it. Maybe it's easier to just use https for everything. I often use the following config: ServerName www.example.com Redirect permanent / https://www.example.com/ ... django and other config 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form for display, not edit
Carl Karsten wrote on 02/01/08 01:34: > newforms is great for creating forms. I need something similar to generate a > display form from a model. > > I looked at subclassing form, but what I would need to override is in the > widgets. which is probably why my hope isn't a good one. but for what I > need, > I only am using char fields, so I don't have to worry about widgets. > > So, is there some way to render a form as just text? > I've been using the following for something similar: class PlainText(forms.HiddenInput): def render(self, name, value, attrs=None): return u'%s%s' % (forms.HiddenInput.render(self, name, value, attrs), value) def myobject_formfield_callback(field, **kwargs): if field.name in ('hostname', 'ipaddress'): kwargs['widget'] = PlainText() return field.formfield(**kwargs) else: return field.formfield(**kwargs) def myview(request): myobject = get_object_from_somewhere() initial = myobject.__dict__ FormClass = forms.form_for_instance(myobject, formfield_callback=myobject_formfield_callback) form = FormClass(initial=initial) ... In my example I just want certain fields to show as text. If you want that for all of them change the formfield_callback to always change the widget. If you only want the plain value without a hidden field change the PlainText.render method accordingly. Works for me. hth Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Template tag arguments
Aaron Fay wrote on 02/04/08 21:21: > Hi list, > > I have a custom template tag that is supposed to take an argument from > the template kinda like this: {% profile_user_id object_id %}, problem > is 'object_id' is literally showing up as 'object_id' and not 5 or > whatever it's supposed to be. I think the issue is I'm working within > the context or something (no idea really)... Read about resolve_variable at http://www.djangoproject.com/documentation/templates_python/#passing-template-variables-to-the-tag --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: The best practice for a registration and then getting user to fill up extra information
Ramdas S wrote on 02/09/08 16:37: > Hi, > > I am using Django-registration. It works like a charm as far as registering > new users and validating them from potential bots. However, what is the best > practice as far as getting users to feed in more information. > > Currently in apps I have written, once someone clicks on activation key and > is account is activated, we ask the person to fill up a form, and thus > capture the data. The form is displayed in activate.html (as in the original > django-registration app .4x written by James Bennet). So 60% of users do > fill it up immdly. > > The form is connected to a model UserProfile, that stores all data from > address, telephone numbers and so on. > > Now I am writing an app, where we need to take certain calls based on the > User's profile, and then provide some offers everytime they log in. Hence it > is almost mandatory that we hook the user with his UserProfile, with a hook > in from AUTH_PROFILE_MODULE > > In such cases, somehow, I am not sure, whether this is the best method. Can > someone advise what is the best way to do? > > Do I create a separate model like UserProfile and capture data there much > the way I've done so far or is there a better practice. > If I understand you correctly you want to force users to fill out their profile. I do something similar, but without Django-registration. For that I've written my own login view (see attachment) that checks if the user has a profile. As long as he hasn't created one he always gets redirected to the 'fill out profile form' after login. hth Cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~--- from django import oldforms from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required from django.contrib.auth import REDIRECT_FIELD_NAME from django.utils.translation import ugettext as _ from django.core.urlresolvers import reverse from django.core.exceptions import ObjectDoesNotExist from django.contrib.sites.models import Site, RequestSite from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.models import User def _post_login(request, user, redirect_to): try: profile = user.get_profile() return HttpResponseRedirect(redirect_to) except ObjectDoesNotExist: return HttpResponseRedirect('%s?next=%s' % (reverse('accounts__edit_profile'), redirect_to)) def _check_redirect_to(redirect_to): # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or '//' in redirect_to or ' ' in redirect_to: from django.conf import settings redirect_to = settings.LOGIN_REDIRECT_URL return redirect_to def login(request, template_name='accounts/login.html', redirect_field_name=REDIRECT_FIELD_NAME): "Displays the login form and handles the login action." manipulator = AuthenticationForm(request) redirect_to = request.REQUEST.get(redirect_field_name, '') redirect_to = _check_redirect_to(redirect_to) if request.user and request.user.is_authenticated(): # User is already logged in return _post_login(request, request.user, redirect_to) error_message = None if request.POST: errors = manipulator.get_validation_errors(request.POST) if errors: from django.contrib.admin.sites import ERROR_MESSAGE error_message = ERROR_MESSAGE else: from django.contrib.auth import login user = manipulator.get_user() login(request, user) request.session.delete_test_cookie() return _post_login(request, user, redirect_to) else: errors = {} request.session.set_test_cookie() if Site._meta.installed: current_site = Site.objects.get_current() else: current_site = RequestSite(request) return render_to_response(template_name, { 'form': oldforms.FormWrapper(manipulator, request.POST, errors), redirect_field_name: redirect_to, 'site_name': current_site.name, 'error_message' : error_message, }, context_instance=RequestContext(request))
Re: django runserver freeze after 10-15 min
diadya_vova wrote on 02/15/08 11:55: > Thank you for quick response! > > Dev. server not crashes. It's stop to respond on browsers requests. > Yeah, Apache is better choice for this. > But I need this application to be portable. Without instalation. > Because this I use "Instant Django" and SQLite. > > I tried Google before asking :) > And tried to search for "Instant Apache". > Is it exist Apache, that don't need to be installed? > Have a look at this http://www.gordontillman.info/Development/DjangoCherryPy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: datetime 8 hours off
Simon Oberhammer wrote on 04/01/08 10:46: > hey group, > I have an inconsistant time problem, which goes away when I restart > apache, but then creeps up again after some time. When writing > comments in my custom app the time is 8hours behind (i'm CEST) *for > some users*. When I login with others, its okay. > > in settings.py I have > TIME_ZONE = 'Europe/Vienna' > > [EMAIL PROTECTED]:~/pm3$ date > Tue Apr 1 10:44:32 CEST 2008 > > any ideas what I should look for? This is annyoing.. it forces my to > apache2ctl restart quite often :-) > Is the time constantly 8 hours behind or does that vary e.g. does the offset get larger over time? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FTP upload of files threw django
[EMAIL PROTECTED] wrote on 04/23/08 13:40: > Hello All, > > I've been working on a quality control portal that uses some features > of django. The application is now completely running but the upload of > large data files is quit slow. I've been looking around how to speed > things up and the only thing i saw was using ftp upload instead of the > http file upload. > > I want to incorporate this feature in the existing frontend, is there > something in the newforms library that already covers some of this ? > If not is it possible to put the ftp upload under the file selection > box created by the newforms library. > > are there any snippets around that show how to use the ftp upload from > a webapplication ? There's no way to do that. > > Any help or pointers in the right direction would be greatly > appreciated. I've been thinking about the following for an upcoming project where we have to upload huge video files: - Use a ftp server which can authenticate against SQL and configure it to use the django user db. - Have the user upload files through a normal ftp client into his personal 'inbox' folder. - The user then loggs in to the web application and can further process the files from his ftp inbox. e.g. move them around, assign them to projects. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Need some slightly advanced routing help
Chris Hartjes wrote on 05/05/08 02:53: > I've been trying to do something that I *think* should be simple, > but apparently is not. Or, the more likely answer is that I am missing > something pretty obvious. I spent some time googling around for the answer > but didn't find what I was looking for. So here goes. > I'm building a web service to return sports game information. I have three > routes: > > / -- shows a help page on how to use the web service > // > /// > > is the name of a team in lowercase, could be 'yankees' or > 'red+sox' > the date fields are formatted as -MM-DD. Now, I've looked at both the > Django book and the online Django documentation to try and figure out the > correct way to get the routes to work. Here's what's in my urls.py file: > > from django.conf.urls.defaults import * > > urlpatterns = patterns('', > (r'^(?P\w+)/(?P\w+)/$', 'rallyhat.ws.views.team_by_date'), > (r'^(?P\w+)/(?P\w+)/(?P\w+)/$', > 'rallyhat.ws.views.team_by_date_range'), > (r'^/?$', 'rallyhat.ws.views.index'), > ) > > Now, my index page route works just fine, but the two others won't work. > > When I try /yankees/2008-08-15 I get this: > > * > > Using the URLconf defined in rallyhat.urls, Django tried these URL patterns, > in this order: > > >1. ^(?P\w+)/(?P\w+)/$ > >2. ^(?P\w+)/(?P\w+)/(?P\w+)/$ > >3. ^/?$ > > > The current URL, /yankees/2008-05-18/, didn't match any of these. > * > > I *know* it's something dumb, but I just can't see it. Any help would be > greatly appreciated. > Hi Chris \w matches [a-zA-Z0-9_] [1] The dashes there are not understood as dashes per se, but rather specify a range. I'd use either: (r'^(?P\w+)/(?P[^/]+)/$', 'myview'), or: (r'^(?P\w+)/(?P[\w-]+)/$', 'myview'), or, if you want it more specific: (r'^(?P\w+)/(?P\d{4}-\d{2}-\d{2})/$', 'myview'), Personally I'd go with the last example in this case. [1] http://docs.python.org/lib/re-syntax.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django and Linux distros
JonSidnell wrote on 05/16/08 12:24: > Hi everyone > > I'm suddenly struck by the notion that I would like to be dev'ing > Django on Linux of some flavour rather than Windows. > > It's been a wee while since I stuck my toes in the Linux waters, so I > was wondering if anyone here has any recommendations for a dev machine > setup? Due to the django host I've signed with, I'm largely stuck with > MySQL, and don't mind using the manage.py dev server while actually > developing. Everything else is up for grabs in my mind - distro, > editor, desktop manager skin, whatever! Although I'm unlikely to man > up to something like emacs or vi for code editing... > > What works for you? > > Cheers > Jon I've you're a linux noob go with {k,u}buntu. If you're a hardcore *nix lover go with slackware. If you're a developer go with gentoo linux, as then, all the fancy libs you need to do your work are just an emerge away :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to avoid uploading .py source files to shared hosting server
James Bennett wrote on 05/16/08 20:11: > On Fri, May 16, 2008 at 11:52 AM, ydjango <[EMAIL PROTECTED]> wrote: >> I do not want to make it easy for some one who breaks in , either a >> outsider or may be an rougue hosting provider employee or contractor, >> to easily get access to all the information - data and code. > > Again: if this is your worry, you have bigger problems. Allow me to > suggest an alternate method: > > (satire begins here, for the humor-impaired) > > 1. Physically obtain the server upon which the code is stored. Write > random data to the relevant sectors of the hard drive seven times > over, then write zeroes to it seven times over, then write random data > again. > > 2. Physically destroy the hard drive. Sledgehammers are good for this. > > 3. Place the shards of the hard drive into a vat of highly caustic acid. > > 4. Once the shards have dissolved, burn the resulting acidic liquid. > Be sure to capture the smoke. > > 5. Cool the smoke until it turns back to ash. Mix the ash into the > center of a reinforced concrete slab, at least 27 cubic feet in > volume. > > 6. If you have access to sufficient technology, launch the concrete > slab into space, on a course to collide with the Sun or (better) with > any singularity which happens to be nearby. The singularity is best > because -- even though it may not guarantee destruction of the > information -- the subjective time to observe the rocket crossing the > event horizon, from the frame of reference of a person some distance > from it, will be effectively infinite, causing most attackers to give > up. > > 7. If you do not have access to sufficient technology, have the > concrete slab stored in a nuclear-hardened bunker, with no Internet > connection, in a room using biometric identification keyed to > yourself, and with the whole complex guarded 24/7 by US Navy SEALs. > Maintain this watch until the technology available to complete step > (6) becomes available to you. > > Once you've completed this process, your application code will be > safe, for a reasonable value of "safe". > > (satire ends here) > > Or you could just find a host who properly sets up file permissions so > that random people can't access your application code. Unless you own > and personally supervise all of the following you will be susceptible > to rogue employees: the server, the rack in which it's located and the > datacenter in which the rack is found. Many people do not find that > the perceived security gains of doing so outweigh the financial and > maintenance drawbacks. YMMV. > > James, your the man :-) I would have suggested: Book a trip to the himalaya (well maybe after china has stopped being a PITA). March all the way to the top (make sure no CIA satellites are watching you). Dig a deep hole, say 100 foot deep, then barry your code in the hole. Then fill it up (again, check that those evil nasty satellites aren't watching), and go back home with the good feeling that your code, that nobody else on this planet could have written in such an elegant, perfect way will never be found and used by anybody. ;-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: memcache not used?
Oscar Carlsson wrote on 07/01/08 19:02: > Heh, ops! > > That was a typo, but even after fixing it, nothing changed :( > (still no change in memory usage, that is) > > Here is the ZeroDivisionError, btw: > http://dpaste.com/60185/ > > Oscar > The python-memcached client fails silently if it encounters an error, e.g. can't connect to the server. You could try changing how the client is created in django/core/cache/backends/memcached.py from: self._cache = memcache.Client(server.split(';')) to: self._cache = memcache.Client(server.split(';'), debug=1) And see if you get some error message in the server log. hth cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: memcache not used?
Oscar Carlsson wrote on 07/01/08 21:48: > I've checked the following logs, but nothing turned up: > /var/log/nginx* > /var/log/httpd* (apache) > > Previously, when something went wrong with the app, all error messages > appeared in /var/log/httpd-error.log, but this time - nothing. > > This is all the output I get when I restart apache (apachectl restart): > > [Tue Jul 01 21:46:02 2008] [notice] SIGHUP received. Attempting to restart > [Tue Jul 01 21:46:02 2008] [warn] (22)Invalid argument: Failed to enable the > 'httpready' Accept Filter > [Tue Jul 01 21:46:03 2008] [notice] Apache/2.2.9 (FreeBSD) DAV/2 > mod_wsgi/2.0 Python/2.5.2 configured -- resuming normal operations > > I also removed all *.pyc after adding 'debug=1'. I believe you wont see anything on starting apache but rather when the server starts serving requests. Apart from that, can you connect to the memcached daemon from the python prompt? e.g. does something like this work? import memcache mc = memcache.Client(['127.0.0.1:11211'], debug=1) mc.set('foo', 'bar') print mc.get('foo') --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: memcache not used?
Oscar Carlsson wrote on 07/01/08 19:02: > Heh, ops! > > That was a typo, but even after fixing it, nothing changed :( > (still no change in memory usage, that is) > Looking at your dpaste entry again it seems you haven't configured the cache middleware. > Here is the ZeroDivisionError, btw: > http://dpaste.com/60185/ > Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.doc.XViewMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware') Try adding it in your settings.py, e.g: MIDDLEWARE_CLASSES = ( 'django.middleware.cache.CacheMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.doc.XViewMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: memcache not used?
Oscar Carlsson wrote on 07/01/08 23:32: > ...you were very correct - I didn't have CacheMiddleware loaded, and when I > loaded it... > Everything worked. > > Thanks for all your help! :-) > > Oscar > (I feel a bit stupid, tho) Hacking for to long without a break, ey? Guess we've all been there ... :-D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Generating object documentation from its instance
[EMAIL PROTECTED] wrote: > Hi, > > (This is not directly related to Django, but would help me in that domain) > > I was wondering if there exists some kind of automated documentation generator > (html, pdf, text, whatever readable format) for instanciated objects. > > Basic use for me would be to pass a [newform] object, and it would output its > methods (with docstrings), attributes, and if attributes are objects, > recursively build their auto-documentation. > > I have used Epydoc, pydoc, and similar tools in the past, but from the > command-line and I believe it reads source code, not analyse an existing > object. > > You might have guessed, I am a lazy code reader. > When it comes to newform module, or similar libraries for other projects (did > I > say complex?), this would reveal helpful to dig the APIs using live code. > > Thanks in advance. > Maybe have a look how django generates the automatic filter/tags/model reference/documentation in the admin? Haven't looked at the code, but maybe it gets you started. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: why does django display th/td:hover style incorrectly ?
Aidas Bendoraitis wrote: > I'm not sure about IE7, but all the previous versions of IE certainly > didn't support hover for other html tags than . So it is > not Django issue at all. [...] > If you need some browser specific special > effects, use javascript for IE. > [...] This might help http://www.htmldog.com/articles/suckerfish/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Nested Sets for trees - any models been made before?
Nathan Harmston wrote on 03/27/07 14:10: > HI, > > Currently I am trying to store a "tree" in a database and want to use Nested > Sets in order to do this. I was wondering if this exists within Django atm > or if there are plans to add it in the future or has someone developed it on > the side? If the answer to these questions is "NO", is there a reason which > prevents Nested Sets from being implemented in Django? > > I m imagining a model; > class Node(models.Model): > name = models.TextField() > lft = models.IntegerField() > rgt = models.IntegerField() > objects = NSManager() > > and having a manager do all of the query work...as well as making > changes to save and delete. Does this seem like the right idea? I m just > checking before I jump in. > Maybe you can 'steal' something from here: http://code.google.com/p/django-discussion/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django/mod_python high memory usage - possible leak?
[EMAIL PROTECTED] wrote on 03/29/07 20:15: > I'm running a production Django application on two loadbalanced > webservers and a single, dedicated Postgres server handling around > 500k requests/day. I'm using memcached, and my database server > performance has been fantastic. > > Lately, I've been hitting very high percentages of free memory used, > and occasionally spiking to very high percentages of swap memory used. > I'm pretty familiar with Apache and Django, but not enough to diagnose > what is happening - I'm hoping someone will be able to help fill in > the gaps or tell me my understanding is off-base. > > Symptoms: > > What seems to be happening is that Apache grows to use all available > memory, and my memused percentage will hit about 98%. From what I can > tell, this does not necessarily mean that Apache is actively using 98% > of memory. It is also my understanding that Apache won't automatically > free up any memory until the process is killed. Perhaps someone could > explain this? Is it strange that Apache never goes to 99%, instead > always peaking at 98.x%? > > My swap % has spiked badly a few times, up to 69%. I'm told anything > roughly > 5% is bad. Could inefficiently designed views lead to memory > problems? I've made sure on my most popular pages that I'm only > importing what is absolutely needed, and I've even dereferenced > variables to try and help garbage collection. > > I grepped out the offending time period from my system activity > report, and found the requests were low during the 10-20 minutes that > the swap % spiked. I'm not sure that the request load was the > culprit. > > Incidentals: > > My most popular view looks for a memcached RSS feed, and if it doesn't > exist, uses URLLIB2 to go out and get it (then cache it). I've read > about possible problems with URLLIB2.openurl() that it might not free > the socket after use. I've made sure to close all connections and > dereference all variables/objects before the view returns. Not sure if > this is relevant, but it seems worth mentioning. My memcached hit > ratio is 99%, so I'm comfortable that it's not opening a connection > too often. > > What I've tried: > > I've tweaked one web server and left the other as-is for comparison. > (both are running identical Django codebase) I've upgraded mod_python > from 3.1 to 3.3.1, and I've upgraded Python from 2.4 to 2.5. Neither > seems to have made a noticeable difference. I dropped down the max > requests per child from 4k to 2.5k, and this shorter lifetime for the > process seems to have helped. > > Questions: > > It is my understanding that Apache Prefork MPM is memory-intensive. > Will my httpd processes keep growing in size until they are killed? > Should I ever expect them to drop in size during their life? > >>From an application design perspective, are there any obvious culprits > for high swap percentages in a Django project? > > Will increasing my memory from 1GB to 2GB help, or will Apache just > swell to fill this new memory? > > --- > > System: > > OS: Enterprise Red Hat 4 > Memory: 1GB > Apache: 2.0.2 Prefork MPM > Python Version: 2.5 > mod_python: 3.3.1 > Django: .91-bug-fixes > Caching: Memcached > > Relevant httpd.conf: > > Keepalives off > StartServers 8 > MinSpareServers5 > MaxSpareServers 15 > ServerLimit 256 > MaxClients 256 > MaxRequestsPerChild 2500 > > Recent Top Output: > > top - 12:36:23 up 108 days, 8:43, 1 user, load average: 0.01, 0.03, > 0.00 > Tasks: 92 total, 1 running, 91 sleeping, 0 stopped, 0 zombie > Cpu(s): 0.0% us, 50.0% sy, 0.0% ni, 50.0% id, 0.0% wa, 0.0% hi, > 0.0% si > Mem: 1034636k total, 943036k used,91600k free,87320k > buffers > Swap: 1052216k total,22560k used, 1029656k free, 177080k > cached > > PID USER PR NI VIRT RES SHR S %CPU %MEMTIME+ > COMMAND > 5858 apache16 0 72192 68m 404 S0 6.8 0:05.70 > memcached > 5766 apache15 0 70404 63m 3120 S0 6.2 0:09.98 > httpd > 995 apache15 0 69600 62m 3120 S0 6.2 0:10.16 > httpd > 21319 apache15 0 69424 62m 3112 S0 6.2 0:06.73 > httpd > 25133 apache15 0 69492 62m 3112 S0 6.1 0:06.81 > httpd > 24232 apache15 0 68784 61m 3112 S0 6.1 0:06.42 > httpd > 25134 apache16 0 68848 61m 3112 S0 6.1 0:06.20 > httpd > 25132 apache15 0 68368 61m 3112 S0 6.0 0:06.24 > httpd > 29229 apache16 0 59580 52m 3112 S0 5.2 0:04.92 > httpd > 26287 apache15 0 59232 52m 3112 S0 5.2 0:04.95 httpd > > Sample of Bad Recent Sar -r output: > > 08:50:01 AM kbmemfree kbmemused %memused kbbuffers kbcached > kbswpfree kbswpused %swpused kbswpcad > 08:50:01 AM143984890652 86.08 10064 28176 > 962864 89352 8.49 22860 > 09:00:01 AM 15536 1019100 98.50 3608 25516 > 318740733476 69.71
Re: Django/mod_python high memory usage - possible leak?
Graham Dumpleton wrote on 03/30/07 12:27: > On Mar 30, 6:31 pm, Steven Armstrong <[EMAIL PROTECTED]> wrote: >> My understanding is that every apache child pulls in all modules >> (mod_python, mod_perl, mod_php, mod_your_favorite_mod_here) which all >> consume memory. So you end up with loads of processes using ??MB of RAM >> to serve up e.g. a 1k image. >> >> I am by now means an expert on this. But maybe it's worth a shot. > > This doesn't really tell the whole story. Apache modules, like C > extensions for Python are implemented as shared objects, thus the code > segments of the Apache modules themselves should only incur a memory > hit once across all process. For example, the mod_php.so for some > versions of PHP is about 5MB. This does not mean though that each > Apache child process has 5MB of private memory dedicated just to it. > Instead their would generally only be a 5MB hit to the operating > system as a whole. Note though that I am only talking about code here > and not runtime memory usage. > > For mod_python.so though this unfortunately doesn't necessarily apply. > In the best case the mod_python.so file would be about 400KB in size > and it would be shared as described above. If your Python installation > was not built so as to generate a shared library though, when > mod_python.so is created the contents of the static Python library are > incorporated into the mod_python.so file itself, rather than being > linked at run time. As a result, the mod_python.so file can balloon > out to be 1.5-2.0MB in size, or much much more on certain operating > systems if debugger support was enabled when Python was compiled. > Worse is that because the object files from the Python static library > are not position independent, when the mod_python.so file is loaded > into memory, on some systems the operating system is forced to perform > address relocations on the code segments from the Python library > objects where they reside in mod_python.so. Because the address > relocations require modifying the memory it is no longer shared and as > a result it will actually end up consuming 1.5-2.0MB of private memory > in each Apache child process. > > Thus, one way of reducing memory usage with Apache is to ensure that > your Python is built with a shared library and not a static library > and that mod_python.so is actually using it. On Linux/Solaris systems, > running 'ldd' on mod_python.so will tell you. If you don't see a > dependency on libpythonX.Y.so then it isn't using Python as a shared > library and you will get this extra memory hit on every Apache child > process. > > This still isn't the end of the story. Because mod_python is a mix of > C code and Python code and it uses Python code as part of its dispatch > mechanism, when it is first loaded it loads a whole bunch of Python > modules before any request is even handled. It is because of these > Python modules being loaded that the startup memory usage of > mod_python appears to be so big. For a lot of these modules a web > application will generally load them in eventually anyway, so in the > bigger scheme of things it makes no difference, but for some modules a > web application may not use them so the memory usage is an unwelcome > hit. > > Worse is that recent investigations into mod_python show that some of > those Python modules are being loaded to get access to just a single > function. Other modules are being loaded all the time even though the > feature it is required for is optional and not often used. When > changes were made to mod_python to eliminate as many modules as one > could it actually dropped 1MB from the startup memory usage. > Realistically a web application might take back half of that later > when it wants the modules that were eliminated, but the modules for > the optional feature wouldn't. So, mod_python itself could see some > improvements in that area to potentially reduce memory usage as well. > > All in all though, this is still not going to help in the grand scheme > of things because Python web frameworks are just getting too fat. > Django is actually at the better end of the scale here as at minimum > it adds only about an extra 5MB of modules to size of each Apache > child process. TurboGears appears to be the worst, adding about 14MB, > with Pylons somewhere in the middle. > > So, although mod_python does have some things that can be cleaned up, > in the main it is the Python web frameworks themselves which add the > most to process size and that is before any code is run and data > caching becomes a factor. > > Graham > Wow! Many thanks for the detailed explanation. Still, after reading your post,
Re: how to save a dictionary in database
Paul Rauch wrote on 04/07/07 12:28: > Hello, > >> test = bla(rights={'bla':'blupp'}) >> test.save() >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib64/python2.5/site-packages/django/db/models/base.py", >> line 242, in save >>','.join(placeholders)), db_values) >> File "/usr/lib64/python2.5/site-packages/django/db/backends/util.py", >> line 12, in execute >>return self.cursor.execute(sql, params) >> >> rights = models.TextField() > > the "easiest" way seems to easy. > ok, so how can I store a dict in the database? > > mfg Light Lan Hi Paul Maybe this helps: http://groups.google.com/group/django-users/browse_thread/thread/5196655dfbcb8e0/77d84089fbb799a4?lnk=gst&q=Pickling+Sessions+(or+lists+of+instances)&rnum=1#77d84089fbb799a4 cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Authentication of static files without mod_python?
AndyB wrote on 05/07/07 18:17: > I've read the docs on linking Apache authentication with Django's > (http://www.djangoproject.com/documentation/apache_auth/) and also > found a snippet on Django Snippets (http://www.djangosnippets.org/ > snippets/62/). > > The first method definitely requires mod_python and the second one > seems to as well. > > I'm stuck with fcgi at the moment. The standard CGI method would be to > keep all static files away from Apache and pipe them all through > Python code. > > Is there any other solution or failing that does anyone have any > advice/code on the most efficient way to go about this? > > AndyB You may be able to use something like mod_auth_mysql to access the db directly for authentication (assuming you use mysql). Authorization doesn't seem possible without using 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating extensible views ?
kahless wrote on 05/07/07 23:02: > Hi, > I've found documentation on how to make applications to work together > smoothly .. but is there also some documentation on how i could make > an application (or views of an application) extensible.. > > For example like in eclipse having "extension points" where 3rd party > applications could hook into .. and extend the original > functionality .. > in specific i need this (e.g.) for a user profile view.. my project > consists of multiple applications and i want them all to be > independent .. and also have personal settings on their own.. > so i would have a community application which is responsible for > registration & co .. and would also allow the user to change his > profile and edit settings.. but what if i want to make it easily > possible for my wiki and board applications to contribute additional > settings to this view ? is there any django specific way to do > something like it, or any thoughts on how i could implement a generic > interface for such a problem ? > > i guess the signal API would be one possibility ? to simply send out > specific signals like 'render_profile' and 'post_profile' where > multiple application could listen to and respond accordingly ? > > i don't expect that there is any ready-to-use solution out there, so i > would welcome any thoughts on that ;) .. > Hi I've found the following [1] a good starting point for similar functionality in some of my projects. Check out the file /trac/core.py. [1] http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ImportError: No module named mysite.settings
Mark Phillips wrote on 05/14/07 11:07: > Decided to try a clean slate. Set up Django on SME Server 7.1, which > is based on Centos 4. > Compiled and installed mod_python > Amended httpd.conf as follows: > > LoadModule python_module modules/mod_python.so > > and later on in the file... > > SetHandler python-program > PythonPath "['/usr/local/mysite'] + sys.path" > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > PythonDebug On > PythonAutoReload On > > > Downloaded Django into python2.3/site-packages with svn co http:// > code.djangoproject.com/svn/django/trunk/django django > > Restarted the server. Created a new project "mysite". Left the file > mysite.settings as created by "startproject". The manage.py validate > and runserver methods ran without errors. > > Ran into trouble when attempting to browse to the site "www.myweb.com/ > mysite". Here is the trace back from the browser: > > Mod_python error: "PythonHandler django.core.handlers.modpython" > > Traceback (most recent call last): > >File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line > 299, in HandlerDispatch > result = object(req) > >File "/usr/lib/python2.3/site-packages/django/core/handlers/ > modpython.py", line 177, in handler > return ModPythonHandler()(req) > >File "/usr/lib/python2.3/site-packages/django/core/handlers/ > modpython.py", line 145, in __call__ > self.load_middleware() > >File "/usr/lib/python2.3/site-packages/django/core/handlers/ > base.py", line 22, in load_middleware > for middleware_path in settings.MIDDLEWARE_CLASSES: > >File "/usr/lib/python2.3/site-packages/django/conf/__init__.py", > line 28, in __getattr__ > self._import_settings() > >File "/usr/lib/python2.3/site-packages/django/conf/__init__.py", > line 55, in _import_settings > self._target = Settings(settings_module) > >File "/usr/lib/python2.3/site-packages/django/conf/__init__.py", > line 83, in __init__ > raise EnvironmentError, "Could not import settings '%s' (Is it > on sys.path? Does it have syntax errors?): %s" % > (self.SETTINGS_MODULE, e) > > EnvironmentError: Could not import settings 'mysite.settings' (Is it > on sys.path? Does it have syntax errors?): No module named > mysite.settings > > Where did I goof? > > > ... PythonPath "['/usr/local'] + sys.path" ... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Importing models from each other.
On 09/27/06 16:03, Gacha wrote: > I have two model files, the first is: > --- > from proj.base.models import Choice > > class User(meta.Model): > ... > param = model.ForeignKey(Choice) > > --- > > and the second is : > > --- > from proj.auth.models import User > > class Choice(meta.Model): > ... > > class Discount(meta.model): > ... > user = model.ForeignKey(User) > --- > > How you can see there are imports from each other, and there is the > problem, how I understand the class can't be buld before the imported > class is built. > > One of the workaournds is to put all classes in one file, but I don't > want to do that, because auth module is for the user stuff and base > module is for the rest classes. > > maybe someone has any ideas. (sorry, for bad english) > Not sure about this, but maybe it works if you change the order of the imports and the class definition? e.g. class Choice(meta.Model): ... from proj.auth.models import User class Discount(meta.model): ... user = model.ForeignKey(User) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Pickling Sessions (or lists of instances)
On 09/27/06 16:45, Tom Smith wrote: > Hello > > currently I am storing a list of python instances in the > request.session but would like to make a persistent copy of this list > and store it permanently... > > I don't want to just make the timeout of the session a long time in > the future, because each user could have multiple lists of objects > saved. > > How do I take a list of python instances and save them simply to a > Table? Should I somehow serialize/pickle the list into a TEXT field > or is there a better way? > > Thanks > > tom The below class is from one of my projects. Works fine so far. The data is first pickled, then base64 encoded, the result is then stored in the db. By using the 'data' property instead of the real field it all happens transparently. I found some snippets that got me started in the code of the admin's loginform implementation. Hope this helps. class PortletPreference(models.Model): """Persistant storage of portlet preferences. """ portlet = models.ForeignKey(Portlet, unique=True) # don't access 'encoded_data' directly, use the 'data' property instead encoded_data = models.TextField(_('Encoded Data.'), blank=True, null=True) def _get_data(self): return self._decode(self.encoded_data) def _set_data(self, data): self.encoded_data = self._encode(data) data = property(_get_data, _set_data) def __str__(self): return '%s' % self.portlet class Meta: verbose_name = _('PortletPreference') verbose_name_plural = _('PortletPreferences') def _decode(self, data): pickled = base64.decodestring(data) try: return pickle.loads(pickled) except: return {} def _encode(self, preferences_dict): pickled = pickle.dumps(preferences_dict) encoded_data = base64.encodestring(pickled) return encoded_data # Only for testing/debugging. This model should _not_ be edited in the admin. class Admin: pass --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Pickling Sessions (or lists of instances)
On 09/27/06 23:49, Tom Smith wrote: > Thanks, it all seems to work except for when I store a list of > objects in the database and try to get it out I get a string (that > looks like a list of objects) > > >>> products = Product.objects.filter(title__contains='Dog')[:10] > >>> sub = Subscription(email="[EMAIL PROTECTED]", name="Tom Smith") > >>> sub.encoded_data = products > >>> sub.save() > You haven't encoded the data before assigning it to the "encoded_data" member. > .. all fine then . > > > >>> s = Subscription.objects.get(id=2) > >>> s.encoded_data > "[, Dog Listener: The 30-Day Path to a Lifelong Understanding of Your > Dog>, Human Mind>, , , > Tempest, Tweenage Tearaway S.)>, Secrets That Make Good Dog Owners Great>, Your Dog: A Complete Guide to Understanding and Caring for Your Dog, > from Puppyhood to Old Age>, the Perfect Pet>, ]" > > > returns it as listy-looking string, not a collection of > objects trying to get to data, returns this > I guess django figures that the member "encoded_data" is a TextField and converts your queryset to a string when assigning or saving it. > >>> s.data > Traceback (most recent call last): >File "", line 1, in ? >File "/Users/tomsmith/Desktop/django/bah/../bah/burningahole/ > models.py", line 160, in _get_data > return self._decode(self.encoded_data) >File "/Users/tomsmith/Desktop/django/bah/../bah/burningahole/ > models.py", line 168, in _decode > pickled = base64.decodestring(data) >File "/Library/Frameworks/Python.framework/Versions/2.4//lib/ > python2.4/base64.py", line 319, in decodestring > return binascii.a2b_base64(s) > Error: Incorrect padding > >>> > Try this: >>> products = Product.objects.filter(title__contains='Dog')[:10] >>> sub = Subscription(email="[EMAIL PROTECTED]", name="Tom Smith") >>> sub.data = products >>> sub.save() You have to assign the products to the "data" member instead of to "encoded_data". Best to forget that the member encoded_data even exists. So to store something: sub.data = myFancyPythonObject To retrieve something: myFancyPythonObject = sub.data Please note that I have never used this to store QuerySets or Models or the like in the database. Just plain old python objects, preferably dicts. By storing a QuerySet like this you decouple it from the database. I have no idea how this will behave when you decode and try to do something fancy with it later on. The database will most likely have changed in the mean time. cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: How about a Django apps public repository?
On 09/30/06 17:35, Lucas Vogelsang wrote: > Hi, > Is this project/thread dead or is someone working on it? > > I'd like to use this repository, however I am fully tied up with my > other projects and can't help pushing it forward. > > regards, > lucas > looks like all the others have the same 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Localizing dynamic content through the admin interface
On 10/03/06 19:14, Dirk Eschler wrote: > Hello, > > please let me first point out that i'm new to Django. I have experience with > gettext, but only in non-webapp environments. > > I've read through the i18n doc and am quite impressed about the gettext > support. I just wonder how you usually handle dynamic content. Clients/Users > often want to localize the content they add right in the admin interface. Are > there any hooks in Django that make it easier? > > The simplest way i see, is to use separate columns for each language (e.g. > title_en, title_de) in my models. Is there a better approach? Not a complete solution, but maybe gets you started. http://djangoutils.python-hosting.com/wiki/TranslationService --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Auto-archive lists
On 10/05/06 17:34, seemant wrote: > Hi All, > > So, on the right column of http://www.djangoproject.com/weblog/ that > page, we see an index of archived posts, going back 12 months or so. > > And so I thought I'd check out the template: > http://code.djangoproject.com/browser/djangoproject.com/django_website/templates/base_weblog.html > > but the template (and adrian's commit message) seem to imply that that > list is generated manually. Is there no construct in Django that will > auto-gen a link list like that? > I needed just that so I wrote a template tag for it [1]. Usage is like this: {% load archivedates %} {% get_archive_dates news.Entry pub_date as archive_dates %} {% if archive_dates %} News Archiv {% for archive in archive_dates %} {{ archive|date:"F Y" }} {% endfor %} {% endif %} [1] http://www.c-area.ch/code/django/templatetags/archivedates.py Hope that helps Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: print_r
On 10/14/06 19:46, code enquest wrote: > in PhP i used to print_r(array) to see what if got in my array that I > want to bring on the screen. Smarty even had a popup screen to show this. > > How can I see in Django what I got in the view? So that working in the > template goes a tat faster? What is the print_r($array) in the template > or Django version? > > Enquest > http://www.djangoproject.com/documentation/templates/#debug Not exactly what you're after, but maybe it helps anyway. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: print_r
On 10/14/06 20:11, code enquest wrote: > Steven Armstrong schreef: >> On 10/14/06 19:46, code enquest wrote: >> >>> in PhP i used to print_r(array) to see what if got in my array that I >>> want to bring on the screen. Smarty even had a popup screen to show this. >>> >>> How can I see in Django what I got in the view? So that working in the >>> template goes a tat faster? What is the print_r($array) in the template >>> or Django version? >>> >>> Enquest >>> >>> >> >> http://www.djangoproject.com/documentation/templates/#debug >> >> Not exactly what you're after, but maybe it helps anyway. >> >> > I was looking at this but I'm afraid I don't understand how to implement > it correct. Maybe you could elaborate on it. > Put {% debug %} somewhere in your template. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: print_r
On 10/16/06 17:43, Rob Hudson wrote: > [EMAIL PROTECTED] wrote: >> I quite often plug in a nonsense command e.g. "fudge" just to raise the >> debug page, maybe with a few > > I do the same. It would be awesome if there were a "debugger" app > (contrib app anyone?) that we could load in the template: > > {{ debugger }} > > That would show a unobtrusive link that when clicked would open a full > debug window like the ones on template errors with local variables, > etc. I've seen some WSGI presentations where you can even have a > Python shell with those variables. That sounds like it takes some work > to store those but something like this would be very useful for Django. > > -Rob > A djangofied version of this [1] would be cool. [1] http://pythonpaste.org/screencasts/evalerror-screencast.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Need an advice: simple Online Store project (long)
On 10/16/06 22:24, Serg Kovrov wrote: > Hello. I'd like to try to build a simple (I believe) project with > Django - an Online Store. That is, browseble and manageable catalog of > arbitrary goods. > > > Here is the draft data models for my project. > > * Item. Representation of actual goods. Belong to one of the > Categories. Category defines attributes, which may have values. > As well inherit attributes from all parent categories. > > * Category. Hierarchy tree consist of Category entities. Each of > categories can have arbitrary set of Attributes. > > * Attribute. Simple attribute of a Category. Defines name and type > (text, int, bool, etc.). Possibly, can be shared between categories. > > * AttributeValue. Concrete value of Attribute. Each belong to > individual item. > > > assumptions: > > * Parent attributes should be inherited - that's the nature of > real-world hierarchies. > > * Same attributes may be used in different categories not through > inheritance (that is, many to many relationship). For example car > audio and computer parts usually does have a brand, but fruits > usually doesn't. > > > > Example (categories are in '', and attributes are in []): > 'root' [name, price] > |-'electronics' [brand] > | |-'car audio' > | | |-'in-dash receivers' [has_removable_panel, plays_mp3] > | | \-'speakers' [power, size] > | \-'portable players' [battery_capacity] > |-'computers' [brand] > | |-'workstations' [cpu, ram, hdd] > | |-'laptops' [battery_capacity, cpu, ram, hdd] > | \-'parts' > \-'books' [publisher, author, pages] > |-'science fiction' > \-'for kids' > > E.g. every Item in 'laptops' Category can have unique AttributeValue > for [name, price, brand, battery_capacity, cpu, ram, hdd] Attribute. > > > My concerns are: > - how to implement attributes hierarchy (inheritance part) with Django > models API? > - Is there a way to use built-in admin interface to manage this data? > - There are maybe flaws in assumptions and/or data models for given > subject. For example I'm not sure if many-to-many relations are best > for attributes - maybe duplicate attributes could be used instead. Or > force user to refactor hierarchy to avoid attribute duplications... Are you aware of satchmo? http://satchmoproject.com/ http://satchmo.python-hosting.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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: print_r
On 10/16/06 21:11, Rob Hudson wrote: > On Oct 16, 11:17 am, Steven Armstrong <[EMAIL PROTECTED]> wrote: >> A djangofied version of this [1] would be cool. >> >> [1]http://pythonpaste.org/screencasts/evalerror-screencast.html > > I agree. That would be very useful. One could argue that it should > only be accessible when running under WSGI. Would that make it easier > to implement? > I believe the django dev server runs on top of WSGI. So it shouldn't be to difficult to integrate that. I'll have a look at it next time I have a moment. Unless someone else beats me to it that is (hint, hint) ;) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: django embedded web server
On 10/18/06 19:57, Steve M wrote: > I've been following this and related threads with some interest. I > think it would be nice to have a pure python (requiring no setup of, > e.g., Apache) webserver included with Django that was more capable than > the current Django development server. I recently stumbled across this: > > http://pythonpaste.org/module-paste.httpserver.html > > It is a multi-threaded WSGI webserver. It comes with paste, which by > the way seems to have a lot to offer, but even if the whole of paste > cannot be cleanly integrated with Django, doesn't the theory of WSGI > imply that it should be trivial to get a Django project running on this > server? I assume you would pass django.core.handlers.WSGIHandler to the > paste.httpserver.serve() function, although I haven't looked enough to > see how to connect it with a specific project. > > So how realistic is it to replace the Django development server > (assuming licenses permit) with this server? Any reason it wouldn't be > desirable? I guess the single threaded devel server could make > debugging some problems less complex? Maybe I should just give it a > shot. > http://pythonpaste.org/djangopaste/ http://trac.pythonpaste.org/pythonpaste/browser/Paste/DjangoPaste --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Pickled Objects or Tuples?
> > Hi! > > Voltron the Django newbie here! Django IS a breath of fresh air and > I´m happy to be programming again in Python after so many years. That > being said; > > 1. How should one go about marshalling objects for storage in Django? > 2. How should one go about storing tuples in Django? Would I have to > just save the numers as a combined number with a delimiter for later > parsing? > > > Thanks > Maybe you'll find this useful. http://groups.google.ch/group/django-users/browse_frm/thread/5196655dfbcb8e0/e335a120a9ae3e66?tvc=1#e335a120a9ae3e66 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django & eclipse step-by-step (python 2.5) ?
Bram - Smartelectronix wrote: > hey everyone, > > > ( I hope you saw the question mark at the end of the subject ;-) ) > > working in eclipse, it would be so wonderful to get auto completion and > all those other goodies working. Auto completion works just fine for > everything django (i.e. django.*) but no matter what I try there's no > auto completion inside the project/app. > > Does anyone have a nice step-by-step guide to get this up and running? I > seem to see this question asked a lot of times all over the web, but not > one real, concise answer. > > > thanks a lot for any pointers, > > > - bram > You have to add the source folder of your project/apps to the pydev projects PYTHONPATH. That should do the trick. hth Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Install woes: error "python: can't open file 'django-admin.py' "
On 05/05/06 20:23, jbrewer wrote: > Okay when I am looking at the sitepath I have all my python stuff > coming from here: > > /System/Library/Frameworks/Python.framework/... > > But when I used DarwinPorts of SQLite it installed Python 2.4 here: > > /opt/local/bin - and located here also is sqlite3 > > How do I remap this? > The file /opt/local/bin/sqlite3 is probably just the command line client, not the library. Try searching your filesystem for a folder named 'pysqlite2'. e.g. find / -type d -name pysqlite2 Then create a path file in the systems python installation that points to your sqlite3 installation. e.g. create a file: /System/Library/Frameworks/Python.framework/pysqlite2.pth which contains a line that points to the folder you found before. e.g.: /path/to/folder/pysqlite2 hth Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: django site doesn't seem to display right under firefox
On 05/23/06 10:03, Alexandre CONRAD wrote: > Hello, > > I am wondering if you all have the same problem as I am using Firefox > (Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.0.3) Gecko/20060426 > Firefox/1.5.0.3): > > On the home page: > > - the "django" logo doesn't display at all. > - the tagline "the web framework for perfectionists with deadlines. > Django makes it easier to build better web apps more quickly and with > less code." doesn't diaplay at all neither. > - when a menu is selected ("Home", "Download", etc.), the text > highlights correctly in white, but the gradient background doesn't show up. > - the "Latested release: 0.91" on the home page doesn't display the > green background rounded-box. > > All this displays well in Netscape (Netscape 7.2 Mozilla/5.0 (Windows; > U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)) > and MS Internet Explorer (version: 6.0.2900.2180.xpsp_sp2_gdr.050301-1519). > disabled images? Maybe have a look under Edit > Preferences > Content > Load Images? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Django and twisted
On 05/23/06 21:20, Christian Schneider wrote: > Hi all, > > has anyone any experiences as to using django from a twisted application? > I'm asking because I had some issues with MySQL as in crashing connections > and too many database handles open. As far as I can tell, which isn't very > far, my twisted application is running in just one thread, so I'm not sure > where that is coming from. Is it possible for django to have more than one > database handle open for a single process? > Hi Chris The attached file is a small 'proof of concept' test I once did. Maybe it gives you some ideas. Also have a look at [1]. [1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439358 hth cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~--- """ @see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439358 """ import sys import os sys.path.append('/home/me/ws/python/django') sys.path.append('/home/me/ws/python') os.environ['DJANGO_SETTINGS_MODULE'] = 'djportal.settings' def deferred(*args): """deferred(object) -> twisted.internet.defer.Deferred instance Run a potentially blocking callable object in a thread.""" # initialized on first call from twisted.python import threadable threadable.init(1) from twisted.internet.threads import deferToThread global deferred deferred = deferToThread.__get__ return deferred(*args) @deferred def get_active_portlets(): data = {} from portal.models import Portlet for model in Portlet.objects.filter(status=True): data[model.id] = (model.name, model.application, model.module, model.portlet_class) # simulate extra long operation import time time.sleep(2) return data def running(): "Prints a few dots on stdout while the reactor is running." sys.stdout.write(".") sys.stdout.flush() reactor.callLater(.1, running) def print_data(data): "got a result, do something with it" for record in data.items(): print record def print_error(error): "got a error, show it" print error from twisted.internet import reactor def main(): d = get_active_portlets() d.addCallback(print_data) d.addErrback(print_error) reactor.callLater(.1, running) # shutdown the reactor after 5 seconds reactor.callLater(5, reactor.stop) reactor.run() if __name__ == "__main__": main()
Re: How to automatically generate a password input field
On 05/27/06 13:23, Christian Schneider wrote: > Hi all, > > can I specify that a certain model field should be displayed as type="password" /> in the UI? > > I think I saw once how to do it but can't find it anymore. > > chris > Hi Chris The following works for me: class PasswordField(models.CharField): def get_manipulator_field_objs(self): return [forms.PasswordField] def get_internal_type(self): return 'CharField' class MyModel(models.Model): ... password = PasswordField(_('Password'), maxlength=50) ... hth cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Ajax support, there is no need for reinventing the wheel
On 06/03/06 19:21, Vladimir Pouzanov wrote: > On 6/3/06, James Bennett <[EMAIL PROTECTED]> wrote: >> Dojo allows either synchronous or asynchronous calls to a server, >> depending on the parameters passed to dojo.io.bind(). If you're seeing >> something blocking until a server call completes, most likely it's >> using a synchronous call. > > I experience that trouble on all Dojo-powered sites including their > homepage. Anyway don't like a toolkit that locks my browser up even in > 'official' way. > Isn't that because of dojo.require loading libraries synchronously? I believe if you prepackage all required libraries in one js file, which the browser then can cache, it shouldn't be a problem. At least that's my understanding of how it works. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Django Quick Start with Schema Evolution Support
On 06/04/06 18:11, Ilias Lazaridis wrote: > Jay Parlar wrote: >> Ilias: >> >> I thought you would stop bothering Django people after it was revealed >> on Django-dev that you're a known Internet troll: > [...] > > This starts to become ridiculous. > What do you expect? To be honest I actually think some of the things on the page [1] you posted may be usable. But after posting around like a moron to various developers list and wasting everybody's time - how can you expect that anybody would take you or anything that comes from you seriously? [1] http://case.lazaridis.com/multi/wiki/DjangoProductEvaluation --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Easy way to access extra User stuff in templates?
On 06/06/06 17:11, Todd O'Bryan wrote: > On Jun 6, 2006, at 11:03 AM, Adrian Holovaty wrote: > >> >> On 6/6/06, Todd O'Bryan <[EMAIL PROTECTED]> wrote: >>> Here's the problem: How do I get to those in a template? I know >>> there's only one UserInfo object per User object, and ideally I'd >>> like to type something like >>> >>> {{ user.userinfo.formalName }} >>> >>> in the template, but this doesn't work because userinfo is actually >>> userinfo_set and I'd need to get the first element of that. I don't >>> think that's possible in the templating language, but I'd be happy to >>> be wrong. >> >> Get happy! :) >> >> {{ user.userinfo_set.0.formalName }} >> > > Why is it that you can't find stuff until after you send an email > asking about it? > > I actually implemented a context processor, added a > TEMPLATE_CONTEXT_PROCESSORS to my settings.py and then noticed the > line I had missed about list lookup. (Actually, to slightly > complicate things, I tried user.userinfo_set[0].formalName first, but > that's another story.) > > Thanks. I'll just go over here in the corner and play by myself. > Todd > Wouldn't that be a use case for djangos built in (but hardly documented) AUTH_PROFILE_MODULE setting? e.g. settings.py: -- AUTH_PROFILE_MODULE = 'common.UserProfile' myproject.common.models.py: -- class UserProfile(models.Model): user = models.ForeignKey(User) site = models.ForeignKey(Site, default=settings.SITE_ID, blank=True) nick = models.CharField(maxlength=32, blank=True, null=True) def informalName(self): return self.nick def formalName(self): return '%s %s' % (self.user.first_name, self.user.last_name) ... And then in views: request.user.get_profile().formalName() or in templates: {{ user.get_profile.formalName }} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
calendar for blog app?
Hi all Is anybody aware of a template tag or something that renders a calendar for a blogs sidebar? One of those things that shows the month of the blog entry you're currently looking at and the days are links to entries that where made on other days? cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: url path in django template
On 06/14/06 05:45, damacy wrote: > hi, there. > > is there any built-in function which retrieves the current url in a > django template? > > for instance, if my current url is > > http://www.lalala.com/hoho?index=0 > > and i'd like to get the exactly same url as above within a template > (including hoho?index=0). > > i can get the current directory which is http://www.lalala.com/ using a > full stop (i.e. .) unix command, but it does not inlude hoho?index=0. > > sorry if it's got nothing to do with django. > > thanks. > In your settings.py add: from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS TEMPLATE_CONTEXT_PROCESSORS += ( 'django.core.context_processors.request', ) That gives you access to the request object in your templates so you can use: {{ request.get_full_path }} which in your example would be: /hoho?index=0 The available props and methods of the request object can be found here [1]. [1] http://www.djangoproject.com/documentation/request_response/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Root URI in templates
On 06/14/06 10:07, limodou wrote: >> > One method: >> > >> > set a "base" tag in template, so this tag will point the root uri of >> > this page, and other uris can be related with this uri. >> > >> > Two method: >> > >> > Define some template variables used for root uri, and using them in >> > urls. So you can define them in settings.py or somewhere, and if the >> > situation changed, you may only change the settings.py. >> >> that is precisely what i would like to do. how you access a >> variable defined in settings.py from a template tho? i have >> not been able to track this bit down. >> >> > 1. in the view code, pass settings.py variables into template. > > 2. write your own template processor and config it in settings.py > 3. write your own templatetags. see django/contrib/admin/templatetags/ for examples --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Using DB module(s) in another app (twisted)
On 06/15/06 04:01, Jos Yule wrote: > Ok, here is what i had to do to get it to work: > > In a 'test.py' file: > > -- > from django.conf import settings > import settings as mysettings > > settings.configure(mysettings) > > from django import db > > from mainsite.models import Game > from django.contrib.auth.models import User > - > > I copied my 'settings.py' file from my django setup to the same dir as > the 'test.py' file, and imported it as mysettings - so i could then > manually pass it to the settings.configure() method. > > i then had to put my model.py file into a directory structure which > mirrored the django one. I could then also get access to the auth > database stuff (User, Groups, etc). > > Nice! > Aren't the django db calls blocking your twisted reactor? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: why django has no api reference?
On 06/15/06 13:53, Roger Sun wrote: > Just like ruby's > http://api.rubyonrails.org/ > > currently, i don't know where can i refer to these api, > i hope the author can do this for us. ^_^ > > roger > There's an unofficial api reference under [1] [1] http://djangoapi.quamquam.org/trunk/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Using DB module(s) in another app (twisted)
On 06/15/06 14:59, Jos Yule wrote: > I haven't plugged any of this into a twisted app yet, so i don't know. I'ld be very interested to here how it's going once you get there. > I suppose i could put the db stuff into one of the threading defereds > to avoid that kind of blocking... > That's exactly what I'm doing atm. It gets sort of complicated though if you've got related models, 'cause of the lazy loading in querysets. You have to totally isolate any django related function/method calls, cause you never know for sure when/how/where the database is hit. If you find a better way I'ld love to here. Good luck --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Lost with forms
On 06/22/06 18:08, mamcxyz wrote: > I do this: > > (I copy this class from the cookbox) > > class Manipulator(forms.Manipulator): > default = {} > done = False > > def getData(self, request): > return request.POST > > def getForm(self, data, errors): > return forms.FormWrapper(self, data, errors) > > def process(self, request): > data = self.getData(request) > if data: > new_data = data.copy() > errors = self.get_validation_errors(new_data) > if not errors: > self.do_html2python(new_data) > > self.done = True > return self.complete(request, new_data) > else: > errors = {} > new_data = self.default > self.form = self.getForm(new_data, errors) > return self.form > > def complete(self, request, data): > pass > > class SingUpForm(Manipulator): > fields = ( > forms.TextField(field_name='username', is_required=True, > validator_list=['isAlphaNumeric'], maxlength=30), > forms.TextField(field_name='first_name', maxlength=30), > forms.TextField(field_name='last_name', maxlength=30), > forms.EmailField(field_name='email', maxlength=50), > forms.TextField(field_name='password', is_required=True, > maxlength=80), > forms.TextField(field_name='phone', is_required=True, > maxlength=10), > forms.TextField(field_name='celular', is_required=True, > maxlength=10), > forms.SelectField(field_name='sexo', is_required=True, > choices=(('F', 'Femenino'), ('M', 'Masculino'))), > #TODO: Filtrar por pais los deptos... > forms.SelectField(field_name='depto', choices= > fromDictToList(State.objects.values('id', 'name')) ) , > forms.TextField(field_name='ciudad', is_required=True, > maxlength=50), > forms.TextField(field_name='address', is_required=True, > maxlength=50), > ) > > def __init__(self): > # You can also define your fields here, if you'd like. > pass > > def complete(self, request, data): > #Guardar el usuario... > user = User.objects.create_user(data['username'], > data['email'], data['password']) > > user.first_name = data['first_name'] > user.last_name = data['last_name'] > > user.save() > > However, in post I'm getting: > > 'str' object is not callable in > d:\programacion\otros\python24\lib\site-packages\django\django\forms\__init__.py > in run_validator, line 341 > > The thing is is not clear for my how this work... maybe too much > exposure to asp.net ;) > > If I understand, the manipulator is a object representation of the html > form, with optional validator class. > > The process function copy the POST data and run validator then in > complete must be the concrete action (save the object or redirect)? > I believe validator_list should be a list of callables, not strings. Maybe try something like: from wherever import isAlphaNumeric ... validator_list=[isAlphaNumeric] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
if >, if >= in templates?
Hi I've got the following in my template: {% if reference_set.count %} {% for reference in reference_set.all|slice:":5" %} {{ reference.name }} {% endfor %} {% endif %} If there are more then 5 references I'ld like to show a 'more' link that leads to a list of all references. Something like (pseudocode): {% if reference_set.count > 5 %} more {% endif %} Anybody know how to do that? Or am I missing something obvious? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: if >, if >= in templates?
On 06/26/06 07:26, Ivan Sagalaev wrote: > Don Arbow wrote: >> Not sure if it works, but off the top of my head, what I would try is this: >> >> {% if reference_set.all|slice:"5:" %} > > Not exactly this. Here a DB (Postgres at least) will complain that it > can't set OFFSET without LIMIT. This would work: > > {% if reference_set.all|slice:"5:6" %} > Using sqlite, django also complained with AssertionError 'offset' is not allowed without 'limit'. Ivan's variation does the trick. Thanks to both of you :) cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Code exectution and persistent object question
On 07/05/06 03:34, Iain Duncan wrote: > I stumbled on some behaviour that I'm sure is explained somewhere but > not in the tutorials so I haven't found it. > > I made a global log object for debugging. I noticed instantiating > objects in the view global name space executes before anything else in > the views module on page load, very useful for global containers or > loggers. I also noticed that on subsequent page loads, this code does > NOT get re-executed, and the state of member variables in the global > object are preserved. > > Questions: how is this accomplished? Are global objects serialized > behind the scenes in a session indexed table, and if so which one? > Is this behaviour safe to *rely* on for preserving state in an ongoing > session? IE could you safely implement a shopping cart that way? Seems > like very useful default behaviour. > Code in the global namespace is executed at module import time. These variables live as long as the python interpreter runs. (at least thats my understanding of it) This is great for constants and such, but you can't rely on it to store state variables as, depending on the environment/server you run python on, you have no or little control of how or when the interpreter is restarted. With mod_python on *NIX for example, you have multiple apache processes each with it's own python interpreter. An apache process serves n requests, then it's killed and a new one is started. Subsequent requests from one client will not necessarily be served by the same apache process. So no, it's not safe to store important data there. It's better to use a session, database, or file based solution. > Suggestion, maybe there should be a mention of this in the views > tutorial? Or was there one and I've been cramming this all in to my head > so fast it bled out the other end? ;) > > Loving it all so far! > Iain > ( And my tendons are sooo happy not to be reaching for [EMAIL PROTECTED]> all > the time! ) > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Referring to media files
On 07/08/06 17:13, keukaman wrote: > I'm getting tantalizingly close to being able to put a simple Django > site online. Any help on this ticket will get me a long way toward > getting there: > > I have my media directories located at: > > /home/username/media > ./img > ./css > ./js > > I have my templates directory at: > /home/username/templates > > I have setup a subdomain called media.mydomain.com that points to > /home/username/media > > I updated my settings.py file so that > MEDIA_ROOT = '/home/username/media/' > MEDIA_URL = 'http://media.mydomain.com' > > If I have a template called index.html, could someone show me the > actual code in that template to: > > 1. reference a stylesheet in the template > 2. display a logo that is stored in media.mydomain.com/img > The best way is to use template context processors as James Bennett explained nicely on his blog [1]. http://www.b-list.org/weblog/2006/06/14/django-tips-template-context-processors Here's how I use it: myproject/my_app/context_processors.py: def settings(request): from django.conf import settings as config_settings d = {} try: for key in config_settings.TEMPLATE_SETTINGS: d[key] = getattr(config_settings, key, None) except AttributeError: if config_settings.DEBUG: raise return d myproject/settings.py: MEDIA_URL = 'http://media.mydomain.com/' from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS TEMPLATE_CONTEXT_PROCESSORS += ( 'myproject.my_app.context_processors.settings', ) # List all variables from settings.py that should be added to the # RequestContext by the 'settings' context processor TEMPLATE_SETTINGS = ( 'MEDIA_URL', 'SITE_ID', ) index.html: ... ... The site id is {{ SITE_ID }}. hope this helps cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Including a php script in a template
On 07/11/06 10:59, [EMAIL PROTECTED] wrote: > Hello all! > > Is it somehow possible to include an exisiting php-script which prints > a table and some textual data (after some large calculations) in a > django template? > I rather don't want to port the existing php-script as it makes it job > well and is written by someone else. > > Thanks in advance > The guys who wrote the django apps for pycon use both php and django templates. Have a look at their repo [1], specifically [2] and [3]. Maybe you can use their template loader in combination with django's include tag? Not sure if this is what you're after, but it may get you started. cheers Steven [1] http://us.pycon.org/repo [2] http://us.pycon.org/repo/django/trunk/pycon/core/template_loaders.py [3] http://us.pycon.org/repo/django/trunk/pycon/templates/pycon/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Referring to media files
On 07/11/06 04:22, keukaman wrote: > Thanks for the help. Will this work if my site is primarly flat pages? > This will work with any django template. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Referring to media files
> > One more thing, if you don't mind. The documentation, and your > context_processors.py show in the myapp directory. Can that file be in > "mysite", rather than "myapp" so I don't have to repeat it for > application I make? > Yep that'll work. You can put the context_processors.py file wherever you like, it just has to be on your PYTHONPATH and the entry in settings.py has to point to the right place. cheers --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Template widget size
On 07/28/06 02:02, Malcolm Tredinnick wrote: > On Thu, 2006-07-27 at 16:44 -0700, Malcolm Tredinnick wrote: >> On Thu, 2006-07-27 at 17:30 -0600, Jay Klehr wrote: >> > Nagy Károly wrote: >> > > And Jay, (afaik) CSS controls visual size of field, not the number of >> > > characters you can type in (VARCHAR(30) field in 600px input widget >> > > means 2/3 of a box is empty) >> > > >> > > Charlie. >> > > >> > Exactly, the visual size, which is the same as the "size" html >> > attribute, which also has no control of how many characters can be >> > entered into the field. The "maxlength" html attribute does control the >> > number of characters allowed in the field, which CSS doesn't do, as >> > stated poorly in my previous email. ;) >> >> Quite seriously, one way to make it easier to evaluate this would be for >> somebody to finish up the remaining parts of ticket #1665. I'm not >> saying 100% it will be accepted, since it leaks a bit across the line >> between representation and presentation, but there may be no other good >> way to do it, so it's not being rejected out of hand. > > Sorry, that came across a bit more negatively than I intended: it almost > certainly will be accepted (see the threads linked from the bug). So > it's not a roll of the dice -- the solution isn't ideal, but barring a > better solution, it is a reasonable idea. > I've extended some of django's built in model and form fields to accept an additional kwarg named 'html_attributes'. It works like this: class Whatever(models.Model): ... title = models.CharField(maxlength=128, html_attributes={ 'size': 15, 'class': 'myCssClass' } ) content = models.TextField( html_attributes={ 'dojoType': 'Editor', 'items': 'formatBlock;textGroup;|;justifyGroup' } ) ... The fields are then rendered like: Not perfect, but works for me. I could wrap it up as a patch if someone's interested. cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Template widget size
On 07/28/06 19:46, Malcolm Tredinnick wrote: > On Fri, 2006-07-28 at 18:19 +0200, Steven Armstrong wrote: >> On 07/28/06 02:02, Malcolm Tredinnick wrote: >> > On Thu, 2006-07-27 at 16:44 -0700, Malcolm Tredinnick wrote: >> >> On Thu, 2006-07-27 at 17:30 -0600, Jay Klehr wrote: >> >> > Nagy Károly wrote: >> >> > > And Jay, (afaik) CSS controls visual size of field, not the number of >> >> > > characters you can type in (VARCHAR(30) field in 600px input widget >> >> > > means 2/3 of a box is empty) >> >> > > >> >> > > Charlie. >> >> > > >> >> > Exactly, the visual size, which is the same as the "size" html >> >> > attribute, which also has no control of how many characters can be >> >> > entered into the field. The "maxlength" html attribute does control >> >> > the >> >> > number of characters allowed in the field, which CSS doesn't do, as >> >> > stated poorly in my previous email. ;) >> >> >> >> Quite seriously, one way to make it easier to evaluate this would be for >> >> somebody to finish up the remaining parts of ticket #1665. I'm not >> >> saying 100% it will be accepted, since it leaks a bit across the line >> >> between representation and presentation, but there may be no other good >> >> way to do it, so it's not being rejected out of hand. >> > >> > Sorry, that came across a bit more negatively than I intended: it almost >> > certainly will be accepted (see the threads linked from the bug). So >> > it's not a roll of the dice -- the solution isn't ideal, but barring a >> > better solution, it is a reasonable idea. >> > >> >> I've extended some of django's built in model and form fields to accept >> an additional kwarg named 'html_attributes'. >> >> It works like this: >> >> class Whatever(models.Model): >>... >>title = models.CharField(maxlength=128, >> html_attributes={ >>'size': 15, >>'class': 'myCssClass' >> } >>) >>content = models.TextField( >> html_attributes={ >>'dojoType': 'Editor', >>'items': 'formatBlock;textGroup;|;justifyGroup' >> } >>) >>... > > This is the sort of thing that maybe starts crossing the line between > representation and presentation a bit too much. You are putting a lot of > presentation information into the data model description and they > should, as much as possible be separate. That is why I (and others) are > a bit conservative even about putting the textfield length into the > model: it's a leaky abstraction issue and a slippery slope, all in one. > Once we take one thing, where does it stop? Ultimately, we are going to > have to draw the line and it will seem arbitrary to people who aren't > thinking of this as "every single presentation item in a model is there > as a slight wart on the utopian design." > I agree whole heartedly. > I would rather see people put some effort into working out how you can > write a view-layer infrastructure that annotates a model somehow with > the "default visual description" you want. There is nothing against you > making those annotations in the same file as the model descriptions > themselves, but it will help keep the data description and the > presentation information separate. Long lines of code are harder to > maintain, which is why we endeavour to keep things somewhat apart and > compartmentalised where possible. This "annotation" could be an inner > class or something like that -- I don't know; I haven't put a lot of > thought into it. I just feel that something like that would be a better > expenditure of effort than hacking on the existing model stuff to tie it > to a particular visual representation. > My first idea was, just as you propose, to create another inner class or something which holds this kind of information. But I needed a solution quickly and the hack I did worked without breaking anything else. Also I only had to get my head around a small part of django's internals to implement it. Hacking on the metaclass/inner class stuff is a different kind of beast. I guess we should discuss what kind of information should/could go into this new inner class and figure out a good name for it so I or others ca
Re: Template widget size
On 07/28/06 19:20, Nagy Károly wrote: > Steven Armstrong írta: > >>I've extended some of django's built in model and form fields to accept >>an additional kwarg named 'html_attributes'. >> >>It works like this: >> >>class Whatever(models.Model): >> ... >> title = models.CharField(maxlength=128, >> html_attributes={ >> 'size': 15, >> 'class': 'myCssClass' >> } >> ) >> content = models.TextField( >> html_attributes={ >> 'dojoType': 'Editor', >> 'items': 'formatBlock;textGroup;|;justifyGroup' >> } >> ) >> ... >> >>The fields are then rendered like: >>>name="title" size="15" value="" maxlength="128" /> >> >>>items="formatBlock;textGroup;|;justifyGroup"> >> >>Not perfect, but works for me. >>I could wrap it up as a patch if someone's interested. >> >> > I do. Backward compatible and does not hurt nobody(?). > That is perfect for me Steve, if you share i'll thank you. > > Charlie. > Hi Charlie Instead of writing a patch, I've extended/wrapped djangos model and form fields. This way you can update django without having to reapply patches. You can find the code and instructions under [1]. Just for the record. I'm totally with Malcolm that this is not a pretty solution and that in time there must be a better way. [1] http://www.c-area.ch/code/django/ cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: drag & drop for admin-interface
On 08/03/06 11:23, patrickk wrote: [...] > > Good idea. However, with using the change-list for reordering you > have to load all the dojo-stuff - even if you don´t want to reorder > anything. > Since loading Dojo is quite slow (at least in my experience) I´m not > sure about this. > If you use a prebuilt dojo profile (or build your own specialized one) instead of relying on the load-dependencies-on-the-fly system, the slow loading goes away :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: django installation on mac
On 08/03/06 20:50, [EMAIL PROTECTED] wrote: > Hello Django Users, > > I'm trying to install Django on a mac os x (10.3) but i'm experiencing > some problems i can't solve. > When i run import django in mu interpreter it's working fine but when i > start the server i get the following error message. > > > Unhandled exception in thread started by 0x406130> > Traceback (most recent call last): > File > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/management.py", > line 757, in inner_run > validate() > File > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/management.py", > line 741, in validate > num_errors = get_validation_errors(outfile) > File > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/management.py", > line 634, in get_validation_errors > import django.models > File > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/models/__init__.py", > line 1, in ? > from django.core import meta > File > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/meta/__init__.py", > line 3, in ? > from django.core import db > File > "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/db/__init__.py", > line 23, in ? > raise ImproperlyConfigured, "Could not load database backend: %s. > Is your DATABASE_ENGINE setting (currently, %r) spelled correctly? > Available options are: %s" % \ > django.core.exceptions.ImproperlyConfigured: Could not load database > backend: Failure linking new module: /opt/pgsql/lib/libpq.4.dylib: > dyld: /usr/bin/python can't open library: /opt/pgsql/lib/libpq.4.dylib > (No such file or directory, errno = 2) > . Is your DATABASE_ENGINE setting (currently, 'postgresql') spelled > correctly? Available options are: 'ado_mssql', 'mysql', 'postgresql', > 'sqlite3' > > > what i can figure out from this message is that the scripts can't > locate libpq.4.dylib. It's coorect that this file isn't located in the > path (/opt/pgsql/lib/libpq.4.dylib). It's located in a other path > (/usr/local/pgsql/lib/libpq.4.dylib) > > is there something i can adjust so it will work ? > > any suggestions are welcome, > > kind regards > > Richard Mendes Hi Richard Open up a shell and type this (all on one line): sudo ln -s /usr/local/pgsql/lib/libpq.4.dylib /opt/pgsql/lib/libpq.4.dylib This symlinks the library to where python is looking for it. hth cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: accessing was_published_today in a template
On 08/03/06 21:01, skullvulture wrote: > In the tutorial you create a custom method was_published_today. How > can you access it in the template? I'm using generic views. Do I have > to write my own more complicated view to access it? Thanks. > Something like this should work: {% if object.was_published_today %} I was published today :) {% else %} Nope, I wasn't published today :( {% endif %} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: when is 1 != 1? (according to 'ifequal' in template)
On 08/07/06 20:15, hotani wrote: > Code: > > {% if request.session.pfilter %} > {% ifequal request.session.pfilter project.id %} > {{ project }} > > both {{ project.id }} and {{ request.session.pfilter }} return "1" > Maybe one value is an int and the other is a string? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Why 404?
On 08/07/06 22:29, Jarek Zgoda wrote: > I am getting 404 with archive_day date-based generic view. I know that > some objects exist for specified day (they are present in archive_month > view), but I consequently get 404 if I specify a day. > > My urlconf has an entry: > ( > r'^(?P\d{4})/(?P\d{2})/(?P\d{2})/$', > 'django.views.generic.date_based.archive_day', > item_dict > ), > where item_dict contains only queryset, date_field and month_format (I > use "%m"). The dictionary for archive_month view has identical > definition and contains objects with specified date. > > I am stuck here. How can I debug this to get any clue? > > Cheers > Jarek Zgoda > Hi Jarek Don't know if this is related to your problem, but if you're using sqlite the patch at [1] may help. If this does solve your problem, and you have a moment, you could add some more background info about the bug to that ticket and confirm that the patch worked. I was in a rush when I created it and haven't yet taken time to add some more info for the devs. cheers Steven [1] http://code.djangoproject.com/ticket/2471 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Why 404?
On 08/08/06 13:45, Jarek Zgoda wrote: > Steven Armstrong wrote: > >> Don't know if this is related to your problem, but if you're using >> sqlite the patch at [1] may help. >> >> If this does solve your problem, and you have a moment, you could add >> some more background info about the bug to that ticket and confirm that >> the patch worked. I was in a rush when I created it and haven't yet >> taken time to add some more info for the devs. > > This patch didn't solve my problem, I see no difference in behaviour. > > The object with date field value of 2006-08-07 definitely exists (it is > listed in month view), but trying to make a view of objects at URL > 2006/08/07/ results in empty list, thus 404 if allow_empty == False. My > urlconf contains entry for > ^(?P\d{4})/(?P\d{2})/(?P\d{2})/$, so above given URL > should add items 'year': '2006', 'month': '08', 'day': '07' to generic > view call arguments list. Month format is already '%m', day format is > default. It seems that SQLite3 database contains character value of > '2006-08-07' in this field. This is exactly the problem that the patch fixes. In MySQL and friends a DateField is represented as '2006-08-07 00:00:00' while in sqlite it's just '2006-08-07'. The patch changes the archive_day view to test if it's dealing with a DateField or a DateTimeField and builds the sql lookup args depending on that. Have you nuked any *.pyc files still lying around after applying the patch? I had the exact same symptoms that you're describing and the patch solved the problem. hope this helps cheers Steven > > Will try with MySQL, although it's a bit of overkill to me. > > Cheers > Jarek Zgoda > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Using Django in a Cron Job
On 08/09/06 17:56, Joe wrote: > I would like to set up a python script that runs every night to send > out an email subscription. I would like to access a Django model that > has the user's email addresses, as well as use the Django sendmail > function. Can someone help me understand what imports/path setup I > have to do to get this working? (Note: I will not be setting up the > Cron job, nor do I know now. I will simply be giving a python script > to our IT staff for them to set up). > > Thanks for the help, > > Joe > %<-- #!/usr/bin/env python import sys sys.path.append('/path/to/django') sys.path.append('/path/to/your/projects') import os # assuming /path/to/your/projects/myproject/settings.py os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' from myproject.myapp.models import GreenStripedPotatoes ... %<-- Alternatively you can add django and your projects folder to the PYTHONPATH, and define DJANGO_SETTINGS_MODULE as an environment variable before starting your script e.g.: $ export PYTHONPATH="$PYTHONPATH:/path/to/django:/path/to/your/projects" $ export DJANGO_SETTINGS_MODULE="myproject.settings" $ python /path/to/my/cronscript.py The second method is more flexible as your sysadmin can write a shell script that sets up the environment and then runs your script. Like this your script can be used on different servers without changing it. hope this helps cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Multiple Websites using the same project and apps
On 08/09/06 16:50, plungerman wrote: > greetings, > > what would be the best way to manage the settings files for multiple > websites that use the same django project? we have a django project > with 3 applications that we want to use for various clients. through > apache, we set up the virtual host stuff for their domain and send all > python/django requests via mod_python to the same project location > while using different settings files for each site. we want separate > databases and have different template directories and even different > applications available to each client. basically, then, we need a > different settings.py file for each client. most of the values would > be the same across the disparate clients, with the exception of things > like TEMPLATE_DIRS, DATABASE stuff, maybe a few other things. my idea > was to use the custom default settings described here: > > http://www.djangoproject.com/documentation/settings/#creating-your-own-settings > > is that the best way to go about this? i tried the method described > therein and mod_python threw an error, complaining about ROOT_URLCONF, > saying > > AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF' > > here is what i have in the client specific settings file. as you can > see, i import the custom defaults (my_settings) and then over-ride the > defaults using the configure() method: > > from django.conf import settings > from myapp import my_settings > > settings.configure( > default_settings=my_settings, > DEBUG = False, > TEMPLATE_DEBUG = False, > DATABASE_ENGINE = 'mysql', > DATABASE_NAME = 'blah', > DATABASE_USER = 'blah', > DATABASE_PASSWORD = 'blah', > MEDIA_ROOT = '/path/to/media/dir/', > MEDIA_URL = '/django_media/clientmedia/', > ROOT_URL = '/', > ROOT_URLCONF = 'iris.urls-client1', > TEMPLATE_DIRS = ( '/path/to/template/dir/',), > ) > > btw, ROOT_URL is a custom setting, if you are confused by that bit. > > any thoughts on this error or on a better way to deploy multiple sites > using the same project and applications? > > yours, > > steve > The following works for me. /path/to/myapp/settings.py: from settings_default import * # relative import DEBUG = False TEMPLATE_DEBUG = False DATABASE_ENGINE = 'mysql' DATABASE_NAME = 'blah' DATABASE_USER = 'blah' DATABASE_PASSWORD = 'blah' MEDIA_ROOT = '/path/to/media/dir/' MEDIA_URL = '/django_media/clientmedia/' ROOT_URL = '/' ROOT_URLCONF = 'iris.urls-client1' TEMPLATE_DIRS = ( '/path/to/template/dir/',) Where /path/to/myapp/settings_default.py would contain what you now have in my_settings.py. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: syncdb without shell access
On 08/09/06 21:13, Robin Gruyters wrote: > Hi ya, > > My hosting provider doesn't give shell access, so I can't execute like > "syncdb", "startapp", "startproject", etc. > > Is there another way to do this? (e.g. by creating a runsync.py script?! (or > something?)) > > Regards, > > Robin > Haven't tried this, but in theory something like this should/could work. def my_syncdb_view(request): # check if user has permission to run this here # prepare to capture output of syncdb() import sys orig_stdout = sys.stdout orig_stderr = sys.stderr from cStringIO import StringIO sys.stdout = StringIO() sys.stderr = StringIO() from django.core.management import syncdb syncdb() # rewind stringio instances sys.stdout.seek(0) sys.stderr.seek(0) output = [] output.append("Output:") output.append('') output.append(sys.stdout.read()) output.append('') output.append("Errors:") output.append('') output.append(sys.stderr.read()) output.append('') # set stdout and stderr back just in case sys.stdout = orig_stdout sys.stderr = orig_stderr return HttpResponse('\n'.join(output)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: How to support of alternate date formats for DateField
On 08/09/06 22:15, DavidA wrote: > I'm sure I'm just misunderstanding how manipulators and validators > work, but I can't see the right way to do this: I want to support more > formats for a DateField then just '-MM-DD' (which is checked in > DateField by isValidANSIDate). > > It seems like I can add *more restrictive* validators but can't > *replace* the existing ones with more relaxed validators. > > So instead I've manually checked and converted the value in my view > right before the call to manipulator.get_validation_errors (I validate > it, and if its a valid date, I convert it to a string in the format > '-MM-DD' and put it back in the new_data dict so it *will* pass the > isValidANSIDate check.) > > This seems kludgy to me, and 9 times out of 10, when something looks > kludgy in my Django code, its because I'm missing something obvious. > > Thanks in advance, > -Dave > Hi Dave I've had similar problems and solved them like this: myproject/validators.py %<-- from django.utils.translation import gettext_lazy as _ from django.core.validators import * import re my_ansi_date_re = re.compile('put regexp here') def isValidANSIDate(field_data, all_data): if not my_ansi_date_re.search(field_data): raise ValidationError, _('Enter a valid date in PUT FORMAT DESCRIPTION HERE format.') [more custom or overridden validators] %<-- And in my models I do: from myproject import validators instead of from django.core import validators Like this I can override any of djangos validators or add custom ones and they are all still available in one namespace. hope this helps cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: How to support of alternate date formats for DateField
On 08/10/06 20:25, DavidA wrote: > Steven Armstrong wrote: >> I've had similar problems and solved them like this: >> >> myproject/validators.py >> %<-- >> from django.utils.translation import gettext_lazy as _ >> from django.core.validators import * >> import re >> >> my_ansi_date_re = re.compile('put regexp here') >> def isValidANSIDate(field_data, all_data): >> if not my_ansi_date_re.search(field_data): >> raise ValidationError, _('Enter a valid date in PUT FORMAT >> DESCRIPTION HERE format.') >> >> [more custom or overridden validators] >> %<-- >> >> And in my models I do: >> from myproject import validators >> >> instead of >> >> from django.core import validators >> >> >> Like this I can override any of djangos validators or add custom ones >> and they are all still available in one namespace. >> >> hope this helps >> cheers >> Steven > > Hi Steven, > > I tried your suggestion, but it still seems that Django is using the > isValidANSIDate funcion from django.core.validators rather than mine. I > put trace statements in django.core.validators.py as well as my > override and although I could see mine being imported after the core > ones, when the form's validation occurs, its using the core one. I > googled on "override module function in python" and got this hit: > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/30bfdfd91d759275/6eaa3b20deb47d84%236eaa3b20deb47d84 > > I've used the suggested technique in the following way and now it > works: > > my custom validators.py > from pf.utils.convert import toDateRelaxed > > def isValidANSIDate(field_data, all_data): > try: > toDateRelaxed(field_data) > except ValueError: > raise ValidationError, "Invalid date" > > import django.core.validators > django.core.validators.isValidANSIDate = isValidANSIDate > > > And then I import my validators in my models.py class. The downside to > this, as explained in the link, is that if someone uses > > from django.core.validators import isValidANSIDate > > they will get the original, not my custom version. > > Thanks for your suggestion as it got me on the right track. > -Dave > Hi Dave Good to hear you've found a solution. I have yet only used my approach with validators that I've set myself by passing them to the field constructors. Guess it fails with the date related fields because django imports and adds them automagically there. cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: EnvironmentError?
On 08/14/06 18:55, Tom Davis wrote: > I am having a problem getting Django to work properly on my server. I > have Apache setup with mod_python using Python 2.4. I put in the > Location stuff in my Apache config, and when I go to the directory I > get this: > --- > Mod_python error: "PythonHandler django.core.handlers.modpython" > > Traceback (most recent call last): > > File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line > 299, in HandlerDispatch > result = object(req) > > File > "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py", > line 163, in handler > return ModPythonHandler()(req) > > File > "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py", > line 125, in __call__ > if settings.ENABLE_PSYCO: > > File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line > 27, in __getattr__ > self._import_settings() > > File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line > 54, in _import_settings > self._target = Settings(settings_module) > > File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line > 82, in __init__ > raise EnvironmentError, "Could not import settings '%s' (Is it on > sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) > > EnvironmentError: Could not import settings '.settings' (Is it > on sys.path? Does it have syntax errors?): No module named > .settings > --- > > I tried adding the PythonPath line because I figured it was a problem > with my sys.path (well duh the error suggests it), but that didn't > change anything. I also made sure to give chown to the same user/group > that all the web files are, just in case Apache couldn't read the > django directories or something. Thoughts? > Hi Tom Post us your apache config so we have something to work with :) cheers Steven --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: javascript options
> > guys i m trying to figure out which javascript toolkit to use > > i m now trying to figure out which to use between > The major contenders are: > Dojo + lot's of features + great for writing widgets - documentation sucks - large - complex > Mochikit + excellent docs + awesome API for creating DOM elements (like stan from Nevow) + cool interactive js shell + very pythonic - more "handwork" when writing widgets > and prototype [rails fame] - extends builtins (e.g. Object) which kills for in loops and has other ugly implications - doesn't play well with other/custom libraries > > i would love to find out which is very pythonic and clean > if you can also tell about your experience of using one of these > thanks > IMHO: For funky, advanced widgets dojo is king. For slick js/ajax/hijax and client side programming Mochikit rules. And proto..., what's that ;-) It really all depends on what your doing. Pick the best tool for the job. just my 0.02 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Django, mod_python and 403 error
On 08/16/06 23:30, Fabien Schwob wrote: > Nobody have an idea on how to solve this problem ? > > On 8/10/06, Fabien Schwob <[EMAIL PROTECTED]> wrote: >> Hello, >> >> The development of my Django site is on the way. And in order to try >> it online, I've decided to install it under Apache + mod_python. But >> when I'm trying to access it, I get a 403 errors on all pages except >> the index page. >> >> I've installed it at http://www.cocoa.fr and the virtual host >> configuration is the following one : >> >> >> ServerAdmin [EMAIL PROTECTED] >> DocumentRoot /home/cocoa/www >> SuexecUserGroup cocoa users >> ServerName www.cocoa.fr >> ServerAlias cocoa.fr >> CustomLog logs/cocoa-access_log combined >> ScriptAlias /cgi-bin/ /home/cocoa/cgi-bin/ >> AddHandler x-httpd-php5 .php >> >> SetHandler mod_python >> PythonHandler django.core.handlers.modpython >> PythonPath "['/home/cocoa'] + sys.path" >> SetEnv DJANGO_SETTINGS_MODULE chibbi.settings >> Alias /media "/home/cocoa/chibbi/media" >> >> >> SetHandler None >> >> >> >> The project is in the /home/cocoa/chibbi folder. >> >> Thanks in advance. >> > Looks like apache is trying to handle the requests itself instead of passing them to mod_python. There may be more infos about why apache is throwing a 403 in its error log. Maybe try something like: ... SetHandler mod_python PythonHandler django.core.handlers.modpython PythonPath "['/home/cocoa'] + sys.path" SetEnv DJANGO_SETTINGS_MODULE chibbi.settings ... see also http://www.djangoproject.com/documentation/modpython/ If this doesn't work post your urls.py so we can have a look at that. hope this helps cheers --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Django, mod_python and 403 error
On 08/17/06 18:38, Fabien Schwob wrote: >> It'd be a great help if you pasted the errors from Apache's error log. >> Also, what kind of 403 errors do you get -- could you include a link >> to a screenshot? > > In the error log I get : > [Thu Aug 17 18:31:01 2006] [error] [client 86.73.128.192] > (13)Permission denied: cannot read directory for multi: > /home/cocoa/www/, referer: http://www.cocoa.fr/ > > And to see the front error : > http://www.cocoa.fr/lieux/ > http://defindit.com/readme_files/apache_13_error.html I would try to simplify the setup, e.g. nuke the DocumentRoot and PHP related stuff. See if it works with only what's absolutely required for django to work. Then start adding stuff, testing after every change. For what it's worth attached is the relevant parts of a working django setup. Maybe that helps. Good luck --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~--- Django is installed under: /usr/local/lib/python/django DocumentRoot is: /var/www/www.example.com/htdocs Site media is at: /var/www/www.example.com/htdocs/media The custom django project (named foo) is located at: /var/www/www.example.com/foo With settings at: /var/www/www.example.com/foo/settings.py My user/group is: me:mygroup Apache runs as user/group: apache:apache Apache VirtualHost config: ServerName www.example.com DocumentRoot /var/www/www.example.com/htdocs DirectoryIndex index.html LogLevel debug CustomLog /var/www/www.example.com/logs/access.log combined ErrorLog /var/www/www.example.com/logs/error.log Options -All -Multiviews +FollowSymLinks AllowOverride None Order allow,deny Allow from all SetHandler python-program PythonInterpreter foo PythonPath "['/var/www/www.example.com'] + sys.path" PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE foo.settings PythonDebug On SetHandler None Alias /media /var/www/www.example.com/htdocs/media/ SetHandler None Options -All -Multiviews AllowOverride None Order allow,deny Allow from all SetHandler None Alias /admin_media /usr/local/lib/python/django/django/contrib/admin/media/ SetHandler None Options -All -Multiviews AllowOverride None Order allow,deny Allow from all SetHandler None Directory permissions: $ la /var/www/www.example.com/ total 1 drwxr-xr-x 5 me root128 Jun 16 01:12 . drwxr-xr-x 20 root root632 Jun 16 01:09 .. drwxr-xr-x 2 me mygroup 48 Jun 16 01:43 htdocs drwxr-xr-x 2 apache mygroup 112 Jun 16 01:30 logs drwxr-xr-x 7 me mygroup 744 Jun 16 02:10 foo $ la /var/www/www.examle.com/foo/ total 77 drwxr-xr-x 7 me mygroup 744 Jun 16 02:10 . drwxr-xr-x 5 me root 128 Jun 16 01:12 .. -rw-r--r-- 1 me mygroup 0 Jun 16 00:55 __init__.py -rw-r--r-- 1 me mygroup 104 Jun 16 02:10 __init__.pyc -rw-r--r-- 1 me mygroup 104 Jun 16 02:10 __init__.pyo drwxr-xr-x 10 me mygroup 352 Jun 16 02:10 apps drwxr-xr-x 2 apache mygroup80 Jun 25 21:07 db drwxr-xr-x 4 me mygroup 128 Jun 16 01:06 htdocs -rwxr-xr-x 1 me mygroup 546 Jun 16 00:55 manage.py -rw-r--r-- 1 me mygroup 699 Jun 16 02:10 manage.pyc -rw-r--r-- 1 me mygroup 699 Jun 16 02:10 manage.pyo -rw-r--r-- 1 me mygroup 3408 Jun 16 00:55 settings.py -rw-r--r-- 1 me mygroup 3086 Jun 16 02:10 settings.pyc -rw-r--r-- 1 me mygroup 3086 Jun 16 02:10 settings.pyo -rw-r- 1 me apache376 Jun 16 01:34 settings_local.py -rw-r- 1 me apache424 Jun 16 02:10 settings_local.pyc -rw-r- 1 me apache424 Jun 16 02:10 settings_local.pyo drwxr-xr-x 10 me mygroup 288 Jun 16 02:15 templates -rw-r--r-- 1 me mygroup 1520 Jun 16 01:28 urls.py -rw-r--r-- 1 me mygroup 1577 Jun 16 02:10 urls.pyc -rw-r--r-- 1 me mygroup 1577 Jun 16 02:10 urls.pyo -rw-r--r-- 1 me mygroup 3998 Jun 16 00:55 utils.py -rw-r--r-- 1 me mygroup 4454 Jun 16 02:10 utils.pyc -rw-r--r-- 1 me mygroup 4396 Jun 16 02:10 utils.pyo Note: apache user needs write access to the folder 'db' cause I'm using sqlite and the db is in that folder. All sensitive config is in settings_local.py which get's included by 'from settings_local import *' at the end of settings.py. I usually precompile all python code so apache doesn't need write access to my project directory using the script below. $ cat ~/bin/python-compile #!/bin/bash # # Recursively compiles all Python code in the given directory. # # Usage: #python-compile
OT: got api
Just found something I thought might also be useful for some of you folks :) http://gotapi.com/ No python api yet, but lot's of other stuff useful stuff for web developers. cheers --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: symlink mess
On 08/26/06 21:47, george webzary wrote: > Hi > > > I know this is unrelated to Django. But I guess I mucked up my django sym > links, by linking it number of times. > > How do I remove the multiple level of sym links. This is a Linux newbie > question. But has me stumped. > > When I run setup.py install from updated svn directory, I get this error > > error: > django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django/django: > Too many levels of symbolic links > Hi George Looks like you have a symlink named django inside your django installation which points back to it self. Try something like this: cd /path/to/svn/checkout/django ls -al if you see a symlink in there named django remove it: rm django And all should be fine again. hope this helps ps: you can reproduce this kind of problem like this: mkdir $HOME/test cd /tmp/ ln -s $HOME/test test cd /tmp/test ln -s $HOME/test test After that you'll have a endless hierarchy of symlinks. e.g. /tmp/test/test/test/test//test --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: group traffic
On 08/30/06 07:10, Frank Stüss wrote: > Hi folks, > since this list is getting bigger day by day.. > Eam.. what about splitting this group up in say two or three lists? > > django.newbies (like me :-) > django.apps > django.views > > Looking for better names/categories. > > As all of you answerers are doing a great job helping, may be this would help > even more. Does this make sense? -1, to many mailing lists in this world already. Although, thinking again, maybe create a django-dreamhost list ... (just kidding) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: A few questions about queryset's.
On 08/31/06 17:22, Anders Aagaard wrote: > Hi > > I've been learning to love django lately, but I can't quite wrap my > head around more advanced querysets. I've listed my classes and their > sql tables on the bottom, as all problems are linked to those tables. > > First problem: > I have a class, Content, with a set of tags, how can I filter for > multiple tags? > If I do: > list = Content.objects.filter(tag__id=1).filter(tag__id=2) it makes a > sql query asking content_content_tags for content_id's where tag_id = 1 > and tag_id = 2, which will of course never match. > Something like this should work: mylist = Content.objects.filter(tag_id__range=(1,2,3,4,5)) or: from django.db.models import Q mylist = Content.objects.filter(Q(tag_id=1) | Q(tag_id=2)) > What I'd like to do is something like: > for tag in request.GET.getlist('tag') > content = content.filter('match this tag too') > > > > Second problem: > I've looked at complex_filter for doing this and I can't quite figure > it out. > What if I wanted something like this: > content.objects.filter(id__id=1) | content.objects.filter(id__id=2) > But I needed to match a dynamic list of id's. How could I do something > like > > content = content.objects.filter(content=example) > for match in id_list: > content = content.objects.filter(id__id=match) #And here get a logical > OR comparison with the previus part of the loop. > So this would produce the same effect as: > content.objects.filter(id__id=id_list[0]) | > content.objects.filter(id__id=id_list[1]) > from django.db.models import Q query = Q(tag_id=1) for the_tag_id in (2,5,6,8,9): query = query | Q(tag_id=the_tag_id) mylist = Content.objects.filter(query) Be careful with your use of the the double underscore __ It has special meaning in djangoland. Have a look at http://www.djangoproject.com/documentation/db_api/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Backwards relation (ie XXX_set) across apps
On 09/08/06 16:33, Jay Parlar wrote: > On 9/8/06, Russell Keith-Magee <[EMAIL PROTECTED]> wrote: >> I just tried the following in a test project; >> >> testproject/mytest/models.py: >> from django.db import models >> >> class Image(models.Model): >> name = models.CharField(maxlength=20) >> testproject/mytest2/models.py--- >> from django.db import models >> from testproject.mytest.models import Image >> >> class Article(models.Model): >> name = models.CharField (maxlength=20) >> img = models.ForeignKey(Image) >> >> --- >> >> Then, add both apps to INSTALLED_APPS, sync, and in a shell: >> >> >from testproject.mytest.models import Image >> >from testproject.mytest2.models import Article >> >> >img1 = Image(name='foo') >> >img1.save() >> >> >art1 = Article(name='bar', img=img1) >> >art1.save() >> >> >img1 = Image.objects.all()[0] >> >print img1.article_set.all() >> >> returns [] as expected. Do you get the same result >> if you use this project? >> >> Can you provide any more details about you application? >> >> The only reason I can think that you wouldn't get a _set descriptor is in >> the case of a m2m relation to self. > > Well, from the shell, it seems to work like a charm. It only seems to > broken at the Admin level. > > My Photo model is here: > http://svn.jayparlar.com/website/trunk/awwca/stockphoto/models.py > (This is almost identical to the models.py that ships with the > 'stockphoto' application) > > My Article model is here: > http://svn.jayparlar.com/website/trunk/awwca/articles/models.py > (Although for these tests today, I stripped out all the fields except > 'title' and 'picture') > > Here's what I tried: Added a Photo and Article from the admin. In the > shell, there was no 'article_set' attribute. > > However, staying in the shell, I created (and saved) a *new* Article > instance, giving it the Picture instance that was created in the > Admin. After that, I *would* have an 'article_set' attribute, that > would show both the Article created in the Admin, and the one created > in the shell. > Hi Jay I had a similar problem recently. It turned out to have something to do with the blank=True and null=True arguments. picture = models.ForeignKey(Photo, blank=True,null=True) Maybe, for testing, try removing those and see it the article_set is available as expected without them. picture = models.ForeignKey(Photo) If it is, it may be a bug in django. I don't know if this is really related to your problem, just thought I'll drop a note here as the symptoms sound familiar. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: MySQL Django Wildcard bug...
On 09/08/06 22:56, tom smith wrote: > So... > > Because there aren't quite enough examples that show how to build > pythonic model queries... I'm using the pump-raw-sql at django... > > The only problem is that when my sql contains > > wordsql = wordsql + " AND (title not like ' %" + word +"%') " > > cursor.execute(sql) > > Then because the sql has a % in it.. django complains... > > "not enough arguments for format string" > > which I think is because the % is somehow being seen as a %s.. > > basically... pumping raw sql is fine unless theres a "%" in there... > > > any ideas? > Try escaping the %. e.g. wordsql = wordsql + " AND (title not like ' %%" + word +"%%') " --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Trackback spam in Blogs
On 09/09/06 09:45, [EMAIL PROTECTED] wrote: > Hi. > > My two sites, trogger.de and trogger.info , were recently subjected to > a large trackback-spam attack. We're talking in the area of ten > thousand trackbacks within two or three days. Plus a couple hundred > spam somments in the same period. For the time being, I've disabled > trackbacks and anonymous comments. But that's just punishing the users > for the actions of a few freeloading idiots. > > Are there any technical countermeasures against trackback spam that > Djangonites have already successfully integrated into their Django > sites and used? > Using a keyword list would be one method (also easy to implement), but > then you're always playing catch-up with the spammers. > > Has someone already built an interface to Akismet or a similar service? > Hi Daniel I haven't used this with django yet, but the approach outlined below has worked very well with a different blogging engine. - setup spambayes [1] on your server - train your site's content as "ham" - train some of those spammy comments/trackbacks as "spam" - run all incomming comments/trackbacks through spambayes - nuke messages marked as "spam" - store messages marked as "unsure" as disabled/draft. check these manually once in a while (I have a cronjob that sends me a mail if there are any) - store messages marked as "ham" as enabled/published Spambayes catches +- 99% of the junk. Zero false positives so far. [1] http://spambayes.sourceforge.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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: admin-interface: some questions
On 12/27/05 18:28, patrick k wrote: On 12/27/05, patrick k <[EMAIL PROTECTED]> wrote: - how do i change the numrows for a textarea-field? You can do this with CSS; create custom admin templates that include some custom CSS code. what i meant was changing the numrows for each textarea-field seperately. e.g., a body-field needs more space than a summary (at least in my app). why not thinking about extending the textfield-model with something like "numrows=xxx"? Maybe add css classes to textareas (or generally inputs) based on model and fieldname? e.g.: class Article(meta.Model) summary = meta.TextField() body = meta.TextField() becomes: .article-summary { width: 100%; height: 5em; } .article-body { width: 100%; height: 10em; } That's how some other tools I've used do it. I'ld prefer such a solution to values hardcoded in the model. cheers Steven
django development with eclipse and pydev
Hi all I've written an ant file that wrapps the django-admin.py functionality and adds a few goodies. Basically it let's you run django-admin by executing ant targets. Not perfect, but works for me :) Thought that might be usefull for someone. cheers Steven #print "${workspace_loc}" #print "${user-name}", "${user-email}", "${user-password}" import os os.environ['DJANGO_SETTINGS_MODULE'] = "${django_project}.settings" import sys sys.path.append("${workspace_loc}") #print sys.path from django.models.auth import users #u = users.create_user("${user-name}", "${user-email}", "${user-password}") u = users.create_user("${user-name}", "[EMAIL PROTECTED]", "${user-password}") u.is_staff = True u.is_active = True u.is_superuser = True u.save() #PIDS=`pidof python ${django-admin}` PIDS=`ps axho pid,cmd | grep ${django-admin} | grep -v grep | awk '{print $1}'` echo "killing processes: $PIDS" for pid in $PIDS do kill $pid > /dev/null 2>&1 done
Re: Ellington CMS
On 01/02/06 15:36, Jaanus wrote: Here and there in the discussions and code there are references to the Ellington CMS built on top of Django, and that Adrian and Simon and guys are selling. I've tried to search for more info, but haven't found any. Please point me to more info about the product (if you don't want to spam this group, then privately). Thanks :-) If anyone has some info on this please post it here. I've also been googling for Ellington without any luck. cheers
Re: recommended javascript books/tutorials/howtos?
On 02/14/06 11:07, Gábor Farkas wrote: hi, i'd like to increase/enhance my javascript knowledge, which right now is rather limited (zero?) :) so, are there are books/websites you can recommend? i'm primarily interested in the application of javascript to the webpages, so DOM manipulation and things like that. of course i am also interested in learning about the object-model of javascript and things like that, but what i'm lacking right now is the knowledge about the javascript-webpage interaction. thanks, gabor I'ld have a look at "JavaScript - The Definitive Guide" by David Flanagan [1]. An in dept overview of the language and at the same time a complete reference. In my JS-learning-days I always had it with me, used it daily. cheers Steven [1] http://www.oreilly.com/catalog/jscript4/
using django models with twisted?
Is anybody using django models in twisted (or other async) apps? Any ideas on how to make the two play together nicely? cheers Steven