Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update python and its dependencies to newest versions #32

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ DJANGO_SETTINGS_MODULE=testovac.settings.production
TESTOVAC_FRONT_ALLOWED_HOSTS=testovac.ksp.sk localhost
DEBUG=True

TESTOVAC_FRONT_STATIC_URL=/static
TESTOVAC_FRONT_STATIC_ROOT=staticfiles
TESTOVAC_FRONT_STATIC_URL=/static/
TESTOVAC_FRONT_STATIC_ROOT=static

TESTOVAC_FRONT_DATABASE_NAME=testovac
TESTOVAC_FRONT_DATABASE_USER=testovac
TESTOVAC_FRONT_DATABASE_PASSWORD=testovac
SQL_HOST=db
SQL_PORT=5432
SQL_PORT=5432
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
###########

# pull official base image
FROM python:3.5 as builder
FROM python:3.12 as builder

# set work directory
WORKDIR /usr/src/app
Expand Down Expand Up @@ -32,7 +32,7 @@ RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requir
#########

# pull official base image
FROM python:3.5
FROM python:3.12

# create directory for the app user
RUN mkdir -p /home/app
Expand All @@ -44,14 +44,14 @@ RUN addgroup --system app && adduser --system --group app
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/static
RUN mkdir $APP_HOME/media
RUN mkdir $APP_HOME/submit
RUN mkdir $APP_HOME/statements
WORKDIR $APP_HOME

# install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends netcat
RUN apt-get update && apt-get install -y --no-install-recommends netcat-openbsd
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --upgrade pip
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@ Webová aplikácia, ktorá bude obsahovať:
- ...

Komunikácia s testovačom a odovzdávanie úloh na testovanie bude vyriešené v samostatnej django-app.

## Spustenie

Treba odkomentovať `TESTOVAC_FRONT_SECRET_KEY` v `.env.prod`.
Získať `dump20221009.psql` a umiestniť ho na úroveň `Dockerfile`.

```bash
docker compose up -d --build
docker container start testovac-front-end-db-1

docker exec -it testovac-front-end-db-1 /bin/sh
# vnutri kontajneru
psql -U testovac testovac <dump.psql
exit

docker compose up
# a potom otvoriť http://localhost:1337
```
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
build: ./
command: gunicorn testovac.wsgi:application --access-logfile - --error-logfile - --log-level debug --bind 0.0.0.0:8000
volumes:
- static_volume:/home/app/web/staticfiles
- static_volume:/home/app/web/static
- media_volume:/home/app/web/media
- submits_volume:/home/app/web/submit
- statements_volume:/home/app/web/statements
Expand All @@ -26,7 +26,7 @@ services:
nginx:
build: ./nginx
volumes:
- static_volume:/home/app/web/staticfiles
- static_volume:/home/app/web/static
- media_volume:/home/app/web/media
- submits_volume:/home/app/web/submit
- statements_volume:/home/app/web/statements
Expand Down
2 changes: 1 addition & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx:1.25

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
COPY nginx.conf /etc/nginx/conf.d
4 changes: 2 additions & 2 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ server {
}

location /static/ {
alias /home/app/web/staticfiles/;
alias /home/app/web/static/;
}

location /media/ {
Expand All @@ -33,4 +33,4 @@ server {
alias /home/app/web/statements/;
}

}
}
39 changes: 19 additions & 20 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
Django==2.0.13
psycopg2-binary==2.8.5
django-easy-select2==1.5.7
Markdown==3.1
Pillow==5.4.0
Django==5.0.7
psycopg2-binary==2.9.9
django-easy-select2==1.5.8
Markdown==3.6
Pillow==10.4.0
django-bootstrap-form==3.4
django-nyt==1.1.3
django-sekizai==1.1.0
django-nyt==1.4
django-sekizai==4.1.0
django-sendfile==0.3.11
sorl-thumbnail==12.6.3
wiki==0.5
django-trojsten-news==0.2.2
Unidecode==1.1.1
constants==0.6.0
sorl-thumbnail==12.10.0
wiki==0.11.1
# django-trojsten-news==0.2.2
Unidecode==1.3.8
django-dotenv==1.4.2
django-debug-toolbar==2.2
django-sortedm2m==1.5.0
django-autoslug==1.9.4
django-taggit==0.24.0
sqlparse==0.3.1
django-debug-toolbar==4.4.6
django-sortedm2m==3.1.1
django-autoslug==1.9.9
django-taggit==5.0.1
sqlparse==0.5.1
trojsten-judge-client==1.0.2
# pre-commit==1.18.3
django-js-asset==1.2.3
django-classy-tags==1.0.0
gunicorn==20.0.4
django-js-asset==2.2.0
django-classy-tags==4.1.0
gunicorn==22.0.0
9 changes: 7 additions & 2 deletions testovac/achievements/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.contrib import admin
from django.contrib.auth.models import User

