From b659d8085537eeee63db82e529c9c9e1be3c601b Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 12 Mar 2012 16:40:21 -0400 Subject: [PATCH 1/6] we can only have one order_by per facet! --- frontend/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/views.py b/frontend/views.py index 3cb98bd8..77660e24 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -228,7 +228,7 @@ class WorkListView(ListView): if (facet == 'popular'): return models.Work.objects.order_by('-num_wishes', 'id') elif (facet == 'recommended'): - return models.Work.objects.filter(wishlists__user=recommended_user) + return models.Work.objects.filter(wishlists__user=recommended_user).order_by('-num_wishes') elif (facet == 'new'): return models.Work.objects.filter(num_wishes__gt=0).order_by('-created', '-num_wishes' ,'id') else: @@ -240,8 +240,8 @@ class WorkListView(ListView): context['ungluers'] = userlists.work_list_users(qs,5) context['facet'] =self.kwargs['facet'] context['works_unglued'] = qs.filter(editions__ebooks__isnull=False).distinct() - context['works_active'] = qs.exclude(editions__ebooks__isnull=False).filter(Q(campaigns__status='ACTIVE') | Q(campaigns__status='SUCCESSFUL')).distinct().order_by('-campaigns__status', 'campaigns__deadline') - context['works_wished'] = qs.exclude(editions__ebooks__isnull=False).exclude(campaigns__status='ACTIVE').exclude(campaigns__status='SUCCESSFUL').distinct().order_by('-num_wishes') + context['works_active'] = qs.exclude(editions__ebooks__isnull=False).filter(Q(campaigns__status='ACTIVE') | Q(campaigns__status='SUCCESSFUL')).distinct() + context['works_wished'] = qs.exclude(editions__ebooks__isnull=False).exclude(campaigns__status='ACTIVE').exclude(campaigns__status='SUCCESSFUL').distinct() context['activetab'] = "#3" From f92ea78e6765728836fb65d73f674746d80f3a5d Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 12 Mar 2012 17:04:06 -0400 Subject: [PATCH 2/6] alt attribut goes in img, not a [#25582597] --- frontend/templates/supporter.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/templates/supporter.html b/frontend/templates/supporter.html index b09adf5e..bce3ce80 100644 --- a/frontend/templates/supporter.html +++ b/frontend/templates/supporter.html @@ -259,7 +259,7 @@ there's no tab for seeing ALL my books, only the filters! huh.
  • Wishlisted
  • - Subscribe + RSS feed of {{ supporter }}'s latest wishbooksSubscribe {% if not works %} {% comment %} From 6bd003b0c6288e437ea800f9efbe6a5fa04cdc54 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 12 Mar 2012 15:42:20 -0700 Subject: [PATCH 3/6] It turns out that we were sending "naive" timestamps to PayPal....now passing isoformat() of timezone aware versions of timestamp to PayPal Added a isoformat method to regluit.utils.localdatetime to handle both naive and aware datetimes --- payment/paypal.py | 26 ++++++++++++++++++-------- utils/localdatetime.py | 9 +++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/payment/paypal.py b/payment/paypal.py index fe386c18..b8a280a2 100644 --- a/payment/paypal.py +++ b/payment/paypal.py @@ -10,7 +10,10 @@ from django.db.models.query_utils import Q from django.shortcuts import render_to_response from django.template import RequestContext -import datetime +from datetime import timedelta +from regluit.utils.localdatetime import now, isoformat +import dateutil + import dateutil.parser import hashlib import httplib @@ -601,16 +604,16 @@ class Preapproval( PaypalEnvelopeRequest ): cancel_url = settings.BASE_URL + CANCEL_URL # set the expiration date for the preapproval if not passed in - now = datetime.datetime.utcnow() + now_val = now() if expiry is None: - expiry = now + datetime.timedelta( days=settings.PREAPPROVAL_PERIOD ) - transaction.date_authorized = now + expiry = now_val + timedelta( days=settings.PREAPPROVAL_PERIOD ) + transaction.date_authorized = now_val transaction.date_expired = expiry transaction.save() data = { - 'endingDate': expiry.isoformat(), - 'startingDate': now.isoformat(), + 'endingDate': isoformat(expiry), + 'startingDate': isoformat(now_val), 'maxTotalAmountOfAllPayments': '%.2f' % transaction.amount, 'maxNumberOfPayments':1, 'maxAmountPerPayment': '%.2f' % transaction.amount, @@ -703,9 +706,16 @@ class PreapprovalDetails(PaypalEnvelopeRequest): self.approved = False else: self.approved = None + + try: + self.expiration = dateutil.parser.parse(self.response.get("endingDate")) + except: + self.expiration = None - self.expiration = self.response.get("endingDate", None) - self.date = self.response.get("startingDate", None) + try: + self.date = dateutil.parser.parse(self.response.get("startingDate", None)) + except: + self.date = None except: self.errorMessage = "Error: ServerError" diff --git a/utils/localdatetime.py b/utils/localdatetime.py index 3167dfdb..c6608e19 100644 --- a/utils/localdatetime.py +++ b/utils/localdatetime.py @@ -110,6 +110,15 @@ def make_naive(value, timezone): value = timezone.normalize(value) return value.replace(tzinfo=None) +def isoformat(value): + """ + if value is naive, assume it's in the default_timezone + """ + if is_naive(value): + return make_aware(value, get_default_timezone()).isoformat() + else: + return value.isoformat() + def as_utc_naive(value): """ if value is naive, assume it's in the default time zone, then convert to UTC but make naive From 29ff11af941379bab13e8888674af754b82bf38c Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 12 Mar 2012 15:55:14 -0700 Subject: [PATCH 4/6] Missed a datetime import needed for timedelta --- payment/tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/payment/tests.py b/payment/tests.py index f1ea3785..323b386e 100644 --- a/payment/tests.py +++ b/payment/tests.py @@ -23,6 +23,7 @@ import logging import os from decimal import Decimal as D from regluit.utils.localdatetime import now +from datetime import timedelta def setup_selenium(): # Set the display window for our xvfb @@ -278,7 +279,7 @@ class TransactionTest(TestCase): w = Work() w.save() - c = Campaign(target=D('1000.00'),deadline=now() + datetime.timedelta(days=180),work=w) + c = Campaign(target=D('1000.00'),deadline=now() + timedelta(days=180),work=w) c.save() t = Transaction() From c61408b56b6b5cb0934fa050c6788be253065f59 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 12 Mar 2012 23:01:05 -0400 Subject: [PATCH 5/6] changes "view your profile" to "change username" in stead of "password reset" --- frontend/templates/registration/welcome.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/templates/registration/welcome.html b/frontend/templates/registration/welcome.html index dc31b50a..ed738959 100644 --- a/frontend/templates/registration/welcome.html +++ b/frontend/templates/registration/welcome.html @@ -12,7 +12,7 @@
    {% endblock %} From 6d0e5455f97306db9ab95a4c4df7e7cd31041eb3 Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 12 Mar 2012 23:34:10 -0400 Subject: [PATCH 6/6] metrics enhancements [finish #26329807] --- frontend/templates/metrics.html | 13 +++++++++++++ frontend/views.py | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/frontend/templates/metrics.html b/frontend/templates/metrics.html index ab59e1df..3b4dc55a 100644 --- a/frontend/templates/metrics.html +++ b/frontend/templates/metrics.html @@ -13,6 +13,9 @@ {% endfor %}{% endif %}
    {{ wishlists.today.count }} of them have 1 or more items on a wishlist. +
  • {{ users.yesterday.count }} registered yesterday. +
    {{ wishlists.yesterday.count }} of them have 1 or more items on a wishlist. +
  • {{ users.days7.count }} have registered in the past 7 days.
    {{ wishlists.days7.count }} of them have 1 or more items on a wishlist.
  • @@ -23,6 +26,12 @@
    {{ wishlists.all.count }} of them have 1 or more items on a wishlist. +
      +
    • {{ users.gr.count }} ungluers are connected to GoodReads.
    • +
    • {{ users.lt.count }} ungluers are connected to LibraryThing.
    • +
    • {{ users.fb.count }} ungluers are connected to FaceBook.
    • +
    • {{ users.tw.count }} ungluers are connected to Twitter.
    • +

    Works

    @@ -35,6 +44,8 @@
  • {{work.title}}
  • {% endfor %}{% endif %} +
  • {{ works.yesterday.count }} were added yesterday. +
  • {{ works.days7.count }} have been added in the past 7 days.
  • {{ works.month.count }} have been added in this month. @@ -69,6 +80,8 @@
  • {{ebook.edition.work.title}}
  • {% endfor %}{% endif %} +
  • {{ ebooks.yesterday.count }} were added yesterday. +
  • {{ ebooks.days7.count }} have been added in the past 7 days.
  • {{ ebooks.month.count }} have been added in this month. diff --git a/frontend/views.py b/frontend/views.py index 77660e24..cceb2243 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -1017,11 +1017,23 @@ class InfoPageView(TemplateView): users.days7 = users.filter(date_joined__range = (date_today()-timedelta(days=7), now())) users.year = users.filter(date_joined__year = date_today().year) users.month = users.year.filter(date_joined__month = date_today().month) + if date_today().day==1: + users.yesterday = users.filter(date_joined__range = (date_today()-timedelta(days=1), date_today())) + else: + users.yesterday = users.month.filter(date_joined__day = date_today().day-1) + users.gr = users.filter(profile__goodreads_user_id__isnull = False) + users.lt = users.exclude(profile__librarything_id = '') + users.fb = users.filter(profile__facebook_id__isnull = False) + users.tw = users.exclude(profile__twitter_id = '') works = models.Work.objects works.today = works.filter(created__range = (date_today(), now())) works.days7 = works.filter(created__range = (date_today()-timedelta(days=7), now())) works.year = works.filter(created__year = date_today().year) works.month = works.year.filter(created__month = date_today().month) + if date_today().day==1: + works.yesterday = works.filter(created__range = (date_today()-timedelta(days=1), date_today())) + else: + works.yesterday = works.month.filter(created__day = date_today().day-1) works.wishedby2 = works.filter(num_wishes__gte = 2) works.wishedby20 = works.filter(num_wishes__gte = 20) works.wishedby5 = works.filter(num_wishes__gte = 5) @@ -1033,11 +1045,19 @@ class InfoPageView(TemplateView): ebooks.days7 = ebooks.filter(created__range = (date_today()-timedelta(days=7), now())) ebooks.year = ebooks.filter(created__year = date_today().year) ebooks.month = ebooks.year.filter(created__month = date_today().month) + if date_today().day==1: + ebooks.yesterday = ebooks.filter(created__range = (date_today()-timedelta(days=1), date_today())) + else: + ebooks.yesterday = ebooks.month.filter(created__day = date_today().day-1) wishlists= models.Wishlist.objects.exclude(wishes__isnull=True) wishlists.today = wishlists.filter(created__range = (date_today(), now())) wishlists.days7 = wishlists.filter(created__range = (date_today()-timedelta(days=7), now())) wishlists.year = wishlists.filter(created__year = date_today().year) wishlists.month = wishlists.year.filter(created__month = date_today().month) + if date_today().day==1: + wishlists.yesterday = wishlists.filter(created__range = (date_today()-timedelta(days=1), date_today())) + else: + wishlists.yesterday = wishlists.month.filter(created__day = date_today().day-1) return { 'users': users, 'works': works,