first commit

This commit is contained in:
pacnpal
2024-10-28 17:09:57 -04:00
commit 1339baec59
9993 changed files with 1182741 additions and 0 deletions

0
thrillwiki/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
thrillwiki/asgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
ASGI config for thrillwiki 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.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thrillwiki.settings")
application = get_asgi_application()

203
thrillwiki/settings.py Normal file
View File

@@ -0,0 +1,203 @@
# Django settings for thrillwiki project.
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-=0)^0#h#k$0@$8$ys=^$0#h#k$0@$8$ys=^'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# Third-party apps
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.discord',
'simple_history',
'django_cleanup',
'django_filters',
'django_htmx',
'whitenoise',
# Local apps
'core',
'accounts',
'companies',
'parks',
'rides',
'reviews',
'email_service',
'media', # Added media app
]
MIDDLEWARE = [
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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',
'allauth.account.middleware.AccountMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
]
ROOT_URLCONF = 'thrillwiki.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = 'thrillwiki.wsgi.application'
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'thrillwiki',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'localhost',
'PORT': '5432',
}
}
# Cache settings
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
'TIMEOUT': 300, # 5 minutes
'OPTIONS': {
'MAX_ENTRIES': 1000
}
}
}
CACHE_MIDDLEWARE_SECONDS = 300 # 5 minutes
CACHE_MIDDLEWARE_KEY_PREFIX = 'thrillwiki'
# Password validation
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
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/New_York'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Default primary key field type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Authentication settings
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
]
# django-allauth settings
SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
ACCOUNT_EMAIL_VERIFICATION = 'optional'
LOGIN_REDIRECT_URL = '/' # Updated to use Django template URL
ACCOUNT_LOGOUT_REDIRECT_URL = '/' # Updated to use Django template URL
# Custom adapters
ACCOUNT_ADAPTER = 'accounts.adapters.CustomAccountAdapter'
SOCIALACCOUNT_ADAPTER = 'accounts.adapters.CustomSocialAccountAdapter'
# Social account settings
SOCIALACCOUNT_PROVIDERS = {
'google': {
'APP': {
'client_id': '135166769591-nopcgmo0fkqfqfs9qe783a137mtmcrt2.apps.googleusercontent.com',
'secret': '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',
'key': ''
},
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {'access_type': 'online'},
},
'discord': {
'APP': {
'client_id': '1299112802274902047',
'secret': 'ece7Pe_M4mD4mYzAgcINjTEKL_3ftL11',
'key': ''
},
'SCOPE': ['identify', 'email'],
'OAUTH_PKCE_ENABLED': True,
}
}
# Additional social account settings
SOCIALACCOUNT_LOGIN_ON_GET = True
SOCIALACCOUNT_AUTO_SIGNUP = False # We want to handle the signup process
SOCIALACCOUNT_STORE_TOKENS = True # Store the OAuth tokens
# Email settings
EMAIL_BACKEND = 'email_service.backends.ForwardEmailBackend'
FORWARD_EMAIL_BASE_URL = 'https://api.forwardemail.net'
# Custom User Model
AUTH_USER_MODEL = 'accounts.User'
# WhiteNoise configuration
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

40
thrillwiki/urls.py Normal file
View File

@@ -0,0 +1,40 @@
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from accounts import views as accounts_views
from django.views.generic import TemplateView
from .views import HomeView, SearchView
urlpatterns = [
path('admin/', admin.site.urls),
# Main app URLs
path('', HomeView.as_view(), name='home'),
path('parks/', include('parks.urls')),
path('rides/', include('rides.urls')),
path('reviews/', include('reviews.urls')),
path('companies/', include('companies.urls')),
path('search/', SearchView.as_view(), name='search'),
path('terms/', TemplateView.as_view(template_name='pages/terms.html'), name='terms'),
path('privacy/', TemplateView.as_view(template_name='pages/privacy.html'), name='privacy'),
# Authentication URLs
path('accounts/', include('allauth.urls')), # This includes social auth URLs
path('accounts/email-required/', accounts_views.email_required, name='email_required'),
# User profile URLs
path('users/<str:username>/', accounts_views.ProfileView.as_view(), name='user_profile'),
path('user/<str:username>/', accounts_views.ProfileView.as_view(), name='single_user_profile'),
path('profile/<str:username>/', accounts_views.ProfileView.as_view(), name='profile'),
path('settings/', accounts_views.SettingsView.as_view(), name='settings'),
# Redirect /user/ to the user's profile if logged in
path('user/', accounts_views.user_redirect_view, name='user_redirect'),
# Include remaining accounts URLs
path('', include('accounts.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
handler404 = 'thrillwiki.views.handler404'
handler500 = 'thrillwiki.views.handler500'

75
thrillwiki/views.py Normal file
View File

@@ -0,0 +1,75 @@
from django.shortcuts import render
from django.views.generic import TemplateView
from django.db.models import Count, Q
from parks.models import Park
from rides.models import Ride
from companies.models import Company, Manufacturer
def handler404(request, exception):
return render(request, '404.html', status=404)
def handler500(request):
return render(request, '500.html', status=500)
class HomeView(TemplateView):
template_name = 'home.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Get stats
context['stats'] = {
'total_parks': Park.objects.count(),
'total_rides': Ride.objects.count(),
'total_roller_coasters': Ride.objects.filter(category='RC').count(),
}
# Get popular parks (based on average rating)
context['popular_parks'] = Park.objects.exclude(
average_rating__isnull=True
).order_by('-average_rating')[:5]
# Get popular rides (based on average rating)
context['popular_rides'] = Ride.objects.exclude(
average_rating__isnull=True
).order_by('-average_rating')[:5]
return context
class SearchView(TemplateView):
template_name = 'search_results.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
query = self.request.GET.get('q', '').strip()
if query:
# Search parks
context['parks'] = Park.objects.filter(
Q(name__icontains=query) |
Q(location__icontains=query) |
Q(description__icontains=query)
).select_related('owner').prefetch_related('photos')[:10]
# Search rides
context['rides'] = Ride.objects.filter(
Q(name__icontains=query) |
Q(description__icontains=query) |
Q(manufacturer__name__icontains=query)
).select_related('park', 'coaster_stats').prefetch_related('photos')[:10]
# Search companies
context['companies'] = Company.objects.filter(
Q(name__icontains=query) |
Q(headquarters__icontains=query) |
Q(description__icontains=query)
).prefetch_related('parks')[:10]
# Search manufacturers
context['manufacturers'] = Manufacturer.objects.filter(
Q(name__icontains=query) |
Q(headquarters__icontains=query) |
Q(description__icontains=query)
).prefetch_related('rides')[:10]
return context

16
thrillwiki/wsgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
WSGI config for thrillwiki 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.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thrillwiki.settings")
application = get_wsgi_application()