Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CACHEDIR.TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by Python virtualenv.
# For information about cache directory tags, see:
# https://bford.info/cachedir/
20 changes: 10 additions & 10 deletions WeVoteServerCheatSheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ psql (PostgreSQL) 14.0

#### Setting up ngrok to send stripe webhooks to your local python server
```
(WeVoteServerPy3.7) Steves-MacBook-Pro-32GB-Oct-2018:PycharmProjects stevepodell$ ~/PythonProjects/ngrok http 8000 -host-header="localhost:8000"
(WeVoteServerPy3.7) Steves-MacBook-Pro-32GB-Oct-2018:PycharmProjects stevepodell$ ~/PythonProjects/ngrok http 8000 -host-header="https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:8000"

```
A very useful http inspector is made available by ngrok at [http://127.0.0.1:4040/inspect/http](http://127.0.0.1:4040/inspect/http)
Expand Down Expand Up @@ -109,15 +109,15 @@ There has to be a better way to do this, but this is what I went through...
2020-04-03 21:34:14.414 PDT [13229] HINT: Is another postmaster (PID 13133) running in data directory "/usr/local/var/postgres"?
(WeVoteServerPy3.7) stevepodell@Steves-MacBook-Pro-32GB-Oct-2018 var % !lsof
lsof -i -P | grep post
postgres 13133 stevepodell 5u IPv6 0x9139afcc2c95ec77 0t0 TCP localhost:5432 (LISTEN)
postgres 13133 stevepodell 6u IPv4 0x9139afcc08c6d697 0t0 TCP localhost:5432 (LISTEN)
postgres 13133 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP localhost:57308->localhost:57308
postgres 13135 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP localhost:57308->localhost:57308
postgres 13136 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP localhost:57308->localhost:57308
postgres 13137 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP localhost:57308->localhost:57308
postgres 13138 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP localhost:57308->localhost:57308
postgres 13139 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP localhost:57308->localhost:57308
postgres 13140 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP localhost:57308->localhost:57308
postgres 13133 stevepodell 5u IPv6 0x9139afcc2c95ec77 0t0 TCP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:5432 (LISTEN)
postgres 13133 stevepodell 6u IPv4 0x9139afcc08c6d697 0t0 TCP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:5432 (LISTEN)
postgres 13133 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308->https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308
postgres 13135 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308->https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308
postgres 13136 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308->https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308
postgres 13137 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308->https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308
postgres 13138 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308->https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308
postgres 13139 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308->https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308
postgres 13140 stevepodell 10u IPv6 0x9139afcc016b2ecf 0t0 UDP https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308->https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev:57308
(WeVoteServerPy3.7) stevepodell@Steves-MacBook-Pro-32GB-Oct-2018 var %
```
#### Adding a new "app" (directory of Python classes) to the WeVoteServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def site_configuration_retrieve_doc_template_values(url_root):
},
]
try_now_link_variables_dict = {
'hostname': 'localhost',
'hostname': 'https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev',
}

api_response = '{\n' \
Expand Down
3 changes: 3 additions & 0 deletions apis_v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from django.conf import settings
from django.conf.urls import re_path
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path

from apis_v1.views import views_activity, views_apple, views_docs, views_analytics, views_ballot, \
views_campaign, views_candidate, views_donation, \
Expand All @@ -33,6 +35,7 @@
from voter_guide.views_admin import voter_guides_sync_out_view

urlpatterns = [
path('admin/', admin.site.urls),
# Actual API Calls
re_path(r'^activityCommentSave/',
views_activity.activity_comment_save_view, name='activityCommentSaveView'),
Expand Down
21 changes: 20 additions & 1 deletion apis_v1/views/views_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# Brought to you by We Vote. Be good.
# -*- coding: UTF-8 -*-


from datetime import datetime, timedelta
from django.http import HttpResponse

from django.core.exceptions import ImproperlyConfigured
import json
import threading
import time
Expand All @@ -21,11 +24,27 @@
from voter.models import fetch_voter_we_vote_id_from_voter_device_link, VoterManager, VoterDeviceLinkManager, \
VoterDeviceLink
from wevote_functions.functions import get_voter_device_id, positive_value_exists, wevote_functions
import os
from django.core.exceptions import ImproperlyConfigured
from wevote_functions.functions import wevote_functions

logger = wevote_functions.admin.get_logger(__name__)
def get_environment_variable(var_name):
try:
return os.environ[var_name]
except KeyError:
error_msg = f"ERROR: Unable to set the {var_name} variable from os.environ or JSON file"
raise ImproperlyConfigured(error_msg)

# Use the correct environment variable names
WE_VOTE_SERVER_ROOT_URL = get_environment_variable("WE_VOTE_SERVER_ROOT_URL")
STRIPE_SECRET_KEY = get_environment_variable("STRIPE_SECRET_KEY")

if not STRIPE_SECRET_KEY.startswith('sk_'):
raise ImproperlyConfigured("Configuration error, the stripe secret key, must begin with 'sk_' -- don't use the publishable key on the server!")



logger = wevote_functions.admin.get_logger(__name__)

def activity_comment_save_view(request): # activityCommentSave
"""
Expand Down
2 changes: 1 addition & 1 deletion apis_v1/views/views_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def organization_index_view(request, organization_incoming_domain='', campaign_m
else:
req_url = 'https://wevote.us/main.name.html'

verify_bool = not ('localhost' in organization_incoming_domain or '127.0.0.1' in organization_incoming_domain)
verify_bool = not ('https://super-lamp-44gw5w5jjwp3jrpr-8000.app.github.dev' in organization_incoming_domain or '127.0.0.1' in organization_incoming_domain)
text = requests.get(req_url, verify=verify_bool).text
main_js = re.search(r"<body>(.*?)<\/body>", text)[1]

Expand Down
1 change: 1 addition & 0 deletions apis_v1/views/views_voter.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ def voter_email_address_retrieve_view(request): # voterEmailAddressRetrieve
'email_address_list': results['email_address_list'],
}
return HttpResponse(json.dumps(json_data), content_type='application/json')



def voter_email_address_save_view(request): # voterEmailAddressSave
Expand Down
Empty file added backend/backend/__init__.py
Empty file.
Binary file added backend/backend/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file added backend/backend/__pycache__/urls.cpython-313.pyc
Binary file not shown.
Binary file added backend/backend/__pycache__/wsgi.cpython-313.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions backend/backend/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for backend project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

application = get_asgi_application()
144 changes: 144 additions & 0 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
"""
Django settings for backend project.

Generated by 'django-admin startproject' using Django 5.1.4.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'frontend/build/static'),
]



# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-+_!0maxfp^0v=nfo-=%x_pho-=(negl=9w97!mw!7*3369=sna'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

# own apps
'greetings',
'rest_framework',
'corsheaders',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
]

CORS_ORIGIN_WHITELIST = [
'http://localhost:3000',

]

ROOT_URLCONF = 'backend.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'frontend/build')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'backend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
9 changes: 9 additions & 0 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin
from django.urls import path, include
from django.views.generic import TemplateView

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('greetings.urls')),
path('', TemplateView.as_view(template_name='index.html')),
]
16 changes: 16 additions & 0 deletions backend/backend/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for backend project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

application = get_wsgi_application()
Binary file added backend/db.sqlite3
Binary file not shown.
Empty file added backend/greetings/__init__.py
Empty file.
Binary file not shown.
Binary file added backend/greetings/__pycache__/admin.cpython-313.pyc
Binary file not shown.
Binary file added backend/greetings/__pycache__/apps.cpython-313.pyc
Binary file not shown.
Binary file added backend/greetings/__pycache__/models.cpython-313.pyc
Binary file not shown.
Binary file added backend/greetings/__pycache__/urls.cpython-313.pyc
Binary file not shown.
Binary file added backend/greetings/__pycache__/views.cpython-313.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/greetings/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/greetings/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class GreetingsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'greetings'
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/greetings/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions backend/greetings/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
16 changes: 16 additions & 0 deletions backend/greetings/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# from django.urls import path
# from .views import greet


# urlpatterns = [
# path('greet/', greet, name='greet'),
# ]

from django.urls import path
from django.views.generic import TemplateView
from . import views # Eğer views.py'deki greet fonksiyonunu kullanıyorsanız

urlpatterns = [
path('', TemplateView.as_view(template_name="index.html")), # React'in index.html'i
path('greet/', views.greet, name='greet'), # Greet API endpoint'i
]
11 changes: 11 additions & 0 deletions backend/greetings/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#from django.shortcuts import render

# Create your views here.
from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view(['POST'])
def greet(request):
name = request.data.get('name', 'Guest')
return Response({'message': f'Hello, {name}!'})

22 changes: 22 additions & 0 deletions backend/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Loading