Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 Issues #82

Merged
merged 2 commits into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions smartmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,9 @@ def get_form(self, form_class=None):

if fields is not None:
# filter out our form fields
for name, field in self.form.fields.items():
if not name in fields:
del self.form.fields[name]
remove = [name for name in self.form.fields.keys() if name not in fields]
for name in remove:
del self.form.fields[name]

# stuff in our referer as the default location for where to return
location = forms.CharField(widget=forms.widgets.HiddenInput(), required=False)
Expand Down
8 changes: 5 additions & 3 deletions smartmin/widgets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import unicode_literals

import six

from datetime import datetime
from django.forms import widgets
from django.utils.html import escape
Expand Down Expand Up @@ -50,8 +52,8 @@ def value_from_datadict(self, data, files, name):
return None

class Media:
js = ('js/datepicker.js',)
css = {'all': ('css/datepicker.css',)}
js = ('js/datepicker.js',)
css = {'all': ('css/datepicker.css',)}


class ImageThumbnailWidget(widgets.ClearableFileInput):
Expand All @@ -70,4 +72,4 @@ def render(self, name, value, attrs=None):
thumb_html += '<input type="file" name="%s" /></td>' % name
thumb_html += '</tr></table>'

return mark_safe(unicode('<div class="image-picker">%s</div>' % thumb_html))
return mark_safe(six.text_type('<div class="image-picker">%s</div>' % thumb_html))
17 changes: 17 additions & 0 deletions test_runner/blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.conf import settings
from django.contrib.auth.models import User, Group
from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
Expand All @@ -20,6 +21,7 @@
from smartmin.tests import SmartminTest
from smartmin.users.models import FailedLogin, RecoveryToken, PasswordHistory
from smartmin.views import smart_url
from smartmin.widgets import ImageThumbnailWidget
from test_runner.blog.models import Post, Category
from .views import PostCRUDL

Expand Down Expand Up @@ -1150,3 +1152,18 @@ def test_expiration(self):

self.assertEquals(302, response.status_code)
self.assertIn(reverse('blog.post_list'), response['location'])


class WidgetsTest(SmartminTest):
def test_image_thumbnail(self):
widget = ImageThumbnailWidget(320, 240)
img = SimpleUploadedFile('test_image.jpg', [], content_type='image/jpeg')

html = widget.render('logo', img)

self.assertNotIn('img', html)

img.url = '/media/2423.jpg'
html = widget.render('logo', img)

self.assertIn('<img src="/media/2423.jpg" width="320" width="240" />', html)