incorporate changes from kindle safe title changes.
Merge branch 'master' into kindle_file_size Conflicts: frontend/views.pypull/1/head
commit
b0550999e1
|
@ -9,6 +9,7 @@ import random
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
from ckeditor.fields import RichTextField
|
from ckeditor.fields import RichTextField
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
|
@ -1187,6 +1188,24 @@ class Work(models.Model):
|
||||||
return "%s et al." % self.authors()[0].name
|
return "%s et al." % self.authors()[0].name
|
||||||
return ''
|
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):
|
def last_campaign(self):
|
||||||
# stash away the last campaign to prevent repeated lookups
|
# stash away the last campaign to prevent repeated lookups
|
||||||
if hasattr(self, '_last_campaign_'):
|
if hasattr(self, '_last_campaign_'):
|
||||||
|
|
|
@ -179,7 +179,7 @@ function put_un_in_cookie2(){
|
||||||
<div class="jsmodule">
|
<div class="jsmodule">
|
||||||
<h3 class="module-title">News</h3>
|
<h3 class="module-title">News</h3>
|
||||||
<div class="jsmod-content">
|
<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>
|
</div>
|
||||||
<div class="jsmodule">
|
<div class="jsmodule">
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
{% block ce_content %}
|
{% block ce_content %}
|
||||||
<h2>Kindle email change successful</h2>
|
<h2>Kindle email change successful</h2>
|
||||||
<div id="content-main">
|
<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 %}
|
{% if work %}
|
||||||
<p>
|
<p>
|
||||||
We're now emailing you the ebook you wanted, <i><a href="{% url work work.id %}">{{ work.title }}</a></i>...
|
We're now emailing you the ebook you wanted, <i><a href="{% url work work.id %}">{{ work.title }}</a></i>...
|
||||||
|
|
|
@ -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.)
|
(If you'd like to change your Kindle email, you can do so below. You'll need to download the book again.)
|
||||||
</p>
|
</p>
|
||||||
{% else %}
|
{% 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>You can change it below.</p>
|
||||||
<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.
|
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>
|
<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.
|
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>
|
||||||
<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 %}
|
{% endif %}
|
||||||
{% if work %}
|
{% if work %}
|
||||||
<form method="post" action="{% url kindle_config_download work.id %}">{% csrf_token %}
|
<form method="post" action="{% url kindle_config_download work.id %}">{% csrf_token %}
|
||||||
|
|
|
@ -3150,7 +3150,11 @@ def kindle_config(request, work_id=None):
|
||||||
template = "kindle_change_successful.html"
|
template = "kindle_change_successful.html"
|
||||||
else:
|
else:
|
||||||
form = KindleEmailForm()
|
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
|
@require_POST
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -3186,8 +3190,9 @@ def send_to_kindle(request, work_id, javascript='0'):
|
||||||
ebook_url = acq.get_mobi_url()
|
ebook_url = acq.get_mobi_url()
|
||||||
ebook_format = 'mobi'
|
ebook_format = 'mobi'
|
||||||
filesize = None
|
filesize = None
|
||||||
title = acq.work.title
|
title = acq.work.kindle_safe_title()
|
||||||
ebook=None
|
ebook=None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
non_google_ebooks = work.ebooks().exclude(provider='Google Books')
|
non_google_ebooks = work.ebooks().exclude(provider='Google Books')
|
||||||
try:
|
try:
|
||||||
|
@ -3204,8 +3209,7 @@ def send_to_kindle(request, work_id, javascript='0'):
|
||||||
ebook_format = ebook.format
|
ebook_format = ebook.format
|
||||||
filesize = ebook.filesize
|
filesize = ebook.filesize
|
||||||
logger.info('ebook: {0}, user_ip: {1}'.format(work_id, request.META['REMOTE_ADDR']))
|
logger.info('ebook: {0}, user_ip: {1}'.format(work_id, request.META['REMOTE_ADDR']))
|
||||||
title = ebook.edition.title
|
title = ebook.edition.work.kindle_safe_title()
|
||||||
title = title.replace(' ', '_')
|
|
||||||
context['ebook_url']=ebook_url
|
context['ebook_url']=ebook_url
|
||||||
context['ebook_format']=ebook_format
|
context['ebook_format']=ebook_format
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue