incorporate changes from kindle safe title changes.

Merge branch 'master' into kindle_file_size

Conflicts:
	frontend/views.py
pull/1/head
Raymond Yee 2015-03-09 10:56:20 -07:00
commit b0550999e1
5 changed files with 34 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import random
import urllib
import urllib2
from urlparse import urlparse
import unicodedata
from ckeditor.fields import RichTextField
from datetime import timedelta, datetime
@ -1187,6 +1188,24 @@ class Work(models.Model):
return "%s et al." % self.authors()[0].name
return ''
def kindle_safe_title(self):
"""
Removes accents, keeps letters and numbers, replaces non-Latin characters with "#", and replaces punctuation with "_"
"""
safe = u''
nkfd_form = unicodedata.normalize('NFKD', self.title) #unaccent accented letters
for c in nkfd_form:
ccat = unicodedata.category(c)
#print ccat
if ccat.startswith('L') or ccat.startswith('N'): # only letters and numbers
if ord(c) > 127:
safe = safe + '#' #a non latin script letter or number
else:
safe = safe + c
elif not unicodedata.combining(c): #not accents (combining forms)
safe = safe + '_' #punctuation
return safe
def last_campaign(self):
# stash away the last campaign to prevent repeated lookups
if hasattr(self, '_last_campaign_'):

View File

@ -179,7 +179,7 @@ function put_un_in_cookie2(){
<div class="jsmodule">
<h3 class="module-title">News</h3>
<div class="jsmod-content">
Blog: <a href="http://blog.unglue.it/2014/12/23/new-at-unglue-it-buy-as-a-gift/">New at Unglue.it: Buy as a Gift</a>
Blog: <a href="http://blog.unglue.it/2015/02/27/unglue-it-joins-gitenberg/">Unglue.it joins GITenberg</a>
</div>
</div>
<div class="jsmodule">

View File

@ -23,7 +23,9 @@
{% block ce_content %}
<h2>Kindle email change successful</h2>
<div id="content-main">
<p>Hooray! We can now send most unglued ebooks to you at {{ request.user.profile.kindle_email }}. Some ebooks are too big for us to send, though.</p>
<p>{% if ok_email %}Hooray! We can now send most unglued ebooks to you at {{ request.user.profile.kindle_email }}. Some ebooks are too big for us to send, though.
{% else %}<span class="yikes">{{ request.user.profile.kindle_email }} is probably not the right email for your Kindle; most Kindles use an @kindle.com email address. You can <a href="{% url kindle_config %}">change it</a>, but we'll try sending it anyway.</span> {% endif %}</p>
{% if work %}
<p>
We're now emailing you the ebook you wanted, <i><a href="{% url work work.id %}">{{ work.title }}</a></i>...

View File

@ -33,7 +33,8 @@
(If you'd like to change your Kindle email, you can do so below. You'll need to download the book again.)
</p>
{% else %}
<p>You already have a Kindle email on file with Unglue.it: {{ kindle_email }} .</p>
<p>You already have a Kindle email on file with Unglue.it: {{ kindle_email }} .
{% if not ok_email %}<span class="yikes">That's probably not the right email; most Kindles use an @kindle.com email address.</span> {% endif %}</p>
<p>You can change it below.</p>
<p>
If you emailed yourself an Unglue.it ebook and got a message from Amazon that the sender is not in your approved email list, add <b>notices@gluejar.com</b> to your <a href="http://www.amazon.com/myk#pdocSettings">Approved Personal Document Email List</a> under Personal Document Settings.
@ -43,7 +44,7 @@
<p>
Before your device or app can receive emails from Unglue.it, you'll have to add <b>notices@gluejar.com</b> to your <a href="http://www.amazon.com/myk#pdocSettings">Approved Personal Document Email List</a> under Personal Document Settings.
</p>
<p>Then, enter your Kindle email address below:</p>
<p>Then, enter your Kindle email address below (most Kindles use an @kindle.com email address.):</p>
{% endif %}
{% if work %}
<form method="post" action="{% url kindle_config_download work.id %}">{% csrf_token %}

View File

@ -3150,7 +3150,11 @@ def kindle_config(request, work_id=None):
template = "kindle_change_successful.html"
else:
form = KindleEmailForm()
return render(request, template, {'form': form, 'work': work})
return render(request, template, {
'form': form,
'work': work,
'ok_email': request.user.profile.kindle_email and ('kindle' in request.user.profile.kindle_email),
})
@require_POST
@csrf_exempt
@ -3186,8 +3190,9 @@ def send_to_kindle(request, work_id, javascript='0'):
ebook_url = acq.get_mobi_url()
ebook_format = 'mobi'
filesize = None
title = acq.work.title
title = acq.work.kindle_safe_title()
ebook=None
else:
non_google_ebooks = work.ebooks().exclude(provider='Google Books')
try:
@ -3204,8 +3209,7 @@ def send_to_kindle(request, work_id, javascript='0'):
ebook_format = ebook.format
filesize = ebook.filesize
logger.info('ebook: {0}, user_ip: {1}'.format(work_id, request.META['REMOTE_ADDR']))
title = ebook.edition.title
title = title.replace(' ', '_')
title = ebook.edition.work.kindle_safe_title()
context['ebook_url']=ebook_url
context['ebook_format']=ebook_format