Browse Source

Python 3 support.

master
Nick Sergeant 6 years ago
parent
commit
8642b7b44a
7 changed files with 16 additions and 12 deletions
  1. +1
    -1
      requirements.txt
  2. +4
    -1
      settings.py
  3. +3
    -3
      snipts/api.py
  4. +3
    -3
      snipts/models.py
  5. +1
    -1
      snipts/templatetags/snipt_tags.py
  6. +1
    -1
      teams/views.py
  7. +3
    -2
      views.py

+ 1
- 1
requirements.txt View File

@@ -10,7 +10,7 @@ django-debug-toolbar==1.3.2
django-extensions==1.5.7
django-haystack==2.4.0
django-markdown-deux==1.0.5
django-pagination==1.0.7
django-pagination-py3==1.1.0
django-registration-redux==1.2
django-storages==1.1.8
django-taggit==0.16.2


+ 4
- 1
settings.py View File

@@ -1,7 +1,10 @@
import dj_database_url
import os

from urlparse import urlparse
try:
from urlparse import urlparse
except ImportError:
from urllib import parse as urlparse


if 'DATABASE_URL' in os.environ:


+ 3
- 3
snipts/api.py View File

@@ -191,7 +191,7 @@ class PublicUserResource(ModelResource):
def dehydrate(self, bundle):
bundle.data['snipts'] = '/api/public/snipt/?user=%d' % bundle.obj.id
bundle.data['email_md5'] = hashlib \
.md5(bundle.obj.email.lower()) \
.md5(bundle.obj.email.lower().encode('utf-8')) \
.hexdigest()
bundle.data['snipts_count'] = Snipt.objects.filter(user=bundle.obj.id,
public=True).count()
@@ -333,7 +333,7 @@ class PrivateUserResource(ModelResource):

def dehydrate(self, bundle):
bundle.data['email_md5'] = hashlib \
.md5(bundle.obj.email.lower()) \
.md5(bundle.obj.email.lower().encode('utf-8')) \
.hexdigest()
bundle.data['has_pro'] = bundle.obj.profile.has_pro
bundle.data['stats'] = {
@@ -452,7 +452,7 @@ class PrivateSniptResource(ModelResource):
bundle.data['modified'] = None
bundle.data['user'] = user

if type(bundle.data['tags']) in (str, unicode):
if type(bundle.data['tags']) == str:
bundle.data['tags_list'] = bundle.data['tags']
else:
bundle.data['tags_list'] = ''


+ 3
- 3
snipts/models.py View File

@@ -71,9 +71,9 @@ class Snipt(models.Model):
self.slug = slugify_uniquely(self.title, Snipt)

if not self.key:
self.key = hashlib.md5(self.slug +
str(datetime.datetime.now()) +
str(random.random())).hexdigest()
self.key = hashlib.md5((self.slug +
str(datetime.datetime.now()) +
str(random.random())).encode('utf-8')).hexdigest()

if self.lexer == 'markdown':
self.stylized = markdown(self.code, 'default')


+ 1
- 1
snipts/templatetags/snipt_tags.py View File

@@ -60,7 +60,7 @@ def generate_line_numbers(context, line_numbers):

@register.filter
def md5(string):
return hashlib.md5(string.lower()).hexdigest()
return hashlib.md5(string.lower().encode('utf-8')).hexdigest()


@register.filter


+ 1
- 1
teams/views.py View File

@@ -36,7 +36,7 @@ def for_teams_complete(request):
customer = stripe.Customer.create(card=token,
plan=plan,
email=request.user.email)
except stripe.CardError, e:
except stripe.CardError as e:
error_message = e.json_body['error']['message']
return HttpResponseRedirect('/for-teams/?declined=%s' %
error_message or


+ 3
- 2
views.py View File

@@ -36,7 +36,8 @@ def homepage(request):
user=user, public=True).values('pk').count()

if public_snipts_count:
user.email_md5 = hashlib.md5(user.email.lower()).hexdigest()
user.email_md5 = hashlib.md5(user.email.lower().encode('utf-8')) \
.hexdigest()
coders.append(user)

if len(coders) == 35:
@@ -107,7 +108,7 @@ def pro_complete(request):
customer = stripe.Customer.create(card=token,
plan=plan,
email=request.user.email)
except stripe.CardError, e:
except stripe.CardError as e:
error_message = e.json_body['error']['message']
return HttpResponseRedirect('/pro/?declined=%s' % error_message or
'Your card was declined.')


Loading…
Cancel
Save