Re: using the stable api
On Sat, 2009-08-01 at 19:59 +, Faheem Mitha wrote: > Hi Malcolm, > > Thanks for the helpful reply. > > On Sat, 01 Aug 2009 12:24:29 +1000, Malcolm Tredinnick >wrote: > > > On Fri, 2009-07-31 at 11:42 -0400, Faheem Mitha wrote: [...] > >> 3) Get the sessionid. I had to change request.COOKIES['sessionid'] > >> to request.COOKIES[settings.SESSION_COOKIE_NAME] > > > The default value of settings.SESSION_COOKIE_NAME has always (and > > remains) "sessionid". However, it's a little more portable to use > > the latter form (request.COOKIES[settings.SESSION_COOKIE_NAME) in > > your applications, since then they are usable no matter what the > > setting happens to be. A Django application writer is not > > necessarily in control of the settings that will be used when the > > application is installed. > > To summarize, I've changed settings.SESSION_COOKIE_NAME from their > default value, so this breaks request.COOKIES['sessionid'], and in > this case, using request.COOKIES[settings.SESSION_COOKIE_NAME) is > preferable, because it will work no matter what the value of > settings.SESSION_COOKIE_NAME happens to be. Is that a correct summary? Correct. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using the stable api
Hi Malcolm, Thanks for the helpful reply. On Sat, 01 Aug 2009 12:24:29 +1000, Malcolm Tredinnickwrote: > On Fri, 2009-07-31 at 11:42 -0400, Faheem Mitha wrote: >> >> Hi everybody, >> >> I upgraded from somewhere around Django 1.0 to 1.0.2, and some things >> broke and had to be changed. In the following, f is an object of class >> 'django.core.files.uploadedfile.TemporaryUploadedFile'. I need to >> >> 1) Get the contents of the file corresponding to f. I had to change >> f['content'] to f._file.read() >> >> From the docs (specifically, 'core/files/uploadedfile.py') it looks like >> f.read() might be the right thing? > The correct way to access uploaded file data is documented here: > http://docs.djangoproject.com/en/dev/topics/http/file-uploads > /#handling-uploaded-files > That is the public API, and you are correct in thinking that read() is > the method you're after here. >> 2) Get the filename of the file corresponding to f. I had to change >> f['filename'] to f._name. > This is also documented in the above reference. Use the "name" attribute > on the UploadedFile isntance. Ok, I will change these. >> 3) Get the sessionid. I had to change request.COOKIES['sessionid'] >> to request.COOKIES[settings.SESSION_COOKIE_NAME] > The default value of settings.SESSION_COOKIE_NAME has always (and > remains) "sessionid". However, it's a little more portable to use > the latter form (request.COOKIES[settings.SESSION_COOKIE_NAME) in > your applications, since then they are usable no matter what the > setting happens to be. A Django application writer is not > necessarily in control of the settings that will be used when the > application is installed. To summarize, I've changed settings.SESSION_COOKIE_NAME from their default value, so this breaks request.COOKIES['sessionid'], and in this case, using request.COOKIES[settings.SESSION_COOKIE_NAME) is preferable, because it will work no matter what the value of settings.SESSION_COOKIE_NAME happens to be. Is that a correct summary? >> It is presumably better to use a stable API rather than less stable >> internals, > It is *always* better. :-) Ok. Thanks. Regards, Faheem Mitha. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: using the stable api
On Fri, 2009-07-31 at 11:42 -0400, Faheem Mitha wrote: > > Hi everybody, > > I upgraded from somewhere around Django 1.0 to 1.0.2, and some things > broke and had to be changed. In the following, f is an object of class > 'django.core.files.uploadedfile.TemporaryUploadedFile'. I need to > > 1) Get the contents of the file corresponding to f. I had to change > f['content'] to f._file.read() > > From the docs (specifically, 'core/files/uploadedfile.py') it looks like > f.read() might be the right thing? The correct way to access uploaded file data is documented here: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files That is the public API, and you are correct in thinking that read() is the method you're after here. > > 2) Get the filename of the file corresponding to f. I had to change > f['filename'] to f._name. This is also documented in the above reference. Use the "name" attribute on the UploadedFile isntance. > > 3) Get the sessionid. I had to change request.COOKIES['sessionid'] to > request.COOKIES[settings.SESSION_COOKIE_NAME] The default value of settings.SESSION_COOKIE_NAME has always (and remains) "sessionid". However, it's a little more portable to use the latter form (request.COOKIES[settings.SESSION_COOKIE_NAME) in your applications, since then they are usable no matter what the setting happens to be. A Django application writer is not necessarily in control of the settings that will be used when the application is installed. > > It is presumably better to use a stable API rather than less stable > internals, It is *always* better. :-) Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google 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 -~--~~~~--~~--~--~---
using the stable api
Hi everybody, I upgraded from somewhere around Django 1.0 to 1.0.2, and some things broke and had to be changed. In the following, f is an object of class 'django.core.files.uploadedfile.TemporaryUploadedFile'. I need to 1) Get the contents of the file corresponding to f. I had to change f['content'] to f._file.read() >From the docs (specifically, 'core/files/uploadedfile.py') it looks like f.read() might be the right thing? 2) Get the filename of the file corresponding to f. I had to change f['filename'] to f._name. 3) Get the sessionid. I had to change request.COOKIES['sessionid'] to request.COOKIES[settings.SESSION_COOKIE_NAME] It is presumably better to use a stable API rather than less stable internals, so my question is - what is the best expression to use in the examples above so that they are less likely to break on upgrade? Please CC me on any reply. Regards, Faheem. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google 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 -~--~~~~--~~--~--~---