Compare commits

..

2 Commits

Author SHA1 Message Date
David Taylor
3269e92ef2 Merge pull request #277 from nottinghamtec/davidtaylorhq-patch-1
Explicitly define height in oembed JSON
2017-03-10 15:29:29 +00:00
David Taylor
0ae7bcaf7c Explicitly define height in oembed JSON 2017-03-10 15:26:00 +00:00
3 changed files with 21 additions and 36 deletions

View File

@@ -1,17 +1,16 @@
import cStringIO as StringIO
import datetime
import re
from decimal import Decimal
from django.contrib import messages
from django.core.urlresolvers import reverse_lazy
from django.db.models import Count, Sum, F, FloatField, Q, Value
from django.http import Http404, HttpResponseRedirect
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template import RequestContext
from django.template.loader import get_template
from django.views import generic
from django.db.models import Q
from z3c.rml import rml2pdf
from RIGS import models
@@ -31,8 +30,19 @@ class InvoiceIndex(generic.ListView):
return context
def get_queryset(self):
query = self.model.objects.outstanding().select_related('event', 'event__organisation', 'event__person',
'event__venue', 'event__mic')
# Manual query is the only way I have found to do this efficiently. Not ideal but needs must
sql = "SELECT * FROM " \
"(SELECT " \
"(SELECT COUNT(p.amount) FROM \"RIGS_payment\" AS p WHERE p.invoice_id=\"RIGS_invoice\".id) AS \"payment_count\", " \
"(SELECT SUM(ei.cost * ei.quantity) FROM \"RIGS_eventitem\" AS ei WHERE ei.event_id=\"RIGS_invoice\".event_id) AS \"cost\", " \
"(SELECT SUM(p.amount) FROM \"RIGS_payment\" AS p WHERE p.invoice_id=\"RIGS_invoice\".id) AS \"payments\", " \
"\"RIGS_invoice\".\"id\", \"RIGS_invoice\".\"event_id\", \"RIGS_invoice\".\"invoice_date\", \"RIGS_invoice\".\"void\" FROM \"RIGS_invoice\") " \
"AS sub " \
"WHERE (((cost > 0.0) AND (payment_count=0)) OR (cost - payments) <> 0.0) AND void = '0'" \
"ORDER BY invoice_date"
query = self.model.objects.raw(sql)
return query
@@ -84,7 +94,6 @@ class InvoiceVoid(generic.View):
return HttpResponseRedirect(reverse_lazy('invoice_list'))
return HttpResponseRedirect(reverse_lazy('invoice_detail', kwargs={'pk': object.pk}))
class InvoiceDelete(generic.DeleteView):
model = models.Invoice
@@ -105,7 +114,6 @@ class InvoiceDelete(generic.DeleteView):
def get_success_url(self):
return self.request.POST.get('next')
class InvoiceArchive(generic.ListView):
model = models.Invoice
template_name = 'RIGS/invoice_list_archive.html'
@@ -134,11 +142,11 @@ class InvoiceWaiting(generic.ListView):
events = self.model.objects.filter(
(
Q(start_date__lte=datetime.date.today(), end_date__isnull=True) | # Starts before with no end
Q(end_date__lte=datetime.date.today()) # Has end date, finishes before
) & Q(invoice__isnull=True) # Has not already been invoiced
& Q(is_rig=True) # Is a rig (not non-rig)
).order_by('start_date') \
Q(end_date__lte=datetime.date.today()) # Has end date, finishes before
) & Q(invoice__isnull=True) # Has not already been invoiced
& Q(is_rig=True) # Is a rig (not non-rig)
).order_by('start_date') \
.select_related('person',
'organisation',
'venue', 'mic') \

View File

@@ -1,11 +1,11 @@
import datetime
import hashlib
import pytz
import random
import string
from collections import Counter
from decimal import Decimal
import pytz
import reversion
from django.conf import settings
from django.contrib.auth.models import AbstractUser
@@ -501,34 +501,14 @@ class EventCrew(models.Model):
notes = models.TextField(blank=True, null=True)
class InvoiceManager(models.Manager):
def outstanding(self):
return self.annotate(
_payment_total=models.Sum(models.F('payment__amount'))
).annotate(
_sum_total=models.Sum(models.F('event__items__cost') * models.F('event__items__quantity'),
output_field=models.DecimalField(decimal_places=2))
# ).annotate(
# _balance=models.ExpressionWrapper(models.F('_sum_total') - models.F('_payment_total'),
# models.DecimalField(decimal_places=2))
# ).filter(
# models.Q(_balance__isnull=True) |
# ~models.Q(_sum_total=models.F('_payment_total'))
)
@python_2_unicode_compatible
class Invoice(models.Model):
event = models.OneToOneField('Event')
invoice_date = models.DateField(auto_now_add=True)
void = models.BooleanField(default=False)
objects = InvoiceManager()
@property
def sum_total(self):
if getattr(self, '_sum_total', None):
return Decimal(getattr(self, '_sum_total'))
return self.event.sum_total
@property
@@ -537,10 +517,6 @@ class Invoice(models.Model):
@property
def payment_total(self):
if hasattr(self, '_payment_total') and hasattr(self, '_payment_count'):
if getattr(self, '_payment_count') == 0:
return Decimal(0.00)
return Decimal(getattr(self, '_payment_total', 0.00))
total = self.payment_set.aggregate(total=models.Sum('amount'))['total']
if total:
return total

View File

@@ -61,6 +61,7 @@ class EventOembed(generic.View):
'html': '<iframe src="{0}" frameborder="0" width="100%" height="250"></iframe>'.format(full_url),
'version': '1.0',
'type': 'rich',
'height': '250'
}
json = simplejson.JSONEncoderForHTML().encode(data)