Skip to content

Commit

Permalink
Merge pull request #185 from EarthSchlange/update_beta_pages
Browse files Browse the repository at this point in the history
update beta pages
  • Loading branch information
Michael Hiiva committed May 8, 2021
2 parents 67d1439 + 6456a55 commit 56f51ee
Show file tree
Hide file tree
Showing 20 changed files with 561 additions and 482 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ COPY --from=build --chown=django:django /root/.local /home/django/.local

RUN apt-get update && apt-get install -y \
default-mysql-client \
mime-support \
libmariadb3

USER django
Expand All @@ -41,6 +42,5 @@ ENV PROJECT_ROOT=/srv
ENV TEMPLATE_DIR=/srv/templates

COPY --chown=django:django scripts/ agagd/ /srv/
RUN SECRET_KEY=stub-for-build python manage.py collectstatic --noinput

CMD ["/srv/entrypoint.sh"]
32 changes: 26 additions & 6 deletions agagd/agagd/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
"django.contrib.staticfiles.finders.DefaultStorageFinder",
)

MIDDLEWARE = (
MIDDLEWARE = [
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
# Uncomment the next line for simple clickjacking protection:
"django.middleware.clickjacking.XFrameOptionsMiddleware",
)
]

ROOT_URLCONF = "agagd.urls"

Expand Down Expand Up @@ -123,11 +123,31 @@
# 'django.template.loaders.eggs.Loader',
],
},
}
},
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
"DIRS": [os.path.join(PROJECT_ROOT, "jinja2")],
"OPTIONS": {
"environment": "agagd_core.jinga2.environment",
"context_processors": [
# Standard context_processors
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
# Custom context_processors
"django.template.context_processors.request",
"agagd_core.context_processors.google_analytics_tracking_id",
],
},
},
]


INSTALLED_APPS = (
INSTALLED_APPS = [
"agagd_core",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand All @@ -136,7 +156,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django_tables2",
)
]

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
Expand Down
25 changes: 22 additions & 3 deletions agagd/agagd/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,31 @@

if os.getenv("DEBUG") == "true":
DEBUG = True

# DebugToolbar Middleware
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]

# DebugToobar
INSTALLED_APPS += ["debug_toolbar"]

# Add our Docker host IP to the INTERNAL_IPS
import os
import socket

HOSTNAME = os.getenv("HOSTNAME")
INTERNAL_IPS = ["127.0.0.1", socket.gethostbyname(HOSTNAME)]

# DebugToolbar Configurations
DEBUG_TOOLBAR_CONFIG = {
"INTERCEPT_REDIRECTS": False,
"SHOW_COLLAPSED": True,
"SHOW_TOOLBAR_CALLBACK": lambda request: DEBUG,
}

else:
DEBUG = False


GOOGLE_ANALYTICS_TRACKING_ID = os.getenv("GOOGLE_ANALYTICS_TRACKING_ID", "")

ADMIN_ENABLED = False
Expand All @@ -21,7 +43,6 @@
_dbname = os.getenv("APP_DB_NAME", "")
_dbhost = os.getenv("DB_HOST", "")
_dbport = os.getenv("DB_PORT", "")
_templates = os.getenv("TEMPLATE_DIR", os.path.join(PROJECT_ROOT, "templates"))

SECRET_KEY = _key

Expand All @@ -35,5 +56,3 @@
"PORT": _dbport, # Set to empty string for default. Not used with sqlite3.
}
}

TEMPLATES[0]["DIRS"] = [_templates]
10 changes: 8 additions & 2 deletions agagd/agagd/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.urls import path, reverse_lazy
from django.views.generic import RedirectView

urlpatterns = (
urlpatterns = [
url(r"^$", agagd_views.index, name="index"),
url(r".php$", RedirectView.as_view(url=reverse_lazy("index"))),
url(r"^search/$", agagd_views.search, name="search"),
Expand Down Expand Up @@ -61,4 +61,10 @@
path("qualifications/", QualificationsPageView.as_view()),
# Beta
path("beta/", include(beta_urls.beta_patterns)),
)
]

# DebugToolbar URL Configuration
if settings.DEBUG:
import debug_toolbar

urlpatterns = [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns
28 changes: 28 additions & 0 deletions agagd/agagd_core/jinga2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import agagd_core.models as agagd_models
from django.core.exceptions import ObjectDoesNotExist
from django.templatetags.static import static
from django.urls import reverse
from jinja2 import Environment


def get_members_name_and_id(value):
"""
Provides jinja2 custom filter which returns
the members information as
"[member's full name] (member_id)".
"""
try:
member = agagd_models.Member.objects.values("full_name", "member_id").get(
pk=value
)
except ObjectDoesNotExist:
raise ("Member {value} does not exist.")

return f"{member['full_name']} ({member['member_id']})"


def environment(**options):
env = Environment(**options)
env.filters["get_members_name_and_id"] = get_members_name_and_id
env.globals.update({"static": static, "url": reverse})
return env
Loading

0 comments on commit 56f51ee

Please sign in to comment.