added is_pushed and some "styling"
This commit is contained in:
@@ -28,8 +28,9 @@ class LabelAdmin(PermissionsAdminMixin, admin.ModelAdmin):
|
|||||||
@admin.register(Question)
|
@admin.register(Question)
|
||||||
class QuestionAdmin(PermissionsAdminMixin, admin.ModelAdmin):
|
class QuestionAdmin(PermissionsAdminMixin, admin.ModelAdmin):
|
||||||
autocomplete_fields = ('medias', 'links', 'labels', 'shares')
|
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',)
|
search_fields = ('name', 'question', 'awnser', 'description', 'label__name', 'level__value', 'level__name',)
|
||||||
|
list_editable = ('is_published',)
|
||||||
|
|
||||||
def list_labels(self, instance):
|
def list_labels(self, instance):
|
||||||
if instance.labels:
|
if instance.labels:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from django.utils.safestring import mark_safe
|
|||||||
from filer.fields.file import FilerFileField
|
from filer.fields.file import FilerFileField
|
||||||
|
|
||||||
from lib.core.db.models.base import SharedPermissionBase
|
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):
|
class MediaFile(NameAware, DateAware, AuthorAware, DescriptionAware):
|
||||||
@@ -62,7 +62,7 @@ class SharedQuestion(SharedPermissionBase):
|
|||||||
abstract = False
|
abstract = False
|
||||||
|
|
||||||
|
|
||||||
class Question(DateAware, AuthorAware, DescriptionAware):
|
class Question(DateAware, AuthorAware, PublishedAware, DescriptionAware):
|
||||||
name = models.CharField(max_length=500, unique=True, db_index=True)
|
name = models.CharField(max_length=500, unique=True, db_index=True)
|
||||||
question = models.TextField(db_index=True)
|
question = models.TextField(db_index=True)
|
||||||
buzzword = models.CharField(max_length=25, null=True, blank=True)
|
buzzword = models.CharField(max_length=25, null=True, blank=True)
|
||||||
@@ -90,8 +90,10 @@ class Question(DateAware, AuthorAware, DescriptionAware):
|
|||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_by_tearchterm(term):
|
def get_by_tearchterm(term, queryset=None):
|
||||||
return Question.objects.filter(Question.searchdomain(term)).annotate(cnt=models.Count('id'))
|
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):
|
def to_view(self, for_players: bool = False):
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<form action="/questions" method="get" id="search_q_form">
|
<form action="/questions" method="get" id="search_q_form">
|
||||||
<div id="question-search-field" class="row mb-5 mt-5">
|
<div id="question-search-field" class="row mb-5 mt-5">
|
||||||
<div class="col-12">
|
<div class="col-12 p-0">
|
||||||
<div class="form-group">
|
<div class="form-group border rounded p-3 bg-secondary">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
{% csrf_token %}
|
{# {% csrf_token %} #}
|
||||||
<input type="text" name="term" class="form-control p-2 bg-light" placeholder="Search for ..." value="{{ request.GET.term }}" />
|
<input type="text" name="term" class="form-control p-2 bg-light" placeholder="Search for ..." value="{{ request.GET.term }}" />
|
||||||
<span class="input-group-text">
|
<span class="input-group-text">
|
||||||
<i class="fa fa-search" onclick="document.getElementById('search_q_form').submit();"></i>
|
<i class="fa fa-search" onclick="document.getElementById('search_q_form').submit();"></i>
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ from content.views import public
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('questions/', public.search_question, name='search-questions'),
|
path('questions/', public.search_question, name='search-questions'),
|
||||||
|
path('', public.search_question, name='search-questions'),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ from content.models import Question
|
|||||||
def search_question(request):
|
def search_question(request):
|
||||||
term = request.GET.get('term')
|
term = request.GET.get('term')
|
||||||
items = []
|
items = []
|
||||||
|
published = Question.objects.filter(is_published=True)
|
||||||
if term:
|
if term:
|
||||||
items = Question.get_by_tearchterm(term)
|
items = Question.get_by_tearchterm(term, published)
|
||||||
else:
|
else:
|
||||||
items = Question.objects.all()[:10]
|
items = published.all()[:10]
|
||||||
return render(request, 'questions.html', {'items': items})
|
return render(request, 'questions.html', {'items': items})
|
||||||
|
|||||||
@@ -32,4 +32,10 @@ class NameAware(models.Model):
|
|||||||
|
|
||||||
name = models.CharField(max_length=100, unique=True, db_index=True)
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ from django.template.loader import render_to_string
|
|||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
from content.models import Question as QuestionContent
|
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 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)
|
name = models.CharField(max_length=250)
|
||||||
|
|
||||||
# author = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, default=get_current_user)
|
# author = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, default=get_current_user)
|
||||||
|
|
||||||
# created_at = models.DateTimeField(auto_now_add=True)
|
# created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user