diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 4a60eff..2a82bf3 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -1,9 +1,11 @@
{
"name": "DSA - ActionKit Templates",
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
- "postCreateCommand": "pip install -e .",
+ "postAttachCommand": "pip install -e .",
"containerEnv": {
- "DJANGO_SETTINGS_MODULE": "dsa_actionkit.settings"
+ "DJANGO_SETTINGS_MODULE": "dsa_actionkit.settings",
+ "ROOT_URLCONF": "dsa_actionkit.urls",
+ "DJANGO_SECRET_KEY": "solidarityforever"
},
"customizations": {
"vscode": {
@@ -11,7 +13,13 @@
"ms-python.python",
"tamasfe.even-better-toml",
"samuelcolvin.jinjahtml",
- "batisteo.vscode-django"
+ "batisteo.vscode-django",
+ "charliermarsh.ruff",
+ "eamodio.gitlens",
+ "GitHub.vscode-github-actions",
+ "tamasfe.even-better-toml",
+ "esbenp.prettier-vscode",
+ "redhat.vscode-yaml"
]
},
"settings": {
@@ -23,5 +31,23 @@
"editor.defaultFormatter": "samuelcolvin.jinjahtml",
"editor.formatOnSave": true
},
+ "python.terminal.activateEnvInCurrentTerminal": true,
+ "[python]": {
+ "editor.codeActionsOnSave": {
+ "source.fixAll.ruff": true,
+ "source.organizeImports.ruff": true
+ },
+ "editor.defaultFormatter": "charliermarsh.ruff"
+ },
+ "python.testing.cwd": "tests",
+ "python.testing.unittestEnabled": false,
+ "python.testing.pytestEnabled": true,
+ "editor.formatOnSave": true,
+ "editor.formatOnPaste": true,
+ "editor.stickyScroll.enabled": true,
+ "dbt.enableNewLineagePanel": true,
+ "files.insertFinalNewline": true,
+ "terminal.integrated.environmentChangesIndicator": "on"
+ }
}
-}
\ No newline at end of file
+}
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
new file mode 100644
index 0000000..41cdc16
--- /dev/null
+++ b/.github/workflows/ci.yaml
@@ -0,0 +1,23 @@
+name: CI
+
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+ branches:
+ - main
+
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - name: Install packages
+ run: |
+ pip install .
+ - name: Run Tests
+ run: |
+ pytest
diff --git a/.gitignore b/.gitignore
index 253ba83..4bbb8c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,4 +16,5 @@ site.css.map
build
.venv
dist
-*.egg-info
\ No newline at end of file
+*.egg-info
+db.sqlite
\ No newline at end of file
diff --git a/dsa_actionkit/aktemplates.py b/dsa_actionkit/aktemplates.py
index 8a602dc..9f8f5f6 100755
--- a/dsa_actionkit/aktemplates.py
+++ b/dsa_actionkit/aktemplates.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import os
import sys
+
#STATIC_FALLBACK="/static/js/fallback_local" PYTHONPATH=./djanger django-admin runserver --settings=settings
diff --git a/dsa_actionkit/contexts/account_contexts.py b/dsa_actionkit/contexts/account_contexts.py
index 10805a2..0afc49f 100644
--- a/dsa_actionkit/contexts/account_contexts.py
+++ b/dsa_actionkit/contexts/account_contexts.py
@@ -1,318 +1,320 @@
import datetime
+
from . import lib
+
class subscriptions(list):
list_ids = [1, 3, 7]
contexts = {
- 'user_view.html': {
- 'filename': 'user_view.html',
- 'page': {
- 'title': 'User self serve',
- 'name': 'user view',
+ "user_view.html": {
+ "filename": "user_view.html",
+ "page": {
+ "title": "User self serve",
+ "name": "user view",
},
},
- 'signup.html': {
- 'filename': 'signup.html',
- 'page': {
- 'title': 'Signup!',
- 'name': 'signup',
+ "signup.html": {
+ "filename": "signup.html",
+ "page": {
+ "title": "Signup!",
+ "name": "signup",
"custom_fields": {
"entity": "pac",
- "layout_options": "lost_pages_redesign"
- }
+ "layout_options": "lost_pages_redesign",
+ },
},
- 'form': {
- 'introduction_text': 'Signup now!',
- 'user_fields': {
- 'first_name': 'Ann'
- }
+ "form": {
+ "introduction_text": "Signup now!",
+ "user_fields": {
+ "first_name": "Ann",
+ },
},
- 'user_fields': [
- {'field_name': 'name',
- 'label_text': 'Name',
- 'input_tag': '',
+ "user_fields": [
+ {"field_name": "name",
+ "label_text": "Name",
+ "input_tag": '',
},
- {'field_name': 'email',
- 'label_text': 'Email Address',
- 'input_tag': '',
+ {"field_name": "email",
+ "label_text": "Email Address",
+ "input_tag": '',
},
- {'field_name': 'address1',
- 'label_text': 'Street Address',
- 'input_tag': '',
+ {"field_name": "address1",
+ "label_text": "Street Address",
+ "input_tag": '',
},
- {'field_name': 'zip',
- 'label_text': 'ZIP Code',
- 'input_tag': '',
+ {"field_name": "zip",
+ "label_text": "ZIP Code",
+ "input_tag": '',
},
- {'field_name': 'phone',
- 'label_text': 'Phone',
- 'input_tag': '',
+ {"field_name": "phone",
+ "label_text": "Phone",
+ "input_tag": '',
},
],
},
- 'signup.smssubscribe': {
- 'filename': 'signup.html',
- 'page': {
- 'title': 'Signup! sms-opt-out',
- 'name': 'signup',
+ "signup.smssubscribe": {
+ "filename": "signup.html",
+ "page": {
+ "title": "Signup! sms-opt-out",
+ "name": "signup",
"custom_fields": {
"entity": "pac",
- "phone_mobile": "opt-out"
- }
+ "phone_mobile": "opt-out",
+ },
},
- 'form': {
- 'introduction_text': 'Signup now!',
- 'user_fields': {
- 'first_name': 'Ann'
- }
+ "form": {
+ "introduction_text": "Signup now!",
+ "user_fields": {
+ "first_name": "Ann",
+ },
},
- 'user_fields': [
- {'field_name': 'name',
- 'label_text': 'Name',
- 'input_tag': '',
+ "user_fields": [
+ {"field_name": "name",
+ "label_text": "Name",
+ "input_tag": '',
},
- {'field_name': 'email',
- 'label_text': 'Email Address',
- 'input_tag': '',
+ {"field_name": "email",
+ "label_text": "Email Address",
+ "input_tag": '',
},
- {'field_name': 'address1',
- 'label_text': 'Street Address',
- 'input_tag': '',
+ {"field_name": "address1",
+ "label_text": "Street Address",
+ "input_tag": '',
},
- {'field_name': 'zip',
- 'label_text': 'ZIP Code',
- 'input_tag': '',
+ {"field_name": "zip",
+ "label_text": "ZIP Code",
+ "input_tag": '',
},
- {'field_name': 'phone',
- 'label_text': 'Phone',
- 'input_tag': '',
+ {"field_name": "phone",
+ "label_text": "Phone",
+ "input_tag": '',
},
],
},
- 'user_update.html': lib.userform({
- 'filename': 'user_update.html',
- 'page': {
- 'title': 'Update Your Information',
- 'name': 'user-update',
+ "user_update.html": lib.userform({
+ "filename": "user_update.html",
+ "page": {
+ "title": "Update Your Information",
+ "name": "user-update",
"custom_fields": {
- "entity": "pac"
+ "entity": "pac",
},
"followup": {
- "share_title": ""
- }
+ "share_title": "",
+ },
},
- 'user': lib.user({
+ "user": lib.user({
"id": "7338",
"name": "George Costanza",
"phone": "515-555-0199",
}),
}, { # form
- 'introduction_text': 'Please update your information below',
- 'user_fields': [
- {'field_name': 'email',
- 'label_text': 'Email Address',
- 'input_tag': '',
+ "introduction_text": "Please update your information below",
+ "user_fields": [
+ {"field_name": "email",
+ "label_text": "Email Address",
+ "input_tag": '',
},
- {'field_name': 'prefix',
- 'label_text': 'Prefix',
- 'input_tag': '',
+ {"field_name": "prefix",
+ "label_text": "Prefix",
+ "input_tag": '',
},
- {'field_name': 'first_name',
- 'label_text': 'First name',
- 'input_tag': '',
+ {"field_name": "first_name",
+ "label_text": "First name",
+ "input_tag": '',
},
- {'field_name': 'middle_name',
- 'label_text': 'Middle name',
- 'input_tag': '',
+ {"field_name": "middle_name",
+ "label_text": "Middle name",
+ "input_tag": '',
},
- {'field_name': 'last_name',
- 'label_text': 'Last name',
- 'input_tag': '',
+ {"field_name": "last_name",
+ "label_text": "Last name",
+ "input_tag": '',
},
- {'field_name': 'suffix',
- 'label_text': 'Suffix',
- 'input_tag': '',
+ {"field_name": "suffix",
+ "label_text": "Suffix",
+ "input_tag": '',
},
- {'field_name': 'country',
- 'label_text': 'Country',
- 'input_tag': lib.countries(),
+ {"field_name": "country",
+ "label_text": "Country",
+ "input_tag": lib.countries(),
},
- {'field_name': 'address1',
- 'label_text': 'Street Address',
- 'input_tag': '',
+ {"field_name": "address1",
+ "label_text": "Street Address",
+ "input_tag": '',
},
- {'field_name': 'address2',
- 'label_text': 'Street Address',
- 'input_tag': '',
+ {"field_name": "address2",
+ "label_text": "Street Address",
+ "input_tag": '',
},
- {'field_name': 'city',
- 'label_text': 'City',
- 'input_tag': '',
+ {"field_name": "city",
+ "label_text": "City",
+ "input_tag": '',
},
- {'field_name': 'state',
- 'label_text': 'State',
- 'input_tag': lib.states(),
+ {"field_name": "state",
+ "label_text": "State",
+ "input_tag": lib.states(),
},
- {'field_name': 'zip',
- 'label_text': 'Zip',
- 'input_tag': '',
+ {"field_name": "zip",
+ "label_text": "Zip",
+ "input_tag": '',
},
- {'field_name': 'plus4',
- 'label_text': 'Plus4',
- 'input_tag': '',
+ {"field_name": "plus4",
+ "label_text": "Plus4",
+ "input_tag": '',
},
- {'field_name': 'region',
- 'label_text': 'Region',
- 'input_tag': '',
+ {"field_name": "region",
+ "label_text": "Region",
+ "input_tag": '',
},
- {'field_name': 'postal',
- 'label_text': 'Postal Code',
- 'input_tag': '',
+ {"field_name": "postal",
+ "label_text": "Postal Code",
+ "input_tag": '',
},
- {'field_name': 'lang',
- 'label_text': 'Language',
- 'input_tag': '',
+ {"field_name": "lang",
+ "label_text": "Language",
+ "input_tag": '',
},
],
}),
- 'recurring_update.html': {
- 'filename': 'recurring_update.html',
- 'page': {
- 'title': 'Update Account Information',
- 'name': 'recurring_page',
- 'custom_fields': {
- 'proxypassword': 'abc123'
- }
+ "recurring_update.html": {
+ "filename": "recurring_update.html",
+ "page": {
+ "title": "Update Account Information",
+ "name": "recurring_page",
+ "custom_fields": {
+ "proxypassword": "abc123",
+ },
},
- 'logged_in_user': {
- 'name': 'Daddy Warbucks',
- 'address1': 'Easy Street',
- 'email': 'daddy.warbucks@example.com',
- 'city': 'New York',
- 'state': 'NY',
- 'phone': '555-123-1233',
- 'subscriptions': subscriptions([
- {'list_id': 1},
- {'list_id': 3},
- {'list_id': 7},
- ])
+ "logged_in_user": {
+ "name": "Daddy Warbucks",
+ "address1": "Easy Street",
+ "email": "daddy.warbucks@example.com",
+ "city": "New York",
+ "state": "NY",
+ "phone": "555-123-1233",
+ "subscriptions": subscriptions([
+ {"list_id": 1},
+ {"list_id": 3},
+ {"list_id": 7},
+ ]),
},
- 'active': [{ # profile
- 'id': '123',
- 'payment_processor_information': {
- 'use_cse': False,
- 'cse_key': '123123',
- 'use_tr': True,
+ "active": [{ # profile
+ "id": "123",
+ "payment_processor_information": {
+ "use_cse": False,
+ "cse_key": "123123",
+ "use_tr": True,
},
- 'status': 'active', # get actual data
- 'updated_at': datetime.datetime(2016, 1, 1), # get actual data
- 'created_at': datetime.datetime(2016, 1, 1), # get actual data
- 'start': datetime.datetime(2015, 1, 1), # get actual data
- 'payment_count': 10,
- 'get_period_display': 'Monthly', # get actual data
- 'payment_total_amt': '$200.00', # get actual data
- 'amt': '$20',
- 'order': {
- 'payment_method': 'cc'
+ "status": "active", # get actual data
+ "updated_at": datetime.datetime(2016, 1, 1), # get actual data
+ "created_at": datetime.datetime(2016, 1, 1), # get actual data
+ "start": datetime.datetime(2015, 1, 1), # get actual data
+ "payment_count": 10,
+ "get_period_display": "Monthly", # get actual data
+ "payment_total_amt": "$200.00", # get actual data
+ "amt": "$20",
+ "order": {
+ "payment_method": "cc",
},
- 'card_num': '1234',
- 'display_expiration_date': '05/2060',
- 'next_payment_date': datetime.datetime(2016, 9, 1),
+ "card_num": "1234",
+ "display_expiration_date": "05/2060",
+ "next_payment_date": datetime.datetime(2016, 9, 1),
}],
- 'inactive': [],
+ "inactive": [],
},
- 'recurring_update_paypal': {
- 'filename': 'recurring_update.html',
- 'page': {
- 'title': 'Update Account Information (PayPal)',
- 'name': 'recurring_page',
+ "recurring_update_paypal": {
+ "filename": "recurring_update.html",
+ "page": {
+ "title": "Update Account Information (PayPal)",
+ "name": "recurring_page",
},
- 'logged_in_user': {
- 'name': 'Daddy Warbucks',
- 'address1': 'Easy Street',
- 'email': 'daddy.warbucks@example.com',
- 'city': 'New York',
- 'state': 'NY',
- 'phone': '555-123-1233',
+ "logged_in_user": {
+ "name": "Daddy Warbucks",
+ "address1": "Easy Street",
+ "email": "daddy.warbucks@example.com",
+ "city": "New York",
+ "state": "NY",
+ "phone": "555-123-1233",
},
"show_paypal": True,
"paypal_cohort": 0,
- 'active': [{ # profile
- 'account': 'MoveOnPAC PayPal',
- 'id': '123',
- 'payment_processor_information': {
- 'use_cse': False,
- 'cse_key': '123123',
- 'use_tr': True,
+ "active": [{ # profile
+ "account": "MoveOnPAC PayPal",
+ "id": "123",
+ "payment_processor_information": {
+ "use_cse": False,
+ "cse_key": "123123",
+ "use_tr": True,
},
- 'status': 'active', # get actual data
- 'updated_at': datetime.datetime(2016, 1, 1), # get actual data
- 'created_at': datetime.datetime(2016, 1, 1), # get actual data
- 'start': datetime.datetime(2015, 1, 1), # get actual data
- 'payment_count': 10,
- 'get_period_display': 'Monthly', # get actual data
- 'payment_total_amt': '$200.00', # get actual data
- 'amt': '$20',
- 'order': {
- 'payment_method': 'paypal'
+ "status": "active", # get actual data
+ "updated_at": datetime.datetime(2016, 1, 1), # get actual data
+ "created_at": datetime.datetime(2016, 1, 1), # get actual data
+ "start": datetime.datetime(2015, 1, 1), # get actual data
+ "payment_count": 10,
+ "get_period_display": "Monthly", # get actual data
+ "payment_total_amt": "$200.00", # get actual data
+ "amt": "$20",
+ "order": {
+ "payment_method": "paypal",
},
- 'card_num': '1234',
- 'display_expiration_date': '05/2060',
- 'next_payment_date': datetime.datetime(2016, 9, 1),
+ "card_num": "1234",
+ "display_expiration_date": "05/2060",
+ "next_payment_date": datetime.datetime(2016, 9, 1),
}],
- 'inactive': [],
+ "inactive": [],
},
- 'recurring_update_ach.html': {
- 'filename': 'recurring_update.html',
- 'page': {
- 'title': 'Update Account Information (ACH)',
- 'name': 'recurring_page',
- 'custom_fields': {
- 'proxypassword': 'abc123'
- }
+ "recurring_update_ach.html": {
+ "filename": "recurring_update.html",
+ "page": {
+ "title": "Update Account Information (ACH)",
+ "name": "recurring_page",
+ "custom_fields": {
+ "proxypassword": "abc123",
+ },
},
- 'logged_in_user': {
- 'name': 'Daddy Warbucks',
- 'address1': 'Easy Street',
- 'email': 'daddy.warbucks@example.com',
- 'city': 'New York',
- 'state': 'NY',
- 'phone': '555-123-1233',
- 'subscriptions': subscriptions([
- {'list_id': 1},
- {'list_id': 3},
- {'list_id': 7},
- ])
+ "logged_in_user": {
+ "name": "Daddy Warbucks",
+ "address1": "Easy Street",
+ "email": "daddy.warbucks@example.com",
+ "city": "New York",
+ "state": "NY",
+ "phone": "555-123-1233",
+ "subscriptions": subscriptions([
+ {"list_id": 1},
+ {"list_id": 3},
+ {"list_id": 7},
+ ]),
},
- 'active': [{ # profile
- 'id': '123',
- 'is_ach': True,
- 'payment_processor_information': {
- 'use_cse': False,
- 'cse_key': '123123',
- 'use_tr': True,
+ "active": [{ # profile
+ "id": "123",
+ "is_ach": True,
+ "payment_processor_information": {
+ "use_cse": False,
+ "cse_key": "123123",
+ "use_tr": True,
},
- 'status': 'active', #get actual data
- 'updated_at': datetime.datetime(2016, 1, 1), #get actual data
- 'created_at': datetime.datetime(2016, 1, 1), #get actual data
- 'start': datetime.datetime(2015, 1, 1), #get actual data
- 'payment_count': 10,
- 'get_period_display': 'Monthly', #get actual data
- 'payment_total_amt': '$200.00', #get actual data
- 'amt': '$20',
- 'order': {
- 'payment_method': 'cc'
+ "status": "active", #get actual data
+ "updated_at": datetime.datetime(2016, 1, 1), #get actual data
+ "created_at": datetime.datetime(2016, 1, 1), #get actual data
+ "start": datetime.datetime(2015, 1, 1), #get actual data
+ "payment_count": 10,
+ "get_period_display": "Monthly", #get actual data
+ "payment_total_amt": "$200.00", #get actual data
+ "amt": "$20",
+ "order": {
+ "payment_method": "cc",
},
- 'card_num': '1234',
- 'display_expiration_date': '05/2060',
- 'next_payment_date': datetime.datetime(2016, 9, 1),
+ "card_num": "1234",
+ "display_expiration_date": "05/2060",
+ "next_payment_date": datetime.datetime(2016, 9, 1),
}],
- 'inactive': [],
+ "inactive": [],
},
}
diff --git a/dsa_actionkit/contexts/donation_contexts.py b/dsa_actionkit/contexts/donation_contexts.py
index 9877cdf..ee586e7 100644
--- a/dsa_actionkit/contexts/donation_contexts.py
+++ b/dsa_actionkit/contexts/donation_contexts.py
@@ -1,5 +1,4 @@
-"""
-Scenarios:
+"""Scenarios:
1. single
2. args
10 args.amount_other = "666"
@@ -42,7 +41,7 @@
"donation_type": ["recurring", "single"],
"payment_hash": ["abc123"],
"suggested_ask": ["20", "666"],
- "weekly": ["1"]
+ "weekly": ["1"],
}
def user(recurring=1, payment_hash=False, customfields=None, previous_recurring=False, id=666):
@@ -64,30 +63,30 @@ def user(recurring=1, payment_hash=False, customfields=None, previous_recurring=
"zip": "07091",
"email": "morticia@example.com",
"custom_fields": customfields,
- }
+ },
}
if payment_hash:
- userbase['user'].update({
- 'payment_hash': 'abc123abc123',
- 'has_payment_token': True,
+ userbase["user"].update({
+ "payment_hash": "abc123abc123",
+ "has_payment_token": True,
})
if previous_recurring==False:
- userbase['user'].update({
- 'orderrecurring_set': {
- 'active': {
- 'count': 0,
+ userbase["user"].update({
+ "orderrecurring_set": {
+ "active": {
+ "count": 0,
+ },
+ "count": 0,
},
- 'count': 0
- }
})
else:
- userbase['user'].update({
- 'orderrecurring_set': {
- 'active': {
- 'count': recurring,
+ userbase["user"].update({
+ "orderrecurring_set": {
+ "active": {
+ "count": recurring,
},
- 'count': recurring
- }
+ "count": recurring,
+ },
})
return userbase
@@ -98,8 +97,8 @@ def user(recurring=1, payment_hash=False, customfields=None, previous_recurring=
"portrait_url": "https://fr.web.img2.acsta.net/medias/nmedia/18/35/61/70/19013441.jpg",
"desc": "Seabright (Seab) Cooley from South Carolina and the book Advise and Consent",
"id": "1959",
- }
- ]
+ },
+ ],
}
candidates2 = {
@@ -114,8 +113,8 @@ def user(recurring=1, payment_hash=False, customfields=None, previous_recurring=
"portrait_url": "https://vignette.wikia.nocookie.net/simpsons/images/2/25/Adult_burns.jpg/revision/latest?cb=20111012170021",
"desc": "A recurring character in the animated television series The Simpsons, and is voiced by Harry Shearer. Mr. Burns is the evil owner of the Springfield Nuclear Power Plant and is also Homer Simpson's boss.",
"id": "666",
- }
- ]
+ },
+ ],
}
products = {
@@ -126,8 +125,8 @@ def user(recurring=1, payment_hash=False, customfields=None, previous_recurring=
"desc": "This is a cool product that you should want",
"price": "55.23",
"id": "1",
- }
- ]
+ },
+ ],
}
products2 = {
@@ -137,19 +136,19 @@ def user(recurring=1, payment_hash=False, customfields=None, previous_recurring=
{"name": "This fight is our fight: the battle to save america's middle class",
"desc": "This is a cool product that you should want",
"price": "55.23",
- "id": "1"
+ "id": "1",
},
{"name": "no desc max 1",
"price": "1",
"max": 1,
- "id": "2"
- }
- ]
+ "id": "2",
+ },
+ ],
}
-def base(title='', entity='c4', layout='', filename="donate.html", fields={}, show_paypal=False, allow_international=False, accept_ach=False, liveaddress=None):
+def base(title="", entity="c4", layout="", filename="donate.html", fields={}, show_paypal=False, allow_international=False, accept_ach=False, liveaddress=None):
rv = {
"filename": filename,
"show_paypal": show_paypal,
@@ -161,11 +160,11 @@ def base(title='', entity='c4', layout='', filename="donate.html", fields={}, sh
"custom_fields": {
"layout_options": "2col,no_social,%s" % layout,
"entity": entity, # "pac", "joint_pac_c4",
- "liveaddress": liveaddress
+ "liveaddress": liveaddress,
#"thanks_header_text": "You are the best!", #optional
#"sharing_prompt": False, #optional
},
- "title": 'Donate to Example.com (%s)' % title,
+ "title": "Donate to Example.com (%s)" % title,
"name": "civ-donation",
"id": 123,
"currency_sym": "$",
@@ -179,50 +178,50 @@ def base(title='', entity='c4', layout='', filename="donate.html", fields={}, sh
"amounts": [20,40,75,200,400,750,1500,"other"],
"allow_monthly": True,
}
- rv['page']['custom_fields'].update(fields)
+ rv["page"]["custom_fields"].update(fields)
return rv
-def order(order_type='order', details=None, quickpay=False, paypal=False, apple=False): #get rid of paypal and applepay and switch to "payment method"
+def order(order_type="order", details=None, quickpay=False, paypal=False, apple=False): #get rid of paypal and applepay and switch to "payment method"
#order_type = 'orderrecurring'
orderkey = {
- 'order': {
- 'id': 123456,
- 'amt': '$12.07',
- 'created_at': datetime.datetime.now(),
- 'account': 'Example.com Civic Action',
- }
+ "order": {
+ "id": 123456,
+ "amt": "$12.07",
+ "created_at": datetime.datetime.now(),
+ "account": "Example.com Civic Action",
+ },
}
- if order_type == 'orderrecurring':
- orderkey['orderrecurring'] = orderkey['order']
+ if order_type == "orderrecurring":
+ orderkey["orderrecurring"] = orderkey["order"]
if details:
orderkey[order_type].update(details)
rv = {
- 'akid': '--userakidTEST--',
- 'action': {
- 'id': 654321,
- 'custom_fields': {
- 'upgrade_order_id': '111',
- 'add_me_to_weekly': True, #optional
+ "akid": "--userakidTEST--",
+ "action": {
+ "id": 654321,
+ "custom_fields": {
+ "upgrade_order_id": "111",
+ "add_me_to_weekly": True, #optional
},
- }
+ },
}
if quickpay:
- rv['action']['custom_fields'].update({
- 'payment_token': {
- 'status': 'active',
- 'token': 'abc123999',
+ rv["action"]["custom_fields"].update({
+ "payment_token": {
+ "status": "active",
+ "token": "abc123999",
},
})
if paypal:
- rv['action']['custom_fields'].update({
- 'ak_paypal_transaction_id': '2309147283',
+ rv["action"]["custom_fields"].update({
+ "ak_paypal_transaction_id": "2309147283",
})
if apple:
- rv['action']['custom_fields'].update({
- 'mobile_payment': 'apple_pay',
+ rv["action"]["custom_fields"].update({
+ "mobile_payment": "apple_pay",
})
rv.update(orderkey)
- rv['action'].update(orderkey)
+ rv["action"].update(orderkey)
return rv
def compose(bases, argparams=[], argind=0):
@@ -230,70 +229,70 @@ def compose(bases, argparams=[], argind=0):
for b in bases:
rv.update(b)
arg_dict = dict([(k,args_permutations[k][argind]) for k in argparams])
- rv.update({'args': arg_dict})
+ rv.update({"args": arg_dict})
return rv
contexts = {
- 'donate.1': compose([base('civ')]),
- 'donate.2': compose([base('candidate', entity='pac'), candidates]),
- 'donate.3': compose([base('suggested_ask')], ["suggested_ask",]),
- 'donate.4': compose([base('suggested_ask, recurring')], ["suggested_ask","donation_type"]),
- 'donate.5': compose([base('other suggested_ask, single')], ["suggested_ask","donation_type"], -1),
- 'donate.6': compose([base('suggested_ask, payment_hash'), user(0, payment_hash=True)], ["suggested_ask","payment_hash"]),
- 'donate.7': compose([base('user'), user()]),
- 'donate.8': compose([base('pac', entity='pac', show_paypal=True), user(id=507809)]),
- 'donate.9': compose([base('candidate suggested', entity='pac', layout='donate_5050_split'), candidates], ["suggested_ask"], -1),
- 'donate.10': compose([base('two candidates suggested', entity='pac', layout='donate_5050_split'), user(id=507809), candidates2], ["suggested_ask"], -1),
- 'donate.11': compose([base('two candidates suggested no 5050', entity='pac'), candidates2], ["suggested_ask"], -1),
- 'donate.12': compose([base('candidate, quickpay', entity='pac', layout='donate_5050_split'), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
- 'donate.13': compose([base('two candidates quickpay', entity='pac', layout='donate_5050_split'), user(0, payment_hash=True), candidates2], ["payment_hash"], -1),
- 'donate.14': compose([base('1 product', liveaddress="shipping"), products]),
- 'donate.15': compose([base('2 products', liveaddress="shipping"), products2]),
- 'donate.16': compose([base('weekly recurring checkbox', layout="make_weekly_checkbox")], ["weekly"]),
- 'donate.17': compose([base('quickpay recurring checkbox', entity='pac', layout="donate_5050_split"), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
- 'donate.18': compose([base('quickpay', entity='pac', layout='donate_5050_split donation_no_checkbox'), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
- 'donate.19': compose([base('quickpay with weekly', entity='pac', layout="make_weekly_checkbox"), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
- 'donate.20': compose([base('quickpay', entity='pac', layout='weekly_only'), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
- 'donate.22': compose([base('quickpay with monthly recurring'), user(0, payment_hash=True)], ["donation_type","payment_hash"]),
- 'donate.23': compose([base('civ', show_paypal=True), user(0, id=5079)]),
- 'donate.24': compose([base('civ with international', allow_international=True)]),
- 'donate.25': compose([base('pac', entity='pac', show_paypal=True)]),
- 'donate.26': compose([base('weekly and two candidates', entity='pac', layout="weekly_only"), candidates2]),
- 'donate.27': compose([base('two candidates', entity='pac'), candidates2]),
- 'donate.28': compose([base('pac', entity='pac', show_paypal=True, layout="accept_ach"), user(id=507809)]),
- 'donate.29': compose([base('pac', entity='pac', show_paypal=True), user(id=507810)]),
- 'donate.30': compose([base('pac with ach option', entity='pac', accept_ach=True), user(id=507809)]),
- 'donate.31': compose([base('quickpay with a good weekly param combination', entity='pac', layout='weekly_only'), user(0, payment_hash=True), candidates], ["donation_type","payment_hash"]),
- 'donate.32': compose([base('quickpay with a bad weekly param combination', entity='pac', layout='weekly_only'), user(0, payment_hash=True), candidates], ["payment_hash"]),
- 'donate.thanks.1': compose([base('civ with payment_hash', filename='thanks.html'), user(0, payment_hash=True), order()]),
- 'donate.thanks.2': compose([base('recurring civ', entity='pac', filename='thanks.html'),
- user(), order('orderrecurring')]),
- 'donate.thanks.3': compose([base('recurring civ receipt message',
- entity='pac', filename='thanks.html',
- fields={'thanks_below_receipt_message':'This message is below the receipt!'}
+ "donate.1": compose([base("civ")]),
+ "donate.2": compose([base("candidate", entity="pac"), candidates]),
+ "donate.3": compose([base("suggested_ask")], ["suggested_ask"]),
+ "donate.4": compose([base("suggested_ask, recurring")], ["suggested_ask","donation_type"]),
+ "donate.5": compose([base("other suggested_ask, single")], ["suggested_ask","donation_type"], -1),
+ "donate.6": compose([base("suggested_ask, payment_hash"), user(0, payment_hash=True)], ["suggested_ask","payment_hash"]),
+ "donate.7": compose([base("user"), user()]),
+ "donate.8": compose([base("pac", entity="pac", show_paypal=True), user(id=507809)]),
+ "donate.9": compose([base("candidate suggested", entity="pac", layout="donate_5050_split"), candidates], ["suggested_ask"], -1),
+ "donate.10": compose([base("two candidates suggested", entity="pac", layout="donate_5050_split"), user(id=507809), candidates2], ["suggested_ask"], -1),
+ "donate.11": compose([base("two candidates suggested no 5050", entity="pac"), candidates2], ["suggested_ask"], -1),
+ "donate.12": compose([base("candidate, quickpay", entity="pac", layout="donate_5050_split"), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
+ "donate.13": compose([base("two candidates quickpay", entity="pac", layout="donate_5050_split"), user(0, payment_hash=True), candidates2], ["payment_hash"], -1),
+ "donate.14": compose([base("1 product", liveaddress="shipping"), products]),
+ "donate.15": compose([base("2 products", liveaddress="shipping"), products2]),
+ "donate.16": compose([base("weekly recurring checkbox", layout="make_weekly_checkbox")], ["weekly"]),
+ "donate.17": compose([base("quickpay recurring checkbox", entity="pac", layout="donate_5050_split"), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
+ "donate.18": compose([base("quickpay", entity="pac", layout="donate_5050_split donation_no_checkbox"), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
+ "donate.19": compose([base("quickpay with weekly", entity="pac", layout="make_weekly_checkbox"), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
+ "donate.20": compose([base("quickpay", entity="pac", layout="weekly_only"), user(0, payment_hash=True), candidates], ["payment_hash"], -1),
+ "donate.22": compose([base("quickpay with monthly recurring"), user(0, payment_hash=True)], ["donation_type","payment_hash"]),
+ "donate.23": compose([base("civ", show_paypal=True), user(0, id=5079)]),
+ "donate.24": compose([base("civ with international", allow_international=True)]),
+ "donate.25": compose([base("pac", entity="pac", show_paypal=True)]),
+ "donate.26": compose([base("weekly and two candidates", entity="pac", layout="weekly_only"), candidates2]),
+ "donate.27": compose([base("two candidates", entity="pac"), candidates2]),
+ "donate.28": compose([base("pac", entity="pac", show_paypal=True, layout="accept_ach"), user(id=507809)]),
+ "donate.29": compose([base("pac", entity="pac", show_paypal=True), user(id=507810)]),
+ "donate.30": compose([base("pac with ach option", entity="pac", accept_ach=True), user(id=507809)]),
+ "donate.31": compose([base("quickpay with a good weekly param combination", entity="pac", layout="weekly_only"), user(0, payment_hash=True), candidates], ["donation_type","payment_hash"]),
+ "donate.32": compose([base("quickpay with a bad weekly param combination", entity="pac", layout="weekly_only"), user(0, payment_hash=True), candidates], ["payment_hash"]),
+ "donate.thanks.1": compose([base("civ with payment_hash", filename="thanks.html"), user(0, payment_hash=True), order()]),
+ "donate.thanks.2": compose([base("recurring civ", entity="pac", filename="thanks.html"),
+ user(), order("orderrecurring")]),
+ "donate.thanks.3": compose([base("recurring civ receipt message",
+ entity="pac", filename="thanks.html",
+ fields={"thanks_below_receipt_message":"This message is below the receipt!"},
),
- user(), order('orderrecurring')]),
- 'donate.thanks.4': compose([base('recurring user recurring', filename='thanks.html'),
- user(2), order('orderrecurring')]),
- 'donate.thanks.5': compose([base('pac user payment_hash', entity='pac', filename='thanks.html'),
+ user(), order("orderrecurring")]),
+ "donate.thanks.4": compose([base("recurring user recurring", filename="thanks.html"),
+ user(2), order("orderrecurring")]),
+ "donate.thanks.5": compose([base("pac user payment_hash", entity="pac", filename="thanks.html"),
user(0, payment_hash=True), order()]),
- 'donate.thanks.6': compose([base('pac user quickpay no employer', entity='pac', filename='thanks.html'),
- user(0, payment_hash=True, customfields={'x':1}), order(quickpay=True)]),
- 'donate.thanks.7': compose([base('pac user candidate', entity='pac', filename='thanks.html'),
+ "donate.thanks.6": compose([base("pac user quickpay no employer", entity="pac", filename="thanks.html"),
+ user(0, payment_hash=True, customfields={"x":1}), order(quickpay=True)]),
+ "donate.thanks.7": compose([base("pac user candidate", entity="pac", filename="thanks.html"),
user(0, payment_hash=True),
order(details={
- 'order_details': [
- {'candidate': {'name': "Francis Underwood"},
- 'amount': 10.00,},
+ "order_details": [
+ {"candidate": {"name": "Francis Underwood"},
+ "amount": 10.00},
],
- 'other_amount': 2.07
+ "other_amount": 2.07,
})]),
- 'donate.thanks.8': compose([base('civ with payment_hash', filename='thanks.html'), user(0, payment_hash=True), order()]),
- 'donate.thanks.9': compose([base('civ with payment_hash', filename='thanks.html'), user(recurring=0, payment_hash=True, previous_recurring=False), order(paypal=True)]),
- 'donate.thanks.10': compose([base('civ with payment_hash', filename='thanks.html'), user(recurring=1, payment_hash=True, previous_recurring=True), order(paypal=True)]),
- 'donate.thanks.11': compose([base('civ with payment_hash', filename='thanks.html'), user(recurring=0, payment_hash=True, previous_recurring=False), order()]),
- 'donate.thanks.12': compose([base('civ with payment_hash', filename='thanks.html'), user(recurring=1, payment_hash=True, previous_recurring=True), order()]),
- 'donate.thanks.13': compose([base('civ with payment_hash', filename='thanks.html'), user(recurring=1, payment_hash=True, previous_recurring=False), order(apple=True)]),
- 'donate.thanks.14': compose([base('civ with payment_hash', filename='thanks.html'), user(recurring=1, payment_hash=True, previous_recurring=True), order(apple=True)]),
+ "donate.thanks.8": compose([base("civ with payment_hash", filename="thanks.html"), user(0, payment_hash=True), order()]),
+ "donate.thanks.9": compose([base("civ with payment_hash", filename="thanks.html"), user(recurring=0, payment_hash=True, previous_recurring=False), order(paypal=True)]),
+ "donate.thanks.10": compose([base("civ with payment_hash", filename="thanks.html"), user(recurring=1, payment_hash=True, previous_recurring=True), order(paypal=True)]),
+ "donate.thanks.11": compose([base("civ with payment_hash", filename="thanks.html"), user(recurring=0, payment_hash=True, previous_recurring=False), order()]),
+ "donate.thanks.12": compose([base("civ with payment_hash", filename="thanks.html"), user(recurring=1, payment_hash=True, previous_recurring=True), order()]),
+ "donate.thanks.13": compose([base("civ with payment_hash", filename="thanks.html"), user(recurring=1, payment_hash=True, previous_recurring=False), order(apple=True)]),
+ "donate.thanks.14": compose([base("civ with payment_hash", filename="thanks.html"), user(recurring=1, payment_hash=True, previous_recurring=True), order(apple=True)]),
}
diff --git a/dsa_actionkit/contexts/event_context_json.py b/dsa_actionkit/contexts/event_context_json.py
index 20d164f..031274a 100644
--- a/dsa_actionkit/contexts/event_context_json.py
+++ b/dsa_actionkit/contexts/event_context_json.py
@@ -1,4 +1,4 @@
-#this is for /context/ loading for updating page in
+#this is for /context/ loading for updating page in
#https://roboticdogs.actionkit.com/context/test_create?callback=actionkit.forms.onContextLoaded&form_name=act&action_id=117202230&ar=1&required=email&required=country&want_prefill_data=1&r=0.20345950596532325&url=https://roboticdogs.actionkit.com/event/scott-test_create/create/?action_id=117202230&update=1&want_prefill_data=1
#should be wrapped in actionkit.forms.onContextLoaded()
event_json = {
@@ -75,14 +75,14 @@
"work_phone": 1,
"x": 1,
"y": 1,
- "zip": 1
+ "zip": 1,
},
"blank": [
"suffix",
"prefix",
"middle_name",
"address2",
- "region"
+ "region",
],
"form_name": "act",
"move_fields": [],
@@ -91,8 +91,8 @@
"page": {
"custom_fields": {
"entity": "pac",
- "test_custom_event_field": "random text up to 100 characters"
- }
+ "test_custom_event_field": "random text up to 100 characters",
+ },
},
"prefill_data": {
"action_id": "117202230",
@@ -144,7 +144,7 @@
"prefix": "",
"state": "CO",
"suffix": "",
- "zip": "80210"
+ "zip": "80210",
},
"required": [
"event_starts_at_date",
@@ -155,7 +155,7 @@
"event_starts_at_time",
"event_starts_at_ampm",
"event_host_requirements",
- "event_venue"
+ "event_venue",
],
"text": {
"error_TEMPLATE:invalid": "{0} is invalid.",
@@ -258,6 +258,6 @@
"field_shipping_zip": "shipping ZIP Code",
"field_state": "state",
"field_taf_emails": "one or more friends' email addresses",
- "field_zip": "ZIP Code"
- }
+ "field_zip": "ZIP Code",
+ },
}
diff --git a/dsa_actionkit/contexts/event_contexts.py b/dsa_actionkit/contexts/event_contexts.py
index fdb5593..6e33c50 100644
--- a/dsa_actionkit/contexts/event_contexts.py
+++ b/dsa_actionkit/contexts/event_contexts.py
@@ -3,17 +3,17 @@
import os
import random
-from django.utils import timezone
-from django.utils import dateformat
+from django.utils import dateformat, timezone
from django.utils.html import format_html
+
class signups(list):
pass
class user(dict):
def __str__(self):
- return self.get('name')
+ return self.get("name")
attendees = signups([
# "role": "attendee",
@@ -34,7 +34,7 @@ def __str__(self):
}),
},
])
-attendees.role = 'attendee'
+attendees.role = "attendee"
cohosts = signups([
{
@@ -46,10 +46,10 @@ def __str__(self):
}),
},
])
-cohosts.role = 'host'
+cohosts.role = "host"
# 1000 based off of congressional district offices. lat/lng are not accurate, but nearby
-places_list = list(csv.DictReader(open(os.path.dirname(__file__) + '/event_places.csv')))
+places_list = list(csv.DictReader(open(os.path.dirname(__file__) + "/event_places.csv")))
class MST(datetime.tzinfo):
# use MST because AZ is in MST and doesn't observe DST
@@ -77,12 +77,10 @@ def event_create(days_from_now=7, localtime=15, id=343775,
is_awaiting_confirmation=False,
place_index=None, minutes_from_now=False,
attend_page=False):
-
- """
- localtime = hour of the day
- To get an event time with more precision to the current time,
- set days_from_now=0 and minutes_from_now to an integer, and
- choose a place_index with an MST locale.
+ """Localtime = hour of the day
+ To get an event time with more precision to the current time,
+ set days_from_now=0 and minutes_from_now to an integer, and
+ choose a place_index with an MST locale.
"""
now_utc = datetime.datetime.now(timezone.utc)
@@ -93,8 +91,8 @@ def event_create(days_from_now=7, localtime=15, id=343775,
place_loc = places_list[place_index]
else:
place_loc = places_list[random.randint(0, len(places_list) -1)]
- place_loc['city_etc_no_postal'] = '{}, {}'.format(place_loc['city'], place_loc['state'])
- place_loc['city_etc'] = '{} {}'.format(place_loc['city_etc_no_postal'], place_loc['zip'])
+ place_loc["city_etc_no_postal"] = "{}, {}".format(place_loc["city"], place_loc["state"])
+ place_loc["city_etc"] = "{} {}".format(place_loc["city_etc_no_postal"], place_loc["zip"])
objobj = None
@@ -123,7 +121,7 @@ def event_create(days_from_now=7, localtime=15, id=343775,
# "latitude":
"directions": "Directions.",
- "get_starts_at_display": dateformat.format(event_day, 'l, M j, g:i A'), # "Monday, Jan 1, 1:00 AM",
+ "get_starts_at_display": dateformat.format(event_day, "l, M j, g:i A"), # "Monday, Jan 1, 1:00 AM",
"is_in_past": bool(now_utc > event_day_utc),
"is_full": bool(attendee_count >= max_attendees),
"is_open_for_signup": bool(days_from_now > 0 and not attendee_count >= max_attendees),
@@ -132,22 +130,22 @@ def event_create(days_from_now=7, localtime=15, id=343775,
"is_awaiting_confirmation": is_awaiting_confirmation,
"note_to_attendees": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"public_description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
- "title": "Event Title {}".format(place_index),
+ "title": f"Event Title {place_index}",
"venue": "Venue Name",
"local_campaign": {
"create_page": {
- "name": "Local Event Creation Name"
+ "name": "Local Event Creation Name",
},
"signup_page": {
- "name": "Local Signup Page Name"
- }
+ "name": "Local Signup Page Name",
+ },
},
}
evt_obj.update(place_loc)
return evt_obj
contexts = {
- 'event_host_tools.html': {
+ "event_host_tools.html": {
"akid": "111111",
"filename": "event_host_tools.html",
"page": {
@@ -156,11 +154,11 @@ def event_create(days_from_now=7, localtime=15, id=343775,
},
"followup": {
"taf_subject": "Come to my event!",
- "taf_body": "Hi, blah blah blah about the event!!
[[See the 'Tell-a-friend Body' in After-Action Info for the Host page of this event.]]"
+ "taf_body": "Hi, blah blah blah about the event!!
[[See the 'Tell-a-friend Body' in After-Action Info for the Host page of this event.]]",
},
"title": "Host Tools Page",
"type": "EventCreate",
- "name": "fakecampaign_create"
+ "name": "fakecampaign_create",
},
"attendees": attendees,
"cohosts": cohosts,
@@ -182,7 +180,7 @@ def event_create(days_from_now=7, localtime=15, id=343775,
"phone": "123-456-7890",
}),
},
- 'event_attend.html': {
+ "event_attend.html": {
"filename": "event_attend.html",
"campaign": {
"local_title": "Campaign Title",
@@ -199,42 +197,42 @@ def event_create(days_from_now=7, localtime=15, id=343775,
"events": [event_create(place_index=20)],
"form": {
"signup_text": "
Signup text.
", - "ground_rules": "Please follow these guidelines to ensure a good event:
Please follow these guidelines to ensure a good event:
Signup text.
", - "ground_rules": "Please follow these guidelines to ensure a good event:
Please follow these guidelines to ensure a good event:
Signup text for past event.
", - "ground_rules": "Please follow these guidelines to ensure a good event:
Please follow these guidelines to ensure a good event:
Signup text for past event.
", - "ground_rules": "Please follow these guidelines to ensure a good event:
Please follow these guidelines to ensure a good event:
Search page text for campaign with only future events.
", @@ -476,18 +474,18 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_zip": True, "show_public_description": True, "name": "fakecampaign-with-future-events", - "public_create_page": True + "public_create_page": True, }, "events": [event_create(1, 10, 343123), event_create(1, 15, 343124), event_create(4, 15, 343125), - event_create(0, 15, 343130, place_index=57, minutes_from_now=5) + event_create(0, 15, 343130, place_index=57, minutes_from_now=5), ], }, - 'event_search_with_results': { + "event_search_with_results": { "filename": "event_search.html", "args": { - "page": "event_search" + "page": "event_search", }, "hide_map": False, "campaign": { @@ -500,12 +498,12 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_zip": True, "show_public_description": True, "name": "fakecampaign-with-future-events", - "public_create_page": True + "public_create_page": True, }, "events": [event_create(1, 10, 343123), event_create(1, 15, 343124), event_create(4, 15, 343125), - event_create(0, 15, 343130, place_index=57, minutes_from_now=5) + event_create(0, 15, 343130, place_index=57, minutes_from_now=5), ], "form": { "search_page_text": "Search page text for campaign with only future events.
", @@ -516,10 +514,10 @@ def event_create(days_from_now=7, localtime=15, id=343775, "type": "EventSignup", }, }, - 'event_search_with_results_showaddress1': { + "event_search_with_results_showaddress1": { "filename": "event_search.html", "args": { - "page": "event_search" + "page": "event_search", }, "hide_map": False, "campaign": { @@ -533,12 +531,12 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_address1": True, # to support map in Original template "show_public_description": True, "name": "fakecampaign-with-future-events", - "public_create_page": True + "public_create_page": True, }, "events": [event_create(1, 10, 343123, place_index=126), event_create(1, 15, 343124, place_index=43), event_create(4, 15, 343125, place_index=645), - event_create(0, 15, 343130, place_index=57, minutes_from_now=5) + event_create(0, 15, 343130, place_index=57, minutes_from_now=5), ], "form": { "search_page_text": "Search page text for campaign with only future events.
", @@ -549,7 +547,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "type": "EventSignup", }, }, - 'event_search_noevents.html': { + "event_search_noevents.html": { # this doesn't render as expected - come back to this later "filename": "event_search.html", "form": { @@ -570,13 +568,13 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_zip": True, "show_public_description": True, "name": "fakecampaign-with-no-events", - "public_create_page": True + "public_create_page": True, }, }, - 'event_search_with_no_results': { + "event_search_with_no_results": { "filename": "event_search.html", "args": { - "page": "event_search" + "page": "event_search", }, "campaign": { "local_title": "Campaign Title - no events", @@ -587,7 +585,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "fakecampaign-with-no-events" + "name": "fakecampaign-with-no-events", }, "events": [], "form": { @@ -599,7 +597,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "type": "EventSignup", }, }, - 'event_search_past_events_only.html': { + "event_search_past_events_only.html": { "filename": "event_search.html", "form": { "search_page_text": "Search page text for campaign with only past events.
", @@ -612,7 +610,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "events": [event_create(-1, 10, 343126), event_create(-7, 15, 343127), event_create(-5, 15, 343128), - event_create(0, 15, 343129, place_index=57, minutes_from_now=-5) + event_create(0, 15, 343129, place_index=57, minutes_from_now=-5), ], "campaign": { "local_title": "Campaign Title", @@ -623,13 +621,13 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "resistandwin-volunteerday" + "name": "resistandwin-volunteerday", }, }, - 'event_search_with_results_past_events_only': { + "event_search_with_results_past_events_only": { "filename": "event_search.html", "args": { - "page": "event_search" + "page": "event_search", }, "campaign": { "local_title": "Campaign Title", @@ -640,12 +638,12 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "resistandwin-volunteerday" + "name": "resistandwin-volunteerday", }, "events": [event_create(-1, 10, 343126), event_create(-7, 15, 343127), event_create(-5, 15, 343128), - event_create(0, 15, 343129, place_index=57, minutes_from_now=-5) + event_create(0, 15, 343129, place_index=57, minutes_from_now=-5), ], "form": { "search_page_text": "Search page text for campaign with only past events.
", @@ -656,7 +654,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "type": "EventSignup", }, }, - 'event_search_past_and_future_events.html': { + "event_search_past_and_future_events.html": { "filename": "event_search.html", "form": { "search_page_text": "Search page text for campaign with past and future events.
", @@ -671,7 +669,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, event_create(-5, 15, 343128), event_create(1, 15, 343123), event_create(3, 15, 343124), - event_create(3, 10, 343125) + event_create(3, 10, 343125), ], "campaign": { "local_title": "Campaign Title - Campaign with past and future events", @@ -682,13 +680,13 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "resistandwin-volunteerday" + "name": "resistandwin-volunteerday", }, }, - 'event_search_with_results_past_and_future_events': { + "event_search_with_results_past_and_future_events": { "filename": "event_search.html", "args": { - "page": "event_search" + "page": "event_search", }, "campaign": { "local_title": "Campaign Title", @@ -699,14 +697,14 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "resistandwin-volunteerday" + "name": "resistandwin-volunteerday", }, "events": [event_create(-1, 10, 343126), event_create(-7, 15, 343127), event_create(-5, 15, 343128), event_create(1, 15, 343123), event_create(3, 15, 343124), - event_create(3, 10, 343125) + event_create(3, 10, 343125), ], "form": { "search_page_text": "Search page text for campaign with only past events.
", @@ -717,11 +715,11 @@ def event_create(days_from_now=7, localtime=15, id=343775, "type": "EventSignup", }, }, - 'event_search_with_api_broken': { + "event_search_with_api_broken": { "500_API": True, "filename": "event_search.html", "args": { - "page": "event_search" + "page": "event_search", }, "campaign": { "local_title": "Campaign Title - no events", @@ -732,7 +730,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "fakecampaign-with-no-events" + "name": "fakecampaign-with-no-events", }, "events": [], "form": { @@ -744,7 +742,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "type": "EventSignup", }, }, - 'event_search_with_mueller_load.html': { + "event_search_with_mueller_load.html": { "filename": "event_search.html", "form": { "search_page_text": "Search page text for campaign with 1000 events.
", @@ -764,13 +762,13 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "fakecampaign-mueller_load_events" + "name": "fakecampaign-mueller_load_events", }, }, - 'event_search_with_mueller_load_past.html': { + "event_search_with_mueller_load_past.html": { "filename": "event_search.html", "args": { - "page": "event_search" + "page": "event_search", }, "campaign": { "local_title": "Campaign Title", @@ -781,7 +779,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "fakecampaign-mueller_load_events" + "name": "fakecampaign-mueller_load_events", }, "events": [event_create(0, 17, 10000+place, place_index=place, minutes_from_now=-(place*2)) for place in range(1000)], "form": { @@ -793,7 +791,7 @@ def event_create(days_from_now=7, localtime=15, id=343775, "type": "EventSignup", }, }, - 'event_search_with_mueller_load_slow_api.html': { + "event_search_with_mueller_load_slow_api.html": { "SLOW_API": True, "filename": "event_search.html", "form": { @@ -814,10 +812,10 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "fakecampaign-mueller_load_events" + "name": "fakecampaign-mueller_load_events", }, }, - 'event_search_with_mueller_load_slow_search.html': { + "event_search_with_mueller_load_slow_search.html": { "SLOW_SEARCH": True, "filename": "event_search.html", "form": { @@ -838,21 +836,21 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_city": True, "show_zip": True, "show_public_description": True, - "name": "fakecampaign-mueller_load_events" + "name": "fakecampaign-mueller_load_events", }, }, - 'event_create.html': { + "event_create.html": { "filename": "event_create.html", - 'page': { + "page": { "title": "Event Creation - March on Washington", "canonical_url": "http://example.com/", "type": "EventCreate", }, - 'form': { - 'thank_you_text': 'Thanks!
' + "form": { + "thank_you_text": "Thanks!
", }, - 'campaign': { - 'allow_private': True, + "campaign": { + "allow_private": True, "local_title": "Campaign Title", "use_title": True, "show_venue": True, @@ -860,42 +858,42 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_address1": True, "show_city": True, "show_zip": True, - "show_public_description": True - }, - 'event_starts_at': { - 'name': 'event_starts_at', - 'hidden_date': False, - 'static_date': False, - 'default_date': False, #could be text of date - 'hidden_time': False, - 'static_time': False, - 'default_time': '10:00', - 'default_ampm': 'AM', - }, - 'user_fields': [ - {'field_name': 'name', - 'label_text': 'Name', - 'input_tag': '', + "show_public_description": True, + }, + "event_starts_at": { + "name": "event_starts_at", + "hidden_date": False, + "static_date": False, + "default_date": False, #could be text of date + "hidden_time": False, + "static_time": False, + "default_time": "10:00", + "default_ampm": "AM", + }, + "user_fields": [ + {"field_name": "name", + "label_text": "Name", + "input_tag": '', }, - {'field_name': 'email', - 'label_text': 'Email Address', - 'input_tag': '', + {"field_name": "email", + "label_text": "Email Address", + "input_tag": '', }, - {'field_name': 'address1', - 'label_text': 'Street Address', - 'input_tag': '', + {"field_name": "address1", + "label_text": "Street Address", + "input_tag": '', }, - {'field_name': 'zip', - 'label_text': 'ZIP Code', - 'input_tag': '', + {"field_name": "zip", + "label_text": "ZIP Code", + "input_tag": '', }, - {'field_name': 'phone', - 'label_text': 'Phone', - 'input_tag': '', + {"field_name": "phone", + "label_text": "Phone", + "input_tag": '', }, ], }, - 'event_search_rapidresponse_filter.html': { + "event_search_rapidresponse_filter.html": { "filename": "event_search.html", "form": { "search_page_text": "Search page text for campaign with only future events.
", @@ -905,10 +903,10 @@ def event_create(days_from_now=7, localtime=15, id=343775, "name": "fakecampaign-with-future-events_attend", "type": "EventSignup", "custom_fields": { - "rapid_response_active_event_start_date": rel_date(-1).strftime('%Y-%m-%d'), - "rapid_response_active_event_end_date": rel_date(3).strftime('%Y-%m-%d'), - "rapid_response_stranded_event_disclaimer": 'UNCONFIRMED event (we have not confirmed this event with the host yet)', - } + "rapid_response_active_event_start_date": rel_date(-1).strftime("%Y-%m-%d"), + "rapid_response_active_event_end_date": rel_date(3).strftime("%Y-%m-%d"), + "rapid_response_stranded_event_disclaimer": "UNCONFIRMED event (we have not confirmed this event with the host yet)", + }, }, "campaign": { "local_title": "Campaign Title for campaign with rapid-response filter", @@ -920,40 +918,40 @@ def event_create(days_from_now=7, localtime=15, id=343775, "show_zip": True, "show_public_description": True, "name": "fakecampaign-with-future-events", - "public_create_page": True + "public_create_page": True, }, "events": [event_create(1, 10, 343123), event_create(1, 15, 343124), event_create(4, 15, 343125), - event_create(0, 15, 343130, place_index=57, minutes_from_now=5) + event_create(0, 15, 343130, place_index=57, minutes_from_now=5), ], }, - 'event_create-updating': { + "event_create-updating": { "filename": "event_create.html", - 'update': True, - 'logged_in_user': { - 'akid': 34563841, - 'name': 'Stephen King', - 'first_name': 'Stephen', - 'last_name': 'King', - 'address1': 'Elm Street', - 'city': 'Denver', - 'state': 'CO', - 'zip': "80210", - }, - 'args': { - 'update': 1, - }, - 'page': { + "update": True, + "logged_in_user": { + "akid": 34563841, + "name": "Stephen King", + "first_name": "Stephen", + "last_name": "King", + "address1": "Elm Street", + "city": "Denver", + "state": "CO", + "zip": "80210", + }, + "args": { + "update": 1, + }, + "page": { "title": "Event Creation - update existing event", "type": "EventCreate", "canonical_url": "http://example.com/", - 'custom_fields': { - 'survey_always_show_user_fields': "1", - } + "custom_fields": { + "survey_always_show_user_fields": "1", + }, + }, + "form": { + "thank_you_text": "Thanks!
", }, - 'form': { - 'thank_you_text': 'Thanks!
' - } }, } diff --git a/dsa_actionkit/contexts/lib.py b/dsa_actionkit/contexts/lib.py index 7e397c8..ef44b99 100644 --- a/dsa_actionkit/contexts/lib.py +++ b/dsa_actionkit/contexts/lib.py @@ -1,21 +1,22 @@ from django.utils.html import format_html + class user(dict): def __str__(self): - return self.get('name') + return self.get("name") def field(fielddict): - field = format_html(fielddict.get('input_tag')) - field.name = fielddict.get('field_name') - field.id_for_label = 'id_{}'.format(fielddict.get('field_name', '')) + field = format_html(fielddict.get("input_tag")) + field.name = fielddict.get("field_name") + field.id_for_label = "id_{}".format(fielddict.get("field_name", "")) field.label_tag = format_html('', field.id_for_label, - fielddict.get('label_text', '')) - field.label = fielddict.get('label_text', '') + fielddict.get("label_text", "")) + field.label = fielddict.get("label_text", "") return field - + class userform(dict): @@ -25,19 +26,19 @@ def __init__(self, maindict, formdict): class formobj(dict): def __iter__(self, source=None): if not source: - source = self.get('user_fields', []) + source = self.get("user_fields", []) return iter([field(f) for f in source]) def visible_fields(self): - return self.__iter__(self.get('visible_fields')) - + return self.__iter__(self.get("visible_fields")) + self.update({ - 'form': formobj(formdict), - 'user_fields': formdict.get('user_fields'), - 'templateset': { + "form": formobj(formdict), + "user_fields": formdict.get("user_fields"), + "templateset": { "lang": { - "country_names_us_first": [(c,c) for c in country_list] - } + "country_names_us_first": [(c,c) for c in country_list], + }, }, }) @@ -355,6 +356,6 @@ def states(): ] def countries(): - return ''.join([ - '' % {'c': c} + return "".join([ + '' % {"c": c} for c in country_list]) diff --git a/dsa_actionkit/contexts/page_contexts.py b/dsa_actionkit/contexts/page_contexts.py index f7eea76..a94d303 100644 --- a/dsa_actionkit/contexts/page_contexts.py +++ b/dsa_actionkit/contexts/page_contexts.py @@ -1,29 +1,26 @@ -from . import account_contexts -from . import donation_contexts -from . import event_contexts -from . import survey_contexts +from . import account_contexts, donation_contexts, event_contexts, survey_contexts contexts = { - 'base': { - 'thanks.html': { - 'filename': 'thanks.html', - 'page': { + "base": { + "thanks.html": { + "filename": "thanks.html", + "page": { "title": "Thanks, you are the best", - "canonical_url": "http://example.com/" + "canonical_url": "http://example.com/", }, - 'form': { - 'thank_you_text': 'Thanks!
' - } + "form": { + "thank_you_text": "Thanks!
", + }, + }, + "logout.html": { + "filename": "logout.html", }, - 'logout.html': { - 'filename': 'logout.html' - } - } + }, #kinda silly, but avoid appending to the bottom because then git merge conflicts arise more often. #let's do the context values in alphabetical order. } -contexts.update({'donations': donation_contexts.contexts}) -contexts.update({'events': event_contexts.contexts}) -contexts.update({'accounts': account_contexts.contexts}) -contexts.update({'surveys': survey_contexts.contexts}) +contexts.update({"donations": donation_contexts.contexts}) +contexts.update({"events": event_contexts.contexts}) +contexts.update({"accounts": account_contexts.contexts}) +contexts.update({"surveys": survey_contexts.contexts}) diff --git a/dsa_actionkit/contexts/survey_contexts.py b/dsa_actionkit/contexts/survey_contexts.py index fe5e5f8..fe6ac94 100644 --- a/dsa_actionkit/contexts/survey_contexts.py +++ b/dsa_actionkit/contexts/survey_contexts.py @@ -1,22 +1,22 @@ from django.utils.html import format_html logged_in_data_with_hide_recognized_block = { - 'filename': 'survey.html', - 'page': { + "filename": "survey.html", + "page": { "title": "Survey page (stub)", "canonical_url": "http://example.com/survey/foobar", "custom_fields": { "layout_options": "hide_recognized_block", }, }, - 'form': { - 'introduction_text': 'Take our Survey!', - 'surveyquestion_set': { - 'all': [ - {'question_label': "How do you feel?", - 'question_html': '', - 'input_html': format_html(''), - 'placeholder': 'Share your feelings', + "form": { + "introduction_text": "Take our Survey!", + "surveyquestion_set": { + "all": [ + {"question_label": "How do you feel?", + "question_html": '', + "input_html": format_html(''), + "placeholder": "Share your feelings", }, ], }, @@ -28,89 +28,89 @@ "first_name": "Morticia", "last_name": "Addams", }, - 'user_fields': [ - {'field_name': 'name', - 'label_text': 'Name', - 'input_tag': '', - 'input_html': format_html(''), + "user_fields": [ + {"field_name": "name", + "label_text": "Name", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'email', - 'label_text': 'Email Address', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "email", + "label_text": "Email Address", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'address1', - 'label_text': 'Street Address', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "address1", + "label_text": "Street Address", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'city', - 'label_text': 'City', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "city", + "label_text": "City", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'state', - 'label_text': 'State', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "state", + "label_text": "State", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'zip', - 'label_text': 'ZIP Code', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "zip", + "label_text": "ZIP Code", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'phone', - 'label_text': 'Phone', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "phone", + "label_text": "Phone", + "input_tag": '', + "input_html": format_html(''), }, ], } no_questions = { - 'filename': 'survey.html', - 'page': { + "filename": "survey.html", + "page": { "title": "Survey page (stub)", - "canonical_url": "http://example.com/survey/foobar" + "canonical_url": "http://example.com/survey/foobar", }, - 'form': { - 'introduction_text': 'Take our Survey!', - 'surveyquestion_set': { - 'all': [], + "form": { + "introduction_text": "Take our Survey!", + "surveyquestion_set": { + "all": [], }, }, - 'user_fields': [ - {'field_name': 'name', - 'label_text': 'Name', - 'input_tag': '', - 'input_html': format_html(''), + "user_fields": [ + {"field_name": "name", + "label_text": "Name", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'email', - 'label_text': 'Email Address', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "email", + "label_text": "Email Address", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'address1', - 'label_text': 'Street Address', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "address1", + "label_text": "Street Address", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'zip', - 'label_text': 'ZIP Code', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "zip", + "label_text": "ZIP Code", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'phone', - 'label_text': 'Phone', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "phone", + "label_text": "Phone", + "input_tag": '', + "input_html": format_html(''), }, ], } no_survey = { - 'filename': 'survey.html', - 'page': { + "filename": "survey.html", + "page": { "title": "Survey page (stub)", "canonical_url": "http://example.com/survey/foobar", "custom_fields": { @@ -120,127 +120,127 @@ } survey = { - 'filename': 'survey.html', - 'page': { + "filename": "survey.html", + "page": { "title": "Survey page (stub)", - "canonical_url": "http://example.com/survey/foobar" + "canonical_url": "http://example.com/survey/foobar", }, - 'form': { - 'introduction_text': 'Take our Survey!', - 'surveyquestion_set': { - 'all': [ - {'question_label': "How do you feel?", - 'question_html': '', - 'input_html': format_html(''), - 'placeholder': 'Share your feelings', + "form": { + "introduction_text": "Take our Survey!", + "surveyquestion_set": { + "all": [ + {"question_label": "How do you feel?", + "question_html": '', + "input_html": format_html(''), + "placeholder": "Share your feelings", }, ], }, }, - 'user_fields': [ - {'field_name': 'name', - 'label_text': 'Name', - 'input_tag': '', - 'input_html': format_html(''), + "user_fields": [ + {"field_name": "name", + "label_text": "Name", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'email', - 'label_text': 'Email Address', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "email", + "label_text": "Email Address", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'address1', - 'label_text': 'Street Address', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "address1", + "label_text": "Street Address", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'city', - 'label_text': 'City', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "city", + "label_text": "City", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'state', - 'label_text': 'State', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "state", + "label_text": "State", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'zip', - 'label_text': 'ZIP Code', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "zip", + "label_text": "ZIP Code", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'phone', - 'label_text': 'Phone', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "phone", + "label_text": "Phone", + "input_tag": '', + "input_html": format_html(''), }, ], } shipping_survey = { - 'filename': 'survey.html', - 'page': { + "filename": "survey.html", + "page": { "title": "Shipping survey", - "canonical_url": "http://example.com/survey/foobar" + "canonical_url": "http://example.com/survey/foobar", }, - 'form': { - 'introduction_text': 'verify shipping!', - 'surveyquestion_set': { - 'all': [ - {'question_label': "How do you feel?", - 'question_html': '', - 'input_html': format_html(''), - 'placeholder': 'Share your feelings', - 'field_name': 'howfeel', + "form": { + "introduction_text": "verify shipping!", + "surveyquestion_set": { + "all": [ + {"question_label": "How do you feel?", + "question_html": '', + "input_html": format_html(''), + "placeholder": "Share your feelings", + "field_name": "howfeel", }, - {'question_label': "Address", - 'question_html': '', - 'input_html': format_html(''), - 'field_name': 'shipping_address', + {"question_label": "Address", + "question_html": '', + "input_html": format_html(''), + "field_name": "shipping_address", }, - {'question_label': "Address Line 2", - 'question_html': '', - 'input_html': format_html(''), - 'field_name': 'shipping_address2', + {"question_label": "Address Line 2", + "question_html": '', + "input_html": format_html(''), + "field_name": "shipping_address2", }, - {'question_label': "City", - 'question_html': '', - 'input_html': format_html(''), - 'field_name': 'shipping_city', + {"question_label": "City", + "question_html": '', + "input_html": format_html(''), + "field_name": "shipping_city", }, - {'question_label': "zip", - 'question_html': '', - 'input_html': format_html(''), - 'placeholder': 'Share your feelings', - 'field_name': 'shipping_zip', + {"question_label": "zip", + "question_html": '', + "input_html": format_html(''), + "placeholder": "Share your feelings", + "field_name": "shipping_zip", }, ], }, }, - 'user_fields': [ - {'field_name': 'name', - 'label_text': 'Name', - 'input_tag': '', - 'input_html': format_html(''), + "user_fields": [ + {"field_name": "name", + "label_text": "Name", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'email', - 'label_text': 'Email Address', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "email", + "label_text": "Email Address", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'address1', - 'label_text': 'Street Address', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "address1", + "label_text": "Street Address", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'zip', - 'label_text': 'ZIP Code', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "zip", + "label_text": "ZIP Code", + "input_tag": '', + "input_html": format_html(''), }, - {'field_name': 'phone', - 'label_text': 'Phone', - 'input_tag': '', - 'input_html': format_html(''), + {"field_name": "phone", + "label_text": "Phone", + "input_tag": '', + "input_html": format_html(''), }, ], } @@ -252,35 +252,35 @@ "name": "Morticia Addams", "first_name": "Morticia", "last_name": "Addams", - } + }, } logged_in_data.update(survey) letter_to_congress_base = { - 'filename': 'letter.html', - 'page': { - 'title': 'Tell Letter to Congress', - 'goal': '100', - 'custom_fields': { - 'layout_options': 'lost_pages_redesign' - } + "filename": "letter.html", + "page": { + "title": "Tell Letter to Congress", + "goal": "100", + "custom_fields": { + "layout_options": "lost_pages_redesign", + }, }, - 'form': { - 'statement_leadin': 'Hello, please sign our letter to congress for this very-good-cause.
', - 'letter_text': 'Dear Senator,\n\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.', - 'about_text': 'This is what this thing is all about.', + "form": { + "statement_leadin": "Hello, please sign our letter to congress for this very-good-cause.
", + "letter_text": "Dear Senator,\n\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.\nPlease listen to us?\nThis is very important.", + "about_text": "This is what this thing is all about.", }, - 'progress': { - 'goal': 100, - 'current': 90, - 'total': { - 'actions': 90 + "progress": { + "goal": 100, + "current": 90, + "total": { + "actions": 90, }, - 'goal_type': 'actions' + "goal_type": "actions", }, - 'context': { + "context": { "progress": {"total": {"actions": 1}, "goal": 5, "goal_type": "actions", "recent": {"actions": 1}, "time": 1621261302.6000607, "age": 447.172566652298}, - } + }, } letter_to_congress = {} letter_to_congress_login = {} @@ -291,14 +291,14 @@ letter_to_congress_login.update(letter_to_congress_base) contexts = { - 'survey.html': survey, - 'shipping_survey.html': shipping_survey, - 'survey_logged_in': logged_in_data, - 'survey_logged_in_hide_recognized': logged_in_data_with_hide_recognized_block, - 'survey_no_questions': no_questions, - 'survey_no_survey': no_survey, - 'letter.html': letter_to_congress, - 'letter_logged_in': letter_to_congress_login, + "survey.html": survey, + "shipping_survey.html": shipping_survey, + "survey_logged_in": logged_in_data, + "survey_logged_in_hide_recognized": logged_in_data_with_hide_recognized_block, + "survey_no_questions": no_questions, + "survey_no_survey": no_survey, + "letter.html": letter_to_congress, + "letter_logged_in": letter_to_congress_login, #kinda silly, but avoid appending to the bottom because then git merge conflicts arise more often. #let's do the context values in alphabetical order. } diff --git a/dsa_actionkit/moveon_fakeapi.py b/dsa_actionkit/moveon_fakeapi.py index 1c64a7d..92c9af6 100644 --- a/dsa_actionkit/moveon_fakeapi.py +++ b/dsa_actionkit/moveon_fakeapi.py @@ -2,18 +2,18 @@ def mo_event_data(event): - eobj = event.get('obj') + eobj = event.get("obj") machine_offset = time.time() - time.mktime(time.gmtime()) # correction factor for when this runs on machines that aren't defaulting to UTC - naive_start_time = int(time.mktime(eobj['starts_at_utc'].timetuple())) + naive_start_time = int(time.mktime(eobj["starts_at_utc"].timetuple())) starts_utc = naive_start_time + machine_offset - timezone_offset = (int(time.mktime(eobj['starts_at'].timetuple())) - naive_start_time) / 3600 - full = 0 if not event['max_attendees'] else int(bool(event['max_attendees'] <= event['attendee_count'])) - return {'lat': float(event['latitude']), - 'lng': float(event['longitude']), - 'id': event['id'], - 'utc': starts_utc, - 'tzo': timezone_offset, - 'f': full, + timezone_offset = (int(time.mktime(eobj["starts_at"].timetuple())) - naive_start_time) / 3600 + full = 0 if not event["max_attendees"] else int(bool(event["max_attendees"] <= event["attendee_count"])) + return {"lat": float(event["latitude"]), + "lng": float(event["longitude"]), + "id": event["id"], + "utc": starts_utc, + "tzo": timezone_offset, + "f": full, # this is not a perfect reflection of the api, but we are lazy so we send titles with the main batch - 'city_etc': '{}, {}'.format(event['city'], event['state']), - 'title': event['title']} + "city_etc": "{}, {}".format(event["city"], event["state"]), + "title": event["title"]} diff --git a/dsa_actionkit/settings.py b/dsa_actionkit/settings.py index a48e416..7be57fa 100644 --- a/dsa_actionkit/settings.py +++ b/dsa_actionkit/settings.py @@ -1,71 +1,40 @@ -import json +import contextlib import os -import time - -try: - from urlparse import urlparse -except ImportError: - # python3 - from urllib.parse import urlparse - -from django.urls import re_path -from django.conf.urls.static import static -from django.http import Http404, HttpResponse -from django.shortcuts import redirect, render -from django.template.loader import render_to_string -from django.views.static import serve - -from .moveon_fakeapi import mo_event_data - -""" -try running with -aktemplates runserver 0.0.0.0:1234 -""" +from pathlib import Path DEBUG = True -SECRET_KEY = 'who cares!' -INSTALLED_APPS = ['dsa_actionkit', ] -try: - INSTALLED_APPS.append('django_extensions') -except: - pass - -#one directory down -APP_PATH = os.path.dirname(__file__) -PROJECT_ROOT_PATH = os.path.abspath(os.getcwd()) - -############# -# STATIC DIRECTORY -############# - -#note this only works if DEBUG=True -STATIC_ROOT = os.environ.get('STATIC_ROOT', os.path.join(PROJECT_ROOT_PATH, './static')) -STATIC_URL = os.environ.get('STATIC_URL', '/static/') -STATIC_FALLBACK = os.environ.get('STATIC_FALLBACK', False) -STATIC_LOCAL = os.environ.get('STATIC_URL', None) # an explicit local or not - -############# -# TEMPLATES -############# -DEFAULT_TEMPLATES = os.path.join(APP_PATH, 'templates') +SECRET_KEY = os.environ["DJANGO_SECRET_KEY"] +INSTALLED_APPS = ["dsa_actionkit" ] +with contextlib.suppress(Exception): + INSTALLED_APPS.append("django_extensions") + +ROOT_URLCONF = "dsa_actionkit.urls" +APP_PATH = Path().parent +PROJECT_ROOT_PATH = Path.resolve(Path.cwd()) + +STATIC_ROOT = os.environ.get("STATIC_ROOT", PROJECT_ROOT_PATH / "static") +STATIC_URL = os.environ.get("STATIC_URL", "/static/") +STATIC_FALLBACK = os.environ.get("STATIC_FALLBACK", False) +STATIC_LOCAL = os.environ.get("STATIC_URL", None) +DEFAULT_TEMPLATES = APP_PATH / "templates" DIR_TEMPLATES = [] -if os.environ.get('TEMPLATE_DIR'): - DIR_TEMPLATES.append(os.environ.get('TEMPLATE_DIR')) +if os.environ.get("TEMPLATE_DIR"): + DIR_TEMPLATES.append(os.environ.get("TEMPLATE_DIR")) else: - for d in ('template_set/', '_layouts/', '_includes/'): - dd = os.path.join(PROJECT_ROOT_PATH, d) - if os.path.exists(dd): + for d in ("template_set/", "_layouts/", "_includes/"): + dd = PROJECT_ROOT_PATH / d + if Path.exists(dd): DIR_TEMPLATES.append(dd) DIR_TEMPLATES.append(DEFAULT_TEMPLATES) TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': DIR_TEMPLATES, - 'APP_DIRS': True, - 'OPTIONS': { - 'builtins': ['dsa_actionkit.templatetags.actionkit_tags'], + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": DIR_TEMPLATES, + "APP_DIRS": True, + "OPTIONS": { + "builtins": ["dsa_actionkit.templatetags.actionkit_tags"], }, }, ] @@ -73,172 +42,9 @@ MIDDLEWARE_CLASSES = [] -def _get_context_data(request, name=None, page=None, use_referer=False): - from dsa_actionkit.contexts.page_contexts import contexts - port = '4000' - hostport = request.get_host().split(':') - if len(hostport) > 1: - port = hostport[1] - - if use_referer: - paths = None - if request.META.get('HTTP_REFERER'): - paths = urlparse(request.META['HTTP_REFERER']).path.split('/') - elif request.GET.get('path'): - # e.g. &path=/events/event_search.html - paths = request.GET['path'].split('/') - if paths and len(paths) > 1: - name = paths[1] - if len(paths) > 2: - page = paths[2] - - custom_contexts_file = os.path.join(PROJECT_ROOT_PATH, - os.environ.get('CUSTOM_CONTEXTS', 'contexts.json')) - if os.path.exists(custom_contexts_file): - try: - contexts.update({'Custom': json.loads(open(custom_contexts_file).read())}) - except ValueError as e: - raise Exception("JSON Parsing Error for context file %s %s" % ( - custom_contexts_file, e.message)) - #first use ?template= if there, otherwise name's template, otherwise homepage - cxt = dict( - devenv={ - 'enabled': True, - 'port': port, - 'STATIC_URL': STATIC_URL, - 'STATIC_LOCAL': STATIC_LOCAL, - 'MO_EVENTS_API': '/fake/api/events' - } - ) - context_data = contexts.get(name, {}) - if page: - context_data = contexts.get(name, {}).get(page, {}) - cxt.update(context_data) - if not context_data: - sections = [] - for section, pages in sorted(contexts.items()): - sections.append([section, sorted(pages.items())]) - cxt.update({ - 'page': {'title':'Homepage'}, - 'pagelinks': sections}) - if request.GET.get('user_id'): - #for debugging tests based on user.id % 2, e.g. - context_data.setdefault('user', {}).update({'id': int(request.GET.get('user_id'))}) - args = cxt.get('args', {}).copy() - args.update(request.GET.dict()) - cxt['args'] = args - if 'akid' not in cxt: - cxt['akid'] = cxt['args'].get('akid') - cxt['request'] = request - cxt['js_context'] = '""' # FUTURE: what should go in here? - return cxt - -############# -# HOME PAGE TEST -############# - -def index(request, name=None, page=None): - cxt = _get_context_data(request, name, page) - template = request.GET.get('template', - cxt.get('filename', "homepagetest.html")) - - return render(request, template, cxt) - -def login_context(request): - cxt = _get_context_data(request, use_referer=True) - from dsa_actionkit.contexts.event_context_json import event_json - event_json_copy = event_json.copy() - coming_from = request.GET.get('url','') - if 'event' in coming_from \ - or 'logged_in' in coming_from \ - or 'survey_logged_in' in coming_from: - if not request.GET.get('login') and 'survey_logged_in' not in coming_from: - del event_json_copy['name'] - return HttpResponse( - 'actionkit.forms.onContextLoaded(%s)' % json.dumps(event_json_copy)) - elif cxt.get('context'): - return HttpResponse('actionkit.forms.onContextLoaded(%s)' % json.dumps(cxt['context'])) - else: - return HttpResponse( - #text key has all the generic error messages - 'actionkit.forms.onContextLoaded({"text": %s})' % json.dumps(event_json['text'])) - -def user_password_forgot(request): - return HttpResponse('unimplemented') - -def logout(request): - if request.GET.get('next'): - return redirect(request.GET.get('next')) - return redirect('/logout.html') - -def event_search_results(request, page): - cxt = _get_context_data(request, 'events', 'WILL_USE_REFERER_HEADER', use_referer=True) - # special query results context: - all = cxt['args'].get('all') == '1' - cxt.update({'all': all}) - if cxt.get('SLOW_SEARCH'): - # This allows us to test for race conditions - time.sleep(2) - search_results = render_to_string('event_search_results.html', cxt) - return HttpResponse('actionkit.forms.onEventSearchResults({})' - .format(json.dumps(search_results))) - -def event_api_moveon_fake(request): - """Fake representation of MoveOn events api""" - cxt = _get_context_data(request, 'events', 'WILL_USE_REFERER_HEADER', use_referer=True) - events = cxt.get('events', []) - if cxt.get('SLOW_API'): - # This allows us to test for race conditions - time.sleep(2) - if cxt.get('500_API'): - raise Exception('Cause failure to allow graceful degradation') - search_results = [mo_event_data(evt) for evt in events] - return HttpResponse(json.dumps({'events': search_results}), content_type='application/json') - -def proxy_serve(request, path, document_root=None, show_indexes=False): - try_proxy = True - try: - import requests - except ImportError: - try_proxy = False - try: - return serve(request, path, document_root, show_indexes) - except Http404: - if try_proxy: - prefix = request.path.split('/')[1] - content = requests.get('https://roboticdogs.actionkit.com/{}/{}'.format(prefix, path), verify=False) - if content.status_code == 200: - return HttpResponse(content.content, content_type=content.headers['Content-Type']) - raise Http404 - - -############# -# URLS -############# - -ROOT_URLCONF = 'dsa_actionkit.settings' - -urlpatterns = [ - re_path(r'^context', login_context), - re_path(r'^progress', login_context, name='progress'), - re_path(r'^logout', logout, name="logout"), - re_path(r'^(?P