Skip to content

Commit

Permalink
Remove sites and flatpages (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmihalik authored Nov 24, 2024
1 parent 52e2685 commit bf37733
Show file tree
Hide file tree
Showing 26 changed files with 120 additions and 401 deletions.
9 changes: 3 additions & 6 deletions base/fixtures/sites.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
[
{
"model": "sites.site",
"model": "base.Site",
"pk": 0,
"fields": {
"domain": "seminar.strom.sk",
"name": "STROM"
}
},
{
"model": "sites.site",
"model": "base.Site",
"pk": 1,
"fields": {
"domain": "matik.strom.sk",
"name": "Matik"
}
},
{
"model": "sites.site",
"model": "base.Site",
"pk": 2,
"fields": {
"domain": "malynar.strom.sk",
"name": "Malyn\u00e1r"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Generated by Django 4.2.16 on 2024-11-23 22:54
# Generated by Django 4.2.16 on 2024-11-24 11:59

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('cms', '0003_alter_menuitem_url'),
]

operations = [
migrations.CreateModel(
name='FileUpload',
name='Site',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(upload_to='uploads/')),
('name', models.CharField(max_length=10, unique=True)),
],
),
]
4 changes: 4 additions & 0 deletions base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ def clean(self, *args, **kwargs):
'Nepovolený typ súboru')

return file


class Site(models.Model):
name = models.CharField(max_length=10, unique=True)
10 changes: 10 additions & 0 deletions base/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from rest_framework.permissions import SAFE_METHODS, BasePermission


class IsAdminOrReadOnly(BasePermission):
def has_permission(self, request, view):
return bool(
request.method in SAFE_METHODS or
request.user and
request.user.is_staff
)
10 changes: 0 additions & 10 deletions base/serializers.py

This file was deleted.

10 changes: 1 addition & 9 deletions base/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
from django.urls import path
from rest_framework.routers import DefaultRouter

from base import views

app_name = 'base'

# Create a router and register our viewsets with it.
router = DefaultRouter()
router.register(r'flat-page', views.FlatPageViewSet)


urlpatterns = [
path(r'api-docs/', views.SwaggerSchemaView.as_view(), name='api-docs')
path(r'api-docs/', views.SwaggerSchemaView.as_view(), name='api-docs'),
]

urlpatterns += router.urls
26 changes: 1 addition & 25 deletions base/views.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
from django.contrib.flatpages.models import FlatPage
from rest_framework import status, viewsets
from rest_framework.decorators import action
from rest_framework.permissions import (DjangoModelPermissionsOrAnonReadOnly,
IsAdminUser)
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.schemas import SchemaGenerator
from rest_framework.views import APIView
from rest_framework_swagger import renderers

from base.serializers import FlatPageSerializer

# Create your views here.


class FlatPageViewSet(viewsets.ModelViewSet):
"""
Statické stránky
"""
queryset = FlatPage.objects.all()
serializer_class = FlatPageSerializer
permission_classes = [DjangoModelPermissionsOrAnonReadOnly, ]

@action(methods=['get'], detail=False, url_path=r'by-url/(?P<page_url>.+)')
def by_url(self, request, page_url):
"""Vráti statickú stránku podľa jej url"""
page = FlatPage.objects.filter(url=page_url).first()
serializer = FlatPageSerializer(page)
return Response(serializer.data, status=status.HTTP_200_OK)


class SwaggerSchemaView(APIView):
"""Prehľad API pointov"""
Expand Down
59 changes: 10 additions & 49 deletions base/fixtures/flatpages.json → cms/fixtures/flatpages.json

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions cms/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.13 on 2024-06-10 20:10
# Generated by Django 4.2.16 on 2024-11-24 11:59