from testovac.achievements.models import Achievement, AchievementTaskSet, AchievementToUser
from testovac.achievements.models import (
Achievement,
AchievementTaskSet,
AchievementToUser,
)


class AchievementAdmin(admin.ModelAdmin):
Expand All @@ -13,7 +17,6 @@ class AchievementTaskSetAdmin(admin.ModelAdmin):
exclude = ("achievement",)

def save_model(self, request, obj, form, change):

self.slug = obj.slug
if not change:
obj.achievement = Achievement.objects.create(
Expand Down Expand Up @@ -53,9 +56,11 @@ def save_related(self, request, form, formsets, change):
):
achievement.users.add(user)


class AchievementToUserAdmin(admin.ModelAdmin):
list_display = ("created", "user", "achievement")


admin.site.register(AchievementTaskSet, AchievementTaskSetAdmin)
admin.site.register(Achievement, AchievementAdmin)
admin.site.register(AchievementToUser, AchievementToUserAdmin)
12 changes: 9 additions & 3 deletions testovac/achievements/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ def handler(sender, **kwargs):
.values("submit__receiver__task")
.distinct()
.count()
== len(task_list) and AchievementToUser.objects.filter(achievement=achievementTaskSet.achievement, user=user).count() == 0
== len(task_list)
and AchievementToUser.objects.filter(
achievement=achievementTaskSet.achievement, user=user
).count()
== 0
):
achievementToUser = AchievementToUser(achievement=achievementTaskSet.achievement, user=user)
achievementToUser = AchievementToUser(
achievement=achievementTaskSet.achievement, user=user
)
achievementToUser.save()
#achievementTaskSet.achievement.users.add(user)
# achievementTaskSet.achievement.users.add(user)


class AchievementToUser(models.Model):
Expand Down
6 changes: 3 additions & 3 deletions testovac/achievements/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf.urls import url
from django.urls import re_path

from testovac.achievements import views

urlpatterns = [
url(r"^$", views.overview, name="achievement_overview"),
url(r"^(?P<slug>[A-Za-z0-9_-]+)/$", views.detail, name="achievement_detail"),
re_path(r"^$", views.overview, name="achievement_overview"),
re_path(r"^(?P<slug>[A-Za-z0-9_-]+)/$", views.detail, name="achievement_detail"),
]
2 changes: 1 addition & 1 deletion testovac/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from django.utils.translation import ugettext as _
from django.utils.translation import gettext_lazy as _


def group_apps(app_list, main_app_label, grouped_apps_labels):
Expand Down
8 changes: 4 additions & 4 deletions testovac/login/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.conf.urls import url
from django.urls import re_path

from testovac.login.views import login, logout, register

urlpatterns = [
url(r"^login/$", login, name="login"),
url(r"^logout/$", logout, name="logout"),
url(r"^register/$", register, name="registration"),
re_path(r"^login/$", login, name="login"),
re_path(r"^logout/$", logout, name="logout"),
re_path(r"^register/$", register, name="registration"),
]
11 changes: 6 additions & 5 deletions testovac/login/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
from django.urls import reverse
from django.utils.http import is_safe_url
from django.utils.translation import ugettext_lazy as _
from django.utils.http import url_has_allowed_host_and_scheme
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
Expand All @@ -19,7 +19,7 @@ def add_form_errors_to_messages(request, form):
for field in form:
for error in field.errors:
messages.add_message(
request, messages.ERROR, u"%s: %s" % (field.label, error)
request, messages.ERROR, "%s: %s" % (field.label, error)
)
for error in form.non_field_errors():
messages.add_message(request, messages.ERROR, error)
Expand All @@ -39,9 +39,10 @@ def login(request):

