Skip to content

Commit

Permalink
[Bug #126300921] Delete image during photo deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Nwuguru Sunday committed Jul 15, 2016
1 parent 2290788 commit ff61cb2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/photos/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.shortcuts import get_object_or_404
from django.views.generic import View
from django.http import HttpResponse, HttpResponseNotFound
import json
import json, os
import time
from rest_framework.generics import (
ListCreateAPIView,
Expand Down Expand Up @@ -213,6 +213,15 @@ class SinglePhotoAPIView(RetrieveUpdateDestroyAPIView):
permission_classes = [IsOwner]
lookup_field = 'id'

def perform_destroy(self, instance):
if(os.path.isfile(instance.image.path)):
os.remove(instance.image.path)

if(os.path.isfile(instance.image.path.replace('main', 'edited'))):
os.remove(instance.image.path.replace('main', 'edited'))

instance.delete()


class PhotoDetailAPIView(RetrieveUpdateDestroyAPIView):

Expand Down
2 changes: 2 additions & 0 deletions app/static/build/client.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -52353,6 +52353,7 @@
}, {
key: 'updateComplete',
value: function updateComplete(result) {
this.setState({ loaded: true });
if (result.status == 200) {
Toast.ok('Photo updated');
} else {
Expand Down Expand Up @@ -52443,6 +52444,7 @@
key: 'onSubmit',
value: function onSubmit(e) {
e.preventDefault();
this.setState({ loaded: false });
var form = this.getFormData();
_PhotoStore2.default.update(form);
}
Expand Down
2 changes: 2 additions & 0 deletions app/static/components/EditImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class extends React.Component {
}

updateComplete(result){
this.setState({loaded: true});
if(result.status == 200){
Toast.ok('Photo updated')
}else{
Expand Down Expand Up @@ -137,6 +138,7 @@ export default class extends React.Component {

onSubmit(e) {
e.preventDefault();
this.setState({loaded: false});
var form = this.getFormData();
storePhoto.update(form);
}
Expand Down

0 comments on commit ff61cb2

Please sign in to comment.