From 180c6dc1915e8504d77a4d140fa869726c9c18ad Mon Sep 17 00:00:00 2001 From: kovacspe Date: Fri, 17 May 2024 22:07:16 +0200 Subject: [PATCH] Remove problem database (#373) --- problem_database/__init__.py | 0 problem_database/admin.py | 11 -- problem_database/apps.py | 5 - problem_database/migrations/__init__.py | 0 problem_database/models.py | 139 --------------- problem_database/serializers.py | 65 ------- problem_database/tests.py | 214 ------------------------ problem_database/urls.py | 22 --- problem_database/views.py | 87 ---------- webstrom/settings.py | 3 +- webstrom/urls.py | 1 - 11 files changed, 1 insertion(+), 546 deletions(-) delete mode 100644 problem_database/__init__.py delete mode 100644 problem_database/admin.py delete mode 100644 problem_database/apps.py delete mode 100644 problem_database/migrations/__init__.py delete mode 100644 problem_database/models.py delete mode 100644 problem_database/serializers.py delete mode 100644 problem_database/tests.py delete mode 100644 problem_database/urls.py delete mode 100644 problem_database/views.py diff --git a/problem_database/__init__.py b/problem_database/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/problem_database/admin.py b/problem_database/admin.py deleted file mode 100644 index 35cbcb85..00000000 --- a/problem_database/admin.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.contrib import admin - -from problem_database import models - - -@admin.register(models.ActivityType) -class ActivityTypeAdmin(admin.ModelAdmin): - list_display = ( - 'name', - 'seminar' - ) diff --git a/problem_database/apps.py b/problem_database/apps.py deleted file mode 100644 index b8426de6..00000000 --- a/problem_database/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class ProblemDatabaseConfig(AppConfig): - name = 'problem_database' diff --git a/problem_database/migrations/__init__.py b/problem_database/migrations/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/problem_database/models.py b/problem_database/models.py deleted file mode 100644 index 390ce37b..00000000 --- a/problem_database/models.py +++ /dev/null @@ -1,139 +0,0 @@ -from django.db import models - -# Create your models here. - - -class Seminar(models.Model): - class Meta: - verbose_name = 'seminár' - verbose_name_plural = 'semináre' - - name = models.CharField(max_length=32, verbose_name='názov seminára') - - def __str__(self): - return self.name - - -class ActivityType(models.Model): - class Meta: - verbose_name = 'typ aktivity' - verbose_name_plural = 'typy aktivít' - - name = models.CharField(verbose_name='názov', max_length=64) - seminar = models.ForeignKey( - Seminar, default=1, on_delete=models.CASCADE, verbose_name='seminár') - - def __str__(self): - return self.name - - -class Activity(models.Model): - class Meta: - verbose_name = 'aktivita' - verbose_name_plural = 'aktivity' - - # dátum je vo formáte YYYY-MM-DD - date = models.DateField(verbose_name='dátum') - activity_type = models.ForeignKey( - ActivityType, default=1, on_delete=models.CASCADE, verbose_name='typ aktivity') - description = models.TextField(verbose_name='popis') - soft_deleted = models.BooleanField(default=False) - - def __str__(self): - return self.description - - -class Difficulty(models.Model): - class Meta: - verbose_name = 'náročnosť' - verbose_name_plural = 'náročnosti' - - name = models.CharField(verbose_name='názov', max_length=128) - activity_type = models.ForeignKey( - ActivityType, default=1, on_delete=models.CASCADE, verbose_name='typ aktivity') - - def __str__(self): - return self.name - - -class ProblemType(models.Model): - class Meta: - verbose_name = 'typ príkladu' - verbose_name_plural = 'typy príkladov' - - seminar = models.ForeignKey( - Seminar, default=1, on_delete=models.CASCADE, verbose_name='seminár') - name = models.CharField(verbose_name='názov', max_length=64) - description = models.TextField(verbose_name='popis') - - def __str__(self): - return self.name - - -class Problem(models.Model): - class Meta: - verbose_name = 'príklad' - verbose_name_plural = 'príklady' - - problem = models.TextField(verbose_name='príklad') - result = models.CharField(verbose_name='výsledok', max_length=128) - solution = models.TextField(verbose_name='riešenie') - soft_deleted = models.BooleanField(default=False) - problem_type = models.ManyToManyField(ProblemType) - - def __str__(self): - return self.problem - - -class Media(models.Model): - class Meta: - verbose_name = 'súbor' - verbose_name_plural = 'súbory' - - data = models.ImageField(verbose_name='priložené súbory') - problem = models.ForeignKey( - Problem, default=1, on_delete=models.CASCADE, verbose_name='príklad') - soft_deleted = models.BooleanField(default=False) - - def __str__(self): - return f'{self.problem} - {self.data.name}' - - -class ProblemActivity(models.Model): - class Meta: - verbose_name = 'priradenie problému k aktivite/obtiežnosti' - verbose_name_plural = 'priradenie problémov k aktivitám/obtiažnostiam' - - problem = models.ForeignKey( - Problem, default=1, on_delete=models.CASCADE, verbose_name='príklad') - activity = models.ForeignKey( - Activity, default=1, on_delete=models.CASCADE, verbose_name='aktivita') - difficulty = models.ForeignKey( - Difficulty, default=1, on_delete=models.CASCADE, verbose_name='náročnosť') - - def __str__(self): - return f'{ self.problem }, { self.activity }, { self.difficulty }' - - -class Tag(models.Model): - class Meta: - verbose_name = 'tag' - verbose_name_plural = 'tagy' - name = models.CharField(max_length=64, verbose_name='názov tagu') - - def __str__(self): - return self.name - - -class ProblemTag(models.Model): - class Meta: - verbose_name = 'priradenie príkladu k tagu' - verbose_name_plural = 'priradenia príkladov k tagom' - - problem = models.ForeignKey( - Problem, default=1, on_delete=models.CASCADE, verbose_name='príklad') - tag = models.ForeignKey( - Tag, default=1, on_delete=models.CASCADE, verbose_name='aktivita') - - def __str__(self): - return f'{ self.problem }, { self.tag }' diff --git a/problem_database/serializers.py b/problem_database/serializers.py deleted file mode 100644 index 682f3eeb..00000000 --- a/problem_database/serializers.py +++ /dev/null @@ -1,65 +0,0 @@ -from django_typomatic import ts_interface -from rest_framework import serializers - -from problem_database import models - - -@ts_interface(context='problem_database') -class SeminarSerializer(serializers.ModelSerializer): - class Meta: - model = models.Seminar - fields = '__all__' - -@ts_interface(context='problem_database') -class ActivityTypeSerializer(serializers.ModelSerializer): - class Meta: - model = models.ActivityType - fields = '__all__' - -@ts_interface(context='problem_database') -class ActivitySerializer(serializers.ModelSerializer): - class Meta: - model = models.Activity - fields = '__all__' - -@ts_interface(context='problem_database') -class DifficultySerializer(serializers.ModelSerializer): - class Meta: - model = models.Difficulty - fields = '__all__' - -@ts_interface(context='problem_database') -class ProblemSerializer(serializers.ModelSerializer): - class Meta: - model = models.Problem - fields = '__all__' - -@ts_interface(context='problem_database') -class MediaSerializer(serializers.ModelSerializer): - class Meta: - model = models.Media - fields = '__all__' - -@ts_interface(context='problem_database') -class ProblemActivitySerializer(serializers.ModelSerializer): - class Meta: - model = models.ProblemActivity - fields = '__all__' - -@ts_interface(context='problem_database') -class ProblemTypeSerializer(serializers.ModelSerializer): - class Meta: - model = models.ProblemType - fields = '__all__' - -@ts_interface(context='problem_database') -class TagSerializer(serializers.ModelSerializer): - class Meta: - model = models.Tag - fields = '__all__' - -@ts_interface(context='problem_database') -class ProblemTagSerializer(serializers.ModelSerializer): - class Meta: - model = models.ProblemTag - fields = '__all__' diff --git a/problem_database/tests.py b/problem_database/tests.py deleted file mode 100644 index c54efad2..00000000 --- a/problem_database/tests.py +++ /dev/null @@ -1,214 +0,0 @@ -from django.test import TestCase -from rest_framework import status -from rest_framework.test import APITestCase - -from problem_database import models, serializers - - -class TestSeminar(TestCase): - ''' - seminar create - ''' - - def setUp(self): - return models.Seminar.objects.create(name='Malynár') - - def test_seminar_check_title(self): - mod = self.setUp() - self.assertTrue(isinstance(mod, models.Seminar)) - self.assertEqual(str(mod), 'Malynár') - - -class SeminarViewsTest(APITestCase): - ''' - prolem_database/seminars - ''' - - def setUp(self): - self.seminars = [models.Seminar.objects.create(name="Malynár"), - models.Seminar.objects.create(name="Matik"), - models.Seminar.objects.create(name="Strom")] - - URL_PREFIX = '/problem-database/seminars' - - def test_can_browse_all_seminars(self): - response = self.client.get(self.URL_PREFIX, {}, 'json') - - self.assertEqual(status.HTTP_200_OK, response.status_code) - self.assertEqual(len(self.seminars), len(response.data)) - - for seminar in self.seminars: - self.assertIn( - serializers.SeminarSerializer(instance=seminar).data, - response.data - ) - - -class TestActivityType(TestCase): - ''' - activity type create - ''' - - def setUp(self): - seminar = models.Seminar.objects.create(name='Malynár') - return models.ActivityType.objects.create(name='Mamut', seminar=seminar) - - def test_activity_type_check_title(self): - mod = self.setUp() - self.assertTrue(isinstance(mod, models.ActivityType)) - self.assertEqual(str(mod), 'Mamut') - - -class ActivityTypeViewsTest(APITestCase): - ''' - problem_database/activity_types - ''' - - def setUp(self): - self.seminar1 = models.Seminar.objects.create(name='Malynár') - self.seminar2 = models.Seminar.objects.create(name='Matik') - self.activity_types = [ - models.ActivityType.objects.create( - name="Malynár", seminar=self.seminar1), - models.ActivityType.objects.create( - name="Mamut", seminar=self.seminar1), - models.ActivityType.objects.create( - name="Lomihlav", seminar=self.seminar2)] - - URL_PREFIX = '/problem-database/activity-types' - - def test_can_browse_all_activity_types(self): - response = self.client.get(self.URL_PREFIX, {}, 'json') - - self.assertEqual(status.HTTP_200_OK, response.status_code) - self.assertEqual(len(self.activity_types), len(response.data)) - - for activity_type in self.activity_types: - self.assertIn( - serializers.ActivityTypeSerializer( - instance=activity_type).data, - response.data - ) - - def test_filter_activity_types(self): - response = self.client.get( - f'{self.URL_PREFIX}/?seminar={self.seminar2.pk}', {}, 'json') - - self.assertEqual(status.HTTP_200_OK, response.status_code) - self.assertEqual(1, len(response.data)) - - self.assertIn( - serializers.ActivityTypeSerializer( - instance=self.activity_types[2]).data, - response.data - ) - - response = self.client.get( - f'{self.URL_PREFIX}/?seminar={self.seminar1.pk}', {}, 'json') - - self.assertEqual(status.HTTP_200_OK, response.status_code) - self.assertEqual(2, len(response.data)) - - for activity_type in self.activity_types[:2]: - self.assertIn( - serializers.ActivityTypeSerializer( - instance=activity_type).data, - response.data - ) - - -class TestActivity(TestCase): - ''' - activity create - ''' - - def setUp(self): - seminar = models.Seminar.objects.create(name='Malynár') - activity_type = models.ActivityType.objects.create( - name='Mamut', seminar=seminar) - return models.Activity.objects.create( - date='2020-06-20', - activity_type=activity_type, - description='Mamut 2020') - - def test_activity_type_check_title(self): - mod = self.setUp() - self.assertTrue(isinstance(mod, models.Activity)) - self.assertEqual(str(mod), 'Mamut 2020') - - -class TestProblemTag(TestCase): - ''' - problem tag create - ''' - - def setUp(self): - problem = models.Problem.objects.create( - problem='Lorem?', result='Ipsum') - tag = models.Tag.objects.create(name='Výroková logika') - return models.ProblemTag.objects.create(problem=problem, tag=tag) - - def test_problem_tag_check_title(self): - mod = self.setUp() - self.assertTrue(isinstance(mod, models.ProblemTag)) - self.assertEqual(str(mod), 'Lorem?, Výroková logika') - - -class ProblemTagTest(APITestCase): - ''' - problem_database/problem_tags - ''' - - def setUp(self): - problems = [ - models.Problem.objects.create( - problem='Koľko je 1+2?', result='3', solution='indukciou'), - models.Problem.objects.create( - problem='Koľko je 2+3?', result='5', solution='priamo') - ] - tags = [ - models.Tag.objects.create(name='Indukcia'), - models.Tag.objects.create(name='Aritmetika') - ] - self.problem_tags = [ - models.ProblemTag.objects.create(problem=problems[0], tag=tags[0]), - models.ProblemTag.objects.create(problem=problems[0], tag=tags[1]), - models.ProblemTag.objects.create(problem=problems[1], tag=tags[1]) - ] - - URL_PREFIX = '/problem-database/problem-tags' - - def test_can_browse_all_problem_tags(self): - response = self.client.get(self.URL_PREFIX, {}, 'json') - - self.assertEqual(status.HTTP_200_OK, response.status_code) - self.assertEqual(len(self.problem_tags), len(response.data)) - - for problem_tag in self.problem_tags: - self.assertIn( - serializers.ProblemTagSerializer(instance=problem_tag).data, - response.data - ) - - def test_filter_problem_tags(self): - response = self.client.get(self.URL_PREFIX + '/?problem=1', {}, 'json') - - self.assertEqual(status.HTTP_200_OK, response.status_code) - self.assertEqual(2, len(response.data)) - - for problem_tag in self.problem_tags[:2]: - self.assertIn( - serializers.ProblemTagSerializer(instance=problem_tag).data, - response.data - ) - - response = self.client.get(self.URL_PREFIX + '/?tag=1', {}, 'json') - - self.assertEqual(status.HTTP_200_OK, response.status_code) - self.assertEqual(1, len(response.data)) - - self.assertIn( - serializers.ProblemTagSerializer( - instance=self.problem_tags[0]).data, - response.data - ) diff --git a/problem_database/urls.py b/problem_database/urls.py deleted file mode 100644 index bd3c6c27..00000000 --- a/problem_database/urls.py +++ /dev/null @@ -1,22 +0,0 @@ -from django.urls.conf import include, path -from rest_framework.routers import DefaultRouter - -from problem_database import views - -router = DefaultRouter() -router.register(r'seminars', views.SeminarViewSet) -router.register(r'activity-types', views.ActivityTypeViewSet) -router.register(r'activities', views.ActivityViewSet) -router.register(r'difficulty', views.DifficultyViewSet) -router.register(r'problems', views.ProblemViewSet) -router.register(r'media', views.ProblemViewSet) -router.register(r'problem-activities', views.ProblemActivityViewSet) -router.register(r'problem-types', views.ProblemTypeViewSet) -router.register(r'tags', views.TagViewSet) -router.register(r'problem-tags', views.ProblemTagViewSet) - -app_name = "problem_database" - -urlpatterns = [ - path('', include(router.urls)), -] diff --git a/problem_database/views.py b/problem_database/views.py deleted file mode 100644 index 5a12bf19..00000000 --- a/problem_database/views.py +++ /dev/null @@ -1,87 +0,0 @@ -# Create your views here. -from django_filters.rest_framework import DjangoFilterBackend -from rest_framework import status, viewsets -from rest_framework.filters import SearchFilter -from rest_framework.response import Response - -from problem_database import models, serializers - -# Filterset umoznuju pouzit URL v tvare profile/districts/?county=1 -# Search filter umoznuju pouzit URL v tvare profile/schools/?search=Alej - - -class SeminarViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.Seminar.objects.all() - serializer_class = serializers.SeminarSerializer - - def create(self, request, *args, **kwargs): # pylint: disable=unused-argument - many = isinstance(request.data, list) - serializer = serializers.SeminarSerializer( - data=request.data, many=many) - if serializer.is_valid(): - serializer.save() - return Response(serializer.data, status=status.HTTP_201_CREATED) - - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - -class ActivityTypeViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.ActivityType.objects.all() - serializer_class = serializers.ActivityTypeSerializer - filterset_fields = ['seminar', ] - - -class ActivityViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.Activity.objects.all() - serializer_class = serializers.ActivitySerializer - filterset_fields = ['activity_type', ] - - -class DifficultyViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.Difficulty.objects.all() - serializer_class = serializers.DifficultySerializer - - -class ProblemTypeViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.ProblemType.objects.all() - serializer_class = serializers.ProblemTypeSerializer - - -class ProblemViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.Problem.objects.all() - serializer_class = serializers.ProblemSerializer - filterset_fields = ['problem_type', ] - filter_backends = [DjangoFilterBackend, SearchFilter] - search_fields = ['problem'] - - def create(self, request, *args, **kwargs): # pylint: disable=unused-argument - many = isinstance(request.data, list) - serializer = serializers.ProblemSerializer( - data=request.data, many=many) - if serializer.is_valid(): - serializer.save() - return Response(serializer.data, status=status.HTTP_201_CREATED) - - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - -class MediaViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.Media.objects.all() - serializer_class = serializers.MediaSerializer - filterset_fields = ['problem', ] - - -class ProblemActivityViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.ProblemActivity.objects.all() - serializer_class = serializers.ProblemActivitySerializer - - -class TagViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.Tag.objects.all() - serializer_class = serializers.TagSerializer - - -class ProblemTagViewSet(viewsets.ReadOnlyModelViewSet): - queryset = models.ProblemTag.objects.all() - serializer_class = serializers.ProblemTagSerializer - filterset_fields = ['problem', 'tag'] diff --git a/webstrom/settings.py b/webstrom/settings.py index 35144f0b..62684328 100644 --- a/webstrom/settings.py +++ b/webstrom/settings.py @@ -45,8 +45,7 @@ 'competition', 'cms', 'user', - 'personal', - 'problem_database' + 'personal' ] INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS diff --git a/webstrom/urls.py b/webstrom/urls.py index 6b18d490..ed425585 100644 --- a/webstrom/urls.py +++ b/webstrom/urls.py @@ -12,7 +12,6 @@ path('base/', include('base.urls')), # Dočasná cesta pre allauth bez rest frameworku path('accounts/', include('allauth.urls')), - path('problem-database/', include('problem_database.urls')) ] # Pri vývoji servuj media files priamo z djanga