From c621e316cfc907a683bb8bdc5a70931b654b5724 Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 11 Dec 2021 22:29:41 +0000 Subject: [PATCH] . --- generic/filters.py | 23 ++++----- generic/models.py | 1 + generic/tables.py | 53 +++++++++----------- generic/templates/generic/question_view.html | 21 ++++++++ generic/urls.py | 2 +- generic/views.py | 17 ++++++- 6 files changed, 72 insertions(+), 45 deletions(-) create mode 100644 generic/templates/generic/question_view.html diff --git a/generic/filters.py b/generic/filters.py index 251ab129..3c7f321e 100644 --- a/generic/filters.py +++ b/generic/filters.py @@ -3,17 +3,12 @@ import django_filters from django.contrib.auth.models import User -#class UserAnswerFilter(django_filters.FilterSet): -# class Meta: -# #model = AnatomyQuestion -# abstract = True -# fields = ( -# "cid", -# "question", -# "answer", -# #"answer_compare", -# "exam", -# "created", -# "updateded", -# "created_date", -# ) \ No newline at end of file +from generic.models import CidUser + +class CidUserFilter(django_filters.FilterSet): + class Meta: + model = CidUser + fields = ( + "cid", + "active", + ) \ No newline at end of file diff --git a/generic/models.py b/generic/models.py index 22afb54c..8e589d26 100644 --- a/generic/models.py +++ b/generic/models.py @@ -190,6 +190,7 @@ class QuestionNote(models.Model): class CidUser(models.Model): cid = models.IntegerField(blank=True, null=True) passcode = models.CharField(blank=True, max_length=50) + active = models.BinaryField(default=True) def __str__(self) -> str: return str(self.cid) diff --git a/generic/tables.py b/generic/tables.py index e87ae678..77f8acf4 100644 --- a/generic/tables.py +++ b/generic/tables.py @@ -7,6 +7,8 @@ from easy_thumbnails.files import get_thumbnailer from easy_thumbnails.exceptions import InvalidImageFormatError +from generic.models import CidUser + class ImageColumn(tables.Column): def render(self, value): @@ -17,31 +19,26 @@ class ImageColumn(tables.Column): return format_html('Invalid image url', value) -#class UserAnswerTable(tables.Table): -# #edit = tables.LinkColumn( -# # "anatomy:anatomy_question_update", text="Edit", args=[A("pk")], orderable=False -# #) -# #view = tables.LinkColumn( -# # "anatomy:question_detail", text="View", args=[A("pk")], orderable=False -# #) -# #image = ImageColumn("image", orderable=False) -# # clone = tables.LinkColumn('anatomy:anatomy_question_clone', -# # text='Clone', -# # args=[A('pk')], -# # orderable=False) -# #exams = tables.ManyToManyColumn(verbose_name="Exams") -# -# class Meta: -# #model = AnatomyQuestion -# abstract = True -# template_name = "django_tables2/bootstrap4.html" -# fields = ( -# "cid", -# "question", -# "answer", -# #"answer_compare", -# "exam", -# "created", -# "updated", -# ) -# #sequence = ("view") \ No newline at end of file +class CidUserTable(tables.Table): + #edit = tables.LinkColumn( + # "anatomy:anatomy_question_update", text="Edit", args=[A("pk")], orderable=False + #) + #view = tables.LinkColumn( + # "anatomy:question_detail", text="View", args=[A("pk")], orderable=False + #) + #image = ImageColumn("image", orderable=False) + # clone = tables.LinkColumn('anatomy:anatomy_question_clone', + # text='Clone', + # args=[A('pk')], + # orderable=False) + physics_exams = tables.ManyToManyColumn(verbose_name="Physics Exams") + + class Meta: + model = CidUser + template_name = "django_tables2/bootstrap4.html" + fields = ( + "cid", + "passcode", + "active", + ) + #sequence = ("view") \ No newline at end of file diff --git a/generic/templates/generic/question_view.html b/generic/templates/generic/question_view.html new file mode 100644 index 00000000..78c5773f --- /dev/null +++ b/generic/templates/generic/question_view.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} + +{% load render_table from django_tables2 %} +{% block css %} +{% endblock %} + +{% block content %} + +
+

Filter CID Users

+
+ {{ filter.form }} + +
+
+{% render_table table %} + +{% endblock %} + +{% block js %} +{% endblock %} \ No newline at end of file diff --git a/generic/urls.py b/generic/urls.py index ea6baf43..c9749411 100755 --- a/generic/urls.py +++ b/generic/urls.py @@ -26,5 +26,5 @@ urlpatterns = [ ), name="examination-autocomplete", ), - path("cids/manage/", views.create_examination, name="create_examination"), + path("cids/manage/", views.CidUserView.as_view(), name="manage_cids"), ] diff --git a/generic/views.py b/generic/views.py index 6f3dbe99..e184a21b 100644 --- a/generic/views.py +++ b/generic/views.py @@ -23,12 +23,17 @@ import json import urllib from django.views import View +from django_filters.views import FilterView +from django_tables2.views import SingleTableMixin +from generic.filters import CidUserFilter + +from generic.tables import CidUserTable from .forms import ( ExaminationForm, ) -from .models import Examination, QuestionNote +from .models import CidUser, Examination, QuestionNote from rapids.models import Rapid as RapidQuestion from rapids.models import Exam as RapidExam @@ -830,4 +835,12 @@ class ExaminationAutocomplete(autocomplete.Select2QuerySetView): except FieldError: return Examination.objects.none() - return qs \ No newline at end of file + return qs + + +class CidUserView(LoginRequiredMixin, SingleTableMixin, FilterView): + model = CidUser + table_class = CidUserTable + template_name = "generic/question_view.html" + + filterset_class = CidUserFilter \ No newline at end of file