Merge pull request #143 from Gluejar/seo

sitemap, schema.org and fix bad urls in wishlist feeds
pull/1/head
Raymond Yee 2013-03-15 14:43:55 -07:00
commit 494457ae73
12 changed files with 93 additions and 35 deletions

View File

@ -15,7 +15,7 @@ class SupporterWishlistFeed(Feed):
return "Latest wishbooks for %s on unglue.it" % obj.username
def link(self, obj):
return "/%s/feed/" % obj.username
return "/supporter/%s/feed/" % obj.username
def item_title(self, item):
return "%s" % item.title
@ -24,4 +24,4 @@ class SupporterWishlistFeed(Feed):
return "/work/%s" % item.id
def items(self, obj):
return obj.wishlist.works.all().order_by('-id')[:5]
return obj.wishlist.works.all().order_by('-id')[:100]

View File

@ -13,9 +13,11 @@ from django.db import models
from django.db.models import Q, get_model
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
import regluit
import regluit.core.isbn
from regluit.core.signals import successful_campaign, unsuccessful_campaign, wishlist_added
@ -816,6 +818,9 @@ class Work(models.Model):
except:
return False
def get_absolute_url(self):
return reverse('work', args=[str(self.id)])
class Author(models.Model):
created = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=500)

View File

@ -249,7 +249,7 @@ def handle_wishlist_added(supporter, work, **kwargs):
notification.send([claim[0].user], "new_wisher", {
'supporter': supporter,
'work': work,
'base_url': settings.BASE_URL,
'base_url': settings.BASE_URL_SECURE,
}, True)
from regluit.core.tasks import emit_notifications
@ -269,13 +269,13 @@ def handle_wishlist_near_deadline(campaign, **kwargs):
notification.send(pledgers, "wishlist_near_deadline", {
'campaign': campaign,
'domain': settings.BASE_URL,
'domain': settings.BASE_URL_SECURE,
'pledged': True,
}, True)
notification.send(nonpledgers, "wishlist_near_deadline", {
'campaign': campaign,
'domain': settings.BASE_URL,
'domain': settings.BASE_URL_SECURE,
'pledged': False,
}, True)

37
core/sitemaps.py Normal file
View File

@ -0,0 +1,37 @@
from django.contrib.sitemaps import Sitemap
from django.core.urlresolvers import reverse
from regluit.core.models import Work, Edition
class WorkSitemap(Sitemap):
protocol = 'https'
limit = 10000
def items(self):
return Work.objects.all()
def priority(self,work):
if work.last_campaign():
return '1.0'
if work.num_wishes>1000:
return '0.8'
if work.num_wishes>100:
return '0.6'
if work.num_wishes>10:
return '0.4'
if work.num_wishes>1:
return '0.3'
if work.num_wishes==1:
return '0.2'
if work.num_wishes==0:
return '0.1'
return '0.1'
class PublisherSitemap(Sitemap):
priority = 0.2
protocol = 'https'
def items(self):
return Edition.objects.exclude(publisher__isnull=True).exclude(publisher="").order_by('publisher').values('publisher').distinct()
def location(self, pub):
return reverse("bypub_list",args=[pub['publisher']])

View File

@ -2,7 +2,7 @@
{% block title %} Everything You Always Wanted to Know {% endblock %}
{% block doccontent %}
<h2>About</h2>
<p><a href="http://unglue.it">Unglue.it</a> is a service provided by <a href="http://gluejar.com">Gluejar, Inc.</a> It's a place for individuals and institutions to join together to liberate specific ebooks and other types of digital content by paying rights holders to relicense their works under <a href="http://creativecommons.org">Creative Commons</a> licenses.</p>
<p><a href="https://unglue.it">Unglue.it</a> is a service provided by <a href="http://gluejar.com">Gluejar, Inc.</a> It's a place for individuals and institutions to join together to liberate specific ebooks and other types of digital content by paying rights holders to relicense their works under <a href="http://creativecommons.org">Creative Commons</a> licenses.</p>
<p>What does this mean?</p>
<ul>

View File