import base.models
from django.db import migrations, models
Expand All @@ -10,10 +10,26 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('sites', '0002_alter_domain_unique'),
('base', '0001_initial'),
]

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/')),
],
),
migrations.CreateModel(
name='FlatPage',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.SlugField(max_length=100, unique=True, verbose_name='url')),
('title', models.CharField(max_length=200, verbose_name='title')),
('content', models.TextField(blank=True, verbose_name='content')),
],
),
migrations.CreateModel(
name='InfoBanner',
fields=[
Expand Down Expand Up @@ -64,7 +80,7 @@ class Migration(migrations.Migration):
('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')),
('sites', models.ManyToManyField(to='base.site')),
],
options={
'verbose_name': 'príspevok',
Expand All @@ -90,11 +106,11 @@ class Migration(migrations.Migration):
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')),
('url', models.TextField(help_text='URL stránky kam má preklik viesť', 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')),
('sites', models.ManyToManyField(to='base.site')),
],
options={
'verbose_name': 'položka v menu',
Expand Down
5 changes: 2 additions & 3 deletions cms/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.13 on 2024-06-10 20:10
# Generated by Django 4.2.16 on 2024-11-24 11:59

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -9,7 +9,6 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('flatpages', '0001_initial'),
('competition', '0001_initial'),
('cms', '0001_initial'),
]
Expand All @@ -28,7 +27,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='infobanner',
name='page',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='flatpages.flatpage'),
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='cms.flatpage'),
),
migrations.AddField(
model_name='infobanner',
Expand Down
18 changes: 0 additions & 18 deletions cms/migrations/0003_alter_menuitem_url.py

This file was deleted.

15 changes: 12 additions & 3 deletions cms/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.timezone import now

from base.models import RestrictedFileField
from base.models import RestrictedFileField, Site
from competition.models import Event, Series

from .querysets import VisibilityQuerySet
Expand All @@ -25,6 +23,17 @@ class Meta:
abstract = True


class FlatPage(models.Model):
"""Statická stránka"""

url = models.SlugField("url", max_length=100, unique=True)
title = models.CharField("title", max_length=200)
content = models.TextField("content", blank=True)

def __str__(self):
return f"{self.url} - {self.title}"


class MessageTemplate(models.Model):
class Meta:
verbose_name = 'Generické správy pre banner a posty'
Expand Down
8 changes: 7 additions & 1 deletion cms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from cms import models

from .models import FileUpload
from .models import FileUpload, FlatPage


@ts_interface(context='cms')
Expand Down Expand Up @@ -57,3 +57,9 @@ class FileUploadSerializer(serializers.ModelSerializer):
class Meta:
model = FileUpload
fields = ('id', 'file')


class FlatPageSerializer(serializers.ModelSerializer):
class Meta:
model = FlatPage
fields = ('id', 'url', 'title', 'content')
7 changes: 5 additions & 2 deletions cms/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from rest_framework.routers import DefaultRouter

from .views import (FileUploadViewSet, InfoBannerViewSet, LogoViewSet,
MenuItemViewSet, MessageTemplateViewSet, PostViewSet)
from .views import (FileUploadViewSet, FlatPageViewSet, InfoBannerViewSet,
LogoViewSet, MenuItemViewSet, MessageTemplateViewSet,
PostViewSet)

router = DefaultRouter()

Expand All @@ -11,6 +12,8 @@
router.register('message-template', MessageTemplateViewSet)
router.register('logo', LogoViewSet)
router.register('uploads', FileUploadViewSet)
router.register('flat-page', FlatPageViewSet)

app_name = 'cms'

urlpatterns = router.urls
25 changes: 22 additions & 3 deletions cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
from django.utils.timezone import now
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound
from rest_framework.request import Request
from rest_framework.response import Response

from cms.models import (FileUpload, InfoBanner, Logo, MenuItem,
from base.permissions import IsAdminOrReadOnly
from cms.models import (FileUpload, FlatPage, InfoBanner, Logo, MenuItem,
MessageTemplate, Post)
from cms.permissions import PostPermission
from cms.serializers import (FileUploadSerializer, InfoBannerSerializer,
LogoSerializer, MenuItemShortSerializer,
from cms.serializers import (FileUploadSerializer, FlatPageSerializer,
InfoBannerSerializer, LogoSerializer,
MenuItemShortSerializer,
MessageTemplateSerializer, PostSerializer)
from competition.models import Competition, Event, Series

Expand Down Expand Up @@ -137,3 +140,19 @@ class MessageTemplateViewSet(viewsets.ModelViewSet):
class FileUploadViewSet(viewsets.ModelViewSet):
serializer_class = FileUploadSerializer
queryset = FileUpload.objects.all()


class FlatPageViewSet(viewsets.ModelViewSet):
serializer_class = FlatPageSerializer
queryset = FlatPage.objects.all()
permission_classes = (IsAdminOrReadOnly,)

@action(detail=False, methods=['get'], url_path='by-url/(?P<slug>.+)')
def by_url(self, request, slug):
try:
page = self.queryset.get(url=slug)

return Response(FlatPageSerializer(page).data)

except FlatPage.DoesNotExist as exc:
raise NotFound from exc
9 changes: 5 additions & 4 deletions competition/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 4.2.13 on 2024-06-10 20:10
# Generated by Django 4.2.16 on 2024-11-24 11:59

import base.models
import base.validators
import competition.models
import competition.utils.validations
import django.core.files.storage
import django.core.validators
from django.db import migrations, models
Expand Down Expand Up @@ -194,7 +195,7 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('solution', 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')),
('corrected_solution', 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')),
('score', models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='body')),
('score', models.PositiveSmallIntegerField(blank=True, null=True, validators=[competition.utils.validations.validate_points], verbose_name='body')),
('vote', models.IntegerField(choices=[(-1, 'negatívny'), (0, 'žiaden'), (1, 'pozitívny')], default=0)),
('uploaded_at', models.DateTimeField(auto_now_add=True, verbose_name='dátum pridania')),
('is_online', models.BooleanField(default=False, verbose_name='internetové riešenie')),
Expand Down Expand Up @@ -231,8 +232,8 @@ class Migration(migrations.Migration):
('best_solution', models.ManyToManyField(to='competition.solution', verbose_name='najkrajšie riešenia')),
],
options={
'verbose_name': 'opravenie úlohy',
'verbose_name_plural': 'opravene ulohy',
'verbose_name': 'Opravenie úlohy',
'verbose_name_plural': 'Opravené úlohy',
},
),
]
Loading

0 comments on commit bf37733

Please sign in to comment.