when a user views another users contributor page, works they already have on their wishlist show up that way instead of as "add to wishlist"
parent
97e630c196
commit
93404d42ff
|
@ -145,11 +145,13 @@ class Edition(models.Model):
|
|||
return e
|
||||
return None
|
||||
|
||||
|
||||
class Wishlist(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
user = models.OneToOneField(User, related_name='wishlist')
|
||||
works = models.ManyToManyField('Work', related_name='wishlists')
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
user = models.OneToOneField(User, related_name='profile')
|
||||
tagline = models.CharField(max_length=140, blank=True)
|
||||
|
|
|
@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
|||
from django.test import TestCase
|
||||
from django.utils import unittest
|
||||
from django.db import IntegrityError
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from regluit.payment.models import Transaction
|
||||
from regluit.core.models import Campaign, Work, UnglueitError
|
||||
|
@ -104,7 +105,6 @@ class CampaignTests(TestCase):
|
|||
c = Campaign(target=D('1000.00'), deadline=datetime(2012, 1, 1), work=w)
|
||||
c.save()
|
||||
|
||||
|
||||
def test_campaign_status(self):
|
||||
w = Work()
|
||||
w.save()
|
||||
|
@ -155,3 +155,17 @@ class CampaignTests(TestCase):
|
|||
c5.save()
|
||||
c5.activate().withdraw('testing')
|
||||
self.assertEqual(c5.status, 'WITHDRAWN')
|
||||
|
||||
|
||||
class WishlistTest(TestCase):
|
||||
|
||||
def test_add_remove(self):
|
||||
# add a work to a user's wishlist
|
||||
user = User.objects.create_user('test', 'test@example.com', 'testpass')
|
||||
edition = bookloader.add_by_isbn('0441012035')
|
||||
work = edition.work
|
||||
user.wishlist.works.add(work)
|
||||
self.assertEqual(user.wishlist.works.count(), 1)
|
||||
user.wishlist.works.remove(work)
|
||||
self.assertEqual(user.wishlist.works.count(), 0)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<div class="js-search" style="float: left; margin-left: 50px;">
|
||||
<div class="js-search-inner">
|
||||
<form action="{% url search %}" method="get">
|
||||
<input type="text" placeholder="Search for a book..." size="30" class="inputbox" name="q" value="{{ q }}">
|
||||
<input type="text" placeholder="Search for a book..." size="25" class="inputbox" name="q" value="{{ q }}">
|
||||
<input type="button" onclick="this.form.searchword.focus();" class="button" value="Search">
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -230,11 +230,15 @@ how do I integrate the your wishlist thing with the tabs thing?
|
|||
<div class="remove-wishlist">
|
||||
<span id="{{ work.id }}">Remove from Wishlist</span>
|
||||
</div>
|
||||
{% else %}{% if work in shared_works %}
|
||||
<div>
|
||||
<span>On Your Wishlist!</span>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="add-wishlist">
|
||||
<span id="{{ work.editions.all.0.googlebooks_id }}">Add to Wishlist</span>
|
||||
</div>
|
||||
{% endifequal %}
|
||||
{% endif %}{% endifequal %}
|
||||
<div class="booklist-status">
|
||||
<span class="booklist-status-text">{{ work.campaign_set.all.count }}</span>
|
||||
<span class="booklist-status-img">
|
||||
|
|
|
@ -37,14 +37,25 @@ def supporter(request, supporter_username):
|
|||
wished = supporter.wishlist.works.count()
|
||||
|
||||
date = supporter.date_joined.strftime("%B %d, %Y")
|
||||
|
||||
# figure out what works the users have in commmon if someone
|
||||
# is looking at someone elses supporter page
|
||||
if request.user != supporter:
|
||||
w1 = request.user.wishlist
|
||||
w2 = supporter.wishlist
|
||||
shared_works = models.Work.objects.filter(wishlists__in=[w1])
|
||||
shared_works = list(shared_works.filter(wishlists__in=[w2]))
|
||||
else:
|
||||
shared_works = []
|
||||
|
||||
context = {
|
||||
"supporter": supporter,
|
||||
"wishlist": wishlist,
|
||||
"backed": backed,
|
||||
"backing": backing,
|
||||
"wished": wished,
|
||||
"date": date,
|
||||
"supporter": supporter,
|
||||
"wishlist": wishlist,
|
||||
"backed": backed,
|
||||
"backing": backing,
|
||||
"wished": wished,
|
||||
"date": date,
|
||||
"shared_works": shared_works,
|
||||
}
|
||||
|
||||
return render(request, 'supporter.html', context)
|
||||
|
|
Loading…
Reference in New Issue