Sphene Community Tools

Community

Copyright © 2007-2018 by Herbert Poul

You are not logged in.
Login
Register

Change Language:



AddThis Social Bookmark Button

A Django site.

Powered by Sphene Community Tools
Board » General » attachment -> file.foo + file_.foo

I have some unexpected behavior with attachments.

1 - uploaded twice
If I attach a file to a snip the file ends up twice in my machine (once as "*.*" and then again as "*_.*").

Deleting the attachment via the web-interface only takes care of the file called *_.*, leaving the file with the nice filename in the filesystem.

I looked at WikiAttachment.save and it seems very sane - do you have any idea where my strange behaviour is coming from, and why (perhaps it is the expected and desired modus operandi).

I get the impression that the file is uploaded once as a file or something and then again as the proper attachment (?).

Or am I missing something?


2 - url to attachments
Also the links to attachments seem strange: the href I get is "var/sphene/sphwiki/attachment/..." whereas I would have expected MEDIA_ROOT + "var/sphene/sphwiki/attachment/..." since this is where it ends up in the machine.

Again: am I just missing some setting?

Thanks,

/Per
Per Strandberg said @ 2008-05-22 09:36:28:
[...]
href I get is "var/sphene/sphwiki/attachment/..." whereas I would have expected MEDIA_ROOT + "var/sphene/sphwiki/attachment/..." since this is where it ends up in the machine.
[...]
I overrode and edited "macros/_attachments.html".

Thanks for your patience :)

/P
Per Strandberg said @ 2008-05-22 09:51:28:
Per Strandberg said @ 2008-05-22 09:36:28:
[...]
href I get is "var/sphene/sphwiki/attachment/..." whereas I would have expected MEDIA_ROOT + "var/sphene/sphwiki/attachment/..." since this is where it ends up in the machine.
[...]
I overrode and edited "macros/_attachments.html".

[...]
But now I have the same problem with images so my spider sense is tingling. I think my problem is that the file ends up in one place and the file thinks it is ending up somewhere else.

in class ImageMacro.handleMacroCall:
el.setAttribute( 'src', attachment.get_fileupload_url() )


That looks perfect to me - so I started looking at get_fileupload_url() and I do not see any special magic anywhere in WikiAttachment so I guess it's the django default action I get :(

Any help is welcome,
Per
most fileupload magic is done by django .. i'm just using the 'FileField' :)

http://www.djangoproject.com/documentation/model-api/#filefield

but.. as you can see in the above link .. all upload should be in MEDIA_ROOT

upload_to A local filesystem path that will be appended to your MEDIA_ROOT setting to determine the output of the get_<fieldname>_url() helper function.


so the files should be under <MEDIA_ROOT>/var/sphene/sphwiki/attachments/2008/05/22/

if you don't like the above after MEDIA_ROOT you can change it using the SPH_SETTING wiki_attachments_upload_to

the default value is:

    'wiki_attachments_upload_to': 'var/sphene/sphwiki/attachment/%Y/%m/%d',




as for your first problem regarding the underscores (*_.*) .. unfortunately this is always added by django if it detects a file in the filesystem with the same name..

hmm.. i just tried it myself ... and i saw that if i upload a file once .. it will be stored twice.. this is weird .. i see if i can debug it .. at least i can reproduce the problem :|

Hey, we have Signatures !!! Great, isn't it ? ;)
ok .. i found the problem..
the attachment got saved twice into the model's FileField ... once by the Form itself and a second time by myself in the view.. (don't ask me why i saved it a second time.. :( )

http://yourhell.com/wsvn/root/django/communitytools/trunk/sphenecoll/sphene/sphwiki/views.py?op=diff&rev=616&sc=1

anyway .. update from SCT trunk .. and it should work

thanks for the bug report :)
herbert
Hey, we have Signatures !!! Great, isn't it ? ;)
[...]
so the files should be under <MEDIA_ROOT>/var/sphene/sphwiki/attachments/2008/05/22/

if you don't like the above after MEDIA_ROOT you can change it using the SPH_SETTING wiki_attachments_upload_to

[...]
No, I am happy with wherever they end up - that is related to my problem but not exactly my problem.

When I make an attachment I have difficulties linking to it from a wiki page.

When I create a link (from within a wiki page) then...
Per Strandberg said @ 2008-05-22 09:36:28:
[...]
the href I get is "var/sphene/sphwiki/attachment/..."
[...]
I would have expected MEDIA_ROOT + "var/sphene/sphwiki/attachment/..."
[...]


So all links to attachments in the wiki snippets are wrong.

Any ideas?

Thanks,
Per
are you sure you have defined MEDIA_URL in settings.py ?

the get_fileupload_url() should use settings.MEDIA_URL + filepath
Hey, we have Signatures !!! Great, isn't it ? ;)
are you sure you have defined MEDIA_URL in settings.py ?

the get_fileupload_url() should use settings.MEDIA_URL + filepath
Ok, then I can be sure the problem is in my system any way.

Thanks,
Per
FYI - MEDIA_ROOT is the path on the local filesystem to the media directory and MEDIA_URL is for the public URLs .. so maybe these two aren't set correctly for you ..

and check the django code django/db/models/base.py line 439 (method _get_FIELD_url):

    def _get_FIELD_url(self, field):
        if getattr(self, field.attname): # value is not blank
            import urlparse
            return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.attname)).replace('\\', '/')
        return ''


this is where MEDIA_URL is prepanded to the file path .. so maybe you could start debugging there if you are still experiencing problems
Hey, we have Signatures !!! Great, isn't it ? ;)
[...] MEDIA_URL is for the public URLs [...]
Of course!

My MEDIA_URL was just blank - for some reason we had missed it...

Thanks :) :) :)

/Per

Please login to post a reply.



Powered by Sphene Community Tools