On 9/17/07, Jacob Kaplan-Moss <[EMAIL PROTECTED]> wrote:
> I think I prefer exposing file attributes as properties instead of
> methods (so ``myobject.file.name`` instead of
> ``myobject.file.get_filename()``. It just feels a bit cleaner, and it
> will allow setting in circumstances where appropriate.
Well, I'm a bit on the fence on this. Right now, the File object has
an attribute called "filename" which is precisely what's stored in the
database, so get_filename() would be the equivalent of
get_FIELD_filename(), which returns the absolute path to the file. So
the filename attribute is already read/write, though writing to it
won't really affect anything except to make get_absolute_url() point
to the wrong location. I wouldn't vote for having the full path
read/write, but I wouldn't be opposed to calling its method
get_absolute_path() instead of get_filename().
As for others, get_absolute_url() could just as easily be made into a
dsecriptor, but that doesn't fit as well with other uses of such a
function. I also hadn't considered this before, but I should probably
see if it's possible to get that method hooked into the {% url %} tag
somewhere.
And Michael's absolutely right about the need for laziness on some of
these. get_filesize(), get_width() and get_height() may have to make
an HTTP request (for S3, for instance) in order to retrieve the
information, so the options would be to set the attributes during
initialization of the object (slow on larger querysets, and not all
attributes will actually be used) or trick people into thinking that
it's just a regular attribute reference, even though there's HTTP
going on behind the scenes. I think a method is still good for those.
Besides, people are already used to calling methods for that
information, so it'd just be swapping out one method for another.
Obviously open() and save_file() would remain methods no matter what,
so I think that about covers all of the new API. So to sum up, I guess
I'm -0 on an attribute for URL (but +1 on making it work with {% url
%}), and -1 on the rest.
I suppose if you clarify what semantics you'd like to see in setting
those attributes, I might be swayed, but currently I'm not yet sure
what purpose would be served by doing so.
-Gul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---