encoding fix
This commit is contained in:
parent
7e43e78a7c
commit
1a0150e93f
|
@ -2,7 +2,7 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from ih import images
|
||||
#from ih import images
|
||||
import os
|
||||
|
||||
class Post(models.Model):
|
||||
|
@ -19,16 +19,17 @@ class Post(models.Model):
|
|||
return self.name
|
||||
|
||||
def thumb_name(self):
|
||||
x = str(self.file)
|
||||
t = x.split('/')
|
||||
|
||||
return '/thumb_' + t[1]
|
||||
x = os.path.split(self.file.name)[-1]
|
||||
return '/thumb_' + x
|
||||
|
||||
thumb_name = property(thumb_name)
|
||||
|
||||
def orig_name(self):
|
||||
x = str(self.file)
|
||||
return x.split('/')[1]
|
||||
|
||||
x = os.path.split(self.file.name)[-1]
|
||||
return x
|
||||
|
||||
orig_name = property(orig_name)
|
||||
|
||||
'''def resize_image(self.file):
|
||||
|
|
|
@ -31,15 +31,16 @@ from django.views.decorators.csrf import requires_csrf_token
|
|||
|
||||
|
||||
def create_thumb_from_file(filename):
|
||||
orig_file = 'mysite/media/images/' + str(filename)
|
||||
|
||||
print(filename)
|
||||
orig_file = 'imagehost/media/images/' + filename
|
||||
#f = str(filename)
|
||||
#print(filename)
|
||||
#print f
|
||||
# Create thumbnail
|
||||
print("DEBUG: Resizing image " + orig_file)
|
||||
thumb_name = images.resize_image(orig_file, {
|
||||
'name': filename,
|
||||
'size': [300, 300],
|
||||
'dest': 'mysite/media/images'
|
||||
'dest': 'imagehost/media/images'
|
||||
}
|
||||
|
||||
)
|
||||
|
@ -55,27 +56,28 @@ def image_new(request):
|
|||
# thumb_name = create_thumbnail(request)
|
||||
post = form.save(commit=False)
|
||||
post.save()
|
||||
print("FILE: ", post.file)
|
||||
#print("FILE: ", post.file)
|
||||
print post.orig_name
|
||||
create_thumb_from_file(post.orig_name)
|
||||
return redirect('imagehost.views.image_detail', pk=post.id)
|
||||
return redirect('imagehosting.views.image_detail', pk=post.id)
|
||||
else:
|
||||
form = PostForm()
|
||||
return render(request, 'imagehost/index.html', {'form': form})
|
||||
return render(request, 'imagehosting/index.html', {'form': form})
|
||||
|
||||
|
||||
def image_detail(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
print(post)
|
||||
return render(request, 'imagehost/image.html', {'post': post})
|
||||
return render(request, 'imagehosting/image.html', {'post': post})
|
||||
|
||||
|
||||
def all_posts(request):
|
||||
all = Post.objects.order_by('-pk')
|
||||
page = request.POST.get("page")
|
||||
return render(request, 'imagehost/all.html', {'all': all})
|
||||
return render(request, 'imagehosting/all.html', {'all': all})
|
||||
|
||||
def carousel(request):
|
||||
return render(request, 'imagehost/carousel.html', {'all': Post.objects.all()})
|
||||
return render(request, 'imagehosting/carousel.html', {'all': Post.objects.all()})
|
||||
|
||||
@requires_csrf_token
|
||||
def delete_post(request, pk):
|
||||
|
@ -86,8 +88,8 @@ def delete_post(request, pk):
|
|||
if not request.user.is_authenticated():
|
||||
return HttpResponseRedirect('/admin')
|
||||
post_to_delete.delete()
|
||||
return redirect('imagehost.views.all_posts')
|
||||
return redirect('imagehosting.views.all_posts')
|
||||
else:
|
||||
form = DeleteForm(instance=post_to_delete)
|
||||
|
||||
return render(request, 'imagehost/delete.html', {'form': form})
|
||||
return render(request, 'imagehosting/delete.html', {'form': form})
|
||||
|
|
Loading…
Reference in New Issue
Block a user