Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…backend into data_migration
  • Loading branch information
kovacspe committed Nov 22, 2024
2 parents 770cbb1 + 20f059d commit 4923efc
Show file tree
Hide file tree
Showing 54 changed files with 1,605 additions and 1,104 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: deploy
name: Deploy Test Environment

on: workflow_dispatch

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: wshihadeh/docker-deployment-action@v2
with:
remote_docker_host: [email protected]
ssh_private_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PRIVATE_KEY }}
ssh_public_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PUBLIC_KEY }}
stack_file_name: compose.yaml
stack_file_name: deployment/compose-test.yaml
args: up --build --force-recreate --detach
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Upgrade pip
run: pip3 install --upgrade pip
Expand All @@ -37,7 +37,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Upgrade pip
run: pip3 install --upgrade pip
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/migrate-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Migrate Test Environment

on: workflow_dispatch

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: wshihadeh/docker-deployment-action@v2
with:
remote_docker_host: [email protected]
ssh_private_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PRIVATE_KEY }}
ssh_public_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PUBLIC_KEY }}
stack_file_name: deployment/compose-test.yaml
args: run --rm webstrom-backend python manage.py migrate --noinput
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ db.sqlite3-journal
/media
/protected_media

**/migrations/**
!**/migrations/__init__.py

fixtures/sources
!fixtures/sources/*.py
!fixtures/sources/requirements.txt
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"editor.defaultFormatter": "ms-python.autopep8",
"editor.formatOnSave": true,
},
"files.associations": {
"compose-*.yaml": "dockercompose"
},
"git.branchProtection": [
"master"
],
"git.branchProtectionPrompt": "alwaysCommitToNewBranch"
}
}
6 changes: 4 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ verify_ssl = true
name = "pypi"

[packages]
daphne = "~=4.0.0"
dj-rest-auth = "~=5.0.1"
django = "~=3.2.23"
django = "~=4.2.11"
django-allauth = "~=0.58.2"
django-filter = "~=23.5"
django-sendfile2 = "~=0.7.1"
djangorestframework = "~=3.14.0"
drf-writable-nested = "~=0.7.0"
gunicorn = "~=22.0.0"
pillow = "~=10.3.0"
psycopg = "~=3.1.18"
python-magic = "~=0.4.27"

[dev-packages]
Expand Down
705 changes: 300 additions & 405 deletions Pipfile.lock

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion base/fixtures/flatpages.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
{
"model": "flatpages.flatpage",
"pk": 3,
"pk": 4,
"fields": {
"url": "kontakty",
"title": "Kontakty",
Expand All @@ -65,5 +65,22 @@
2
]
}
},
{
"model": "flatpages.flatpage",
"pk": 5,
"fields": {
"url": "ako-riesit",
"title": "Ako získať 9 bodov",
"content": "Tu pribudnú tipy, ako riešiť a získať 9 bodov.",
"enable_comments": false,
"template_name": "",
"registration_required": false,
"sites": [
0,
1,
2
]
}
}
]
105 changes: 105 additions & 0 deletions cms/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Generated by Django 4.2.13 on 2024-06-10 20:10

import base.models
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('sites', '0002_alter_domain_unique'),
]

operations = [
migrations.CreateModel(
name='InfoBanner',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('visible_after', models.DateTimeField(verbose_name='Zobrazuj od')),
('visible_until', models.DateTimeField(verbose_name='Zobrazuj do')),
('message', models.CharField(help_text='Správa sa zobrazí v baneri. Správa musí byť stručná - jedna krátka veta.', max_length=200, verbose_name='správa')),
],
options={
'verbose_name': 'Informácia v pohyblivom baneri',
'verbose_name_plural': 'Informácie v pohyblivom baneri',
},
),
migrations.CreateModel(
name='Logo',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=150, verbose_name='názov loga')),
('disabled', models.BooleanField()),
('image', base.models.RestrictedFileField(upload_to='logo_images/', verbose_name='Logo')),
],
options={
'verbose_name': 'logo',
'verbose_name_plural': 'logá',
'ordering': ['name'],
},
),
migrations.CreateModel(
name='MessageTemplate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text='Pomenovanie generickej správy. Slúži pre orientáciu', max_length=50, verbose_name='Názov')),
('message', models.CharField(help_text='Generické správy pre banner a posty', max_length=200, verbose_name='Generická správa')),
('is_active', models.BooleanField(default=True, verbose_name='Aktívna')),
],
options={
'verbose_name': 'Generické správy pre banner a posty',
'verbose_name_plural': 'Generické správy pre banner a posty',
},
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('visible_after', models.DateTimeField(verbose_name='Zobrazuj od')),
('visible_until', models.DateTimeField(verbose_name='Zobrazuj do')),
('caption', models.CharField(max_length=50, verbose_name='nadpis')),
('short_text', models.CharField(help_text='Krátky 1-2 vetový popis.', max_length=200, verbose_name='krátky text')),
('details', models.TextField(blank=True, help_text='Dlhší text, ktorý sa zobrazí po rozkliknutí.', verbose_name='podrobnosti k príspevku')),
('added_at', models.DateTimeField(auto_now_add=True, verbose_name='pridané')),
('sites', models.ManyToManyField(to='sites.site')),
],
options={
'verbose_name': 'príspevok',
'verbose_name_plural': 'príspevky',
'ordering': ['-added_at'],
},
),
migrations.CreateModel(
name='PostLink',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('caption', models.CharField(help_text='Nápis, ktorý po kliknutí presmeruje na link. Maximálne 2 slová.', max_length=25, verbose_name='názov')),
('url', models.CharField(help_text='URL stránky kam má preklik viesť', max_length=100, verbose_name='URL')),
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='links', to='cms.post', verbose_name='Relevantný príspevok')),
],
options={
'verbose_name': 'link k príspevku',
'verbose_name_plural': 'linky k príspevkom',
},
),
migrations.CreateModel(
name='MenuItem',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('caption', models.CharField(help_text='Nápis, ktorý sa zobrazí v menu. Maximálne 2 slová.', max_length=25, verbose_name='názov')),
('url', models.CharField(help_text='URL stránky kam má preklik viesť', max_length=100, verbose_name='URL')),
('priority', models.SmallIntegerField(help_text='Priorita, čím väčšie, tým vyššie v menu.', verbose_name='priorita')),
('in_footer', models.BooleanField(default=False, verbose_name='Je v pätičke')),
('in_menu', models.BooleanField(default=True, verbose_name='Je v menu')),
('sites', models.ManyToManyField(to='sites.site')),
],
options={
'verbose_name': 'položka v menu',
'verbose_name_plural': 'položky v menu',
'ordering': ['-priority'],
},
),
]
38 changes: 38 additions & 0 deletions cms/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.13 on 2024-06-10 20:10

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('flatpages', '0001_initial'),
('competition', '0001_initial'),
('cms', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='infobanner',
name='event',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='competition.event'),
),
migrations.AddField(
model_name='infobanner',
name='message_template',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='cms.messagetemplate'),
),
migrations.AddField(
model_name='infobanner',
name='page',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='flatpages.flatpage'),
),
migrations.AddField(
model_name='infobanner',
name='series',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='competition.series'),
),
]
11 changes: 7 additions & 4 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ class Meta:
verbose_name='správa',
help_text='Správa sa zobrazí v baneri. Správa musí byť stručná - jedna krátka veta.',
max_length=200)
page = models.ForeignKey(FlatPage, on_delete=models.CASCADE, null=True)
event = models.ForeignKey(Event, on_delete=models.CASCADE, null=True)
series = models.ForeignKey(Series, on_delete=models.CASCADE, null=True)
page = models.ForeignKey(
FlatPage, on_delete=models.CASCADE, null=True, blank=True)
event = models.ForeignKey(
Event, on_delete=models.CASCADE, null=True, blank=True)
series = models.ForeignKey(
Series, on_delete=models.CASCADE, null=True, blank=True)
message_template = models.ForeignKey(
MessageTemplate, on_delete=models.PROTECT, null=True)
MessageTemplate, on_delete=models.PROTECT, null=True, blank=True)

def clean(self):
try:
Expand Down
64 changes: 64 additions & 0 deletions cms/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@


from datetime import datetime

from django.utils.timezone import now
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.request import Request
Expand All @@ -10,6 +13,7 @@
from cms.serializers import (InfoBannerSerializer, LogoSerializer,
MenuItemShortSerializer,
MessageTemplateSerializer, PostSerializer)
from competition.models import Competition, Event, Series


class MenuItemViewSet(viewsets.ReadOnlyModelViewSet):
Expand Down Expand Up @@ -62,6 +66,66 @@ class InfoBannerViewSet(viewsets.ModelViewSet):
queryset = InfoBanner.objects.visible()
filterset_fields = ['event', 'page', 'series']

def format_date(self, datetime_: datetime):
return datetime_.strftime("%d.%m.%Y %H:%M")

@action(methods=['get'], detail=False, url_path=r'series-problems/(?P<series_id>\d+)')
def series_problems(self, request, series_id: int) -> list[str]:
series_messages = InfoBanner.objects.filter(series=series_id).all()
messages = [message.render_message() for message in series_messages]
series = Series.objects.get(pk=series_id)
if series.complete:
messages.append('Séria je uzavretá')
elif series.can_submit:
messages.append(
f'Termín série: {self.format_date(series.deadline)}'
)
else:
messages.append('Prebieha opravovanie')
return Response(messages)

@action(methods=['get'], detail=False, url_path=r'series-results/(?P<series_id>\d+)')
def series_results(self, request, series_id):
series = Series.objects.get(pk=series_id)
if not series.complete:
return Response(['Poradie nie je uzavreté'])
return Response([])

@action(methods=['get'], detail=False, url_path=r'competition/(?P<competition_id>\d+)')
def event(self, request, competition_id: int) -> list[str]:
competition = Competition.objects.get(pk=competition_id)
try:
event = Event.objects.filter(
competition=competition_id, end__gte=now()).earliest('start')
except Event.DoesNotExist:
return Response([])
event_messages = InfoBanner.objects.filter(event=event).all()
messages = [message.render_message() for message in event_messages]

if event.registration_link is not None:
if competition.competition_type.name == 'Seminár':
if event.registration_link.start > now():
messages.append(
'Prihlasovanie na sústredenie bude spustené '
f'{self.format_date(event.registration_link.start)}')
elif event.registration_link.end > now():
messages.append(
'Prihlasovanie na sústredenie končí '
f'{self.format_date(event.registration_link.end)}')
else:
if event.registration_link.start > now():
messages.append(
'Registrácia bude spustená '
f'{self.format_date(event.registration_link.start)}')
elif event.registration_link.end > now():
messages.append(
'Registrácia bude uzavretá '
f'{self.format_date(event.registration_link.end)}')

else:
messages.append('Registrácia ukončená')
return Response(messages)


class MessageTemplateViewSet(viewsets.ModelViewSet):
"""Templaty správ pre info banner/posty"""
Expand Down
Loading

0 comments on commit 4923efc

Please sign in to comment.