@ -1,8 +1,9 @@
<div id="comments">
{% for comment in comment_list reversed %}
<div class="work_supporter {% if comment.content_object.last_campaign and comment.user in comment.content_object.last_campaign.managers.all %}official{% endif %}">
<a href="{% url supporter supporter_username=comment.user.username %}">
<div itemprop="comment" itemscope itemtype="http://schema.org/UserComments" class="work_supporter {% if comment.content_object.last_campaign and comment.user in comment.content_object.last_campaign.managers.all %}official{% endif %}">
<span itemprop="creator" itemscope itemtype="http://schema.org/Person">
<a itemprop="url" href="{% url supporter supporter_username=comment.user.username %}">
<div class="work_supporter_avatar">
{% if comment.user.profile.pic_url %}
<img class="user-avatar" src="{{ comment.user.profile.pic_url }}" height="50" width="50" alt="Picture of {{ comment.user }}" title="{{ comment.user }}" />
@ -10,7 +11,10 @@
<img class="user-avatar" src="/static/images/header/avatar.png" height="50" width="50" alt="Generic Ungluer Avatar" title="Ungluer" />
{% endif %}
</div>
<span class="comment_username">{{comment.user.username }}</span></a> <span>({{ comment.submit_date }})</span> <br /><span class="comment">{{ comment.comment|linebreaksbr }}<br /></span>
<span class="comment_username">{{comment.user.username }}</span>
</a>
</span>
<span itemprop="commentTime">({{ comment.submit_date }})</span> <br /><span class="comment" itemProp="commentText">{{ comment.comment|linebreaksbr }}<br /></span>
</div>
{% endfor %}
</div>

View File

@ -96,7 +96,7 @@ there's no tab for seeing ALL my books, only the filters! huh.
<div class="js-topnews1">
<div class="js-topnews2">
<div class="js-topnews3">
<div class="user-block">
<div class="user-block" itemscope itemtype="http://schema.org/Person">
<div id="user-block1">
<div class="block-inner">
{% if supporter.profile.pic_url %}
@ -105,7 +105,7 @@ there's no tab for seeing ALL my books, only the filters! huh.
<img class="user-avatar" src="/static/images/header/avatar.png" height="50" width="50" alt="Generic Ungluer Avatar" title="Ungluer" />
{% endif %}
<span class="user-name">
<a href="#">{{ supporter.username }}</a>
<a href="#"><span itemprop="name">{{ supporter.username }}</span></a>
</span>
</div>
<span class="user-badges">

View File

@ -117,7 +117,7 @@
</div>
<div id="js-maincol">
<div class="js-maincol-inner">
<div id="content-block">
<div id="content-block" itemscope itemtype="http://schema.org/Book">
<div class="book-detail">
{% if work.googlebooks_id %}
<div id="book-detail-img"><a href="{{ work.googlebooks_url }}">
@ -125,16 +125,16 @@
</div>
{% else %}
<div id="book-detail-img">
<img src="{% if work.cover_image_thumbnail %}{{ work.cover_image_thumbnail }}{% else %}/static/images/generic_cover_larger.png{% endif %}" alt="{{ work.title }}" title="{{ work.title }}" width="131" height="192" />
<img itemprop="image" src="{% if work.cover_image_thumbnail %}{{ work.cover_image_thumbnail }}{% else %}/static/images/generic_cover_larger.png{% endif %}" alt="{{ work.title }}" title="{{ work.title }}" width="131" height="192" />
</div>
{% endif %}
<div class="book-detail-info">
<div class="layout">
<h2 class="book-name">{{ work.title }}</h2>
<h2 class="book-name" itemprop="name">{{ work.title }}</h2>
<div>
<div class="pubinfo">
<h3 class="book-author">{{ work.author }}</h3>
<h3 class="book-year">{{ work.publication_date_year }}</h3>
<h3 class="book-author" itemprop="author">{{ work.author }}</h3>
<h3 class="book-year" itemprop="datePublished">{{ work.publication_date_year }}</h3>
</div>
{% if status == 'ACTIVE' %}
{% if pledged %}
@ -227,10 +227,10 @@
<div id="tabs-1" class="tabs {% if activetab == '1' %}active{% endif %}">
<div class="tabs-content">
{% if status == 'ACTIVE' or status == 'SUCCESSFUL' %}
{{ work.last_campaign.description|safe }}
<span itemprop="description">{{ work.last_campaign.description|safe }}</span>
{% else %}
<h3 class="tabcontent-title">{{work.title}}</h3>
<p>{{ work.description|safe }}
<p itemprop="description">{{ work.description|safe }}
{% endif %}
</p>
</div>
@ -282,8 +282,8 @@
{% else %}
{% for wish in work.wishes.all reversed %}
{% with wish.wishlist.user as supporter %}
<div class="work_supporter_nocomment">
<a href="{% url supporter supporter_username=supporter.username %}">
<div class="work_supporter_nocomment" itemscope itemtype="http://schema.org/Person">
<a itemprop="url" href="{% url supporter supporter_username=supporter.username %}">
<div class="work_supporter_avatar">
{% if supporter.profile.pic_url %}
<img class="user-avatar" src="{{ supporter.profile.pic_url }}" height="50" width="50" alt="Picture of {{ supporter }}" title="{{ supporter }}" />
@ -362,7 +362,7 @@
<h4>Subjects</h4>
<ul>
{% for subject in work.subjects.all %}
<li>{{ subject.name }}</li>
<li itemprop="keywords">{{ subject.name }}</li>
{% endfor %}
</ul>
{% endif %}
@ -384,7 +384,7 @@
<div class="metadata" id="edition_{{edition.id}}">{% if edition.publisher %}Publisher: <a href="{% url bypub_list edition.publisher %}">{{edition.publisher}}</a><br />{% endif %}
{% if edition.publication_date %}Published: {{edition.publication_date}}<br />{% endif %}
{% if edition.isbn_13 %}
ISBN: {{ edition.isbn_13 }}<br />
ISBN: <spam itemprop="isbn">{{ edition.isbn_13 }}</span><br />
{% endif %}
{% if edition.oclc %}
OCLC: <a href="http://www.worldcat.org/oclc/{{ edition.oclc }}">{{ edition.oclc }}</a><br />

