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
# | |
# Cookbook Name:: solr | |
# Recipe:: default | |
# | |
# Copyright 2012, Example Com | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# |
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
try: | |
django_obj = self.django_model.objects.get(my_field=value) | |
except self.django_model.DoesNotExist: | |
try: | |
django_obj = self.django_model.objects.get(**{ | |
'other_field1': other_value1, | |
'other_field2': other_value2, | |
'other_field3': other_value3, | |
'other_field4': other_value4, | |
}) |
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
for Model, relations in RELATIONSHIPS.items(): | |
fields = [relations[relation]['field'] \ | |
for relation in relations \ | |
if relations[relation]['model'] is Constituent] | |
relationship_fields = {field: '{}_constituent_id'.format(field) \ | |
for field in fields} | |
or_filters = [Q(**{'{}__isnull'.format(field): True}) \ | |
for field in fields] | |
null_relations = reduce(lambda x, y: x | y, or_filters) | |
filters = null_relations |
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 | |
def equal(triplet): | |
return len(set(triplet)) == 1 | |
def finished(world): | |
for i in range(len(world)): | |
if len(world[i:]) < 3: |
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
(virtualenv)project :: (±branch) » ./manage.py shell ~/Projects/project | |
Python 2.7.3 (default, Aug 11 2012, 18:22:59) | |
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
(InteractiveConsole) | |
>>> from exceptions import UnicodeEncodeError | |
>>> from app.module import RECORD_TYPES | |
Traceback (most recent call last): | |
File "<console>", line 1, in <module> | |
File "/Users/josho/Projects/project/app/module.py", line 2, in <module> |
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
@classmethod | |
def import_events_to_django(klas, events): | |
num_created = 0 | |
num_updated = 0 | |
num_skipped = 0 | |
events_dict = {int(event['id']): event for event in events} | |
existing_django_events = klas.objects.in_bulk(events_dict.keys()) | |
for key in existing_django_events: |
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.conf import settings | |
>>> settings.DATABASES | |
{'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'TEST_MIRROR': None, 'NAME': '', 'TEST_CHARSET': None, 'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'OPTIONS': {}, 'HOST': 'localhost', 'USER': None, 'TEST_NAME': None, 'PASSWORD': None, 'PORT': 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
<form method="POST" action="{% url accounts_admin_bulk_upload account.pk %}" enctype="multipart/form-data"> | |
<input type="file" name="bulk" /> | |
<input class="button" type="submit" name="" value="Bulk Upload Sub-accounts" /> | |
</form> |
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
filters = reduce(lambda x, y: x | y, | |
[Q(**{'account_name__istartswith': letter}) for | |
letter in letter_range]) | |
return self.object.get_children().filter(filters) |
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
#Given a variable, x, that stores | |
#the value of any decimal number, | |
#write Python code that prints out | |
#the nearest whole number to x. | |
#You can assume x is not negative. | |
# x = 3.14159 -> 3 (not 3.0) | |
# x = 27.63 -> 28 (not 28.0) |