thumbnail and overview
This commit is contained in:
@@ -15,7 +15,13 @@
|
||||
<li data-question_pk={{question.pk}}>
|
||||
<span class="flex-col">
|
||||
<a href="{% url 'anatomy:exam_question_detail' pk=exam.pk sk=forloop.counter0 %}">
|
||||
<img src="{{ question.image|thumbnail_url:'exam-list' }}" alt="thumbail" />
|
||||
|
||||
{% if question.image %}
|
||||
<img src="{{ question.image|thumbnail_url:'exam-list' }}" alt="thumbail" />
|
||||
{% else %}
|
||||
No image added.
|
||||
{% endif %}
|
||||
|
||||
</a>
|
||||
</span>
|
||||
<span class="flex-col-4">
|
||||
|
||||
@@ -231,6 +231,29 @@ class QuestionBase(models.Model, AuthorMixin, QuestionMixin):
|
||||
|
||||
return False
|
||||
|
||||
def get_thumbnail(self, recreate=False, fail_loudly=False):
|
||||
images = self.images.all()
|
||||
|
||||
if len(images) < 1:
|
||||
return "No images", 0
|
||||
|
||||
img = findMiddle(images).image
|
||||
try:
|
||||
thumbnailer = get_thumbnailer(img)
|
||||
if recreate:
|
||||
thumbnailer.delete_thumbnails()
|
||||
thumbnail = thumbnailer["exam-list"]
|
||||
|
||||
except InvalidImageFormatError as e:
|
||||
if fail_loudly:
|
||||
raise e
|
||||
return format_html(
|
||||
'<img title="{}" src="/static/not-found-image.jpg" />', img
|
||||
), len(images)
|
||||
return format_html('<span style="border: 1px solid;"><img src="/media/{}" /></span>', thumbnail), len(images)
|
||||
|
||||
|
||||
|
||||
|
||||
class SeriesImageBase(models.Model):
|
||||
"""
|
||||
|
||||
@@ -265,6 +265,8 @@ def generic_view_urls(generic_views: GenericViewBase):
|
||||
path(
|
||||
"question/<int:pk>/", generic_views.question_detail, name="question_detail"
|
||||
),
|
||||
path("question/<int:pk>/thumbnail/fail", generic_views.question_thumbnail_fail, name="series_thumbnail_fail"),
|
||||
path("question/<int:pk>/thumbnail", generic_views.question_thumbnail, name="series_thumbnail"),
|
||||
path(
|
||||
"question/<int:pk>/user_answers",
|
||||
generic_views.question_user_answers,
|
||||
|
||||
@@ -2639,6 +2639,18 @@ class GenericViewBase:
|
||||
self.cid_user_answer_object.objects.get(pk=id).delete()
|
||||
return JsonResponse({"status": "success"})
|
||||
|
||||
@method_decorator(login_required)
|
||||
def question_thumbnail_fail(self, request, pk):
|
||||
return self.question_thumbnail(request, pk=pk, fail_loudly=True)
|
||||
|
||||
@method_decorator(login_required)
|
||||
def question_thumbnail(self, request, pk, fail_loudly=False):
|
||||
question = get_object_or_404(self.question_object, pk=pk)
|
||||
|
||||
thumbnail, _ = question.get_thumbnail(recreate=True, fail_loudly=fail_loudly)
|
||||
|
||||
return HttpResponse(thumbnail)
|
||||
|
||||
@method_decorator(login_required)
|
||||
def question_detail(self, request, pk):
|
||||
question: QuestionBase = get_object_or_404(self.question_object, pk=pk)
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
<a href="{% url 'rapids:exam_question_detail' pk=exam.pk sk=forloop.counter0 %}">
|
||||
{% for image in question.get_images %}
|
||||
<img src="{{ image|thumbnail_url:'exam-list' }}" alt="thumbail" />
|
||||
{% empty %}
|
||||
No image added.
|
||||
{% endfor %}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
@@ -22,18 +22,21 @@
|
||||
<a href="{% url 'shorts:exam_question_detail' pk=exam.pk sk=forloop.counter0 %}">
|
||||
{% for image in question.get_images %}
|
||||
<img src="{{ image|thumbnail_url:'exam-list' }}" alt="thumbail" />
|
||||
{% empty %}
|
||||
No image added.
|
||||
{% endfor %}
|
||||
</a>
|
||||
</span>
|
||||
<span class="flex-col-4">
|
||||
|
||||
<span title="Best sample answer">
|
||||
{% if question.get_best_sample_answer %}
|
||||
{{ question.get_best_sample_answer }}
|
||||
{{ question.get_best_sample_answer }} (Score: {{question.get_best_sample_answer.score}})
|
||||
|
||||
{% else %}
|
||||
No sample answer available.
|
||||
No sample answer available. <a href='{% url "shorts:question_sample_answers" question.pk %}'>Add one now?</a>
|
||||
|
||||
{% endif %}
|
||||
</span>
|
||||
|
||||
<br />
|
||||
Examination: {{ question.get_examinations }},
|
||||
|
||||
@@ -117,8 +117,6 @@ def question_split(request, pk):
|
||||
|
||||
images = question.images.all()
|
||||
|
||||
old_abnormality = question.abnormality.all()
|
||||
old_region = question.region.all()
|
||||
old_examination = question.examination.all()
|
||||
# old_site = rapid.site.all()
|
||||
old_author = question.author.all()
|
||||
@@ -131,8 +129,6 @@ def question_split(request, pk):
|
||||
|
||||
question.save()
|
||||
|
||||
question.abnormality.set(old_abnormality)
|
||||
question.region.set(old_region)
|
||||
question.examination.set(old_examination)
|
||||
# question.site.set(old_site)
|
||||
question.author.set(old_author)
|
||||
@@ -197,8 +193,6 @@ class QuestionCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
# @login_required
|
||||
class QuestionCreate(QuestionCreateBase):
|
||||
|
||||
# initial = {"laterality": Question.NONE}
|
||||
|
||||
def get_initial(self):
|
||||
if "pk" in self.kwargs:
|
||||
initial = super().get_initial()
|
||||
|
||||
Reference in New Issue
Block a user