Skip to content

Commit

Permalink
Merge pull request #5 from Bloodmallet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Bloodmallet authored Apr 30, 2019
2 parents 4cb48d8 + 48c1d91 commit 5dbe4f9
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 60 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 0 additions & 6 deletions bloodmallet/bloodmallet/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
import os

if os.getenv('GAE_APPLICATION', None):
from .production import *
else:
from .development import *
27 changes: 21 additions & 6 deletions bloodmallet/bloodmallet/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
'crispy_forms',
'vinaigrette',
'general_website.apps.GeneralWebsiteConfig',
'compute_api.apps.ComputeApiConfig',
]

MIDDLEWARE = [
Expand All @@ -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 = [
Expand Down Expand Up @@ -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/
Expand Down Expand Up @@ -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'

Expand Down
67 changes: 35 additions & 32 deletions bloodmallet/bloodmallet/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'
Expand All @@ -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)
8 changes: 7 additions & 1 deletion bloodmallet/bloodmallet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion bloodmallet/bloodmallet/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 3 additions & 5 deletions deploy.ps1 → bloodmallet/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 3 additions & 2 deletions bloodmallet/general_website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 8 additions & 0 deletions bloodmallet/general_website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<uuid:chart_id>', views.chart, name='chart'),
Expand All @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion bloodmallet/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion requirements_commented.txt → requirements.txt
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pylint>=2.1.1
yapf>=0.24.0
-r requirements_commented.txt
-r requirements.txt

0 comments on commit 5dbe4f9

Please sign in to comment.