From e7b2dff23329e881091b7b40406f15eca2458acf Mon Sep 17 00:00:00 2001 From: Holger Sielaff Date: Sat, 13 Jul 2024 10:19:49 +0200 Subject: [PATCH] added is_pushed and some "styling" --- content/admin.py | 3 ++- content/models.py | 10 ++++++---- content/templates/questions.html | 6 +++--- content/urls.py | 1 + content/views/public.py | 5 +++-- lib/core/db/models/mixins.py | 6 ++++++ quiz/models.py | 6 +++--- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/content/admin.py b/content/admin.py index d42e702..1d459b6 100644 --- a/content/admin.py +++ b/content/admin.py @@ -28,8 +28,9 @@ class LabelAdmin(PermissionsAdminMixin, admin.ModelAdmin): @admin.register(Question) class QuestionAdmin(PermissionsAdminMixin, admin.ModelAdmin): autocomplete_fields = ('medias', 'links', 'labels', 'shares') - list_display = ('name', 'list_labels', 'list_level', 'author') + list_display = ('name', 'list_labels', 'list_level', 'author', 'is_published') search_fields = ('name', 'question', 'awnser', 'description', 'label__name', 'level__value', 'level__name',) + list_editable = ('is_published',) def list_labels(self, instance): if instance.labels: diff --git a/content/models.py b/content/models.py index a04b8e7..1edad1d 100644 --- a/content/models.py +++ b/content/models.py @@ -11,7 +11,7 @@ from django.utils.safestring import mark_safe from filer.fields.file import FilerFileField from lib.core.db.models.base import SharedPermissionBase -from lib.core.db.models.mixins import DateAware, AuthorAware, DescriptionAware, NameAware +from lib.core.db.models.mixins import DateAware, AuthorAware, DescriptionAware, NameAware, PublishedAware class MediaFile(NameAware, DateAware, AuthorAware, DescriptionAware): @@ -62,7 +62,7 @@ class SharedQuestion(SharedPermissionBase): abstract = False -class Question(DateAware, AuthorAware, DescriptionAware): +class Question(DateAware, AuthorAware, PublishedAware, DescriptionAware): name = models.CharField(max_length=500, unique=True, db_index=True) question = models.TextField(db_index=True) buzzword = models.CharField(max_length=25, null=True, blank=True) @@ -90,8 +90,10 @@ class Question(DateAware, AuthorAware, DescriptionAware): @staticmethod - def get_by_tearchterm(term): - return Question.objects.filter(Question.searchdomain(term)).annotate(cnt=models.Count('id')) + def get_by_tearchterm(term, queryset=None): + if not queryset: + queryset = Question.objects + return queryset.filter(Question.searchdomain(term)).annotate(cnt=models.Count('id')) def to_view(self, for_players: bool = False): diff --git a/content/templates/questions.html b/content/templates/questions.html index d7ab33e..752325a 100644 --- a/content/templates/questions.html +++ b/content/templates/questions.html @@ -2,10 +2,10 @@ {% block content %}
-
-
+
+
- {% csrf_token %} + {# {% csrf_token %} #} diff --git a/content/urls.py b/content/urls.py index 271c169..afa13d5 100644 --- a/content/urls.py +++ b/content/urls.py @@ -3,4 +3,5 @@ from content.views import public urlpatterns = [ path('questions/', public.search_question, name='search-questions'), + path('', public.search_question, name='search-questions'), ] diff --git a/content/views/public.py b/content/views/public.py index 9bcebc3..18bfe29 100644 --- a/content/views/public.py +++ b/content/views/public.py @@ -6,8 +6,9 @@ from content.models import Question def search_question(request): term = request.GET.get('term') items = [] + published = Question.objects.filter(is_published=True) if term: - items = Question.get_by_tearchterm(term) + items = Question.get_by_tearchterm(term, published) else: - items = Question.objects.all()[:10] + items = published.all()[:10] return render(request, 'questions.html', {'items': items}) diff --git a/lib/core/db/models/mixins.py b/lib/core/db/models/mixins.py index 29fcacc..752e6b3 100644 --- a/lib/core/db/models/mixins.py +++ b/lib/core/db/models/mixins.py @@ -32,4 +32,10 @@ class NameAware(models.Model): name = models.CharField(max_length=100, unique=True, db_index=True) +class PublishedAware(models.Model): + class Meta: + abstract= True + + is_published = models.BooleanField(default=False, blank=True) + diff --git a/quiz/models.py b/quiz/models.py index 70ce8d4..4b39135 100644 --- a/quiz/models.py +++ b/quiz/models.py @@ -11,13 +11,13 @@ from django.template.loader import render_to_string from django.utils.safestring import mark_safe from content.models import Question as QuestionContent -from lib import get_current_user +from lib.core.db.models.mixins import AuthorAware, DateAware, PublishedAware from tablequizwiki.settings import BASE_DIR -from lib.core.db.models.mixins import AuthorAware, DateAware -class Quiz(AuthorAware, DateAware): +class Quiz(AuthorAware, DateAware, PublishedAware): name = models.CharField(max_length=250) + # author = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, default=get_current_user) # created_at = models.DateTimeField(auto_now_add=True)