Automatically printing display of model object's data
Here I have a silly function for pretty printing any model object's data. def pprint(res): for instr in dict(res.__dict__): if instr[-3:] == "_id": instr = instr[:-3] displaymeth = "get_%s_display" % instr try: atr =getattr(res,displaymeth) except: atr =getattr(res,instr) print "%s: %s" % (instr,atr) It sort of prints out an easy to read representation of any model object. Is there a better way to do this? I am sure there was something already in Django to do this, but I am having a hard way of finding. I am still on .96 Thanks, Brian Ray --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Chicago Python User Group: Customize Django Admin
Hello: I will be presenting tonight at ChiPy http://chipy.org If anyone is around Chicago tonight, feel free to stop in. Here is the official announcement http://mail.python.org/pipermail/chicago/2010-June/006863.html thanks, Brian Ray http://twitter.com/brianray -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Session problems
Jakub: Why not temporarily switch to SCGI and see if the symptoms goes away? You need to concrete-ize this problem. BTW, is the cookie even being set on the browser. What version of mod_python? Did you compile yourself? Graham: This behavior has been seen with mod_python under certian instances. For example how to the settings in httpd.conf effect this? For example, "PythonAutoReload On" and apache's MaxRequestsPerChild 1. Maybe they can aggravate a problem when something else is going wrong. I am just saying, I can see other places on the mod_python list where sessions were not working properly for many reasons. I can recall once I build mod_python linking to the wrong libraries, and some strange stuff happened. -- Brian Ray (http://kazavoo.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?hl=en -~--~~~~--~~--~--~---
Apache Authentication
I see it's possible to `Authenticate against Django database from Apache <http://www.djangoproject.com/documentation/apache_auth/>`_. I would like to experiment with using Apache Authentication for Django instead of a login webpage, as well. Likewise, I would like to use mod_python. I am having trouble writing my section of my httpd.conf to handle both. Can this be done? If so, does anybody have a working example. Regards, Brian Ray http://brianray.chipy.org
Re: Apache Authentication
Hi Adrian: When placed together, I do get asked for Authentication from browser. When good credentials are provided, I do get through but then an error is displayed. I would like to determine wether or not I am doing something wrong. Otherwise, can log this intro Trac as a feature request? -- Brian More details RHEL3 Django recently updated from SVN Head Apache/2.0.54 (Unix) DAV/2 SVN/1.1.4 mod_python/3.1.4 Python/2.4.2 Server httpd.conf: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE myproject.settings PythonPath "['/home/django/projects'] + sys.path" PythonDebug On AuthType basic AuthName "example.com" Require valid-user SetEnv DJANGO_SETTINGS_MODULE myproject.settings PythonAuthenHandler django.contrib.auth.handlers.modpython Displayed to browser: Mod_python error: "PythonAuthenHandler django.contrib.auth.handlers.modpython" Traceback (most recent call last): File "/usr/local/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/usr/local/lib/python2.4/site-packages/django/contrib/auth/handlers/modpython.py", line 20, in authenhandler staff_only = _str_to_bool(options.get('DjangoRequireStaffStatus', "on")) TypeError: 'tuple' object is not callable Apache's error log's say the same thing.
Re: Apache Authentication
Adrian, I took a look at modpython.py. I changed line 16 to: _str_to_bool = lambda s: s.lower() in ('1', 'true', 'on', 'yes') Note the parethesis. Seems to work now. Cool, Thanks!
Re: Apache Authentication
Anouther issues with Authenticating this way, the Django user is still Anonymous although the REMOTE_USER is not: , POST:, COOKIES:{}, META:{'AUTH_TYPE': 'Basic', 'CONTENT_LENGTH': 0L, 'CONTENT_TYPE': None, 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': '*/*', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate', 'HTTP_ACCEPT_LANGUAGE': 'en', 'HTTP_AUTHORIZATION': 'Basic YnJILikeBeEROnSatURdayNA==', 'HTTP_HOST': 'localhost:8080', 'HTTP_MAX_FORWARDS': '10', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412.7 (KHTML, like Gecko) Safari/412.5', 'HTTP_X_FORWARDED_FOR': '10.1.5.112', 'HTTP_X_FORWARDED_HOST': 'www.foo.com', 'HTTP_X_FORWARDED_SERVER': 'foo.com', 'PATH_INFO': '/', 'PATH_TRANSLATED': None, 'QUERY_STRING': None, 'REMOTE_ADDR': '127.0.0.1', 'REMOTE_HOST': None, 'REMOTE_IDENT': None, 'REMOTE_USER': 'bray', 'REQUEST_METHOD': 'GET', 'SCRIPT_NAME': None, 'SERVER_NAME': 'foo.com', 'SERVER_PORT': 0, 'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_SOFTWARE': 'mod_python'}, user:AnonymousUser>' So, request.user.is_anonymous() returns True. I do know know what made me think django.contrib.auth.handlers.modpython would start a session automatically. Instead, it just gives Apache the ok to let the request through to Django. Would it be appropriate to take the HOST_USER from the request object and just log the user in after the Apache Authentication by setting request.session and request.user? More important, is this safe? If so, this is fine by me. Regards, Brian Ray
Re: Apache Authentication
Thanks Ian. But, this is not really what I am doing here. I do not want to create users from Apache. Kind Regards, Brian
Re: Apache Authentication
This is in my view *after* the Authenticaion: def login(request): user = users.get_object(username__exact=request.META['REMOTE_USER'] request.session[users.SESSION_KEY] = user.id request.user = user # do something else ... Seems to make both Django and Apache happy. Regards, Brian btw, I will fill out a Trac ticket for the modpython.py fix, just in case this thread get's lost in cyberspace.
Model Inheritence
I am trying to take some data schemes already setup in SQLObject and use the Django model-api instead. My SQLObject has things like: class account(SQLObject): accountsaccessrequest = MultipleJoin('accountsaccessrequest') class accountsaccessrequest(SQLObject): account= ForeignKey('account') So I tryed to convert this with: class account(meta.Model): accountsaccessrequest = meta.ManyToManyField(accountsaccessrequest) class accountsaccessrequest(meta.Model): account= meta.ForeignKey(account) Although, this clearly will not work because 'accountsaccessrequest' is not yet defined. I got around the validation error by making a accountsaccessrequest the prototype, "class accountsaccessrequest(meta.Model): pass". Although this tried to make two tables and would not work either. Any ideas how I should proceed. Workarounds? Kind Regards, Brian Ray
Database API Boolean Queries
Is there a full-proof way to query a Boolean Field? For Boolean matching I have been sending anything representative of true or false as string, "t" here for PostgreSQL <http://www.postgresql.org/docs/8.1/static/datatype-boolean.html>: beerlist = beers.get_list(domestic__exact="t"); Alhtough, I am unsure if this will work if I switch Database platforms. Is there a better way? Thanks, Brian Ray bray sent com http://brianray.chipy.org
Re: django interface
Reread the section "Serving the admin files" from <http://www.djangoproject.com/documentation/modpython/>. So, you have to move or point to the location of the media files and they need to be accessable from Apache. hth, Brian Ray bray sent com http://brianray.chipy.org
Manipulator Change calls INSERT
I get an SQL error when trying to Change an already displayed form field. When loggedin() returns True and changes have already been made at are currently trying to be submitted, this view is still tries to INSERT: def changeaccount(request): uid = '-1' if loggedin(request.user): uid = request.user.id thisuser = accounts.get_object(uid__exact=uid) manipulator = accounts.ChangeManipulator(thisuser.id) thisaccount = manipulator.original_object else: manipulator = accounts.AddManipulator() if request.POST: new_data = request.POST.copy() errors = manipulator.get_validation_errors(new_data) if not errors: manipulator.do_html2python(new_data) manipulator.save(new_data) return HttpResponseRedirect('/thanks') else: errors = new_data = {} if loggedin(request.user): new_data = thisaccount.__dict__ form = formfields.FormWrapper(manipulator, new_data, errors) return render_to_response('nwmail/account', {'form': form, 'uid':uid, 'loggedin':loggedin(request.user), 'searchbar':searchbar(request), 'crumbsbar':crumbsbar(request), }) The manipulator is a AccountManipulatorChange. I double checked by calling HttpResponse on manipulator.__class__.__name__. I do use a "_pre_save" in my model and I was wondering if this somehow was causing this unexpected behaviour. tia, Brian Ray <http://brianray.chipy.org> aim: brianray34
Any Django developers in Chicago?
Hey all, We are having a Django focused meetup with ChiPy (Chicago Python User Group) tomorrow night: RSVP http://chipy.org and/or http://www.meetup.com/_ChiPy_/events/220117890/ Talks will be recorded. Also looking for more talks. Hope to see some of you there. Warm Regards, Brian Ray -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c81a7151-8e73-41ab-80ee-f2e5535433ab%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.