form = AuthenticationForm(request, data=request.POST)
if form.is_valid():

# Ensure the user-originating redirection url is safe.
if not is_safe_url(url=success_redirect, allowed_hosts=request.get_host()):
if not url_has_allowed_host_and_scheme(
url=success_redirect, allowed_hosts={request.get_host()}
):
return HttpResponseRedirect(problem_redirect)

# Okay, security check complete. Log the user in.
Expand Down
14 changes: 7 additions & 7 deletions testovac/menu/templatetags/menu_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

from django import template
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from wiki.models import URLPath

register = template.Library()


def static_menu_items(request):
items = [
{
"url_regex": r"^/news",
"text": _("News"),
"link": reverse("news_list", kwargs={"page": 1}),
},
# {
# "url_regex": r"^/news",
# "text": _("News"),
# "link": reverse("news_list", kwargs={"page": 1}),
# },
{
"url_regex": r"^/tasks",
"text": _("Tasks"),
Expand All @@ -23,7 +23,7 @@ def static_menu_items(request):
{
"url_regex": r"^/results",
"text": _("Results"),
"link": "%s?group=ls_2022_zaciatocnici" % reverse('results_index'),
"link": "%s?group=ls_2022_zaciatocnici" % reverse("results_index"),
},
{
"url_regex": r"^/achievements",
Expand Down
4 changes: 2 additions & 2 deletions testovac/results/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from itertools import chain

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from sortedm2m.fields import SortedManyToManyField

from testovac.tasks.models import Contest
Expand All @@ -22,7 +22,7 @@ class Meta:
verbose_name_plural = _("custom results tables")

def __str__(self):
return u"{} ({})".format(self.name, self.slug)
return "{} ({})".format(self.name, self.slug)

def task_list(self, user):
tasks = []
Expand Down
10 changes: 5 additions & 5 deletions testovac/results/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.conf.urls import url
from django.urls import re_path

from testovac.results.views import contest_results, results_index

urlpatterns = [
url(r"^$", results_index, name="results_index"),
url(
re_path(r"^$", results_index, name="results_index"),
re_path(
r"^contest/(?P<contest_slug>[\w-]+)/$", contest_results, name="contest_results"
),
url(r"^(?P<group>\w+)/$", results_index, name="results_index_group"),
url(
re_path(r"^(?P<group>\w+)/$", results_index, name="results_index_group"),
re_path(
r"^contest/(?P<contest_slug>[\w-]+)/(?P<group>\w+)/$",
contest_results,
name="contest_results_group",
Expand Down
2 changes: 1 addition & 1 deletion testovac/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def env(name, default):
"wiki.plugins.notifications",
"wiki.plugins.images",
"wiki.plugins.macros",
"news",
# "news",
"testovac.achievements",
)

Expand Down
3 changes: 2 additions & 1 deletion testovac/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
# Dummy email configuration
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

ALLOWED_HOSTS = ['testovac.ksp.sk']
ALLOWED_HOSTS = ["testovac.ksp.sk", "localhost"]
CSRF_TRUSTED_ORIGINS = ["http://localhost:1337"]
10 changes: 6 additions & 4 deletions testovac/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import

import os

from django.core.exceptions import ImproperlyConfigured

from testovac.settings.common import *
Expand All @@ -12,12 +14,12 @@ def requiredenv(name):
)
return os.environ.get(name)

SENDFILE_BACKEND = 'sendfile.backends.nginx'
SENDFILE_ROOT = '/home/app/web/'
SENDFILE_URL = '/protected-files'

SENDFILE_BACKEND = "sendfile.backends.nginx"
SENDFILE_ROOT = "/home/app/web/"
SENDFILE_URL = "/protected-files"


DEBUG = False
SECRET_KEY = requiredenv("TESTOVAC_FRONT_SECRET_KEY")
ALLOWED_HOSTS = requiredenv("TESTOVAC_FRONT_ALLOWED_HOSTS").split(" ")

Loading