Skip to content

Instantly share code, notes, and snippets.

View bengolder's full-sized avatar

Ben Golder bengolder

  • Oakland, CA, USA
  • 12:09 (UTC -07:00)
View GitHub Profile
@bengolder
bengolder / analysis_serializers.py
Created April 24, 2017 18:37
Anonymized serializers for SNs
from intake import models
import Levenshtein
from rest_framework import serializers
from .fields import FormattedLocalDateField
from intake.services import status_notifications as StatusNotificationsService
class StatusNotificationAnalysisSerializer(serializers.ModelSerializer):
contact_info = serializers.SerializerMethodField()
message_change = serializers.SerializerMethodField()
@bengolder
bengolder / index.html
Last active April 25, 2017 16:37
Status Notifications
<!DOCTYPE html>
<style>
body {
margin: 0; padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif;
}
main {
padding: 1em 2em;
}
.day-row > td:first-child {
./manage.py behave --keepdb
Using existing test database for alias 'default'...
Feature: HomePage # features/homepage.feature:1

 Scenario:                                                       # features/homepage.feature:2
   Given the homepage loads                                      # features/steps/homepage.py:4 1.613s
   Then it should have the "apply-now" link and say "Apply now"  # features/steps/homepage.py:9 0.218s
   And it should have the "learn-more" link and say "Learn more" # features/steps/homepage.py:9 0.198s
   And "learn-more" should deeplink to "#learn_more_section"     # None

Split screen slideaway menu

This is an attempt to work out the essential pieces for a navigation menu that slides in and out on the left of the screen.

What is the core set of HTML, CSS, and Javascript necessary to create a usable version?

from django.db import models
class TransferPartnershipManager(models.Manager):
def get_by_natural_key(self, from_name, to_name):
return self.get(
from_organization__name=from_name,
to_organization__name=to_name)
class HumbleCachedContext:
"""Only pulls what it needs, and never pulls twice
"""
def __init__(self, **context_items):
self.get_functions = {}
for key, value in context_items:
self.add(key, value)

Transfers between Organizations

Refactoring transfer relationships

commit 1b3276d2271518ef0e5bc5d5083fa029b101fb14

Before this refactor, the Organization model had a method, get_transfer_org which hardcoded the transfer capability between organizations.

# in user_accounts/models/organization.py
def get_transfer_org(self):
self.assertAlmostEqual()
self.assertAlmostEquals()
self.assertContains()
self.assertCountEqual()
self.assertDictContainsSubset()
self.assertDictEqual()
self.assertEqual()
self.assertEquals()
self.assertFalse()
self.assertFieldOutput()
# in intake.models
class FormSubmission(models.Model):
	organizations = models.ManyToManyField('user_accounts.Organization')

# in user_accounts.models
class Organization(models.Model):
	# some attributes
@bengolder
bengolder / ipdb.python.sublime-snippet
Created January 13, 2017 19:02
ipd breakpoint shortcut for Sublime Text
<snippet>
<content><![CDATA[
import ipdb; ipdb.set_trace()
]]></content>
<tabTrigger>ipd</tabTrigger>
<scope>source.python</scope>
<description>import ipdb; ipdb.set_trace()</description>
</snippet>