Przeglądaj źródła

Python 3 support.

master
Nick Sergeant 7 lat temu
rodzic
commit
8642b7b44a
  1. 2
      requirements.txt
  2. 5
      settings.py
  3. 6
      snipts/api.py
  4. 6
      snipts/models.py
  5. 2
      snipts/templatetags/snipt_tags.py
  6. 2
      teams/views.py
  7. 5
      views.py

2
requirements.txt

@ -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

5
settings.py

@ -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:

6
snipts/api.py

@ -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'] = ''

6
snipts/models.py

@ -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')

2
snipts/templatetags/snipt_tags.py

@ -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

2
teams/views.py

@ -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

5
views.py

@ -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.')

Ładowanie…
Anuluj
Zapisz