This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookingManager(models.Manager): | |
@property | |
def departures_today(self): | |
return Booking.objects.filter(start__gte=self._this_morning, start__lt=self._tomorrow_morning) | |
@property | |
def arrivals_today(self): | |
return Booking.objects.filter(end__gte=self._this_morning, end__lt=self._tomorrow_morning) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookingManager(models.Manager): | |
@property | |
def _filters(self): | |
today = datetime.now().date() | |
tomorrow = today+timedelta(days=1) | |
day_after_tomorrow = date_today+timedelta(days=2) | |
this_morning = datetime.combine(date_today, DAY_CUTOFF_TIME) | |
tomorrow_morning = datetime.combine(tomorrow, DAY_CUTOFF_TIME) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel(PolymorphicModel): | |
@property | |
def driver(self): | |
if self.is_departure: return self.delivery_driver | |
else: return self.collection_driver | |
@driver.setter | |
def driver(self, value): | |
if self.is_departure: self.delivery_driver = value | |
else self.collection_driver = value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<footer id="footer"> | |
<div id="footer-inside"> | |
</div> | |
</footer><!--footer--> | |
<div class="social"> | |
<div> | |
<ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InventoryEvent(AbstractEvent): | |
booking_stock_item = models.ForeignKey('office.BookingStockItem', null=True, blank=True) | |
booking_consumable = models.ForeignKey('office.BookingConsumable', null=True, blank=True) | |
purchase = models.ForeignKey('inventory.Purchase', null=True, blank=True) | |
cross_hire = models.ForeignKey('inventory.CrossHire', null=True, blank=True) | |
booking_cross_hire = models.ForeignKey('office.BookingCrossHire', null=True, blank=True) | |
repair = models.ForeignKey('inventory.Repair', null=True, blank=True) | |
missing = models.ForeignKey('inventory.Missing', null=True, blank=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_inventory_events(self, | |
stock_items = self.stockitem_set.all() | |
qs = InventoryEvent.objects.filter( | |
Q(booking_stock_item__stock_item__in=stock_items) | | |
Q(booking_cross_hire__stock_item__in=stock_items) | | |
Q(purchase__stock_item__in=stock_items) | | |
Q(cross_hire__stock_item__in=stock_items) | | |
Q(repair__stock_item__in=stock_items) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IntercoolerContentNegotiation(DefaultContentNegotiation): | |
""" | |
Used to automatically select StaticHTMLRenderer for Intercooler requests | |
""" | |
def select_renderer(self, request, renderers, format_suffix): | |
if request.DATA.get('ic-request', False): | |
return StaticHTMLRenderer(), 'text/html' | |
else: | |
return super(IntercoolerContentNegotiation, self).select_renderer(request, renderers, format_suffix) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "custom_base.html" %} | |
{% block content %} | |
<form id="defaults" > | |
<input name="csrfmiddlewaretoken" type="hidden" value="{{ csrf_token }}"> | |
</form> | |
<table> | |
{% for row in items %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from django.conf import settings | |
from django.http import HttpResponseRedirect | |
from django.core.urlresolvers import reverse | |
class DefaultFilterMiddleware(object): | |
def process_request(self, request): | |
# This middleware is not for admin only | |
if not request.user.is_staff: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version 1 | |
return Response(dict([( | |
int(pk), | |
{'lowest_stock': ItemModel.objects.get(id=int(pk)) \ | |
.get_lowest_stock_for_subbooking(subbooking)} | |
) for pk in request.QUERY_PARAMS.get('item_models', '').split(',')])) | |
# Version 2 |