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

File uploads #452

Merged
merged 1 commit into from
Nov 24, 2024
Merged
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
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down
11 changes: 10 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions cms/admin.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -64,3 +64,6 @@ class InfoBannerAdmin(admin.ModelAdmin):
'visible_until',
'message_template'
)


admin.site.register(FileUpload)
20 changes: 20 additions & 0 deletions cms/migrations/0004_fileupload.py
Original file line number Diff line number Diff line change
@@ -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/')),
],
),
]
6 changes: 6 additions & 0 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
9 changes: 9 additions & 0 deletions cms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from cms import models

from .models import FileUpload


@ts_interface(context='cms')
class MenuItemShortSerializer(serializers.ModelSerializer):
Expand All @@ -27,6 +29,7 @@ class Meta:
model = models.Post
fields = '__all__'


@ts_interface(context='cms')
class LogoSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -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')
25 changes: 10 additions & 15 deletions cms/urls.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
@@ -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'),
),
]
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down