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

Fixes to make it work with Django 1.6.5 and Pillow instead of PIL #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions crowdsourcing/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import


import datetime
import logging
from math import sin, cos
from operator import itemgetter
Expand All @@ -13,6 +11,7 @@
except ImportError:
import json

from django.utils import timezone
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.cache import cache
Expand Down Expand Up @@ -73,7 +72,7 @@

class LiveSurveyManager(models.Manager):
def get_query_set(self):
now = datetime.datetime.now()
now = timezone.now()
return super(LiveSurveyManager, self).get_query_set().filter(
is_published=True,
starts_at__lte=now).filter(
Expand Down Expand Up @@ -116,7 +115,7 @@ class Survey(models.Model):
"post-close: Results are public on or after the "
"\"ends at\" option documented below. never: Results are "
"never public."))
starts_at = models.DateTimeField(default=datetime.datetime.now)
starts_at = models.DateTimeField(default=timezone.now)
survey_date = models.DateField(blank=True, null=True, editable=False)
ends_at = models.DateTimeField(null=True, blank=True)
is_published = models.BooleanField(default=False)
Expand Down Expand Up @@ -171,14 +170,14 @@ class Meta:

@property
def is_open(self):
now = datetime.datetime.now()
now = timezone.now()
if self.ends_at:
return self.starts_at <= now < self.ends_at
return self.starts_at <= now

@property
def is_live(self):
now = datetime.datetime.now()
now = timezone.datetime.now()
return all([
self.is_published,
self.starts_at <= now,
Expand Down Expand Up @@ -321,7 +320,7 @@ class Question(models.Model):
max_length=max([len(key) for key, v in OPTION_TYPE_CHOICES._choices]),
choices=OPTION_TYPE_CHOICES,
help_text=_('You must not change this field on a live survey.'))
# For NUMERIC_(SELECT|CHOICE) use it as an int unless they use a decimal.
# For NUMERIC_(SELECT|CHOICE) use it as an int unless they use a decimal.
numeric_is_int = models.BooleanField(default=True, editable=False)
options = models.TextField(
blank=True,
Expand Down Expand Up @@ -560,7 +559,7 @@ def _extra_from_distance(filter, submission_id_column):
"%f * cos(latitude / %f) * "
"cos((longitude - %f) / %f)") % acos_of_args
# if acos_of >= 1 then the address in the database is practically the
# same address we're searching for and acos(acos_of) is mathematically
# same address we're searching for and acos(acos_of) is mathematically
# impossible so just always include it. If acos_of < 1 then we need to
# check the distance.
where = "".join((
Expand Down Expand Up @@ -732,7 +731,7 @@ class Submission(models.Model):
survey = models.ForeignKey(Survey)
user = models.ForeignKey(User, blank=True, null=True)
ip_address = models.IPAddressField()
submitted_at = models.DateTimeField(default=datetime.datetime.now)
submitted_at = models.DateTimeField(default=timezone.now)
session_key = models.CharField(max_length=40, blank=True, editable=False)
featured = models.BooleanField(default=False)

Expand Down
6 changes: 3 additions & 3 deletions crowdsourcing/templatetags/crowdsourcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.template import Node
from django.utils.safestring import mark_safe
from django.utils.html import escape, strip_tags, linebreaks
from sorl.thumbnail.base import ThumbnailException
from sorl.thumbnail.helpers import ThumbnailError

from crowdsourcing.models import (
extra_from_filters, AggregateResultCount, AggregateResultSum,
Expand Down Expand Up @@ -618,7 +618,7 @@ def simple_slideshow(display, question, request_GET, css):
for answer in answers:
try:
image = answer.image_answer.thumbnail_tag
except ThumbnailException:
except ThumbnailError:
image = "Can't find %s" % answer.image_answer.url
out.extend([
'<li>',
Expand Down Expand Up @@ -673,7 +673,7 @@ def submission_fields(submission,
args = (thmb, answer.id,)
out.append('<img src="%s" id="img_%d" />' % args)
x_y = get_image_dimensions(answer.image_answer.file)
except ThumbnailException as ex:
except ThumbnailError as ex:
valid = False
out.append('<div class="error">%s</div>' % str(ex))
thumb_width = Answer.image_answer_thumbnail_meta["size"][0]
Expand Down
2 changes: 1 addition & 1 deletion crowdsourcing/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import

from django.conf.urls.defaults import patterns, url
from django.conf.urls import patterns, url

from .views import (allowed_actions,
embeded_survey_questions,
Expand Down
8 changes: 4 additions & 4 deletions crowdsourcing_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# $ pip install -r crowdsourcing_requirements.txt

# Python Image Library for processing image answers.
PIL>=1.1.6
Pillow

# for image thumbnailing
sorl-thumbnail==3.2.5
sorl-thumbnail==11.12.1b

# for ordering inlines
-e git://github.com/jpwatts/django-positions.git#egg=django-positions
django-positions==0.5.1

# For geocoding addresses and address lookups
geopy
Expand All @@ -20,7 +20,7 @@ geopy

# For Flickr support. Crowdsourcing is fairly graceful if you don't install
# flickrapi.
flickrapi
# flickrapi

# For asynchronously synching Flickr. Sync synchronously by default.
# carrot>=0.10.3
Expand Down