Skip to content

Instantly share code, notes, and snippets.

View guyjacks's full-sized avatar

Guy L Jacks guyjacks

View GitHub Profile
def some_func():
organization = Organization.objects.get(id=1)
action_qs = organization.actions.filter(action='fund').by_month()
return action_qs
def test():
organization_mock = mocker.Mock()
patch(..., organization_mock)
@guyjacks
guyjacks / goals.py
Last active December 14, 2017 00:47
class Goal(models.Model):
def __init__(self):
organization
recurring_until (datestamp)
resets ('monthly', 'yearly')
action_type ('fund', 'influence', 'beta')
goal (float)
def progress(self):
pass
@guyjacks
guyjacks / badge.py
Last active December 14, 2017 00:13
class Badge(object):
def is_within_limit():
pass
class SingleActionSingleCompletionBadgeMixin():
def has_earned(action_obj):
pass
class FirstAboardBadge(SingleActionCompletionBadgeMixin, Badge):
pass
class ActionType(object):
def __init__(self, handle, human, points, notification):
self.handle = handle
self.human = human
self.points = points
# expects a string template to be formatted
self.notification = notification
def is_influence(self):
return False
Table "public.impact_badge"
Column | Type | Modifiers
-----------------+--------------------------+-----------------------------------------------------------
id | integer | not null default nextval('impact_badge_id_seq'::regclass)
label | character varying(100) | not null
description | text | not null
action | character varying(25) | not null
required_amount | double precision | not null
active | boolean | not null
organization_id | integer | not null
#### users/models.py
class Message(models.Model):
user = ForeignKeyField()
# we could add a priorty or level field if we want, but lets not do that until we know we need it
app_name = CharField(default='users') # i.e. 'impact'
template = CharField(default='message.html') # i.e. 'badge_message.html'
heading = CharField()
content = TextField()
action = HStoreField()
class Message (models.Model):
title = models.CharField()
body = models.CharField()
image = models.HStoreField({'filename': 'filename val', 'alt': 'alt val'})
action = models.HStoreField({'id': 'id_val', 'label': 'label val'})
@pytest.fixture
def mock_user_fixtures():
u1 = UserFactory()
u2 = UserFactory()
return (u1, u2,)
@pytest.fixture
def mock_organization_fixtures():
o1 = OrganizationFactory()
class BadgeQuerySet(models.QuerySet):
def earned_during_month(self, month, year):
first = get_first_date_of_month(month, year)
last = get_last_date_of_month(month, year)
return self.filter(users__created__gte=first, users__created__lte=last)
def earned_during_current_month(self):
today = get_todays_date()
return self.earned_during_month(today.month, today.year)
...
# APP CONFIGURATION
# ------------------------------------------------------------------------------
DJANGO_APPS = [
# Default Django apps:
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',