*Hi Andy, somehow my earlier post got deleted--must have hit the wrong 
button or something.  So I'm reposting it below...*

Thanks for posting on the forum about this... I added the S3 bucket info to 
the documentation, but didn't think to test deleting files from it.  After 
trying it out a little bit ago, I got the same result as you did.  What is 
happening is that the db resource is deleted, but Django hits an error 
while trying to delete the actual file on S3 (that's why the redirect 
didn't work).  You'll see that the files you were trying to delete still 
exist in your bucket.

I was able to fix it up, drawing mainly from this question 
<http://stackoverflow.com/questions/5372934/how-do-i-get-django-admin-to-delete-files-when-i-remove-an-object-from-the-datab>
 (see 
the second answer, and its comments).  It will be easy for you to do in 
this one case, but will require some more info in the documentation, and 
ultimately a modification in the arches code to accommodate S3 storage.

For now, *carefully* head into your virtual environment, and open up this 
file: ENV/lib/python2.7/site-packages/arches/app/models/models.py.  Be sure 
to back it up before you do!  Around line 433 is a function 
called auto_delete_file_on_delete().  In that function, you'll see a line 
that says "if os.path.isfile(instance.val.path):"  That line is causing a 
server error, because instance.val doesn't have a path property when you 
use S3 storage (it has a url property).  
To make the fix, replace the contents of the function with this (note that 
the same first line is used):

    if instance.val:
        try:
            if os.path.isfile(instance.val.path):
                os.remove(instance.val.path)
        except:
            storage, name = instance.val.storage, instance.val.name
            storage.delete(name)

Now it'll still try the old method, but when it comes across an error 
(a.k.a. "exception") it'll skip to the new code that is necessary for 
dealing with S3.

This is really a hack, not a fix, but if you are careful about the 
indentation I think you'll be able to manage just fine.  Also, if you are 
using a text editor like notepad++, be sure that you are using 4 spaces 
(not tab) to make the indentation (4 spaces per indent).

Good luck and thanks again for posting!
Adam

On Wednesday, October 21, 2015 at 3:38:32 PM UTC-5, Andy Graham wrote:
>
> Hello All,
> A question about an error I am getting trying to delete Media resources on 
> S3.  When I delete the resource via the Resource Manager (Delete Resource 
> in the left side tool bar) I get the message that states "You won't be able 
> to undo this operation!", then I click on the Delete button and nothing 
> happens, however, if I go back to the Map or Search the resource has been 
> deleted.
>
> Using the developer tools for the browser I have traced the error back to 
> the delete-resource.js in the arches/app/media/js/views/forms  folder.
>
> Specifically:
>
>         deleteResource: function() {
>             $.ajax({
>                 method: 'DELETE',
>                 url: '',
>                 success: function() {
>                     location.href = arches.urls.home;
>                 }
>             });
>
> The error seems to be taking place at the url:, which isn't populated. 
>  Does anyone have suggestions for the proper way to reference the S3 bucket 
> here, and if there are any specific permissions that need to be set to 
> allow deleting files from S3?  Any help is appreciated, thanks.
>
> Andy
>

-- 
-- To post, send email to [email protected]. To unsubscribe, send 
email to [email protected]. For more information, 
visit https://groups.google.com/d/forum/archesproject?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Arches Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to