[ Launch: unit waves ] 3c9ba978c9583d37488f by andybak[ Launch: unit circle ] 6723241 by enjalot[ Launch: unit circle ] 6723094 by enjalot[ Launch: unit circle ] 6722845 by enjalot[ Launch: unit circle ] 5211082 by ptvans[ Launch: unit circle ] 5210686 by enjalot
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
from django.template.response import TemplateResponse | |
from portfolio.models import PortfolioItem | |
class GalleryPageType(cms.PageType): | |
unique = True | |
required = True | |
can_use_extra_url = True | |
uses_content = True | |
uses_extra_content = 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
publish( | |
'ws_test', | |
'server_ping', | |
{'message': 'Hello bob'}, | |
sender='server' | |
) |
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 TriangleAndSquare { | |
var triangle: EquilateralTriangle { | |
willSet { | |
square.sideLength = newValue.sideLength | |
} | |
} | |
var square: Square { | |
willSet { | |
triangle.sideLength = newValue.sideLength | |
} |
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 parent(self): | |
possible_parents = [ | |
self.booking_row, | |
self.stock_change, | |
self.repair, | |
self.missing, | |
] | |
parents = [p for p in possible_parents if p is not None] |
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 url_choices(): | |
from cms.admin_views import get_linklist_context | |
linklists = get_linklist_context() | |
choices = [] | |
keys = ['links', 'documents', 'secure_documents', ] | |
for key in keys: | |
choices.extend([(link[1], link[0]) for link in linklists[key] or []]) | |
choices.append(['', '']) | |
return choices |
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 HasEvents( | |
HasAdminUrl, | |
TimeStampedModel): | |
def __init__(self, *args, **kwargs): | |
if not issubclass(self.__class__.objects.__class__, HasEventsManager): | |
raise Exception("HasEvents sublasses must have managers that inherit from HasEventsManager") | |
super(HasEvents, self).__init__(*args, **kwargs) |
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
# Put this in the following file: | |
# $VIRTUAL_ENV/lib/python2.7/site-packages/sitecustomize.py | |
import sys | |
reload(sys) | |
sys.setdefaultencoding("utf-8") | |
print "-- setting utf-8 in virtualenv sitecustomize.py --" |
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 BaseOrderRow(HasEvents): | |
timestamp = models.DateTimeField(null=True, blank=True) | |
_item_model = models.ForeignKey('inventory.ItemModel', related_name="%(class)s_itemmodel_set", null=True, blank=True) | |
_stock_item = models.ForeignKey('inventory.ItemModel', related_name="%(class)s_stockitem_seit", null=True, blank=True) | |
@cached_property | |
def stock_item(self): return self._stock_item if self.is_confirmed else None | |
@cached_property |
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
""" | |
adminreverse from here http://djangosnippets.org/snippets/2032/ | |
changed for working with ForeignKeys | |
Fixed for Django 1.6 by @andybak | |
reverseadmin | |
============ | |
Module that makes django admin handle OneToOneFields in a better way. | |
A common use case for one-to-one relationships is to "embed" a model |