diff --git a/README.md b/README.md new file mode 100644 index 00000000..c61add5e --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# bloodmallet.com frontend +> You're seeing the code that runs the frontend of bloodmallet.com. + +Everyone is welcome to add issues, discuss improvements and features, or create +pull requests. + +## Development setup + +1. Get or have [Python 3.6+](https://www.python.org/downloads/) (make sure to install it into PATH on windows) +2. Create a [virtual environment](https://docs.python.org/3/tutorial/venv.html) + - `python3 -m venv env` (creates a directory "env") + - activate virtual environment + - `env/Scripts/activate` (windows) + - `source env/bin/activate` (linux) +3. Get or have [git](https://git-scm.com/downloads) installed +4. Download this repository + - `git clone https://github.com/Bloodmallet/bloodmallet_web_frontend.git bloodmallet` (creates a directory "bloodmallet") +5. Install requirements + - `cd bloodmallet` (navigate into the created directory) + - `python -m pip install --upgrade pip setuptools wheel` (update all basic tools) + - `(env)bloodmallet/$ pip install -U -r requirements.txt` (install the actual requirements, have a look at the *_dev.txt file, too) +6. Create local database and tables + - `(env)bloodmallet/$ cd bloodmallet` (so you're in "bloodmallet/bloodmallet/") + - `(env)bloodmallet/bloodmallet/$ python manage.py migrate` +7. Start local django development server + - `(env)bloodmallet/bloodmallet/$ python manage.py runserver` +8. Open `http://127.0.0.1:8000` in your browser of choice. And code away! :tada: + +### Optional: +Maybe you want to [create a superuser](https://docs.djangoproject.com/en/2.2/intro/tutorial02/#creating-an-admin-user) for local development. diff --git a/bloodmallet/bloodmallet/settings/__init__.py b/bloodmallet/bloodmallet/settings/__init__.py index 415542a9..e69de29b 100644 --- a/bloodmallet/bloodmallet/settings/__init__.py +++ b/bloodmallet/bloodmallet/settings/__init__.py @@ -1,6 +0,0 @@ -import os - -if os.getenv('GAE_APPLICATION', None): - from .production import * -else: - from .development import * diff --git a/bloodmallet/bloodmallet/settings/common.py b/bloodmallet/bloodmallet/settings/common.py index d5d393c2..ba13e803 100644 --- a/bloodmallet/bloodmallet/settings/common.py +++ b/bloodmallet/bloodmallet/settings/common.py @@ -37,7 +37,6 @@ 'crispy_forms', 'vinaigrette', 'general_website.apps.GeneralWebsiteConfig', - 'compute_api.apps.ComputeApiConfig', ] MIDDLEWARE = [ @@ -53,6 +52,14 @@ 'vinaigrette.middleware.VinaigretteAdminLanguageMiddleware', ] +try: + import compute_api +except ModuleNotFoundError: + pass +else: + INSTALLED_APPS.append('compute_api.apps.ComputeApiConfig') + MIDDLEWARE.append('compute_api.broadcast_middleware.BroadcastMiddleware') + ROOT_URLCONF = 'bloodmallet.urls' TEMPLATES = [ @@ -94,7 +101,11 @@ }, ] -from .secrets import SECRET_KEY +try: + from .secrets import SECRET_KEY +except ModuleNotFoundError: + from django.core.management.utils import get_random_secret_key + SECRET_KEY = get_random_secret_key() # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ @@ -142,12 +153,16 @@ # replaces the Django standard User AUTH_USER_MODEL = 'general_website.User' -# Google cloud storage handling -DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage' - LOCALE_PATHS = (BASE_DIR + '/general_website/locale',) -from .secrets import PROJECT, ZONE, CPU_TYPE, IMAGE_FAMILY, FALLBACK_ZONE +try: + from .secrets import PROJECT, ZONE, CPU_TYPE, IMAGE_FAMILY, FALLBACK_ZONE +except ModuleNotFoundError: + # information is not required for local development of the frontend + pass +else: + # Google cloud storage handling + DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage' STANDARD_CHART_NAME = 'Bloodmallet Standard Chart' diff --git a/bloodmallet/bloodmallet/settings/development.py b/bloodmallet/bloodmallet/settings/development.py index f772664b..8ca815c6 100644 --- a/bloodmallet/bloodmallet/settings/development.py +++ b/bloodmallet/bloodmallet/settings/development.py @@ -6,9 +6,6 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -BASE_DIR = os.path.join(BASE_DIR, '..') - ALLOWED_HOSTS = [ 'localhost', '127.0.0.1', @@ -60,40 +57,41 @@ 'level': 'DEBUG' if DEBUG else 'INFO', 'propagate': True, }, - 'allauth.socialaccount.providers.patreon': { - 'handlers': [ - 'console', - ], - 'level': 'DEBUG', - 'propagate': True - } }, } -# 'allauth.account', -# 'allauth.socialaccount', -# 'allauth.socialaccount.providers.patreon', +# don't send mails...print them to console EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases -import pymysql -pymysql.install_as_MySQLdb() -from .secrets import LIVE_DB_HOST, LIVE_DB_NAME, LIVE_DB_USER, LIVE_DB_PASSWORD +try: + from .secrets import LIVE_DB_HOST, LIVE_DB_NAME, LIVE_DB_USER, LIVE_DB_PASSWORD +except ModuleNotFoundError: + # pure frontend development uses a local dbs + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'mydatabase', + } + } +else: + import pymysql + pymysql.install_as_MySQLdb() -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'HOST': '127.0.0.1', - 'PORT': '3306', - 'NAME': LIVE_DB_NAME, - 'USER': LIVE_DB_USER, - 'PASSWORD': LIVE_DB_PASSWORD, - 'OPTIONS': { - 'charset': 'utf8mb4' - }, + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'HOST': '127.0.0.1', + 'PORT': '3306', + 'NAME': LIVE_DB_NAME, + 'USER': LIVE_DB_USER, + 'PASSWORD': LIVE_DB_PASSWORD, + 'OPTIONS': { + 'charset': 'utf8mb4' + }, + } } -} # used to serve files from this path in non-debug production STATIC_ROOT = 'static' @@ -103,7 +101,12 @@ SASS_PROCESSOR_ROOT = STATIC_ROOT # google cloud storage -from .secrets import DEV_BUCKET_NAME, DEV_CREDENTIALS -GS_BUCKET_NAME = DEV_BUCKET_NAME -from google.oauth2 import service_account -GS_CREDENTIALS = service_account.Credentials.from_service_account_file(DEV_CREDENTIALS) +try: + from .secrets import DEV_BUCKET_NAME, DEV_CREDENTIALS +except ModuleNotFoundError: + # not required for local dev + pass +else: + GS_BUCKET_NAME = DEV_BUCKET_NAME + from google.oauth2 import service_account + GS_CREDENTIALS = service_account.Credentials.from_service_account_file(DEV_CREDENTIALS) diff --git a/bloodmallet/bloodmallet/urls.py b/bloodmallet/bloodmallet/urls.py index 7dde77cb..4c2015da 100644 --- a/bloodmallet/bloodmallet/urls.py +++ b/bloodmallet/bloodmallet/urls.py @@ -22,9 +22,15 @@ path('', include('general_website.urls')), path('admin/login/', app_login), path('admin/', admin.site.urls), - path('compute_api/', include('compute_api.urls', namespace='compute_engine')), ] +try: + import compute_api +except ModuleNotFoundError: + pass +else: + urlpatterns.append(path('compute_api/', include('compute_api.urls', namespace='compute_engine'))) + handler400 = 'general_website.views.handler404' handler403 = 'general_website.views.handler404' handler404 = 'general_website.views.handler404' diff --git a/bloodmallet/bloodmallet/wsgi.py b/bloodmallet/bloodmallet/wsgi.py index f70f86ac..ac463810 100644 --- a/bloodmallet/bloodmallet/wsgi.py +++ b/bloodmallet/bloodmallet/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bloodmallet.settings') +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bloodmallet.settings.production') application = get_wsgi_application() diff --git a/deploy.ps1 b/bloodmallet/deploy.ps1 similarity index 87% rename from deploy.ps1 rename to bloodmallet/deploy.ps1 index 7a07c6af..76d98c34 100644 --- a/deploy.ps1 +++ b/bloodmallet/deploy.ps1 @@ -4,12 +4,10 @@ Write-Host "Deploying to bloodmallet.com" $start_location = pwd Write-Host "Starting virtual environment" -NoNewline -# Activate virtual env -env/Scripts/activate -Write-Host " Done" -ForegroundColor Green -# Navigate to necessary subdirectory (which has the actual app for the appengine) -cd bloodmallet/ +# Activate virtual env (here could be a list search that looks for env, venv and .env instead) +../env/Scripts/activate +Write-Host " Done" -ForegroundColor Green Write-Host "Preparing Styles" -NoNewline # Create fresh css files diff --git a/deploy_preparations.ps1 b/bloodmallet/deploy_preparations.ps1 similarity index 85% rename from deploy_preparations.ps1 rename to bloodmallet/deploy_preparations.ps1 index 54dd2443..045e2902 100644 --- a/deploy_preparations.ps1 +++ b/bloodmallet/deploy_preparations.ps1 @@ -3,12 +3,9 @@ $start_location = pwd Write-Host "Starting virtual environment" -NoNewline # Activate virtual env -env/Scripts/activate +../env/Scripts/activate Write-Host " Done" -ForegroundColor Green -# Navigate to necessary subdirectory (which has the actual app for the appengine) -cd bloodmallet/ - Write-Host "Preparing translations" -NoNewline # collect and compile translateable texts $languages = @('cn', 'de', 'es', 'fr', 'it', 'ko', 'pt', 'ru') diff --git a/bloodmallet/general_website/models.py b/bloodmallet/general_website/models.py index 45bb7b4a..6c1f3c34 100644 --- a/bloodmallet/general_website/models.py +++ b/bloodmallet/general_website/models.py @@ -31,8 +31,9 @@ def can_create_chart(self) -> bool: return True if self.is_staff: return True - if self.groups.filter(name='alpha_tester').exists(): # pylint: disable=no-member - return True + # alpha tester weekend has ended + # if self.groups.filter(name='alpha_tester').exists(): # pylint: disable=no-member + # return True return False diff --git a/bloodmallet/general_website/urls.py b/bloodmallet/general_website/urls.py index 27e4a4d5..76911773 100644 --- a/bloodmallet/general_website/urls.py +++ b/bloodmallet/general_website/urls.py @@ -5,11 +5,15 @@ from allauth.socialaccount.views import ConnectionsView urlpatterns = [ + + # general path('', views.index, name='index_empty'), path('index.html', views.index, name='index_long'), path('index', views.index, name='index'), path('FAQ', views.faq, name='FAQ'), path('error', views.error, name='error'), + + # charts path('my_charts', views.my_charts, name='my_charts'), path('chart/create', views.add_charts, name='add_charts'), path('chart/', views.chart, name='chart'), @@ -20,7 +24,11 @@ name='get_standard_chart_data' ), path('chart/delete', views.delete_chart, name='delete_chart'), + + # portals o_O but blizzard killed most...needs heavy data updates path('portals', views.portals, name='portals'), + + # settings path('settings/general', views.settings, name='settings'), path('settings/profile', views.profile, name='profile'), path('settings/change_password', views.change_password, name='change_password'), diff --git a/bloodmallet/manage.py b/bloodmallet/manage.py index d029ab0c..5cb14754 100644 --- a/bloodmallet/manage.py +++ b/bloodmallet/manage.py @@ -3,7 +3,7 @@ import sys if __name__ == '__main__': - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bloodmallet.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bloodmallet.settings.development') try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/requirements_commented.txt b/requirements.txt similarity index 83% rename from requirements_commented.txt rename to requirements.txt index 121f5d45..0732b19b 100644 --- a/requirements_commented.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ -# This requirements file is a commented mirror of bloodmallet/requirements.txt, which is needed where it is for deployment. Furthermore due to the deployment the requirements file can't have comments for now. +# This requirements file is a commented mirror of bloodmallet/requirements.txt, which is needed where it is for deployment. +# Furthermore due to the deployment the requirements file can't have comments for now. +# (It would break the deployment) # Attention! # Make sure to use 'python -m pip install --upgrade pip setuptools wheel' before trying to use 'pip install -U -r requirements.txt' diff --git a/requirements_dev.txt b/requirements_dev.txt index 5cd609b3..d339b27c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,3 +1,3 @@ pylint>=2.1.1 yapf>=0.24.0 --r requirements_commented.txt +-r requirements.txt