View File

@ -912,7 +912,7 @@ class NonprofitCampaign(FormView):
forward['amount']= int(amount)
forward['sent']= Sent.objects.create(user=username,amount=form.cleaned_data['preapproval_amount']).pk
token=signing.dumps(forward)
return HttpResponseRedirect(settings.BASE_URL + reverse('donation_credit',kwargs={'token':token}))
return HttpResponseRedirect(settings.BASE_URL_SECURE + reverse('donation_credit',kwargs={'token':token}))
class DonationCredit(TemplateView):
template_name="donation_credit.html"
@ -2040,7 +2040,7 @@ def emailshare(request, action):
next = form.cleaned_data['next']
except:
# if we totally failed to have a next value, we should still redirect somewhere useful
next = 'http://unglue.it'
next = 'https://unglue.it'
return HttpResponseRedirect(next)
else:
@ -2195,7 +2195,7 @@ def download(request, work_id):
'unglued_ebooks': unglued_ebooks,
'other_ebooks': other_ebooks,
'readmill_epub_url': readmill_epub_url,
'base_url': settings.BASE_URL
'base_url': settings.BASE_URL_SECURE
})
return render(request, "download.html", context)

View File

@ -565,7 +565,7 @@ class PaymentManager( object ):
if return_url is None:
return_path = "{0}?{1}".format(reverse('pledge_complete'),
urllib.urlencode({'tid':transaction.id}))
return_url = urlparse.urljoin(settings.BASE_URL, return_path)
return_url = urlparse.urljoin(settings.BASE_URL_SECURE, return_path)
p = transaction.get_payment_class().Preapproval(transaction, transaction.max_amount, expiry, return_url=return_url, paymentReason=paymentReason)
@ -657,7 +657,7 @@ class PaymentManager( object ):
credit.pledge_transaction(t,user,amount)
return_path = "{0}?{1}".format(reverse('pledge_complete'),
urllib.urlencode({'tid':t.id}))
return_url = urlparse.urljoin(settings.BASE_URL, return_path)
return_url = urlparse.urljoin(settings.BASE_URL_SECURE, return_path)
pledge_created.send(sender=self, transaction=t)
return t, return_url
else:
@ -762,7 +762,7 @@ class PaymentManager( object ):
credit.pledge_transaction(transaction,transaction.user,amount)
return_path = "{0}?{1}".format(reverse('pledge_complete'),
urllib.urlencode({'tid':transaction.id}))
return_url = urlparse.urljoin(settings.BASE_URL, return_path)
return_url = urlparse.urljoin(settings.BASE_URL_SECURE, return_path)
logger.info("Updated amount of transaction to %f" % amount)
pledge_modified.send(sender=self, transaction=transaction,up_or_down=up_or_down)

View File

@ -119,6 +119,7 @@ INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.comments',
@ -216,7 +217,7 @@ LOGIN_URL = "/accounts/login/"
LOGIN_REDIRECT_URL = "/"
LOGOUT_URL = "/accounts/logout/"
USER_AGENT = "unglue.it.bot v0.0.1 <http://unglue.it>"
USER_AGENT = "unglue.it.bot v0.0.1 <https://unglue.it>"
SOUTH_TESTS_MIGRATE = True

11
urls.py
View File

@ -3,6 +3,12 @@ from frontend.forms import ProfileForm
from django.views.generic.simple import direct_to_template
from regluit.admin import admin_site
import notification.urls
from regluit.core.sitemaps import WorkSitemap, PublisherSitemap
sitemaps = {
'works': WorkSitemap,
'publishers': PublisherSitemap,
}
urlpatterns = patterns('',
url(r'^accounts/activate/complete/$','django.contrib.auth.views.login',
@ -23,3 +29,8 @@ urlpatterns = patterns('',
(r'^notification/', include(notification.urls)),
(r'^ckeditor/', include('ckeditor.urls')),
)
urlpatterns += patterns('django.contrib.sitemaps.views',
(r'^sitemap\.xml$', 'index', {'sitemaps': sitemaps}),
(r'^sitemap-(?P<section>.+)\.xml$', 'sitemap', {'sitemaps': sitemaps}),
)