Skip to content

Commit

Permalink
[Fix #126689795] Fix share
Browse files Browse the repository at this point in the history
  • Loading branch information
Nwuguru Sunday committed Jul 20, 2016
1 parent c4913ad commit cec03e8
Show file tree
Hide file tree
Showing 6 changed files with 1,307 additions and 1,293 deletions.
1 change: 1 addition & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
url(r'^$', views.index),
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^logout/$', views.logout_view),
url(r'^download/$', views.download),
url(r'^api/v1/', include('photos.api.urls', namespace="api")),
]

Expand Down
7 changes: 7 additions & 0 deletions app/photos/api/image_edit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.http import HttpResponse
from PIL import (
Image, ImageFilter,
ImageOps, ImageStat,
Expand Down Expand Up @@ -165,3 +166,9 @@ def save(self):
if not os.path.exists(edit_path):
os.makedirs(edit_path)
self.output.save(path, format=self.image_format)

def download(self, title):
response = HttpResponse(content_type="image/jpg")
self.output.save(response, 'JPEG')
response['Content-Disposition'] = 'attachment; filename="{}.jpg"'.format(title)
return response
12 changes: 12 additions & 0 deletions app/photos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import redirect
import urllib
from photos.models import Photo
from photos.api.image_edit import *

# Create your views here.

Expand All @@ -18,3 +21,12 @@ def index(request):
def logout_view(request):
logout(request)
return redirect('/')


def download(request):
id = request.GET.get('image')
photo = Photo.objects.get(id=id)
if photo:
image = ImageEdit(photo.image.path.replace('main','edited'))
return image.download(photo.title)
return redirect('/')
Loading

0 comments on commit cec03e8

Please sign in to comment.