diff --git a/Pipfile b/Pipfile index 4b4d24f..23ea991 100644 --- a/Pipfile +++ b/Pipfile @@ -15,6 +15,7 @@ gunicorn = "~=22.0.0" pillow = "~=10.3.0" psycopg = "~=3.1.18" python-magic = "~=0.4.27" +setuptools = "~=75.6.0" [dev-packages] autopep8 = "*" diff --git a/Pipfile.lock b/Pipfile.lock index bf405c0..c333f5c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "75ce67f261804416a0e3b44aa8c1ad2c3c7ac698014509be1afa264329393385" + "sha256": "f16b414eadaa44ef2f7111117fb0ec2408f3908a33ca752f1fb873101ba8d876" }, "pipfile-spec": 6, "requires": {}, @@ -483,6 +483,15 @@ "markers": "python_version >= '3.4'", "version": "==2.0.0" }, + "setuptools": { + "hashes": [ + "sha256:8199222558df7c86216af4f84c30e9b34a61d8ba19366cc914424cdbd28252f6", + "sha256:ce74b49e8f7110f9bf04883b730f4765b774ef3ef28f722cce7c273d253aaf7d" + ], + "index": "pypi", + "markers": "python_version >= '3.9'", + "version": "==75.6.0" + }, "sqlparse": { "hashes": [ "sha256:9e37b35e16d1cc652a2545f0997c1deb23ea28fa1f3eefe609eee3063c3b105f", diff --git a/cms/admin.py b/cms/admin.py index 09d0ff9..c60555c 100644 --- a/cms/admin.py +++ b/cms/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin -from cms.models import (InfoBanner, Logo, MenuItem, MessageTemplate, Post, - PostLink) +from cms.models import (FileUpload, InfoBanner, Logo, MenuItem, + MessageTemplate, Post, PostLink) @admin.register(MenuItem) @@ -64,3 +64,6 @@ class InfoBannerAdmin(admin.ModelAdmin): 'visible_until', 'message_template' ) + + +admin.site.register(FileUpload) diff --git a/cms/migrations/0004_fileupload.py b/cms/migrations/0004_fileupload.py new file mode 100644 index 0000000..20449d1 --- /dev/null +++ b/cms/migrations/0004_fileupload.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.16 on 2024-11-23 22:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cms', '0003_alter_menuitem_url'), + ] + + operations = [ + migrations.CreateModel( + name='FileUpload', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('file', models.FileField(upload_to='uploads/')), + ], + ), + ] diff --git a/cms/models.py b/cms/models.py index a7a198e..65d6e41 100644 --- a/cms/models.py +++ b/cms/models.py @@ -164,3 +164,9 @@ def render_message(self): if self.series is not None: return self.message_template.render_with(self.series) return self.message_template.render_with({}) + + +class FileUpload(models.Model): + """Slúži na nahrávanie súborov ktoré nepatria priamo k súťažiam""" + + file = models.FileField(upload_to="uploads/") diff --git a/cms/serializers.py b/cms/serializers.py index 232fa56..41a0aa8 100644 --- a/cms/serializers.py +++ b/cms/serializers.py @@ -4,6 +4,8 @@ from cms import models +from .models import FileUpload + @ts_interface(context='cms') class MenuItemShortSerializer(serializers.ModelSerializer): @@ -27,6 +29,7 @@ class Meta: model = models.Post fields = '__all__' + @ts_interface(context='cms') class LogoSerializer(serializers.ModelSerializer): class Meta: @@ -48,3 +51,9 @@ class MessageTemplateSerializer(serializers.ModelSerializer): class Meta: model = models.MessageTemplate fields = ['message'] + + +class FileUploadSerializer(serializers.ModelSerializer): + class Meta: + model = FileUpload + fields = ('id', 'file') diff --git a/cms/urls.py b/cms/urls.py index 68b22e2..6a7270d 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -1,21 +1,16 @@ from rest_framework.routers import DefaultRouter -from cms import views +from .views import (FileUploadViewSet, InfoBannerViewSet, LogoViewSet, + MenuItemViewSet, MessageTemplateViewSet, PostViewSet) -app_name = 'cms' - - -# Create a router and register our viewsets with it. router = DefaultRouter() -router.register(r'post', views.PostViewSet) -router.register(r'menu-item', views.MenuItemViewSet) -router.register(r'info-banner', views.InfoBannerViewSet) -router.register(r'message-template', views.MessageTemplateViewSet) -router.register(r'logo', views.LogoViewSet) +router.register('post', PostViewSet) +router.register('menu-item', MenuItemViewSet) +router.register('info-banner', InfoBannerViewSet) +router.register('message-template', MessageTemplateViewSet) +router.register('logo', LogoViewSet) +router.register('uploads', FileUploadViewSet) -urlpatterns = [ - -] - -urlpatterns += router.urls +app_name = 'cms' +urlpatterns = router.urls diff --git a/cms/views.py b/cms/views.py index a759033..af9bf26 100644 --- a/cms/views.py +++ b/cms/views.py @@ -8,10 +8,11 @@ from rest_framework.request import Request from rest_framework.response import Response -from cms.models import InfoBanner, Logo, MenuItem, MessageTemplate, Post +from cms.models import (FileUpload, InfoBanner, Logo, MenuItem, + MessageTemplate, Post) from cms.permissions import PostPermission -from cms.serializers import (InfoBannerSerializer, LogoSerializer, - MenuItemShortSerializer, +from cms.serializers import (FileUploadSerializer, InfoBannerSerializer, + LogoSerializer, MenuItemShortSerializer, MessageTemplateSerializer, PostSerializer) from competition.models import Competition, Event, Series @@ -131,3 +132,8 @@ class MessageTemplateViewSet(viewsets.ModelViewSet): """Templaty správ pre info banner/posty""" serializer_class = MessageTemplateSerializer queryset = MessageTemplate.objects.all() + + +class FileUploadViewSet(viewsets.ModelViewSet): + serializer_class = FileUploadSerializer + queryset = FileUpload.objects.all() diff --git a/competition/migrations/0004_alter_problemcorrection_options_and_more.py b/competition/migrations/0004_alter_problemcorrection_options_and_more.py new file mode 100644 index 0000000..9ca62e2 --- /dev/null +++ b/competition/migrations/0004_alter_problemcorrection_options_and_more.py @@ -0,0 +1,30 @@ +# Generated by Django 4.2.16 on 2024-11-23 22:54 + +import base.models +import competition.models +import django.core.files.storage +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('competition', '0003_alter_solution_corrected_solution_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='problemcorrection', + options={'verbose_name': 'Opravenie úlohy', 'verbose_name_plural': 'Opravené úlohy'}, + ), + migrations.AlterField( + model_name='solution', + name='corrected_solution', + field=base.models.RestrictedFileField(blank=True, storage=django.core.files.storage.FileSystemStorage(base_url='/protected/', location='/home/mihal/Documents/STROM/webstrom/webstrom-backend/protected_media/'), upload_to=competition.models.get_corrected_solution_path, verbose_name='opravené riešenie'), + ), + migrations.AlterField( + model_name='solution', + name='solution', + field=base.models.RestrictedFileField(blank=True, storage=django.core.files.storage.FileSystemStorage(base_url='/protected/', location='/home/mihal/Documents/STROM/webstrom/webstrom-backend/protected_media/'), upload_to=competition.models.get_solution_path, verbose_name='účastnícke riešenie'), + ), + ] diff --git a/requirements.txt b/requirements.txt index d8d72a1..2aee5d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -39,7 +39,6 @@ pylint-django==2.6.1 pylint-plugin-utils==0.8.2 python-magic==0.4.27 python3-openid==3.2.0 -pytz==2024.2 requests==2.32.3 requests-oauthlib==2.0.0 setuptools==75.6.0